Browse Source

Merge pull request #511 from Bhagyashree-shetty/devel

Issue #510: Test automation script for ethernet
Lucas A. Wilson 3 years ago
parent
commit
8f3c44eff1

+ 47 - 0
control_plane/test/test_eth_mtu.yml

@@ -0,0 +1,47 @@
+#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+---
+- name: Get running config and reload PS
+  hosts: ethernet
+  connection: network_cli
+  gather_facts: no
+  collections:
+   - dellemc.os10
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+  tasks:
+   - name: Set facts
+     set_fact:
+       ansible_ssh_user: "{{ username }}"
+       ansible_ssh_pass: "{{ password }}"
+     tags: mtu,reload
+
+   - name: View running configurations
+     dellos10_command:
+       commands: show interface ethernet {{ validation_port }}
+     register: var1
+     tags: mtu
+
+   - name: Print config
+     debug:
+       msg: "{{ var1 }}"
+     tags: mtu
+
+   - name: Reload switch
+     dellos10_command:
+       commands: 
+          - command: 'reload'
+            prompt: '\[confirm yes/no\]:?$'
+            answer: 'yes'
+     tags: reload

+ 346 - 0
control_plane/test/test_ethernet_config.yml

@@ -0,0 +1,346 @@
+#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+---
+# Testacase OMNIA_1.1_EF_TC_007
+# Execute ethernet.yml with both valid Global and interface configs in ethernet_config.yml
+- name: OMNIA_1.1_EF_TC_007
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_007
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Back up of ethernet_config.yml
+      copy:
+        src: "{{ ethernet_config_dir }}"
+        dest: "{{ ethernet_config_backup_dir }}"
+        mode: "{{ file_perm }}"
+      tags: TC_007
+
+    - name: Executing ethernet role with default ethernet_config
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"      
+
+    - block:
+       - name: Validate default flow
+         assert:
+           that:
+             - ethernet_success_msg in job_status.status
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+
+    - name: Set MTU of port {{ port_num }}
+      lineinfile:
+       dest: "{{ ethernet_config_dir }}"
+       insertbefore: "{{ search_line }}"
+       line: "{{ add_mtu_line }}"
+    
+    - name: Executing ethernet role with default ethernet_config
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+      
+    - name: Getting MTU of ethernet {{ validation_port }}
+      command: ansible-playbook -i "{{ inventory_dir }}" "{{ get_mtu_dir }}" --tags 'mtu'
+      changed_when: false
+      register: mtu_out
+      tags: TC_007,TC_002
+       
+    - name: Validate role exec output pre and post MTU addition
+      assert:
+        that:          
+          - validate_mtu_line in mtu_out.stdout
+        success_msg: "{{ success_message }}"
+        fail_msg: "{{ fail_case }}"
+      changed_when: false
+      failed_when: false
+      tags: TC_007
+
+# Testacase OMNIA_1.1_EF_TC_005
+# Execute ethernet.yml with save_config set to False
+- name: OMNIA_1.1_EF_TC_005
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_005
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Reload switch
+      command: ansible-playbook -i "{{ inventory_dir }}" "{{ get_mtu_dir }}" --tags 'reload'
+      changed_when: false
+    
+    - name: Pausing for switch to come up
+      pause:
+        minutes: "{{ time_to_pause }}"
+        
+    - name: Getting MTU of ethernet {{ validation_port }}
+      command: ansible-playbook -i "{{ inventory_dir }}" "{{ get_mtu_dir }}" --tags 'mtu'
+      changed_when: false
+      register: mtu_out
+      
+    - block:
+       - name: Validate that MTU is changed
+         assert:
+           that:
+             - validate_mtu_line not in mtu_out.stdout
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+         failed_when: false
+                
+# Testacase OMNIA_1.1_EF_TC_006
+# Execute ethernet.yml with save_config set to True
+- name: OMNIA_1.1_EF_TC_006
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_006
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Set save_changes_to_startup to True in ethernet_vars
+      ansible.builtin.replace:
+        dest: "{{ ethernet_config_dir }}"
+        regexp: 'save_changes_to_startup: false'
+        replace: 'save_changes_to_startup: True'
+        
+    - name: Execute network_ethernet role as port 4 has mtu set in ethernet_vars
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+      
+    - name: Reload switch
+      command: ansible-playbook -i "{{ inventory_dir }}" "{{ get_mtu_dir }}" --tags 'reload'
+      changed_when: false
+    
+    - name: Pausing for switch to come up
+      pause:
+        minutes: "{{ time_to_pause }}"
+        
+    - name: Getting MTU of ethernet {{ validation_port }}
+      command: ansible-playbook -i "{{ inventory_dir }}" "{{ get_mtu_dir }}" --tags 'mtu'
+      changed_when: false
+      register: mtu_out
+    
+    - block:
+       - name: Validate that MTU is changed
+         assert:
+           that:
+             - validate_mtu_line in mtu_out.stdout
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+
+# Testcase OMNIA_1.1_EF_TC_010
+# Execute ethernet.yml with invalid Global and correct interface configs in ethernet_config.yml
+- name: OMNIA_1.1_EF_TC_010
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_010
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Making interface config invalid
+      lineinfile:
+        path: "{{ ethernet_config_dir }}"
+        insertafter: 'os10_config:'
+        line: 'gibberish inserted'
+      tags: TC_007
+
+    - name: Executing ethernet role with invalid global config
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+
+    - block:
+       - name: Validate role exec output
+         assert:
+           that:
+             - ethernet_fail_msg in job_status.status
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+
+# Testcase OMNIA_1.1_EF_TC_009
+# Validation of ethernet default configuration
+- name: OMNIA_1.1_EF_TC_009
+  hosts: ethernet
+  gather_facts: false
+  tags: VERIFY_OMNIA_01
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml    
+  tasks:
+    - name: Executing ethernet role
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}" 
+    
+    - block:
+       - name: Validate default flow
+         assert:
+           that:
+             - ethernet_success_msg in job_status.status
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+         
+# Testcase OMNIA_1.1_EF_TC_011
+# Execute ethernet.yml with valid Global  and incorrect interface configs in ethernet_config.yml 
+- name: OMNIA_1.1_EF_TC_011
+  hosts: ethernet
+  gather_facts: false
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Making interface config invalid
+      lineinfile:
+        path: "{{ ethernet_config_dir }}"
+        insertafter: 'os10_interface:'
+        line: 'gibberish inserted'
+        
+    - name: Executing ethernet role with invalid interface config
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+
+    - block:
+       - name: Validate role exec output
+         assert:
+           that:
+             - ethernet_fail_msg in job_status.status
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"      
+
+
+# Testcase OMNIA_1.1_EF_TC_008
+# Execute ethernet.yml with only Global and no interface configs in ethernet_config.yml 
+- name: OMNIA_1.1_EF_TC_008
+  hosts: ethernet
+  gather_facts: false
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Retrieving ethernet_config backup
+      copy:
+        src: "{{ ethernet_config_backup_dir }}"
+        dest: "{{ ethernet_config_dir }}"
+        mode: "{{ file_perm }}"
+      tags: TC_008
+    
+    - name: Removing interface config from ethernet_config
+      ansible.builtin.command: sed -i '22,117d' "{{ ethernet_config_dir }}"
+      args:
+       warn: no
+      changed_when: false
+      tags: TC_008
+      
+    - name: Executing ethernet role with no interface config
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+      
+    - block:
+       - name: Validate default flow
+         assert:
+           that:
+             - ethernet_success_msg in job_status.status
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+
+    - name: Restoring original ethernt_config
+      copy:
+        src: "{{ ethernet_config_backup_dir }}"
+        dest: "{{ ethernet_config_dir }}"
+        mode: "{{ file_perm }}"
+      tags: TC_008
+      
+    - name: Set save_changes_to_startup to True in ethernet_vars
+      ansible.builtin.replace:
+        dest: "{{ ethernet_config_dir }}"
+        regexp: 'save_changes_to_startup: false'
+        replace: 'save_changes_to_startup: True'
+        
+    - name: Execute network_ethernet role as port 4 has mtu set in ethernet_vars
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ eth_template_value }}"
+       job_template_name: "{{ eth_job_name }}"
+       playbook_path: "{{ eth_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+      
+    - name: Set save_changes_to_startup to False in ethernet_vars
+      ansible.builtin.replace:
+        dest: "{{ ethernet_config_dir }}"
+        regexp: 'save_changes_to_startup: True'
+        replace: 'save_changes_to_startup: False'

