Browse Source

Issue #545: Test automation script for infiniband validations

Signed-off-by: Bhagyashree-shetty <Bhagyashree_Shetty@dellteam.com>
Bhagyashree-shetty 3 years ago
parent
commit
8cf062580d

+ 2 - 1
.all-contributorsrc

@@ -124,7 +124,8 @@
       "profile": "https://github.com/abhishek-s-a",
       "contributions": [
         "code",
-        "doc"
+        "doc",
+        "test"
       ]
     },
     {

File diff suppressed because it is too large
+ 1 - 1
README.md


+ 2 - 0
control_plane/test/test_ib_inventory

@@ -0,0 +1,2 @@
+[infiniband]
+1.2.3.4

+ 101 - 0
control_plane/test/test_ib_mtu.yml

@@ -0,0 +1,101 @@
+#  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 MTU of mgmt5
+  hosts: infiniband
+  gather_facts: no
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+  tasks:
+    - name: Set credentials and variables
+      set_fact:
+        username: "{{ username }}"
+        password: "{{ password }}"
+        filtered_dict: {}
+      no_log: true
+      tags: reboot,mtu
+
+    - name: Authenticate
+      block:
+        - name: Authenticate to switch- "{{ inventory_hostname }}"
+          uri:
+            url: http://{{ inventory_hostname }}/admin/launch?script=rh&template=login&action=login
+            method: POST
+            body_format: form-urlencoded
+            body:
+              f_user_id: "{{ username }}"
+              f_password: "{{ password }}"
+              enter: Sign in
+            status_code: 302
+          register: login
+          no_log: true
+ 
+        - name: Verify authentication status
+          fail:
+            msg: "Authentication failed"
+          when: login.set_cookie is undefined
+      rescue:
+        - name: Filtered response creation
+          set_fact:
+            filtered_dict: "{{filtered_dict |combine({item.key: item.value})}}"
+          when: item.key not in 'invocation'
+          with_dict: "{{ login }}"
+          no_log: true
+
+        - name: Authentication failure response
+          fail: 
+            msg: "{{ filtered_dict }}"
+      tags: reboot,mtu
+
+    - name: get MTU from ib {{ validation_port }}
+      uri:
+        url: http://{{ inventory_hostname }}/admin/launch?script=json
+        method: POST
+        body_format: json
+        headers:
+          Cookie: "{{ login.set_cookie.split(';')[0] }}"
+        body:
+          {
+          "commands": 
+           [
+             "show interfaces ib {{ validation_port }}"
+           ]
+          }
+        return_content: yes
+      register: value
+      tags: mtu
+
+    - name: print reistered o/p
+      debug:
+        msg: "{{ value }}"
+      tags: mtu
+
+    - name: reboot IB switch
+      uri:
+        url: http://{{ inventory_hostname }}/admin/launch?script=json
+        method: POST
+        body_format: json
+        headers:
+          Cookie: "{{ login.set_cookie.split(';')[0] }}"
+        body:
+          {
+          "commands":
+           [
+             "reload"
+           ]
+          }
+        return_content: yes
+      tags: reboot

+ 333 - 0
control_plane/test/test_infiniband_config.yml

@@ -0,0 +1,333 @@
+#  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_IB_TC_007
+# Execute infiniband.yml with both valid Global and valid interface configs in ib_config.yml
+- name: OMNIA_1.1_IB_TC_007
+  hosts: infiniband
+  gather_facts: false
+  tags: VERIFY_OMNIA_01
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: Executing network_ib role
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+     
+     - block:
+        - name: Validate default flow
+          assert:
+            that:
+              - ib_success_msg in job_status.status
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+          changed_when: false
+   
+     - name: Backup of ib_vars.yml
+       copy:
+         src: "{{ ib_vars_dir }}"
+         dest: "{{ ib_vars_backup_dir }}"
+         mode: "{{ file_perm }}"
+
+     - name: Set MTU of port {{ port_num }}
+       lineinfile:
+        dest: "{{ ib_vars_dir }}"
+        insertbefore: "{{ search_line }}"
+        line: "{{ line_to_add }}"
+
+     - name: Execute network_ib role after setting MTU
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+
+     - name: Get MTU of port {{ port_num }}
+       command: ansible-playbook -i "{{ inventory_dir }}" "{{ ib_mtu_path }}" --tags 'mtu'
+       register: mtuvalue
+       changed_when: false
+
+     - block:
+        - name: Validate MTU
+          assert:
+            that:
+              - 'var_check in mtuvalue.stdout'
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+            
+# Testcase OMNIA_1.1_IB_TC_005
+# set save_changes_to_startup to false
+- name: OMNIA_1.1_IB_TC_005
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_005
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:        
+     - name: Reload IB switch 
+       command: ansible-playbook -i "{{ inventory_dir }}" "{{ ib_mtu_path }}" --tags 'reboot'
+       changed_when: false
+
+     - name: Pausing for IB switch to come up
+       pause:
+         minutes: "{{ time_to_pause }}"
+   
+     - name: Get MTU of port {{ port_num }}
+       command: ansible-playbook -i "{{ inventory_dir }}" "{{ ib_mtu_path }}" --tags 'mtu'
+       register: mtuvalue
+       changed_when: false
+          
+     - block:
+        - name: Validate that MTU is changed
+          assert:
+            that:
+              - 'var_check not in mtuvalue.stdout'
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+            
+# Testcase OMNIA_1.1_IB_TC_006
+# set save_changes_to_startup to True            
+- name: OMNIA_1.1_IB_TC_006
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_006
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:        
+     - name: Set save_changes_to_startup to True
+       ansible.builtin.replace:
+         dest: "{{ ib_vars_dir }}"
+         regexp: 'save_changes_to_startup: false'
+         replace: 'save_changes_to_startup: True'
+                          
+     - name: Execute network_ib role as port {{ port_num }} has mtu set in ib_Vars
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+       
+     - name: Reload IB switch 
+       command: ansible-playbook -i "{{ inventory_dir }}" "{{ ib_mtu_path }}" --tags 'reboot'
+       changed_when: false
+       
+     - name: Pausing for IB switch to come up
+       pause:
+         minutes: "{{ time_to_pause }}"
+  
+     - name: Get MTU of port {{ port_num }}
+       command: ansible-playbook -i "{{ inventory_dir }}" "{{ ib_mtu_path }}" --tags 'mtu'
+       register: mtuvalue
+       changed_when: false
+       
+     - block:
+        - name: Validate that MTU is not changed
+          assert:
+            that:
+              - 'var_check in mtuvalue.stdout'
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+       
+# Testcase OMNIA_1.1_IB_TC_010
+# Execute infiniband.yml with valid interface and incorrect Global configs in ib_config.yml
+- name: OMNIA_1.1_IB_TC_010
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_010
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml    
+  tasks:
+     - name: Making gobal config incorrect
+       lineinfile:
+        dest: "{{ ib_vars_dir }}"
+        insertafter: 'mellanox_switch_config:'
+        line: "gibberish inserted"
+        
+     - name: Executing network_ib role
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+
+     - block:
+        - name: Validate role exec output
+          assert:
+            that:
+              - ib_fail_msg in job_status.status
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+      
+# Testcase OMNIA_1.1_IB_TC_009
+# Execute infiniband.yml with only interface and no Global configs in ib_config.yml
+- name: OMNIA_1.1_IB_TC_009
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_009
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: Removing global config from ib_vars.yml
+       lineinfile:
+        dest: "{{ ib_vars_dir }}"
+        state: absent
+        regexp: "^gibberish inserted"
+        
+     - name: Executing network_ib role
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+
+     - name: Validate role exec output
+       assert:
+         that:
+           - ib_success_msg in job_status.status
+         success_msg: "{{ success_message }}"
+         fail_msg: "{{ fail_case }}"
+       changed_when: false
+       
+# Testcase OMNIA_1.1_IB_TC_011
+# Execute infiniband.yml with valid Global and incorrect interface configs in ib_config.yml
+- name: OMNIA_1.1_IB_TC_011
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_011
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: Make interface config incorrect
+       lineinfile:
+        dest: "{{ ib_vars_dir }}"
+        insertafter: "{{ line_to_search }}"
+        line: "gibberish inserted"
+        
+     - name: Executing network_ib role
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+ 
+     - name: Validate role exec output
+       assert:
+         that:
+           - ib_fail_msg in job_status.status
+         success_msg: "{{ success_message }}"
+         fail_msg: "{{ fail_case }}"
+      
+# Testcase OMNIA_1.1_IB_TC_008
+# Execute infiniband.yml with only Global and no interface configs in ib_config.yml
+- name: OMNIA_1.1_IB_TC_008
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_008
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml    
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: Removing interface config
+       ansible.builtin.command: sed -i '49,196d' "{{ ib_vars_dir }}"
+       args:
+        warn: no
+       changed_when: false
+     
+     - name: Executing network_ib role
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+
+     - name: Validate role exec output
+       assert:
+         that:
+           - ib_success_msg in job_status.status
+         success_msg: "{{ success_message }}"
+         fail_msg: "{{ fail_case }}"
+       changed_when: false
+
+     - name: Restore orginal ib_vars file
+       copy:
+         src: "{{ ib_vars_backup_dir }}"
+         dest: "{{ ib_vars_dir }}"
+         mode: "{{ file_perm }}"
+         
+     - name: Set save_changes_to_startup to True
+       ansible.builtin.replace:
+         dest: "{{ ib_vars_dir }}"
+         regexp: 'save_changes_to_startup: false'
+         replace: 'save_changes_to_startup: True'
+                          
+     - name: Execute network_ib role to set default IB config as is
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ template_value }}"
+        job_template_name: "{{ job_name }}"
+        playbook_path: "{{ ib_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+       
+     - name: Set save_changes_to_startup back to false
+       ansible.builtin.replace:
+         dest: "{{ ib_vars_dir }}"
+         regexp: 'save_changes_to_startup: True'
+         replace: 'save_changes_to_startup: false'

