diff --git a/0001-Add-parameter-to-specify-certification-file.patch b/0001-Add-parameter-to-specify-certification-file.patch new file mode 100644 index 0000000000000000000000000000000000000000..85faab4ab95be0bfd56393dafa121e0277684f33 --- /dev/null +++ b/0001-Add-parameter-to-specify-certification-file.patch @@ -0,0 +1,235 @@ +From 099796e31bc6648bea53f7ff427cc5e97e067e8e Mon Sep 17 00:00:00 2001 +From: zhanghan +Date: Thu, 24 Aug 2023 11:40:33 +0800 +Subject: [PATCH] Add parameter to specify certification file + +--- + scciclient/irmc/elcm.py | 7 +++++- + scciclient/irmc/scci.py | 34 ++++++++++++++++++++++++------ + scciclient/tests/irmc/test_scci.py | 26 +++++++++++------------ + 3 files changed, 46 insertions(+), 21 deletions(-) + +diff --git a/scciclient/irmc/elcm.py b/scciclient/irmc/elcm.py +index a66aa35..c80df98 100644 +--- a/scciclient/irmc/elcm.py ++++ b/scciclient/irmc/elcm.py +@@ -188,6 +188,10 @@ def elcm_request(irmc_info, method, path, **kwargs): + 'irmc_port': 80 or 443, default is 443, + 'irmc_auth_method': 'basic' or 'digest', default is 'basic', + 'irmc_client_timeout': timeout, default is 60, ++ 'irmc_verify_ca': Either a boolean, in which case it controls ++ whether we verify the server's TLS certificate, ++ or a string, in which case it must be a path to ++ a CA bundle to use. Defaults to ``True``. + ... + } + :param method: request method such as 'GET', 'POST' +@@ -203,6 +207,7 @@ def elcm_request(irmc_info, method, path, **kwargs): + userid = irmc_info['irmc_username'] + password = irmc_info['irmc_password'] + client_timeout = irmc_info.get('irmc_client_timeout', 60) ++ verify = irmc_info.get('irmc_verify_ca', True) + + # Request headers, params, and data + headers = kwargs.get('headers', {'Accept': 'application/json'}) +@@ -229,7 +234,7 @@ def elcm_request(irmc_info, method, path, **kwargs): + headers=headers, + params=params, + data=data, +- verify=False, ++ verify=verify, + timeout=client_timeout, + allow_redirects=False, + auth=auth_obj) +diff --git a/scciclient/irmc/scci.py b/scciclient/irmc/scci.py +index 6dc6d30..f4fe9d2 100755 +--- a/scciclient/irmc/scci.py ++++ b/scciclient/irmc/scci.py +@@ -247,7 +247,7 @@ def get_share_type(share_type): + + + def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic', +- client_timeout=60, do_async=True, **kwargs): ++ client_timeout=60, do_async=True, verify=True, **kwargs): + """execute SCCI command + + This function calls SCCI server modules +@@ -259,6 +259,10 @@ def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic', + :param auth_method: irmc_username + :param client_timeout: timeout for SCCI operations + :param do_async: async call if True, sync call otherwise ++ :param verify: (optional) Either a boolean, in which case it ++ controls whether we verify the server's TLS certificate, ++ or a string, in which case it must be a path to ++ a CA bundle to use. Defaults to ``True``. + :returns: requests.Response from SCCI server + :raises: SCCIInvalidInputError if port and/or auth_method params + are invalid +@@ -294,7 +298,7 @@ def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic', + r = requests.post(protocol + '://' + host + config_type, + data=data, + headers=header, +- verify=False, ++ verify=verify, + timeout=client_timeout, + allow_redirects=False, + auth=auth_obj) +@@ -334,7 +338,7 @@ def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic', + + + def get_client(host, userid, password, port=443, auth_method='basic', +- client_timeout=60, **kwargs): ++ client_timeout=60,verify=True, **kwargs): + """get SCCI command partial function + + This function returns SCCI command partial function +@@ -344,12 +348,17 @@ def get_client(host, userid, password, port=443, auth_method='basic', + :param port: port number of iRMC + :param auth_method: irmc_username + :param client_timeout: timeout for SCCI operations ++ :param verify: Either a boolean, in which case it ++ controls whether we verify the server's TLS certificate, ++ or a string, in which case it must be a path to ++ a CA bundle to use. + :returns: scci_cmd partial function which takes a SCCI command param + """ + + return functools.partial(scci_cmd, host, userid, password, + port=port, auth_method=auth_method, +- client_timeout=client_timeout, **kwargs) ++ client_timeout=client_timeout, ++ verify=verify, **kwargs) + + + def get_virtual_cd_set_params_cmd(remote_image_server, +@@ -416,7 +425,7 @@ def get_virtual_fd_set_params_cmd(remote_image_server, + + + def get_report(host, userid, password, +- port=443, auth_method='basic', client_timeout=60): ++ port=443, auth_method='basic', client_timeout=60, verify=True): + """get iRMC report + + This function returns iRMC report in XML format +@@ -426,6 +435,10 @@ def get_report(host, userid, password, + :param port: port number of iRMC + :param auth_method: irmc_username + :param client_timeout: timeout for SCCI operations ++ :param verify: Either a boolean, in which case it ++ controls whether we verify the server's TLS certificate, ++ or a string, in which case it must be a path to ++ a CA bundle to use. + :returns: root element of SCCI report + :raises: ISCCIInvalidInputError if port and/or auth_method params + are invalid +@@ -448,7 +461,7 @@ def get_report(host, userid, password, + + try: + r = requests.get(protocol + '://' + host + '/report.xml', +- verify=False, ++ verify=verify, + timeout=(10, client_timeout), + allow_redirects=False, + auth=auth_obj) +@@ -671,6 +684,10 @@ def get_firmware_upgrade_status(irmc_info, upgrade_type): + 'irmc_port': 80 or 443, default is 443, + 'irmc_auth_method': 'basic' or 'digest', default is 'digest', + 'irmc_client_timeout': timeout, default is 60, ++ 'irmc_verify_ca': (optional) Either a boolean, in which case it ++ controls whether we verify the server's TLS ++ certificate, or a string, in which case it must be ++ a path to a CA bundle to use. Defaults to ``True``. + ... + } + :param upgrade_type: flag to check upgrade with bios or irmc +@@ -685,6 +702,7 @@ def get_firmware_upgrade_status(irmc_info, upgrade_type): + port = irmc_info.get('irmc_port', 443) + auth_method = irmc_info.get('irmc_auth_method', 'digest') + client_timeout = irmc_info.get('irmc_client_timeout', 60) ++ verify = irmc_info.get('irmc_verify_ca', True) + + auth_obj = None + try: +@@ -704,7 +722,7 @@ def get_firmware_upgrade_status(irmc_info, upgrade_type): + elif upgrade_type == 'irmc': + upgrade_type = '/irmcprogress' + r = requests.get(protocol + '://' + host + upgrade_type, +- verify=False, ++ verify=verify, + timeout=(10, client_timeout), + allow_redirects=False, + auth=auth_obj) +@@ -718,3 +736,5 @@ def get_firmware_upgrade_status(irmc_info, upgrade_type): + return upgrade_status_xml + except ET.ParseError as parse_error: + raise SCCIClientError(parse_error) ++ except requests.RequestException as requests_exception: ++ raise SCCIClientError(requests_exception) +diff --git a/scciclient/tests/irmc/test_scci.py b/scciclient/tests/irmc/test_scci.py +index 2573e15..e06a832 100644 +--- a/scciclient/tests/irmc/test_scci.py ++++ b/scciclient/tests/irmc/test_scci.py +@@ -125,7 +125,7 @@ class SCCITestCase(testtools.TestCase): + 'https://' + self.irmc_address + '/config', + data=scci.POWER_ON, + headers={'Content-type': 'application/x-www-form-urlencoded'}, +- verify=False, ++ verify=True, + timeout=self.irmc_client_timeout, + allow_redirects=False, + auth=mock_requests.auth.HTTPBasicAuth(self.irmc_username, +@@ -919,9 +919,9 @@ class SCCITestCase(testtools.TestCase): + result = scci.get_raid_fgi_status(report_fake) + self.assertEqual(result, fgi_status_expect) + +- @mock.patch('scciclient.irmc.scci.requests') +- def test_fail_get_bios_firmware_status(self, mock_requests): +- mock_requests.get.return_value = mock.Mock( ++ @mock.patch('scciclient.irmc.scci.requests.get') ++ def test_fail_get_bios_firmware_status(self, mock_requests_get): ++ mock_requests_get.return_value = mock.Mock( + status_code=404, + text=""" + +@@ -942,9 +942,9 @@ class SCCITestCase(testtools.TestCase): + scci.get_firmware_upgrade_status, self.irmc_info, + upgrade_type=upgrade_type) + +- @mock.patch('scciclient.irmc.scci.requests') +- def test_success_get_bios_firmware_status(self, mock_requests): +- mock_requests.get.return_value = mock.Mock( ++ @mock.patch('scciclient.irmc.scci.requests.get') ++ def test_success_get_bios_firmware_status(self, mock_requests_get): ++ mock_requests_get.return_value = mock.Mock( + return_value='ok', + status_code=200, + text=""" +@@ -962,9 +962,9 @@ class SCCITestCase(testtools.TestCase): + self.assertEqual(expected_severity, result.find("./Severity").text) + self.assertEqual(expected_message, result.find("./Message").text) + +- @mock.patch('scciclient.irmc.scci.requests') +- def test_fail_get_irmc_firmware_status(self, mock_requests): +- mock_requests.get.return_value = mock.Mock( ++ @mock.patch('scciclient.irmc.scci.requests.get') ++ def test_fail_get_irmc_firmware_status(self, mock_requests_get): ++ mock_requests_get.return_value = mock.Mock( + status_code=404, + text=""" + +@@ -985,9 +985,9 @@ class SCCITestCase(testtools.TestCase): + scci.get_firmware_upgrade_status, self.irmc_info, + upgrade_type=upgrade_type) + +- @mock.patch('scciclient.irmc.scci.requests') +- def test_success_get_irmc_firmware_status(self, mock_requests): +- mock_requests.get.return_value = mock.Mock( ++ @mock.patch('scciclient.irmc.scci.requests.get') ++ def test_success_get_irmc_firmware_status(self, mock_requests_get): ++ mock_requests_get.return_value = mock.Mock( + return_value='ok', + status_code=200, + text=""" +-- +2.33.0 + diff --git a/python-scciclient.spec b/python-scciclient.spec index 037ee1e7429be007ec663b4f2fe29556ca2ce360..9686ad13794fa6392f4f99febf4675a2dfb13751 100644 --- a/python-scciclient.spec +++ b/python-scciclient.spec @@ -1,11 +1,14 @@ %global _empty_manifest_terminate_build 0 Name: python-scciclient Version: 0.8.1 -Release: 3 +Release: 4 Summary: Python ServerView Common Command Interface (SCCI) Client Library License: Apache-2.0 URL: https://opendev.org/x/python-scciclient Source0: https://files.pythonhosted.org/packages/f5/2b/32fb677bbf9d08ea8c0b52b05c42d760cc5c947d55649d097eff954747d0/python-scciclient-0.8.1.tar.gz + +Patch1: 0001-Add-parameter-to-specify-certification-file.patch + BuildArch: noarch Requires: python3-pbr @@ -38,7 +41,7 @@ Python ServerView Common Command Interface (SCCI) Client Library %prep -%autosetup -n python-scciclient-0.8.1 +%autosetup -p1 -n python-scciclient-0.8.1 %build %py3_build @@ -78,6 +81,8 @@ mv %{buildroot}/doclist.lst . %{_docdir}/* %changelog +* Thu Aug 24 2023 zhanghan 0.8.1-4 +- Add parameter to specify certification file * Thu Jan 28 2021 zhangy - Add buildrequires * Mon Jan 04 2021 Python_Bot