From 9e32e3b15254c319699c888490b2e1b53083e5b0 Mon Sep 17 00:00:00 2001 From: Andreas Maier Date: Fri, 10 Nov 2023 16:11:01 +0100 Subject: [PATCH] Added Lpar.start() Details: * Added Lpar.start() * Added unit testcases for Lpar.start() and Lpar.stop(). * End2end testcases have not yet been added, because that requires our own LPAR. Signed-off-by: Andreas Maier --- docs/changes.rst | 3 + tests/unit/zhmcclient/test_lpar.py | 66 +++++++++++++++++++++- zhmcclient/_lpar.py | 88 ++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index e8a2dda3..4ff84b4f 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -159,6 +159,9 @@ Released: not yet 'create-delete-activation-profiles' API feature enabled. (issue #1329) +* Added Lpar.start() to perform the "Start Logical Partition" operation in + classic mode. (issue #1308) + **Cleanup:** **Known issues:** diff --git a/tests/unit/zhmcclient/test_lpar.py b/tests/unit/zhmcclient/test_lpar.py index 97221e13..43f94a56 100644 --- a/tests/unit/zhmcclient/test_lpar.py +++ b/tests/unit/zhmcclient/test_lpar.py @@ -1510,8 +1510,70 @@ def test_console_list_permlpars_add_props( assert_resources(lpars, exp_faked_lpars, prop_names) - # TODO: Test for Lpar.start() - # TODO: Test for Lpar.stop() + +def test_lpar_start(http_mocked_lpar): # noqa: F811 + # pylint: disable=redefined-outer-name,unused-argument + """ + Test function for Lpar.start() + """ + session = http_mocked_lpar.manager.session + uri = http_mocked_lpar.uri + '/operations/start' + + job_uri = '/api/jobs/job-1' + + exp_request_body = None + exp_status_code = 202 + result_body = { + 'job-uri': job_uri, + } + exp_result_job = Job(session, job_uri, 'POST', uri) + + rm_adapter = requests_mock.Adapter(case_sensitive=True) + with requests_mock.mock(adapter=rm_adapter) as m: + + m.post(uri, status_code=exp_status_code, json=result_body) + + result_job = http_mocked_lpar.start(wait_for_completion=False) + + assert rm_adapter.called + request_body = rm_adapter.last_request.body + assert request_body == exp_request_body + assert result_job.uri == exp_result_job.uri + assert result_job.op_method == exp_result_job.op_method + assert result_job.op_uri == exp_result_job.op_uri + + +def test_lpar_stop(http_mocked_lpar): # noqa: F811 + # pylint: disable=redefined-outer-name,unused-argument + """ + Test function for Lpar.stop() + """ + session = http_mocked_lpar.manager.session + uri = http_mocked_lpar.uri + '/operations/stop' + + job_uri = '/api/jobs/job-1' + + exp_request_body = None + exp_status_code = 202 + result_body = { + 'job-uri': job_uri, + } + exp_result_job = Job(session, job_uri, 'POST', uri) + + rm_adapter = requests_mock.Adapter(case_sensitive=True) + with requests_mock.mock(adapter=rm_adapter) as m: + + m.post(uri, status_code=exp_status_code, json=result_body) + + result_job = http_mocked_lpar.stop(wait_for_completion=False) + + assert rm_adapter.called + request_body = rm_adapter.last_request.body + assert request_body == exp_request_body + assert result_job.uri == exp_result_job.uri + assert result_job.op_method == exp_result_job.op_method + assert result_job.op_uri == exp_result_job.op_uri + # TODO: Test for Lpar.psw_restart() # TODO: Test for Lpar.reset_clear() # TODO: Test for Lpar.reset_normal() diff --git a/zhmcclient/_lpar.py b/zhmcclient/_lpar.py index 730dc1a3..59ed2edf 100644 --- a/zhmcclient/_lpar.py +++ b/zhmcclient/_lpar.py @@ -1486,6 +1486,94 @@ def stop(self, wait_for_completion=True, operation_timeout=None, operation_timeout=operation_timeout) return result + @logged_api_call + def start(self, wait_for_completion=True, operation_timeout=None, + status_timeout=None, allow_status_exceptions=False): + """ + Start this LPAR, using the HMC operation "Start Logical + Partition". The start operation starts the processors to process + instructions. + + This operation is not permitted for an LPAR whose 'activation-mode' + property is "zaware" or "ssc". + + In order to succeed, the 'status' property of the LPAR must have one of + the following values: + + * "not-operating" + * "operating" + * "exceptions" + + Authorization requirements: + + * Object-access permission to this LPAR. + * Before HMC API version 3.6 in an update to HMC 2.15.0: Object-access + permission to the CPC of this LPAR. + * Task permission for the "Start" task. + + Parameters: + + wait_for_completion (bool): + Boolean controlling whether this method should wait for completion + of the requested asynchronous HMC operation, as follows: + + * If `True`, this method will wait for completion of the + asynchronous job performing the operation. + + * If `False`, this method will return immediately once the HMC has + accepted the request to perform the operation. + + operation_timeout (:term:`number`): + Timeout in seconds, for waiting for completion of the asynchronous + job performing the operation. The special value 0 means that no + timeout is set. `None` means that the default async operation + timeout of the session is used. If the timeout expires when + `wait_for_completion=True`, a + :exc:`~zhmcclient.OperationTimeout` is raised. + + status_timeout (:term:`number`): + **Deprecated:** This property was used for handling deferred status + behavior, which is not actually needed. Setting it to a non-default + value will cause a :exc:`~py:exceptions.DeprecationWarning` to be + issued. + + allow_status_exceptions (bool): + **Deprecated:** This property was used for handling deferred status + behavior, which is not actually needed. Setting it to a non-default + value will cause a :exc:`~py:exceptions.DeprecationWarning` to be + issued. + + Returns: + + `None` or :class:`~zhmcclient.Job`: + + If `wait_for_completion` is `True`, returns `None`. + + If `wait_for_completion` is `False`, returns a + :class:`~zhmcclient.Job` object representing the asynchronously + executing job on the HMC. + + Raises: + + :exc:`~zhmcclient.HTTPError` + :exc:`~zhmcclient.ParseError` + :exc:`~zhmcclient.AuthError` + :exc:`~zhmcclient.ConnectionError` + :exc:`~zhmcclient.OperationTimeout`: The timeout expired while + waiting for completion of the operation. + """ + warn_deprecated_parameter( + Lpar, Lpar.start, 'status_timeout', status_timeout, None) + warn_deprecated_parameter( + Lpar, Lpar.start, 'allow_status_exceptions', + allow_status_exceptions, False) + body = None + result = self.manager.session.post( + self.uri + '/operations/start', resource=self, body=body, + wait_for_completion=wait_for_completion, + operation_timeout=operation_timeout) + return result + @logged_api_call def reset_clear(self, force=False, wait_for_completion=True, operation_timeout=None, status_timeout=None,