+ 156 - 0
control_plane/test/test_infiniband_facts.yml

@@ -0,0 +1,156 @@
+#  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_IB_TC_002
+# Execute ib_facts.yml with valid IP and valid credentials
+- name: OMNIA_1.1_IB_TC_002
+  hosts: infiniband
+  gather_facts: false
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml
+    - ../input_params/base_vars.yml
+  tasks: 
+     - name: Execute ib_facts
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ fact_template_value }}"
+        job_template_name: "{{ fact_job_name }}"
+        playbook_path: "{{ ib_facts_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+       
+     - block:
+        - name: Validate default flow with valid IP and valid credentials
+          assert:
+            that:
+              - ib_success_msg in job_status.status
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+          changed_when: false
+
+# Testcase OMNIA_1.1_IB_TC_003
+# Execute ib_facts.yml with Invalid IP in inventory group
+- name: OMNIA_1.1_IB_TC_003
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_003
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: setting ip
+       set_fact:
+         ib_host_name: "{{ random_ip }}"
+    
+     - name: Execute ib_facts
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ fact_template_value }}"
+        job_template_name: "{{ fact_job_name }}"
+        playbook_path: "{{ ib_facts_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+
+     - block:
+        - name: Validate invalid IP and valid credentials
+          assert:
+            that:
+              - ib_fail_msg in job_status.status
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+          changed_when: false
+          failed_when: false
+      
+# Testcase OMNIA_1.1_IB_TC_001
+# Execute ib_facts.yml with no hosts in inventory
+- name: OMNIA_1.1_IB_TC_001
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_001
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: Execute ib_facts with no host details
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        template_name: "{{ fact_template_value }}"
+        job_template_name: "{{ fact_job_name }}"
+        playbook_path: "{{ ib_facts_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+  
+     - block:
+        - name: Validate no hosts and valid credentials
+          assert:
+            that:
+              - ib_success_msg in job_status.status
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+          changed_when: false
+
+# Testcase OMNIA_1.1_IB_TC_004
+# Execute ib_facts.yml with valid IP and incorrect credentials
+- name: OMNIA_1.1_IB_TC_004
+  hosts: infiniband
+  gather_facts: false
+  tags: TC_004
+  connection: local
+  vars_files:
+    - test_vars/test_infiniband_vars.yml
+    - ../roles/webui_awx/vars/main.yml
+    - ../input_params/base_vars.yml
+  tasks:
+     - name: Making infiniband_credentials invalid
+       tower_credential:
+         name: "infiniband_credential"
+         credential_type: "Network"
+         inputs:
+           username: "{{ invalid_username }}"
+         
+     - name: Execute ib_facts
+       vars:
+        inventory_name: "{{ ib_inventory_name }}"
+        host_name: "{{ ib_host_name }}"
+        template_name: "{{ fact_template_value }}"
+        job_template_name: "{{ fact_job_name }}"
+        playbook_path: "{{ ib_facts_playbook_path }}"
+        delete_status: true
+       include_tasks: "{{ awx_script_path }}"
+
+     - block:
+        - name: Validate valid IP and invalid credentials
+          assert:
+            that:
+              - ib_fail_msg in job_status.status
+            success_msg: "{{ success_message }}"
+            fail_msg: "{{ fail_case }}"
+          changed_when: false
+  
+     - name: Set credentials back to default
+       tower_credential:
+         name: "infiniband_credential"
+         credential_type: "Network"
+         inputs:
+           username: "{{ username }}"
+           password: "{{ password }}"

