Skip to content

Commit 43e633b

Browse files
ABHISHEK-SINHA10Kritika-Bhateja-03rajshekarp87
authored
9.3.0: Sonar Fix (#667)
* Fixed sonar in changelog.yaml * Fixed security hotspots * FIxed sonar issues * Fixed sonar issues for Integration tests * Fixed space errors * SOnar fixes * Sanity fixed * Fixing sonar * Fixing sonar idrac_certificate * Minor change --------- Co-authored-by: Kritika-Bhateja-03 <Kritika.Bhateja@Dell.com> Co-authored-by: Rajshekar P <rajshekar_p@dell.com> Co-authored-by: Kritika-Bhateja-03 <121278954+Kritika-Bhateja-03@users.noreply.github.com>
1 parent 6ed1483 commit 43e633b

File tree

23 files changed

+221
-136
lines changed

23 files changed

+221
-136
lines changed

changelogs/changelog.yaml

+35-27
Original file line numberDiff line numberDiff line change
@@ -1836,48 +1836,56 @@ releases:
18361836
release_date: '2024-04-30'
18371837
9.3.0:
18381838
changes:
1839-
release_summary: '- The ``ome_session`` module is added to allow you to create and delete the sessions on
1840-
OpenManage Enterprise and OpenManage Enterprise Modular.
1839+
release_summary: '- The ``ome_session`` module is added to allow you to
1840+
create and delete the sessions on OpenManage Enterprise and
1841+
OpenManage Enterprise Modular.
18411842
1842-
- Added support to use session ID for authentication of iDRAC, OpenManage Enterprise and OpenManage
1843-
Enterprise Modular modules.
1843+
- Added support to use session ID for authentication of iDRAC,
1844+
OpenManage Enterprise and OpenManage Enterprise Modular modules.
18441845
18451846
- Added time_to_wait option in ``idrac_storage_volume`` module.
18461847
18471848
- Added support for Python 3.12.'
18481849
major_changes:
1849-
- ome_session - This module allows you to create and delete the sessions on
1850+
- ome_session - This module allows you to create and delete the
1851+
sessions on OpenManage Enterprise and OpenManage Enterprise Modular.
1852+
- Added support to use session ID for authentication of iDRAC,
18501853
OpenManage Enterprise and OpenManage Enterprise Modular.
1851-
- Added support to use session ID for authentication of iDRAC, OpenManage Enterprise and OpenManage
1852-
Enterprise Modular.
18531854
minor_changes:
18541855
- Added time_to_wait option in ``idrac_storage_volume`` module.
18551856
- Added support for Python 3.12.
18561857
bugfixes:
1857-
- Resolved the issue in ``idrac_virtual_media`` module where the Authorization request header was included
1858-
in the request. (https://github.com/dell/dellemc-openmanage-ansible-modules/issues/612)
1859-
- Resolved the issue in ``idrac_certificates`` module where subject_alt_name parameter was only accepting
1860-
first item in list. (https://github.com/dell/dellemc-openmanage-ansible-modules/issues/584)
1861-
- Resolved the issue in ``ome_application_certificate`` module related to a padding error in generated CSR file.
1858+
- Resolved the issue in ``idrac_virtual_media`` module where the
1859+
Authorization request header was included in the request.
1860+
(https://github.com/dell/dellemc-openmanage-ansible-modules/issues/612)
1861+
- Resolved the issue in ``idrac_certificates`` module where
1862+
subject_alt_name parameter was only accepting first item in list.
1863+
(https://github.com/dell/dellemc-openmanage-ansible-modules/issues/584)
1864+
- Resolved the issue in ``ome_application_certificate`` module related
1865+
to a padding error in generated CSR file.
18621866
(https://github.com/dell/dellemc-openmanage-ansible-modules/issues/370)
18631867
known_issues:
1864-
- idrac_storage_volume - Issue(290766) - The module will report success instead of showing
1865-
failure for new virtual creation on the BOSS-N1 controller if a virtual disk is already
1866-
present on the same controller.
1867-
- idrac_diagnostics - Issue(285322) - This module doesn't support export of diagnostics
1868-
file to HTTP and HTTPS share via SOCKS proxy.
1869-
- idrac_firmware - Issue(279282) - This module does not support firmware update using
1870-
HTTP, HTTPS, and FTP shares with authentication on iDRAC8.
1871-
- ome_diagnostics - Issue(279193) - Export of SupportAssist collection logs to the
1872-
share location fails on OME version 4.0.0.
1873-
- ome_smart_fabric_uplink - Issue(186024) - The module supported by OpenManage
1874-
Enterprise Modular, however it does not allow the creation of multiple uplinks
1875-
of the same name. If an uplink is created using the same name as an existing
1876-
uplink, then the existing uplink is modified.
1868+
- idrac_storage_volume - Issue(290766) - The module will report success
1869+
instead of showing failure for new virtual creation on the BOSS-N1
1870+
controller if a virtual disk is already present on the same
1871+
controller.
1872+
- idrac_diagnostics - Issue(285322) - This module doesn't support
1873+
export of diagnostics file to HTTP and HTTPS share via SOCKS
1874+
proxy.
1875+
- idrac_firmware - Issue(279282) - This module does not support
1876+
firmware update using HTTP, HTTPS, and FTP shares with
1877+
authentication on iDRAC8.
1878+
- ome_diagnostics - Issue(279193) - Export of SupportAssist
1879+
collection logs to the share location fails on OME version 4.0.0.
1880+
- ome_smart_fabric_uplink - Issue(186024) - The module supported by
1881+
OpenManage Enterprise Modular, however it does not allow the
1882+
creation of multiple uplinks of the same name. If an uplink is
1883+
created using the same name as an existing uplink, then the existing
1884+
uplink is modified.
18771885
modules:
18781886
- description:
1879-
This module allows you to create and delete sessions on OpenManage Enterprise and
1880-
OpenManage Enterprise Modular.
1887+
This module allows you to create and delete sessions on OpenManage
1888+
Enterprise and OpenManage Enterprise Modular.
18811889
name: ome_session
18821890
namespace: ''
18831891
release_date: '2024-05-31'

plugins/module_utils/session_utils.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
from ansible.module_utils.urls import open_url
3535
from ansible.module_utils.six.moves.urllib.parse import urlencode
3636
from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import config_ipv6
37-
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
38-
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
37+
from ansible.module_utils.urls import open_url
3938
from abc import ABC, abstractmethod
4039

4140
HEADER_TYPE = "application/json"
@@ -305,15 +304,12 @@ def invoke_request(self, uri, method, data=None, query_param=None, headers=None,
305304
:return: The response data from the request.
306305
:rtype: OpenURLResponse
307306
"""
308-
try:
309-
url_kwargs = self._args_session(method, api_timeout, headers=headers, url_kwargs=url_kwargs)
310-
if data and dump:
311-
data = json.dumps(data)
312-
url = self._build_url(uri, query_param=query_param)
313-
resp = open_url(url, data=data, **url_kwargs)
314-
resp_data = OpenURLResponse(resp)
315-
except (HTTPError, URLError, SSLValidationError, ConnectionError) as err:
316-
raise err
307+
url_kwargs = self._args_session(method, api_timeout, headers=headers, url_kwargs=url_kwargs)
308+
if data and dump:
309+
data = json.dumps(data)
310+
url = self._build_url(uri, query_param=query_param)
311+
resp = open_url(url, data=data, **url_kwargs)
312+
resp_data = OpenURLResponse(resp)
317313
return resp_data
318314

319315
def _get_omam_ca_env(self):

plugins/modules/ome_session.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,10 @@ def get_session_status(self, session_url, session_id):
233233
int: The status code of the session status response. If an HTTPError occurs, the status
234234
code of the error is returned.
235235
"""
236-
try:
237-
session_status_response = self.instance.invoke_request(SESSION_URL, "GET")
238-
sessions_data = session_status_response.json_data
239-
session_ids = [session_id["@odata.id"].split("'")[1] for session_id in sessions_data["value"]]
240-
session_status = session_id in session_ids
241-
except HTTPError as err:
242-
raise err
236+
session_status_response = self.instance.invoke_request(SESSION_URL, "GET")
237+
sessions_data = session_status_response.json_data
238+
session_ids = [session_id["@odata.id"].split("'")[1] for session_id in sessions_data["value"]]
239+
session_status = session_id in session_ids
243240
return session_status
244241

245242
def create_session(self):

roles/idrac_attributes/molecule/default/converge.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
- name: Asserting after performing operation with wrong hostname
2020
ansible.builtin.assert:
21-
that:
22-
- '"<urlopen error [Errno -2] Name or service not known>" in idrac_attributes_out.msg'
21+
that: >-
22+
'"<urlopen error [Errno -2] Name or service not known>" in
23+
idrac_attributes_out.msg'
2324
2425
- name: Perform update with wrong username
2526
ansible.builtin.import_role:
@@ -73,11 +74,9 @@
7374

7475
- name: Asserting after performing operation with invalid https_port
7576
ansible.builtin.assert:
76-
that:
77-
- '"<urlopen error [Errno 111] Connection refused>" in idrac_attributes_out.msg'
78-
# - ('"Connection refused" in idrac_attributes_out.msg')
79-
# or
80-
# ('"urlopen error timed out" in idrac_attributes_out.msg')
77+
that: >-
78+
'"<urlopen error [Errno 111] Connection refused>" in
79+
idrac_attributes_out.msg'
8180
8281
- name: Perform update with invalid validate_certs
8382
ansible.builtin.import_role:
@@ -116,8 +115,10 @@
116115

117116
- name: Asserting after performing operation with wrong ca_path
118117
ansible.builtin.assert:
119-
that:
120-
- '"<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)>" in idrac_attributes_out.msg'
118+
that: >-
119+
'"<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify
120+
failed: self signed certificate (_ssl.c:1129)>" in
121+
idrac_attributes_out.msg'
121122
122123
- name: Perform update with wrong manager_id
123124
ansible.builtin.import_role:

roles/idrac_boot/molecule/boot_source_override_enabled_as_continuous_reset_type_none/converge.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,7 @@
109109

110110
- name: Asserting TC-115433 in normal mode
111111
ansible.builtin.assert:
112-
that: idrac_boot_out.msg == "The boot settings operation is triggered/submitted successfully."
112+
that: >-
113+
"The boot settings operation is triggered/submitted successfully." in
114+
idrac_boot_out.msg
113115
when: not ansible_check_mode

roles/idrac_boot/molecule/boot_source_override_enabled_as_disabled_reset_type_none/converge.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@
9292

9393
- name: Asserting TC-115431 in normal mode
9494
ansible.builtin.assert:
95-
that: idrac_boot_out.msg == "The boot settings operation is triggered/submitted successfully."
95+
that: >-
96+
"The boot settings operation is triggered/submitted successfully." in
97+
idrac_boot_out.msg
9698
when: not ansible_check_mode and idrac_boot_out.changed
9799

98100
- name: Asserting TC-115431 in idempotence mode

roles/idrac_boot/molecule/boot_source_override_enabled_as_once_reset_type_none/converge.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191

9292
- name: Asserting TC-115432 in normal mode or idempotence mode
9393
ansible.builtin.assert:
94-
that:
95-
- 'idrac_boot_out.msg == "The boot settings operation is triggered/submitted successfully." or "No changes found to be applied."'
94+
that: >-
95+
'idrac_boot_out.msg == "The boot settings operation is
96+
triggered/submitted successfully." or "No changes found to be
97+
applied."'
9698
when: not ansible_check_mode and not idrac_boot_out.changed

roles/idrac_boot/molecule/boot_source_override_mode_legacy_job_wait_false/converge.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105

106106
- name: Asserting TC-115429 in normal mode or idempotence mode
107107
ansible.builtin.assert:
108-
that:
109-
- 'idrac_boot_out.msg == "The boot settings operation is triggered/submitted successfully." or "No changes found to be applied."'
108+
that: >-
109+
'idrac_boot_out.msg == "The boot settings operation is
110+
triggered/submitted successfully." or "No changes found to
111+
be applied."'
110112
when: not ansible_check_mode and not idrac_boot_out.changed

roles/idrac_certificate/molecule/default/converge.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@
165165

166166
- name: Verify task status - Negative - invalid unreachable host
167167
ansible.builtin.assert:
168-
that:
169-
- idrac_certificate_out.unreachable
170-
- '"<urlopen error [Errno -2] Name or service not known>" in idrac_certificate_out.msg'
168+
that: >-
169+
'"<urlopen error [Errno -2] Name or service not known>" in
170+
idrac_certificate_out.msg' and idrac_certificate_out.unreachable
171171
172172
- name: Negative - invalid idrac user
173173
ansible.builtin.import_role:

roles/idrac_certificate/molecule/default/molecule.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
scenario:
23
test_sequence:
34
- dependency

roles/idrac_gather_facts/molecule/passensor/converge.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
tasks:
3030
- name: Fetching Presence and Status Sensor info
3131
ansible.builtin.uri:
32-
url: "https://{{ hostname }}{{ api_system }}/Oem/Dell/DellPresenceAndStatusSensors"
32+
url: "https://{{ hostname }}{{ api_system }}/Oem/
33+
Dell/DellPresenceAndStatusSensors"
3334
validate_certs: "{{ validate_certs }}"
3435
ca_path: "{{ ca_path | default(omit) }}"
3536
method: "{{ idrac_gather_facts_uri_method }}"
@@ -44,8 +45,10 @@
4445

4546
- name: Set presence and status sensor facts
4647
ansible.builtin.set_fact:
47-
api_response: "{{ passensor_result.json.Members | ansible.utils.remove_keys(target=['@odata.context',
48+
api_response: "{{ passensor_result.json.Members |
49+
ansible.utils.remove_keys(target=['@odata.context',
4850
'@odata.id', '@odata.type', 'Assembly', 'Links']) }}"
51+
when: passensor_result.json.Members is defined
4952

5053
- name: Gather Facts for the Presence and Status Sensor
5154
ansible.builtin.include_role:
@@ -54,14 +57,16 @@
5457
- name: Assert Presence and Status Sensor data
5558
ansible.builtin.assert:
5659
that:
57-
- "((api_response | length == 0) and (presence_and_status_sensor | length == 0))"
60+
- "((api_response | length == 0) and
61+
(presence_and_status_sensor | length == 0))"
5862
fail_msg: "The response from the role does not match"
5963
success_msg: "The response from the role matches"
6064
when: api_response | length == 0
6165

6266
- name: Check whether output differs
6367
ansible.builtin.set_fact:
64-
result_diff: "{{ presence_and_status_sensor | symmetric_difference(api_response) }}"
68+
result_diff: "{{ presence_and_status_sensor |
69+
symmetric_difference(api_response) }}"
6570
when: api_response | length > 0
6671

6772
- name: Assert the differences in List

roles/idrac_gather_facts/molecule/physicaldisk/converge.yml

+16-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343

4444
- name: Get all storage controller ids.
4545
ansible.builtin.set_fact:
46-
storage_ids_list: "{{ idrac_gather_facts_controllers_result.json.Members | map('dict2items') | flatten | map(attribute='value') }}"
46+
storage_ids_list:
47+
"{{ idrac_gather_facts_controllers_result.json.Members |
48+
map('dict2items') | flatten | map(attribute='value') }}"
49+
when: idrac_gather_facts_controllers_result.json.Members is defined
4750

