From 31830bda4ea72030ecbcb77d71351564684eeed3 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 13 Nov 2024 03:16:39 -0500 Subject: [PATCH] validation/omevv_firmware_compliance_info --- .../defaults/main.yaml | 3 + .../files/ansible_doc.txt | 190 +++++++++++++++++ .../meta/main.yaml | 3 + .../tasks/main.yaml | 23 ++ .../tests/__post_req_delete.yml | 13 ++ .../tests/__pre_req_create.yml | 18 ++ .../tests/_cluster_helper.yml | 88 ++++++++ .../tests/_hosts_helper.yml | 48 +++++ .../tests/_specific_host_helper.yml | 26 +++ .../tests/ansible_doc.yaml | 22 ++ .../tests/cluster_info.yaml | 69 ++++++ .../tests/hosts_info.yaml | 76 +++++++ .../tests/invalid.yaml | 201 ++++++++++++++++++ 13 files changed, 780 insertions(+) create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/defaults/main.yaml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/files/ansible_doc.txt create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/meta/main.yaml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tasks/main.yaml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/__post_req_delete.yml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/__pre_req_create.yml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/_cluster_helper.yml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/_hosts_helper.yml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/_specific_host_helper.yml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/ansible_doc.yaml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/cluster_info.yaml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/hosts_info.yaml create mode 100644 tests/integration/targets/omevv_firmware_compliance_info/tests/invalid.yaml diff --git a/tests/integration/targets/omevv_firmware_compliance_info/defaults/main.yaml b/tests/integration/targets/omevv_firmware_compliance_info/defaults/main.yaml new file mode 100644 index 000000000..852a6bee3 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/tests/integration/targets/omevv_firmware_compliance_info/files/ansible_doc.txt b/tests/integration/targets/omevv_firmware_compliance_info/files/ansible_doc.txt new file mode 100644 index 000000000..5fe51c9be --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/files/ansible_doc.txt @@ -0,0 +1,190 @@ +- ' This module allows to fetch the firmware compliance report of' +- ' all the hosts of the cluster, or a specific host of the' +- ' cluster, or multiple clusters.' +- '' +- 'ADDED IN: version 9.9.0 of dellemc.openmanage' +- '' +- 'OPTIONS (= is mandatory):' +- '' +- '- ca_path' +- ' The Privacy Enhanced Mail (PEM) file that contains a CA' +- ' certificate to be used for the validation.' +- ' default: null' +- ' type: path' +- '' +- '- clusters' +- ' The cluster details to retrieve the firmware compliance' +- ' report.' +- ' default: null' +- ' elements: dict' +- ' type: list' +- '' +- ' SUBOPTIONS:' +- '' +- ' = cluster_name' +- ' The cluster name of the hosts for which the firmware' +- ' compliance report needs to be fetched.' +- ' If `servicetags'' or `hosts'' is provided, then firmware' +- ' compliance report of only the specified hosts will be' +- ' fetched and shown.' +- ' type: str' +- '' +- ' - hosts' +- ' The IP address or hostname of the hosts.' +- ' The hosts for which the firmware compliance reports needs' +- ' to be fetched.' +- ' default: null' +- ' elements: str' +- ' type: list' +- '' +- ' - servicetags' +- ' The service tag of the hosts.' +- ' The hosts for which the firmware compliance reports needs' +- ' to be fetched.' +- ' default: null' +- ' elements: str' +- ' type: list' +- '' +- = hostname +- ' IP address or hostname of the OpenManage Enterprise Modular.' +- ' type: str' +- '' +- '- port' +- ' OpenManage Enterprise HTTPS port.' +- ' default: 443' +- ' type: int' +- '' +- '- timeout' +- ' The socket level timeout in seconds.' +- ' default: 30' +- ' type: int' +- '' +- '- validate_certs' +- ' Whether to check SSL certificate. - If `true'', the SSL' +- ' certificates will be validated. - If `false'', the SSL' +- ' certificates will not be validated.' +- ' default: true' +- ' type: bool' +- '' +- '- vcenter_password' +- ' Password for OpenManage Enterprise Integration for VMware' +- ' vCenter (OMEVV).' +- ' If the password is not provided, then the environment variable' +- ' `OMEVV_VCENTER_PASSWORD'' is used.' +- ' Example: export OMEVV_VCENTER_PASSWORD=password' +- ' default: null' +- ' type: str' +- '' +- '- vcenter_username' +- ' Username for OpenManage Enterprise Integration for VMware' +- ' vCenter (OMEVV).' +- ' If the username is not provided, then the environment variable' +- ' `OMEVV_VCENTER_USERNAME'' is used.' +- ' Example: export OMEVV_VCENTER_USERNAME=username' +- ' default: null' +- ' type: str' +- '' +- '- vcenter_uuid' +- ' Universally Unique Identifier (UUID) of vCenter.' +- ' vCenter UUID details can be retrieved using' +- ' [dellemc.openmanage.omevv_vcenter_info] module.' +- ' If UUID is not provided, then the environment variable' +- ' `OMEVV_VCENTER_UUID'' is used.' +- ' Example: export OMEVV_VCENTER_UUID=uuid' +- ' default: null' +- ' type: str' +- '' +- '' +- 'ATTRIBUTES:' +- '' +- ' check_mode:' +- ' description: Runs task to validate without performing action on the target + machine.' +- ' support: full' +- ' diff_mode:' +- ' description: Runs the task to report the changes that are made or the + changes that' +- ' must be applied.' +- ' support: full' +- '' +- 'NOTES:' +- ' * Run this module from a system that has direct access to' +- ' Dell OpenManage Enterprise.' +- '' +- '' +- 'REQUIREMENTS: python >= 3.9.6' +- '' +- 'AUTHOR: Abhishek Sinha(@ABHISHEK-SINHA10)' +- '' +- 'EXAMPLES:' +- '' +- '---' +- '- name: Fetch firmware compliance report of all the cluster' +- ' dellemc.openmanage.omevv_firmware_compliance_info:' +- ' hostname: "192.168.0.1"' +- ' vcenter_uuid: "xxxxx"' +- ' vcenter_username: "username"' +- ' vcenter_password: "password"' +- ' ca_path: "path/to/ca_file"' +- '' +- '- name: Fetch firmware compliance report of all the hosts in the specific cluster' +- ' dellemc.openmanage.omevv_firmware_compliance_info:' +- ' hostname: "192.168.0.1"' +- ' vcenter_uuid: "xxxxx"' +- ' vcenter_username: "username"' +- ' vcenter_password: "password"' +- ' ca_path: "path/to/ca_file"' +- ' clusters:' +- ' - cluster_name: cluster_a' +- '' +- '- name: Fetch firmware compliance report of a specific hosts in the cluster' +- ' dellemc.openmanage.omevv_firmware_compliance_info:' +- ' hostname: "192.168.0.1"' +- ' vcenter_uuid: "xxxxx"' +- ' vcenter_username: "username"' +- ' vcenter_password: "password"' +- ' ca_path: "path/to/ca_file"' +- ' clusters:' +- ' - cluster_name: cluster_a' +- ' servicetags:' +- ' - SVCTAG1' +- ' - SVCTAG2' +- ' hosts:' +- ' - host1' +- ' - xx.xx.xx.xx' +- '' +- '- name: Fetch firmware compliance report of multiple cluster' +- ' dellemc.openmanage.omevv_firmware_compliance_info:' +- ' hostname: "192.168.0.1"' +- ' vcenter_uuid: "xxxxx"' +- ' vcenter_username: "username"' +- ' vcenter_password: "password"' +- ' ca_path: "path/to/ca_file"' +- ' clusters:' +- ' - cluster_name: cluster_a' +- ' - cluster_name: cluster_b' +- '' +- '' +- 'RETURN VALUES:' +- '- firmware_compliance_info' +- ' Details of the compliance report.' +- ' elements: dict' +- ' returned: on HTTP error' +- ' sample: [{cluster: cluster_a, complianceStatus: NonCompliant, hostComplianceReports: + [{complianceStatus: WARNING,' +- ' componentCompliances: [{baselineValue: 4303A19, complianceStatus: + WARNING,' +- ' componentName: Enterprise UEFI Diagnostics, criticality: Optional, + currentValue: 4303A15,' +- ' driftStatus: NonCompliant, rebootRequired: false, sourceName: + ''DCIM:INSTALLED#802__Diagnostics.Embedded.1:LC.Embedded.1'',' +- ' updateAction: UPGRADE}], deviceModel: PowerEdge R660xs, hostAddress: + XX.XX.XX.XX,' +- ' hostId: 1002, serviceTag: SVCTAG}]}]' +- ' type: list' +- '' +- '- msg' +- ' Retrive the firmware compliance report.' +- ' returned: always' +- ' sample: Successfully fetched the firmware compliance report.' +- ' type: str' diff --git a/tests/integration/targets/omevv_firmware_compliance_info/meta/main.yaml b/tests/integration/targets/omevv_firmware_compliance_info/meta/main.yaml new file mode 100644 index 000000000..f77b5cfb2 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_omevv_registration diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tasks/main.yaml b/tests/integration/targets/omevv_firmware_compliance_info/tasks/main.yaml new file mode 100644 index 000000000..49e57ca34 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tasks/main.yaml @@ -0,0 +1,23 @@ +--- +- name: Collect all test cases + ansible.builtin.find: + paths: '{{ role_path }}/tests' + patterns: '{{ testcase }}.yaml' + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Fail if no test cases are found as per pattern. + ansible.builtin.fail: + msg: "Could not find test cases to run!!!" + when: not test_items|length > 0 + +- name: Run test case + ansible.builtin.include_tasks: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/__post_req_delete.yml b/tests/integration/targets/omevv_firmware_compliance_info/tests/__post_req_delete.yml new file mode 100644 index 000000000..b3fefb4f0 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/__post_req_delete.yml @@ -0,0 +1,13 @@ +--- +- name: Post-requisite - Delete a baseline profile + dellemc.openmanage.omevv_baseline_profile: + hostname: "{{ hostname }}" + vcenter_uuid: "{{ uuid }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + name: "AnsibleTest" + state: "absent" + validate_certs: false + register: delete_result + no_log: true + ignore_errors: true diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/__pre_req_create.yml b/tests/integration/targets/omevv_firmware_compliance_info/tests/__pre_req_create.yml new file mode 100644 index 000000000..4e465cdd3 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/__pre_req_create.yml @@ -0,0 +1,18 @@ +--- +- name: Pre-requisite - Create a baseline profile + dellemc.openmanage.omevv_baseline_profile: + hostname: "{{ hostname }}" + vcenter_uuid: "{{ uuid }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + name: "AnsibleTest" + repository_profile: "Dell Default Catalog" + validate_certs: false + description: "Firmware repository profile created by Module" + cluster: + - "{{ cluster_name }}" + days: + - "sunday" + time: "03:59" + register: create_result + no_log: true diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/_cluster_helper.yml b/tests/integration/targets/omevv_firmware_compliance_info/tests/_cluster_helper.yml new file mode 100644 index 000000000..987a4e008 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/_cluster_helper.yml @@ -0,0 +1,88 @@ +--- +- name: Get all clusters by uri. + ansible.builtin.uri: + url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port + }}/omevv/GatewayService/v1/Consoles/{{ uuid }}/Clusters + user: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: false + force_basic_auth: true + status_code: 200 + headers: + x_omivv-api-vcenter-identifier: "{{ uuid }}" + register: all_clusters_resp + +- name: Extract entityIds + ansible.builtin.set_fact: + entity_ids: "{{ entity_ids | default([]) + [item.entityId] }}" + loop: "{{ all_clusters_resp.json }}" + +- name: Extract cluster names + ansible.builtin.set_fact: + cluster_names: "{{ cluster_names | default([]) + [item.name] }}" + loop: "{{ all_clusters_resp.json }}" + +- name: Create payload + ansible.builtin.set_fact: + payload: + clustIds: "{{ entity_ids }}" + +- name: Get list of groupIDs for given cluster IDs. + ansible.builtin.uri: + url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port + }}/omevv/GatewayService/v1/Consoles/{{ uuid + }}/Groups/getGroupsForClusters + user: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: false + method: POST + body: "{{ payload | to_json }}" + body_format: json + force_basic_auth: true + status_code: 200 + headers: + x_omivv-api-vcenter-identifier: "{{ uuid }}" + register: group_ids_resp + +- name: Set fact for groupIds + ansible.builtin.set_fact: + group_ids: "{{ group_ids_resp.json | map(attribute='groupId') | list }}" + +- name: Get cluster drift info. + ansible.builtin.uri: + url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port + }}/omevv/GatewayService/v1/Consoles/{{ uuid + }}/Groups/{{ item }}/FirmwareDriftReport + user: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: false + method: GET + force_basic_auth: true + status_code: 200 + headers: + x_omivv-api-vcenter-identifier: "{{ uuid }}" + loop: "{{ group_ids }}" + register: cluster_drift_info + ignore_errors: true + +- name: Initialize all_cluster_drift_info + ansible.builtin.set_fact: + all_cluster_drift_info: [] + +- name: Set fact to store all drift info + ansible.builtin.set_fact: + all_cluster_drift_info: "{{ all_cluster_drift_info + [item.json] }}" + loop: "{{ cluster_drift_info.results }}" + when: item.json is defined + +- name: Remove error and message from all_cluster_drift_info response + ansible.builtin.set_fact: + all_cluster_drift_info: "{{ all_cluster_drift_info | ansible.utils. + remove_keys(target=['errorCode', 'message'], + matching_parameter='regex') }}" + +- name: Remove cluster key from module response + ansible.builtin.set_fact: + modified_response: "{{ info_result.firmware_compliance_info | + ansible.utils.remove_keys(target=['cluster', 'error_code', 'message'], + matching_parameter='regex') }}" diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/_hosts_helper.yml b/tests/integration/targets/omevv_firmware_compliance_info/tests/_hosts_helper.yml new file mode 100644 index 000000000..80e513cf3 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/_hosts_helper.yml @@ -0,0 +1,48 @@ +--- +- name: Get group details + ansible.builtin.uri: + url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port + }}/omevv/GatewayService/v1/Consoles/{{ uuid }}/Groups + user: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: false + force_basic_auth: true + status_code: 200 + headers: + x_omivv-api-vcenter-identifier: "{{ uuid }}" + register: group_details + +- name: Find the CLUSTER group + ansible.builtin.set_fact: + cluster_name: "{{ item.consoleEntityName }}" + group_id: "{{ item.groupId }}" + loop: "{{ group_details.json }}" + when: item.groupType == "CLUSTER" + register: cluster_result + until: cluster_result is defined + retries: 1 + delay: 0 + +- name: Find hosts details + ansible.builtin.uri: + url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port + }}/omevv/GatewayService/v1/Consoles/{{ uuid }}/ManagedHosts + user: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: false + force_basic_auth: true + status_code: 200 + headers: + x_omivv-api-vcenter-identifier: "{{ uuid }}" + register: host_details + +- name: Find the host and its servicetag + ansible.builtin.set_fact: + host: "{{ item.hostName }}" + servicetag: "{{ item.serviceTag }}" + loop: "{{ host_details.json }}" + when: item.omevvpGroupId|string == group_id + register: host_result + until: host_result is defined + retries: 1 + delay: 0 diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/_specific_host_helper.yml b/tests/integration/targets/omevv_firmware_compliance_info/tests/_specific_host_helper.yml new file mode 100644 index 000000000..ce434bb2f --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/_specific_host_helper.yml @@ -0,0 +1,26 @@ +--- +- name: Get cluster drift info. + ansible.builtin.uri: + url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port + }}/omevv/GatewayService/v1/Consoles/{{ uuid + }}/Groups/{{ group_id }}/FirmwareDriftReport + user: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: false + method: GET + force_basic_auth: true + status_code: 200 + headers: + x_omivv-api-vcenter-identifier: "{{ uuid }}" + register: specific_cluster_drift_info + ignore_errors: true + +- name: Initialize cluster_drift_info + ansible.builtin.set_fact: + cluster_drift_info: "{{ specific_cluster_drift_info.json }}" + +- name: Remove cluster key from module response + ansible.builtin.set_fact: + modified_response: "{{ info_result.firmware_compliance_info | + ansible.utils.remove_keys(target=['cluster', 'error_code', 'message'], + matching_parameter='regex') }}" diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/ansible_doc.yaml b/tests/integration/targets/omevv_firmware_compliance_info/tests/ansible_doc.yaml new file mode 100644 index 000000000..969d1a5ab --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/ansible_doc.yaml @@ -0,0 +1,22 @@ +# Dell OpenManage Ansible modules +# Copyright (C) 2024 Dell Inc. or its subsidiaries. All Rights Reserved. + +# GNU General Public License v3.0+ (see COPYING or +# https://www.gnu.org/licenses/gpl-3.0.txt) +--- +- block: + - name: ansible-doc + command: ansible-doc dellemc.openmanage.omevv_firmware_compliance_info + register: ansible_doc_hash + + - name: Get ansible-doc output + local_action: copy content={{ansible_doc_hash.stdout_lines[2:] | + to_nice_yaml }} dest={{ role_path }}/files/ansible_doc.txt + register: ansible_doc + check_mode: true + diff: true + + - name: Verify if doc changed + ansible.builtin.assert: + that: not ansible_doc.changed + run_once: true diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/cluster_info.yaml b/tests/integration/targets/omevv_firmware_compliance_info/tests/cluster_info.yaml new file mode 100644 index 000000000..d887122fa --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/cluster_info.yaml @@ -0,0 +1,69 @@ +# Dell OpenManage Ansible modules +# Copyright (C) 2024 Dell Inc. or its subsidiaries. All Rights Reserved. + +# GNU General Public License v3.0+ (see COPYING or +# https://www.gnu.org/licenses/gpl-3.0.txt) +--- +- name: Test that we have an OME host, OME username and OME password + ansible.builtin.fail: + msg: "Please define the following variables: hostname, vcenter_username + and vcenter_password." + when: + hostname is not defined or ome_username is not defined or ome_password + is not defined + +- block: + - name: Get Cluster name, hosts and servicetags + ansible.builtin.include_tasks: _hosts_helper.yml + + - ansible.builtin.include_tasks: __pre_req_create.yml + + - name: Fetch firmware compliance report of all the cluster. + (Check mode) + dellemc.openmanage.omevv_firmware_compliance_info: &retrieve_info + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_uuid: "{{ uuid }}" + register: cm_changes + check_mode: true + + - name: Verify task status - Fetch firmware compliance report of all + the cluster. (Check mode) + ansible.builtin.assert: + that: + - not cm_changes.changed + - cm_changes.msg == "Successfully fetched the firmware compliance + report." + + - name: Fetch firmware compliance report of all the cluster. (Normal Mode) + dellemc.openmanage.omevv_firmware_compliance_info: + <<: *retrieve_info + register: info_result + + - name: Verify task status - Fetch firmware compliance report of all + the cluster. (Normal Mode) + ansible.builtin.assert: + that: + - not info_result.changed + - info_result.msg == "Successfully fetched the firmware compliance + report." + + - ansible.builtin.include_tasks: _cluster_helper.yml + + - name: Verify - Whether module output matches with api details by uri. + ansible.builtin.assert: + that: + - modified_response == all_cluster_drift_info + + always: + - name: Cleanup + ansible.builtin.include_tasks: __post_req_delete.yml + + module_defaults: + dellemc.openmanage.omevv_firmware_compliance_info: + validate_certs: "{{ validate_certs }}" + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + port: "{{ port }}" diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/hosts_info.yaml b/tests/integration/targets/omevv_firmware_compliance_info/tests/hosts_info.yaml new file mode 100644 index 000000000..69c26cd08 --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/hosts_info.yaml @@ -0,0 +1,76 @@ +# Dell OpenManage Ansible modules +# Copyright (C) 2024 Dell Inc. or its subsidiaries. All Rights Reserved. + +# GNU General Public License v3.0+ (see COPYING or +# https://www.gnu.org/licenses/gpl-3.0.txt) +--- +- name: Test that we have an OME host, OME username and OME password + ansible.builtin.fail: + msg: "Please define the following variables: hostname, vcenter_username + and vcenter_password." + when: + hostname is not defined or ome_username is not defined or ome_password + is not defined + +- block: + - name: Get Cluster name, hosts and servicetags + ansible.builtin.include_tasks: _hosts_helper.yml + + - ansible.builtin.include_tasks: __pre_req_create.yml + + - name: Fetch firmware compliance report of specific host in the cluster. + (Check mode) + dellemc.openmanage.omevv_firmware_compliance_info: &retrieve_info + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_uuid: "{{ uuid }}" + clusters: + - cluster_name: "{{ cluster_name }}" + servicetags: + - "{{ servicetag }}" + hosts: + - "{{ host }}" + register: cm_changes + check_mode: true + + - name: Verify task status - Fetch firmware compliance report of specific + host in the cluster. (Check mode) + ansible.builtin.assert: + that: + - not cm_changes.changed + - cm_changes.msg == "Successfully fetched the firmware compliance + report." + + - name: Fetch firmware compliance report of specific host in the cluster. + (Normal Mode) + dellemc.openmanage.omevv_firmware_compliance_info: + <<: *retrieve_info + register: info_result + + - name: Verify task status - Fetch firmware compliance report of specific + host in the cluster. (Normal Mode) + ansible.builtin.assert: + that: + - not info_result.changed + - info_result.msg == "Successfully fetched the firmware compliance + report." + + - ansible.builtin.include_tasks: _specific_host_helper.yml + + - name: Verify - Whether module output matches with api details by uri. + ansible.builtin.assert: + that: + - modified_response[0] == cluster_drift_info + + always: + - name: Cleanup + ansible.builtin.include_tasks: __post_req_delete.yml + + module_defaults: + dellemc.openmanage.omevv_firmware_compliance_info: + validate_certs: "{{ validate_certs }}" + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + port: "{{ port }}" diff --git a/tests/integration/targets/omevv_firmware_compliance_info/tests/invalid.yaml b/tests/integration/targets/omevv_firmware_compliance_info/tests/invalid.yaml new file mode 100644 index 000000000..14322868d --- /dev/null +++ b/tests/integration/targets/omevv_firmware_compliance_info/tests/invalid.yaml @@ -0,0 +1,201 @@ +# Dell OpenManage Ansible modules +# Copyright (C) 2024 Dell Inc. or its subsidiaries. All Rights Reserved. + +# GNU General Public License v3.0+ (see COPYING or +# https://www.gnu.org/licenses/gpl-3.0.txt) +--- +- name: Test that we have an OME host, OME username and OME password + ansible.builtin.fail: + msg: "Please define the following variables: hostname, vcenter_username + and vcenter_password." + when: + hostname is not defined or ome_username is not defined or ome_password + is not defined + +- block: + - name: Negative - Invalid hostname + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "invalid" + ignore_unreachable: true + register: invalid_hostname + + - name: Verify task status- Negative - Invalid hostname + ansible.builtin.assert: + that: + - invalid_hostname.unreachable + - not invalid_hostname.changed + - invalid_hostname.msg == "" + + - name: Negative - Invalid vcenter_username + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: invalid + vcenter_password: "{{ vcenter_password }}" + ignore_errors: true + register: invalid_user + + - name: Verify task status - Negative - Invalid user + ansible.builtin.assert: + that: + - invalid_user.failed + - not invalid_user.changed + - 'invalid_user.msg == "HTTP Error 401: 401" or + "HTTP Error 400: 400"' + + - name: Negative - Invalid vcenter_password + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: invalid + ignore_errors: true + register: invalid_vcenter_password + + - name: Verify task status - Negative - Invalid vcenter_password + ansible.builtin.assert: + that: + - invalid_vcenter_password.failed + - not invalid_vcenter_password.changed + - 'invalid_vcenter_password.msg == "HTTP Error 401: 401" or + "HTTP Error 400: 400"' + + - name: Negative - Invalid ca_path + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + ca_path: invalid + ignore_errors: true + register: invalid_ca_path + + - name: Verify task status - Negative - Invalid ca_path + ansible.builtin.assert: + that: + - invalid_ca_path.failed + - not invalid_ca_path.changed + - 'invalid_ca_path.msg == "[Errno 2] No such file or + directory: b''invalid''"' + + - name: Negative - Invalid validate_certs + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + validate_certs: invalid + register: invalid_validate_certs + ignore_errors: true + + - ansible.builtin.set_fact: + invalid_validate_certs_expected_msg: "argument 'validate_certs' is of + type and we were unable to convert to bool: The value + 'invalid' is not a valid boolean. Valid booleans include: " + + - name: Verify task status - Negative - Invalid validate_certs + ansible.builtin.assert: + that: + - invalid_validate_certs.failed + - not invalid_validate_certs.changed + - invalid_validate_certs_expected_msg in invalid_validate_certs.msg + + - name: Negative - Invalid vcenter_uuid + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_uuid: "invalid" + ignore_errors: true + register: invalid_vcenter_uuid + + - name: Verify task status- Negative - Invalid vcenter_hostname + ansible.builtin.assert: + that: + - invalid_vcenter_uuid.failed + - 'invalid_vcenter_uuid.msg.message == "vCenter with UUID invalid is + not registered."' + + - name: Negative - Invalid argument + dellemc.openmanage.omevv_firmware_compliance_info: + invalid_argument: unsupported + register: invalid_argument + ignore_errors: true + + - name: Verify task status - Negative - Invalid argument + ansible.builtin.assert: + that: + - invalid_argument.failed + - not invalid_argument.changed + - 'invalid_argument.msg == "Unsupported parameters for + (dellemc.openmanage.omevv_firmware_compliance_info) + module: invalid_argument. Supported parameters include: ca_path, + clusters, hostname, port, timeout, validate_certs, + vcenter_password, vcenter_username, vcenter_uuid."' + + - name: Negative - Invalid cluster name + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_uuid: "{{ uuid }}" + clusters: + - cluster_name: "invalid" + ignore_errors: true + register: invalid_cluster_name + + - name: Verify task status- Negative - Invalid cluster name + ansible.builtin.assert: + that: + - invalid_cluster_name.skipped + - 'invalid_cluster_name.msg == "Unable to complete the operation + because none of clusters and hosts are valid."' + + - ansible.builtin.include_tasks: _hosts_helper.yml + + - name: Negative - Invalid service tag + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_uuid: "{{ uuid }}" + clusters: + - cluster_name: "{{ cluster_name }}" + servicetags: + - "invalid" + ignore_errors: true + register: invalid_service_tag + + - name: Verify task status- Negative - Invalid service tag + ansible.builtin.assert: + that: + - invalid_service_tag.skipped + - 'invalid_service_tag.msg == "Unable to complete the operation + because none of clusters and hosts are valid."' + + - name: Negative - Invalid host + dellemc.openmanage.omevv_firmware_compliance_info: + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_uuid: "{{ uuid }}" + clusters: + - cluster_name: "{{ cluster_name }}" + servicetags: + - "{{ servicetag }}" + hosts: + - "invalid" + ignore_errors: true + register: invalid_host + + - name: Verify task status- Negative - Invalid host + ansible.builtin.assert: + that: + - invalid_host.skipped + - 'invalid_host.msg == "Unable to complete the operation + because none of clusters and hosts are valid."' + + module_defaults: + dellemc.openmanage.omevv_firmware_compliance_info: + validate_certs: "{{ validate_certs }}" + hostname: "{{ hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + port: "{{ port }}"