+ 56 - 0
control_plane/test/test_vars/test_infiniband_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_infiniband_config.yml
+ib_inventory_name: "infiniband_inventory"
+template_value: 'infiniband_template'
+ib_host_name: 100.96.28.140
+job_name: "test_infiniband_template"
+ib_playbook_path: "control_plane/infiniband.yml"
+success_message: "Execution Successful"
+fail_case: "Failed. please check input parameters and try again!"
+awx_script_path: "test_prepare.yml"
+ib_vars_dir: ../input_params/ib_vars.yml
+ib_vars_backup_dir: ib_vars_backup.yml
+inventory_dir: test_ib_inventory
+ib_mtu_path: test_ib_mtu.yml
+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_ib_mtu.yml
+username: admin
+password: admin
+var_check: '"MTU": "2048"'
+
+# Usage: test_infiniband_facts.yml
+fact_template_value: 'infiniband_template'
+fact_job_name: 'test_ib_fact_job'
+ib_facts_playbook_path: "control_plane/tools/ib_facts.yml"
+test_infiniband_vars_dir: "test_vars/test_infiniband_vars.yml"
+random_ip: 100.100.100.100
+invalid_username: 'invalid_username'
+
+# Usage: test_infiniband_facts.yml
+validation_port: 1/5
+port_num: 5
+search_line: "  ib 1/6:"
+line_to_add: '      - "mtu 2K"'
+time_to_pause: 2
+line_to_search: "^(.*)port 8"
+ib_success_msg: "successful"
+ib_fail_msg: "failed"