+ 157 - 0
control_plane/test/test_ethernet_fact.yml

@@ -0,0 +1,157 @@
+#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+---
+# Testcase OMNIA_1.1_EF_TC_002
+# Execute ethernetfacts.yml with valid IP with valid credentials in ethernet inventory group
+- name: OMNIA_1.1_EF_TC_002
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_002
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Execute ethernet_facts with valid creds and valid IP
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ fact_template_value }}"
+       job_template_name: "{{ fact_job_name }}"
+       playbook_path: "{{ eth_facts_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+      tags: TC_002
+   
+    - block:
+       - name: Validate default flow with valid IP and valid credentials
+         assert:
+           that:
+             - "'successful' in job_status.status"
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+
+# Testcase OMNIA_1.1_EF_TC_003
+# Execute ethernetfacts.yml with Invalid IP in ethernet inventory group
+- name: OMNIA_1.1_EF_TC_003
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_003
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: setting ip
+      set_fact:
+        eth_host_name: "{{ random_ip }}"
+         
+    - name: Execute ethernet_facts with random IP
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ fact_template_value }}"
+       job_template_name: "{{ fact_job_name }}"
+       playbook_path: "{{ eth_facts_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+
+    - block:
+        - name: Validate invalid IP and valid credentials
+          assert:
+            that:
+              - "'failed' in job_status.status"
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+          changed_when: false
+
+# Testcase OMNIA_1.1_EF_TC_001
+# Execute ethernetfacts.yml with no hosts in ethernet inventory group
+- name: OMNIA_1.1_EF_TC_001
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_001
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Execute ethernet_facts with no host details
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"       
+       template_name: "{{ fact_template_value }}"
+       job_template_name: "{{ fact_job_name }}"
+       playbook_path: "{{ eth_facts_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+    
+    - block:
+       - name: Validate no hosts and valid credentials
+         assert:
+           that:
+             - "'successful' in job_status.status"
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+
+# Testcase OMNIA_1.1_EF_TC_004
+# Execute ethernetfacts.yml with valid IP in ethernet inventory group with incorrect credentials
+- name: OMNIA_1.1_EF_TC_004
+  hosts: ethernet
+  gather_facts: false
+  tags: TC_004
+  connection: local
+  vars_files:
+    - test_vars/test_ethernet_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+    - name: Making ethernet_credentials invalid
+      tower_credential:
+        name: "ethernet_credential"
+        credential_type: "Machine"
+        inputs:
+          username: "{{ invalid_username }}"
+       
+    - name: Execute ethernet_facts with invalid credentials
+      vars:
+       inventory_name: "{{ eth_inventory_name }}"
+       host_name: "{{ eth_host_name }}"
+       template_name: "{{ fact_template_value }}"
+       job_template_name: "{{ fact_job_name }}"
+       playbook_path: "{{ eth_facts_playbook_path }}"
+       delete_status: true
+      include_tasks: "{{ awx_script_path }}"
+     
+    - block:
+       - name: Validate valid IP and invalid credentials
+         assert:
+           that:
+             - "'failed' in job_status.status"
+           success_msg: "{{ success_message }}"
+           fail_msg: "{{ fail_case }}"
+         changed_when: false
+         
+    - name: Set credentials back to default
+      tower_credential:
+        name: "ethernet_credential"
+        credential_type: "Machine"
+        inputs:
+          username: "{{ username }}"
+          password: "{{ password }}"

