Skip to content

Commit

Permalink
Added Lpar.start()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
andy-maier committed Nov 16, 2023
1 parent 9b84948 commit 9e32e3b
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
66 changes: 64 additions & 2 deletions tests/unit/zhmcclient/test_lpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
88 changes: 88 additions & 0 deletions zhmcclient/_lpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9e32e3b

Please sign in to comment.