Skip to content

Commit 7785f8c

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Added reboot command for PersistentResource
PiperOrigin-RevId: 638796373
1 parent 71fbc81 commit 7785f8c

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

google/cloud/aiplatform/persistent_resource.py

+31
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,34 @@ def list(
420420
location=location,
421421
credentials=credentials,
422422
)
423+
424+
@base.optional_sync()
425+
def reboot(
426+
self,
427+
sync: Optional[bool] = True, # pylint: disable=unused-argument
428+
) -> None:
429+
"""Reboots this Persistent Resource.
430+
431+
Args:
432+
name (str):
433+
Required. The name of the PersistentResource resource.
434+
Name should be in the following format:
435+
``projects/{project_id_or_number}/locations/{location_id}/persistentResources/{persistent_resource_id}``
436+
437+
This corresponds to the ``name`` field
438+
on the ``request`` instance; if ``request`` is provided, this
439+
should not be set.
440+
sync (bool):
441+
Whether to execute this method synchonously. If False, this
442+
method will be executed in concurrent Future and any downstream
443+
object will be immediately returned and synced when the Future
444+
has completed.
445+
"""
446+
447+
_LOGGER.log_action_start_against_resource("Rebooting", "", self)
448+
lro = self.api_client.reboot_persistent_resource(name=self.resource_name)
449+
_LOGGER.log_action_started_against_resource_with_lro(
450+
"Reboot", "", self.__class__, lro
451+
)
452+
lro.result(timeout=None)
453+
_LOGGER.log_action_completed_against_resource("rebooted.", "", self)

tests/unit/aiplatform/test_persistent_resource.py

+34
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ def delete_persistent_resource_mock():
153153
yield delete_persistent_resource_mock
154154

155155

156+
@pytest.fixture
157+
def reboot_persistent_resource_mock():
158+
with mock.patch.object(
159+
(persistent_resource_service_client_v1.PersistentResourceServiceClient),
160+
"reboot_persistent_resource",
161+
) as reboot_persistent_resource_mock:
162+
reboot_lro = mock.Mock(ga_operation.Operation)
163+
reboot_lro.result.return_value = (
164+
persistent_resource_service_v1.RebootPersistentResourceRequest()
165+
)
166+
reboot_persistent_resource_mock.return_value = reboot_lro
167+
yield reboot_persistent_resource_mock
168+
169+
156170
@pytest.mark.usefixtures("google_auth_mock")
157171
class TestPersistentResource:
158172
def setup_method(self):
@@ -359,3 +373,23 @@ def test_delete_persistent_resource(
359373
delete_persistent_resource_mock.assert_called_once_with(
360374
name=_TEST_PERSISTENT_RESOURCE_ID,
361375
)
376+
377+
@pytest.mark.parametrize("sync", [True, False])
378+
def test_reboot_persistent_resource(
379+
self,
380+
get_persistent_resource_mock,
381+
reboot_persistent_resource_mock,
382+
sync,
383+
):
384+
test_resource = persistent_resource.PersistentResource(
385+
_TEST_PERSISTENT_RESOURCE_ID
386+
)
387+
test_resource.reboot(sync=sync)
388+
389+
if not sync:
390+
test_resource.wait()
391+
392+
get_persistent_resource_mock.assert_called_once()
393+
reboot_persistent_resource_mock.assert_called_once_with(
394+
name=_TEST_PERSISTENT_RESOURCE_ID,
395+
)

0 commit comments

Comments
 (0)