4851
- name: Get physical disk information using API.
4952
ansible.builtin.uri:
@@ -52,17 +55,25 @@
5255
loop: "{{ storage_ids_list }}"
5356
no_log: true
5457
register: idrac_gather_facts_disk_result
58+
when: storage_ids_list is defined
5559

5660
- name: Count the number of drives in drives_result.results
5761
ansible.builtin.set_fact:
58-
drives_count: "{{ idrac_gather_facts_disk_result.results | map(attribute='json.drives') | list | length }}"
62+
drives_count: "{{ idrac_gather_facts_disk_result.results |
63+
map(attribute='json.drives') | list | length }}"
64+
when: idrac_gather_facts_disk_result.results is defined
5965

6066
- name: Set Physical Disk facts
6167
ansible.builtin.set_fact:
6268
api_response:
63-
"{{ idrac_gather_facts_disk_result.results | selectattr('json', 'defined') | map(attribute='json') | selectattr('Drives', 'defined') |
64-
map(attribute='Drives') | flatten | ansible.utils.remove_keys(target=['@odata.context', '@odata.id', '@odata.type',
65-
'Actions', 'Assembly', 'Links', 'DellDriveSMARTAttributes', 'DellNVMeSMARTAttributes', 'Operations@odata.count']) }}"
69+
"{{ idrac_gather_facts_disk_result.results |
70+
selectattr('json', 'defined') | map(attribute='json') |
71+
selectattr('Drives', 'defined') | map(attribute='Drives') |
72+
flatten | ansible.utils.remove_keys(target=['@odata.context',
73+
'@odata.id', '@odata.type', 'Actions', 'Assembly', 'Links',
74+
'DellDriveSMARTAttributes', 'DellNVMeSMARTAttributes',
75+
'Operations@odata.count']) }}"
76+
when: idrac_gather_facts_disk_result.results is defined
6677

