summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2019-01-09 21:36:27 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2019-01-09 21:36:27 +0800
commitbda8202f6d91cc46f082f5c54128c5eb2b40f6ec (patch)
tree7f8a156e0beeec7c41a8f0c8b206b1e6a72b799a
parentb1b7da4dc7f7bc4875de9c3aa73d850589165537 (diff)
Add support to rewrite the flavor id in restore
When using karbor to restore server to another openstack cluster(cross keystone), and if the another cluster do not have the same flavor id, the restore will fail. We should add support for adding flavor id as a parameter to rewrite the flavor id in checkpoint metadata. Change-Id: Ie5c7a1adf07b7f9b1225ee4a5e16000a3453a7cc Closes-Bug: #1811090
Notes
Notes (review): Code-Review+2: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Code-Review+2: liushuai <liushuai@cmss.chinamobile.com> Workflow+1: liushuai <liushuai@cmss.chinamobile.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 11 Jan 2019 01:21:31 +0000 Reviewed-on: https://review.openstack.org/629482 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/services/protection/protection_plugins/server/nova_protection_plugin.py4
-rw-r--r--karbor/services/protection/protection_plugins/server/server_plugin_schemas.py5
-rw-r--r--karbor/tests/unit/protection/test_nova_protection_plugin.py62
3 files changed, 68 insertions, 3 deletions
diff --git a/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py b/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py
index 8c38897..723623a 100644
--- a/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py
+++ b/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py
@@ -230,6 +230,10 @@ class RestoreOperation(protection_plugin.Operation):
230 230
231 # restore server instance 231 # restore server instance
232 restore_net_id = parameters.get("restore_net_id", None) 232 restore_net_id = parameters.get("restore_net_id", None)
233 restore_flavor_id = parameters.get("restore_flavor_id", None)
234 if restore_flavor_id:
235 resource_definition["server_metadata"]['flavor'] = (
236 restore_flavor_id)
233 new_server_id = self._restore_server_instance( 237 new_server_id = self._restore_server_instance(
234 nova_client, new_resources, original_server_id, 238 nova_client, new_resources, original_server_id,
235 parameters.get("restore_name", "karbor-restore-server"), 239 parameters.get("restore_name", "karbor-restore-server"),
diff --git a/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py b/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py
index bf2b054..39b682c 100644
--- a/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py
+++ b/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py
@@ -30,6 +30,11 @@ RESTORE_SCHEMA = {
30 "type": "string", 30 "type": "string",
31 "title": "Restore Server Net Id", 31 "title": "Restore Server Net Id",
32 "description": "The net id of the restore server" 32 "description": "The net id of the restore server"
33 },
34 "restore_flavor_id": {
35 "type": "string",
36 "title": "Restore Server Flavor Id",
37 "description": "The flavor id of the restore server"
33 } 38 }
34 }, 39 },
35 "required": ["restore_name"] 40 "required": ["restore_name"]
diff --git a/karbor/tests/unit/protection/test_nova_protection_plugin.py b/karbor/tests/unit/protection/test_nova_protection_plugin.py
index fc22e92..7437eab 100644
--- a/karbor/tests/unit/protection/test_nova_protection_plugin.py
+++ b/karbor/tests/unit/protection/test_nova_protection_plugin.py
@@ -29,7 +29,7 @@ from karbor.tests import base
29 29
30class Server(object): 30class Server(object):
31 def __init__(self, id, addresses, availability_zone, 31 def __init__(self, id, addresses, availability_zone,
32 flavor, key_name, security_groups): 32 flavor, key_name, security_groups, status):
33 super(Server, self).__init__() 33 super(Server, self).__init__()
34 self.id = id 34 self.id = id
35 self.addresses = addresses 35 self.addresses = addresses
@@ -37,6 +37,7 @@ class Server(object):
37 self.flavor = flavor 37 self.flavor = flavor
38 self.key_name = key_name 38 self.key_name = key_name
39 self.security_groups = security_groups 39 self.security_groups = security_groups
40 self.status = status
40 41
41 42
42class Volume(object): 43class Volume(object):
@@ -94,7 +95,8 @@ FakeServers = {
94 'rel': 'bookmark'} 95 'rel': 'bookmark'}
95 ]}, 96 ]},
96 key_name=None, 97 key_name=None,
97 security_groups="default"), 98 security_groups="default",
99 status="ACTIVE"),
98 "vm_id_2": Server(id="vm_id_2", 100 "vm_id_2": Server(id="vm_id_2",
99 addresses={'fake_net': [ 101 addresses={'fake_net': [
100 {'OS-EXT-IPS-MAC:mac_addr': 'mac_address_2', 102 {'OS-EXT-IPS-MAC:mac_addr': 'mac_address_2',
@@ -109,7 +111,8 @@ FakeServers = {
109 'rel': 'bookmark'} 111 'rel': 'bookmark'}
110 ]}, 112 ]},
111 key_name=None, 113 key_name=None,
112 security_groups="default") 114 security_groups="default",
115 status="ACTIVE")
113} 116}
114 117
115FakeVolumes = { 118FakeVolumes = {
@@ -455,6 +458,59 @@ class NovaProtectionPluginTest(base.TestCase):
455 {}) 458 {})
456 459
457 @mock.patch('karbor.services.protection.protection_plugins.utils.' 460 @mock.patch('karbor.services.protection.protection_plugins.utils.'
461 'update_resource_restore_result')
462 @mock.patch('karbor.services.protection.clients.neutron.create')
463 @mock.patch('karbor.services.protection.clients.glance.create')
464 @mock.patch('karbor.services.protection.clients.nova.create')
465 @mock.patch('karbor.services.protection.clients.cinder.create')
466 def test_restore_backup_with_parameters(self, mock_cinder_client,
467 mock_nova_client,
468 mock_glance_client,
469 mock_neutron_client,
470 mock_update_result):
471 resource = Resource(id='vm_id_1',
472 type=constants.SERVER_RESOURCE_TYPE,
473 name='fake_vm')
474 fake_bank._plugin._objects[
475 "/resource_data/checkpoint_id/vm_id_1/metadata"] = {
476 "server_metadata": {
477 "availability_zone": "nova",
478 "key_name": None,
479 "floating_ips": [],
480 "flavor": "fake_flavor_id_1",
481 "networks": ["fake_net_id_1"],
482 "security_groups": [{"name": "default"}]},
483 "boot_metadata": {
484 "boot_image_id": "fake_image_id",
485 "boot_device_type": "image"},
486 "attach_metadata": {},
487 "resource_id": "vm_id_1"}
488 restore_operation = self.plugin.get_restore_operation(resource)
489 mock_cinder_client.return_value = self.cinder_client
490 mock_nova_client.return_value = self.nova_client
491 mock_glance_client.return_value = self.glance_client
492 mock_neutron_client.return_value = self.neutron_client
493 parameters = {'restore_net_id': 'fake_net_id_2',
494 'restore_flavor_id': 'fake_flavor_id_2'}
495 checkpoint = Checkpoint()
496 new_resources = {"new_resources": {"fake_image_id": "fake_image_id"}}
497 self.nova_client.servers.create = mock.MagicMock()
498 self.nova_client.servers.create.return_value = FakeServers['vm_id_2']
499 call_hooks(restore_operation, checkpoint, resource, self.cntxt,
500 parameters, **new_resources)
501 properties = {
502 "availability_zone": "nova",
503 "flavor": "fake_flavor_id_2",
504 "name": "karbor-restore-server",
505 "image": "fake_image_id",
506 "key_name": None,
507 "security_groups": ['default'],
508 "nics": [{'net-id': 'fake_net_id_2'}],
509 "userdata": None
510 }
511 self.nova_client.servers.create.assert_called_with(**properties)
512
513 @mock.patch('karbor.services.protection.protection_plugins.utils.'
458 'update_resource_verify_result') 514 'update_resource_verify_result')
459 def test_verify_backup(self, mock_update_verify): 515 def test_verify_backup(self, mock_update_verify):
460 resource = Resource(id="123", 516 resource = Resource(id="123",