Add nova profile support for vm rescue and unrescue operation
Change-Id: Id2a9ca793be3d158c99d7eb3d2760d92e642d8be Signed-off-by: Yuanbin.Chen <cybing4@gmail.com>
This commit is contained in:
parent
da6600f96b
commit
9606ff9a16
|
@ -308,7 +308,7 @@ LIFECYCLE_TRANSITION_TYPE = (
|
||||||
)
|
)
|
||||||
|
|
||||||
VM_STATUS = (
|
VM_STATUS = (
|
||||||
VS_ACTIVE, VS_ERROR, VS_SUSPENDED, VS_SHUTOFF, VS_PAUSED,
|
VS_ACTIVE, VS_ERROR, VS_SUSPENDED, VS_SHUTOFF, VS_PAUSED, VS_RESCUE,
|
||||||
) = (
|
) = (
|
||||||
'ACTIVE', 'ERROR', 'SUSPENDED', 'SHUTOFF', 'PAUSED',
|
'ACTIVE', 'ERROR', 'SUSPENDED', 'SHUTOFF', 'PAUSED', 'RESCUE',
|
||||||
)
|
)
|
||||||
|
|
|
@ -1677,3 +1677,21 @@ class ServerProfile(base.Profile):
|
||||||
"""Handler for the unpause operation."""
|
"""Handler for the unpause operation."""
|
||||||
return self._handle_generic_op(obj, 'server_unpause',
|
return self._handle_generic_op(obj, 'server_unpause',
|
||||||
'unpause', consts.VS_ACTIVE)
|
'unpause', consts.VS_ACTIVE)
|
||||||
|
|
||||||
|
def handle_rescue(self, obj, **options):
|
||||||
|
"""Handler for the rescue operation."""
|
||||||
|
password = options.get(self.ADMIN_PASSWORD, None)
|
||||||
|
image = options.get(self.IMAGE, None)
|
||||||
|
if not image:
|
||||||
|
return False
|
||||||
|
|
||||||
|
self._validate_image(obj, image)
|
||||||
|
return self._handle_generic_op(obj, 'server_rescue',
|
||||||
|
'rescue', consts.VS_RESCUE,
|
||||||
|
admin_pass=password,
|
||||||
|
image_ref=image)
|
||||||
|
|
||||||
|
def handle_unrescue(self, obj):
|
||||||
|
"""Handler for the unrescue operation."""
|
||||||
|
return self._handle_generic_op(obj, 'server_unrescue',
|
||||||
|
'unrescue', consts.VS_ACTIVE)
|
||||||
|
|
|
@ -1871,3 +1871,89 @@ class TestNovaServerBasic(base.SenlinTestCase):
|
||||||
"timeout.", six.text_type(ex))
|
"timeout.", six.text_type(ex))
|
||||||
cc.server_unpause.assert_called_once_with('FAKE_ID')
|
cc.server_unpause.assert_called_once_with('FAKE_ID')
|
||||||
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'ACTIVE')
|
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'ACTIVE')
|
||||||
|
|
||||||
|
def test_handle_rescue(self):
|
||||||
|
obj = mock.Mock(physical_id='FAKE_ID')
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
cc = mock.Mock()
|
||||||
|
profile._computeclient = cc
|
||||||
|
|
||||||
|
# do it
|
||||||
|
res = profile.handle_rescue(obj, admin_pass='new_pass',
|
||||||
|
image='FAKE_IMAGE')
|
||||||
|
|
||||||
|
self.assertTrue(res)
|
||||||
|
cc.server_rescue.assert_called_once_with(
|
||||||
|
'FAKE_ID', admin_pass='new_pass', image_ref='FAKE_IMAGE')
|
||||||
|
|
||||||
|
def test_handle_rescue_image_none(self):
|
||||||
|
obj = mock.Mock(physical_id='FAKE_ID')
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
cc = mock.Mock()
|
||||||
|
profile._computeclient = cc
|
||||||
|
|
||||||
|
res = profile.handle_rescue(obj, admin_pass='new_pass',
|
||||||
|
image=None)
|
||||||
|
self.assertFalse(res)
|
||||||
|
|
||||||
|
def test_handle_rescue_no_physical_id(self):
|
||||||
|
obj = mock.Mock(physical_id=None)
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
|
||||||
|
# do it
|
||||||
|
res = profile.handle_rescue(obj)
|
||||||
|
self.assertFalse(res)
|
||||||
|
|
||||||
|
def test_handle_rescue_failed_waiting(self):
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
cc = mock.Mock()
|
||||||
|
ex = exc.InternalError(code=500, message='timeout')
|
||||||
|
cc.wait_for_server.side_effect = ex
|
||||||
|
profile._computeclient = cc
|
||||||
|
node_obj = mock.Mock(physical_id='FAKE_ID')
|
||||||
|
|
||||||
|
ex = self.assertRaises(exc.EResourceOperation,
|
||||||
|
profile.handle_rescue,
|
||||||
|
node_obj, admin_pass='new_pass',
|
||||||
|
image='FAKE_IMAGE')
|
||||||
|
|
||||||
|
self.assertEqual("Failed in rescue server 'FAKE_ID': "
|
||||||
|
"timeout.", six.text_type(ex))
|
||||||
|
cc.server_rescue.assert_called_once_with('FAKE_ID',
|
||||||
|
admin_pass='new_pass',
|
||||||
|
image_ref='FAKE_IMAGE')
|
||||||
|
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'RESCUE')
|
||||||
|
|
||||||
|
def test_handle_unrescue(self):
|
||||||
|
obj = mock.Mock(physical_id='FAKE_ID')
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
profile._computeclient = mock.Mock()
|
||||||
|
|
||||||
|
# do it
|
||||||
|
res = profile.handle_unrescue(obj)
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
def test_handle_unresuce_no_physical_id(self):
|
||||||
|
obj = mock.Mock(physical_id=None)
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
|
||||||
|
# do it
|
||||||
|
res = profile.handle_unrescue(obj)
|
||||||
|
self.assertFalse(res)
|
||||||
|
|
||||||
|
def test_handle_unrescue_failed_waiting(self):
|
||||||
|
profile = server.ServerProfile('t', self.spec)
|
||||||
|
cc = mock.Mock()
|
||||||
|
ex = exc.InternalError(code=500, message='timeout')
|
||||||
|
cc.wait_for_server.side_effect = ex
|
||||||
|
profile._computeclient = cc
|
||||||
|
node_obj = mock.Mock(physical_id='FAKE_ID')
|
||||||
|
|
||||||
|
ex = self.assertRaises(exc.EResourceOperation,
|
||||||
|
profile.handle_unrescue,
|
||||||
|
node_obj)
|
||||||
|
|
||||||
|
self.assertEqual("Failed in unrescue server 'FAKE_ID': "
|
||||||
|
"timeout.", six.text_type(ex))
|
||||||
|
cc.server_unrescue.assert_called_once_with('FAKE_ID')
|
||||||
|
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'ACTIVE')
|
||||||
|
|
Loading…
Reference in New Issue