6778
- name: Gather Facts for the Physical Disk component
6879
ansible.builtin.include_role:

roles/idrac_gather_facts/tests/asserts/mmetrics_assert.yml

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
- name: Get Memory Metrics ids
1616
ansible.builtin.set_fact:
17-
memory_metrics_ids: "{{ response_memory.json.Members | selectattr('Metrics', 'defined') | map(attribute='Metrics') | flatten }}"
17+
memory_metrics_ids: "{{ response_memory.json.Members |
18+
selectattr('Metrics', 'defined') | map(attribute='Metrics') | flatten }}"
19+
when: response_memory.json.Members is defined
1820

1921
- name: Get Memory Metrics information.
2022
ansible.builtin.uri:
@@ -26,20 +28,25 @@
2628

2729
- name: Set Memory Metrics facts
2830
ansible.builtin.set_fact:
29-
api_memory_metrics: "{{ response_memory_metrics.results | selectattr('json', 'defined') | map(attribute='json') | flatten |
30-
ansible.utils.remove_keys(target=['@odata.context', '@odata.type', '@odata.id', 'DataSourceUri']) }}"
31+
api_memory_metrics: "{{ response_memory_metrics.results |
32+
selectattr('json', 'defined') | map(attribute='json') |
33+
flatten | ansible.utils.remove_keys(target=['@odata.context',
34+
'@odata.type', '@odata.id', 'DataSourceUri']) }}"
35+
when: response_memory_metrics.results is defined
3136

