compute: Add support for legacy 'onSharedStorage' param

This is supported by early revisions of the server evacuate action.

Change-Id: I452fa9bb7077b3a1ce66552bbbf68ffd6702d1e2
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-05-09 15:43:33 +01:00
parent 30d5753bcf
commit 1ba107faa1
4 changed files with 44 additions and 5 deletions

View File

@ -1072,7 +1072,15 @@ class Proxy(proxy.Proxy):
server = self._get_resource(_server.Server, server)
server.unrescue(self)
def evacuate_server(self, server, host=None, admin_pass=None, force=None):
def evacuate_server(
self,
server,
host=None,
admin_pass=None,
force=None,
*,
on_shared_storage=None,
):
"""Evacuates a server from a failed host to a new host.
:param server: Either the ID of a server or a
@ -1084,10 +1092,18 @@ class Proxy(proxy.Proxy):
:param force: Force an evacuation by not verifying the provided
destination host by the scheduler. (New in API version
2.29).
:param on_shared_storage: Whether the host is using shared storage.
(Optional) (Only supported before API version 2.14)
:returns: None
"""
server = self._get_resource(_server.Server, server)
server.evacuate(self, host=host, admin_pass=admin_pass, force=force)
server.evacuate(
self,
host=host,
admin_pass=admin_pass,
force=force,
on_shared_storage=on_shared_storage,
)
def start_server(self, server):
"""Starts a stopped server and changes its state to ``ACTIVE``.

View File

@ -687,7 +687,14 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin):
body = {"unrescue": None}
self._action(session, body)
def evacuate(self, session, host=None, admin_pass=None, force=None):
def evacuate(
self,
session,
host=None,
admin_pass=None,
force=None,
on_shared_storage=None,
):
"""Evacuate the server.
:param session: The session to use for making this request.
@ -695,6 +702,8 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin):
:param admin_pass: The admin password to set on the evacuated instance.
(Optional)
:param force: Whether to force evacuation.
:param on_shared_storage: Whether the host is using shared storage.
(Optional) (Only supported before microversion 2.14)
:returns: None
"""
body: ty.Dict[str, ty.Any] = {"evacuate": {}}
@ -704,6 +713,8 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin):
body["evacuate"]["adminPass"] = admin_pass
if force is not None:
body["evacuate"]["force"] = force
if on_shared_storage is not None:
body["evacuate"]["onSharedStorage"] = on_shared_storage
self._action(session, body)
def start(self, session):

View File

@ -1181,7 +1181,12 @@ class TestCompute(TestComputeProxy):
self.proxy.evacuate_server,
method_args=["value"],
expected_args=[self.proxy],
expected_kwargs={"host": None, "admin_pass": None, "force": None},
expected_kwargs={
"host": None,
"admin_pass": None,
"force": None,
"on_shared_storage": None,
},
)
def test_server_evacuate_with_options(self):
@ -1189,11 +1194,13 @@ class TestCompute(TestComputeProxy):
"openstack.compute.v2.server.Server.evacuate",
self.proxy.evacuate_server,
method_args=["value", 'HOST2', 'NEW_PASS', True],
method_kwargs={'on_shared_storage': False},
expected_args=[self.proxy],
expected_kwargs={
"host": "HOST2",
"admin_pass": 'NEW_PASS',
"force": True,
"on_shared_storage": False,
},
)

View File

@ -905,7 +905,11 @@ class TestServer(base.TestCase):
sot = server.Server(**EXAMPLE)
res = sot.evacuate(
self.sess, host='HOST2', admin_pass='NEW_PASS', force=True
self.sess,
host='HOST2',
admin_pass='NEW_PASS',
force=True,
on_shared_storage=False,
)
self.assertIsNone(res)
@ -915,6 +919,7 @@ class TestServer(base.TestCase):
'host': 'HOST2',
'adminPass': 'NEW_PASS',
'force': True,
'onSharedStorage': False,
}
}
headers = {'Accept': ''}