Merge "Add nova profile support for vm snapshot and restore operation"

This commit is contained in:
Zuul 2018-08-03 04:30:27 +00:00 committed by Gerrit Code Review
commit 1ea42387e4
2 changed files with 71 additions and 1 deletions

View File

@ -1626,7 +1626,9 @@ class ServerProfile(base.Profile):
if server is None:
return None, False
image_id = self._get_image_id(obj, server, 'rebuilding')
image_id = options.get(self.IMAGE, None)
if not image_id:
image_id = self._get_image_id(obj, server, 'rebuilding')
admin_pass = self.properties.get(self.ADMIN_PASS)
name = self.properties[self.NAME] or obj.name
@ -1711,3 +1713,16 @@ class ServerProfile(base.Profile):
"""Handler for the migrate operation."""
return self._handle_generic_op(obj, 'server_migrate',
'migrate', consts.VS_ACTIVE)
def handle_snapshot(self, obj):
"""Handler for the snapshot operation."""
return self._handle_generic_op(obj, 'server_create_image',
'snapshot', consts.VS_ACTIVE,
name=obj.name)
def handle_restore(self, obj, **options):
"""Handler for the restore operation."""
image = options.get(self.IMAGE, None)
if not image:
return False
return self.handle_rebuild(obj, **options)

View File

@ -2070,3 +2070,58 @@ class TestNovaServerBasic(base.SenlinTestCase):
"timeout.", six.text_type(ex))
cc.server_migrate.assert_called_once_with('FAKE_ID')
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'ACTIVE')
def test_handle_snapshot(self):
obj = mock.Mock(physical_id='FAKE_ID', name='NODE001')
profile = server.ServerProfile('t', self.spec)
profile._computeclient = mock.Mock()
# do it
res = profile.handle_snapshot(obj)
self.assertTrue(res)
def test_handle_snapshot_no_physical_id(self):
obj = mock.Mock(physical_id=None, name='NODE001')
profile = server.ServerProfile('t', self.spec)
# do it
res = profile.handle_snapshot(obj)
self.assertFalse(res)
def test_handle_snapshot_failed_waiting(self):
profile = server.ServerProfile('t', self.spec)
cc = mock.Mock(name='NODE001')
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', name='NODE001')
ex = self.assertRaises(exc.EResourceOperation,
profile.handle_snapshot,
node_obj)
self.assertEqual("Failed in snapshot server 'FAKE_ID': "
"timeout.", six.text_type(ex))
cc.wait_for_server.assert_called_once_with('FAKE_ID', 'ACTIVE')
def test_handle_restore(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_restore(obj, admin_pass='new_pass',
image='FAKE_IMAGE')
self.assertTrue(res)
def test_handle_restore_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_restore(obj, admin_pass='new_pass',
image=None)
self.assertFalse(res)