3237
- name: Assert memory metrics
3338
ansible.builtin.assert:
3439
that:
35-
- "((api_memory_metrics | length == 0) and (memory_metrics | length == 0))"
40+
- "((api_memory_metrics | length == 0) and
41+
(memory_metrics | length == 0))"
3642
fail_msg: "The response from the role does not match"
3743
success_msg: "The response from the role matches"
3844
when: api_memory_metrics| length == 0
3945

4046
- name: Check whether output differs
4147
ansible.builtin.set_fact:
42-
result_diff: "{{ memory_metrics | symmetric_difference(api_memory_metrics) }}"
48+
result_diff: "{{ memory_metrics |
49+
symmetric_difference(api_memory_metrics) }}"
4350
when: api_memory_metrics| length > 0
4451

4552
- name: Assert the differences in List

roles/idrac_gather_facts/tests/asserts/tmetrics_assert.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
- name: Get Thermal Metrics information.
33
ansible.builtin.uri:
4-
url: "https://{{ hostname }}{{ api_chassis }}/ThermalSubsystem/ThermalMetrics"
4+
url:
5+
"https://{{ hostname }}{{ api_chassis }}/ThermalSubsystem/ThermalMetrics"
56
validate_certs: "{{ validate_certs }}"
67
method: "{{ idrac_gather_facts_uri_method }}"
78
user: "{{ username }}"
@@ -16,19 +17,24 @@
1617
- name: Set Thermal Metrics facts
1718
ansible.builtin.set_fact:
1819
api_thermal_metrics: "{{ response_thermal_metrics.json |
19-
ansible.utils.remove_keys(target=['@odata.context', '@odata.type', '@odata.id', 'DataSourceUri', 'TemperatureReadingsCelsius@odata.count']) }}"
20+
ansible.utils.remove_keys(target=['@odata.context', '@odata.type',
21+
'@odata.id', 'DataSourceUri',
22+
'TemperatureReadingsCelsius@odata.count']) }}"
23+
when: response_thermal_metrics is defined
2024

2125
- name: Assert thermal metrics
2226
ansible.builtin.assert:
2327
that:
24-
- "((api_thermal_metrics | length == 0) and (thermal_metrics | length == 0))"
28+
- "((api_thermal_metrics | length == 0) and
29+
(thermal_metrics | length == 0))"
2530
fail_msg: "The response from the role does not match"
2631
success_msg: "The response from the role matches"
2732
when: api_thermal_metrics| length == 0
2833

2934
- name: Check whether output differs
3035
ansible.builtin.set_fact:
31-
result_diff: "{{ thermal_metrics | symmetric_difference(api_thermal_metrics) }}"
36+
result_diff: "{{ thermal_metrics |
37+
symmetric_difference(api_thermal_metrics) }}"
3238
when: api_thermal_metrics | length > 0
3339

3440
- name: Assert the differences in List

0 commit comments

Comments
 (0)