Add nova profile support for vm lock and unlock operation

Change-Id: Ib2fba6cc71322fe07dbcea99aa99f0c04a1a202b
Signed-off-by: Yuanbin.Chen <cybing4@gmail.com>
This commit is contained in:
Yuanbin.Chen 2018-05-15 15:04:58 +08:00
parent 9865d71b33
commit c75527260b
2 changed files with 63 additions and 0 deletions

View File

@ -1684,3 +1684,31 @@ class ServerProfile(base.Profile):
raise exc.EResourceOperation(op='stop', type='server',
id=server_id,
message=six.text_type(ex))
def handle_lock(self, obj):
"""Handler for the lock operation."""
if not obj.physical_id:
return False
server_id = obj.physical_id
try:
self.compute(obj).server_lock(server_id)
return True
except exc.InternalError as ex:
raise exc.EResourceOperation(op='lock', type='server',
id=server_id,
message=six.text_type(ex))
def handle_unlock(self, obj):
"""Handler for the unlock operation."""
if not obj.physical_id:
return False
server_id = obj.physical_id
try:
self.compute(obj).server_unlock(server_id)
return True
except exc.InternalError as ex:
raise exc.EResourceOperation(op='unlock', type='server',
id=server_id,
message=six.text_type(ex))

View File

@ -1768,3 +1768,38 @@ class TestNovaServerBasic(base.SenlinTestCase):
"timeout.", six.text_type(ex))
cc.server_stop.assert_called_once_with('FAKE_ID')
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'SHUTOFF')
def test_handle_lock(self):
obj = mock.Mock(physical_id='FAKE_ID')
profile = server.ServerProfile('t', self.spec)
profile._computeclient = mock.Mock()
# do it
res = profile.handle_lock(obj)
self.assertTrue(res)
def test_handle_lock_no_physical_id(self):
obj = mock.Mock(physical_id=None)
profile = server.ServerProfile('t', self.spec)
# do it
res = profile.handle_lock(obj)
self.assertFalse(res)
def test_handle_unlock(self):
obj = mock.Mock(physical_id='FAKE_ID')
profile = server.ServerProfile('t', self.spec)
profile._computeclient = mock.Mock()
# do it
res = profile.handle_unlock(obj)
self.assertTrue(res)
def test_handle_unlock_no_physical_id(self):
obj = mock.Mock(physical_id=None)
profile = server.ServerProfile('t', self.spec)
profile._computeclient = mock.Mock()
# do it
res = profile.handle_unlock(obj)
self.assertFalse(res)