+ 5 - 0
control_plane/test/test_ethernet_inventory

@@ -0,0 +1,5 @@
+[ethernet]
+1.2.3.4
+
+[ethernet:vars]
+ansible_network_os= dellemc.os10.os10

+ 56 - 0
control_plane/test/test_vars/test_ethernet_vars.yml

@@ -0,0 +1,56 @@
+#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+---
+# Usage : test_ethernet_facts.yml
+failed_msg: "Unexpected scenario"
+success_message: "Execution successful"
+eth_inventory_name: "ethernet_inventory"
+eth_host_name: "100.96.23.241"
+fact_template_value: "ethernet_template"
+fact_job_name: "ethernet_template"
+eth_facts_playbook_path: "control_plane/tools/ethernet_facts.yml"
+awx_script_path: "test_prepare.yml"
+random_ip: 100.100.100.100
+invalid_username: "invalid_username"
+username: admin
+password: admin
+
+# Usage : test_ethernet_config.yml
+ethernet_dir: "ethernet.yml"
+ethernet_config_dir: "../input_params/ethernet_vars.yml"
+ethernet_config_backup_dir: "ethernet_config_backup.yml"
+get_mtu_dir: "test_eth_mtu.yml"
+appliance_dir: "/root/ethernet/control_plane"
+fail_case: "Expected error, please check the configurations"
+sed_condition: '/Port 4/a mtu2345'
+eth_template_value: "ethernet_template"
+eth_job_name: "ethernet_template"
+eth_playbook_path: "control_plane/ethernet.yml"
+inventory_dir: "test_ethernet_inventory"
+login_vars_path: "../input_params/login_vars.yml"
+login_vars_vault_path: "../input_params/.login_vault_key"
+tower_config_file_path: "../roles/webui_awx/files/.tower_cli.cfg"
+tower_vault_file_path: "../roles/webui_awx/files/.tower_vault_key"
+file_perm: '0644'
+
+# Usage : test_eth_mtu.yml, test_ethernet_config.yml
+validation_port: 1/1/4:1
+port_num: 4
+search_line: "    ethernet 1/1/5:"
+add_mtu_line: "      mtu: 2345"
+time_to_pause: 4
+validate_mtu_line: "MTU 2345 bytes"
+ethernet_success_msg: "successful"
+ethernet_fail_msg: "failed"