"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "karbor/tests/unit/protection/test_nova_protection_plugin.py" between
karbor-1.1.0.tar.gz and karbor-1.3.0.tar.gz

About:

test_nova_protection_plugin.py  (karbor-1.1.0):test_nova_protection_plugin.py  (karbor-1.3.0)
skipping to change at line 31 skipping to change at line 31
from karbor.services.protection.bank_plugin import BankPlugin from karbor.services.protection.bank_plugin import BankPlugin
from karbor.services.protection.bank_plugin import BankSection from karbor.services.protection.bank_plugin import BankSection
from karbor.services.protection.protection_plugins.server \ from karbor.services.protection.protection_plugins.server \
import server_plugin_schemas import server_plugin_schemas
from karbor.services.protection.protection_plugins.server. \ from karbor.services.protection.protection_plugins.server. \
nova_protection_plugin import NovaProtectionPlugin nova_protection_plugin import NovaProtectionPlugin
from karbor.tests import base from karbor.tests import base
class Server(object): class Server(object):
def __init__(self, id, addresses, availability_zone, def __init__(self, id, addresses, availability_zone,
flavor, key_name, security_groups): flavor, key_name, security_groups, status):
super(Server, self).__init__() super(Server, self).__init__()
self.id = id self.id = id
self.addresses = addresses self.addresses = addresses
self.__setattr__("OS-EXT-AZ:availability_zone", availability_zone) self.__setattr__("OS-EXT-AZ:availability_zone", availability_zone)
self.flavor = flavor self.flavor = flavor
self.key_name = key_name self.key_name = key_name
self.security_groups = security_groups self.security_groups = security_groups
self.status = status
class Volume(object): class Volume(object):
def __init__(self, id, volume_type, status, bootable, def __init__(self, id, volume_type, status, bootable,
attachments, name=None): attachments, name=None):
super(Volume, self).__init__() super(Volume, self).__init__()
self.id = id self.id = id
self.volume_type = volume_type self.volume_type = volume_type
self.status = status self.status = status
self.bootable = bootable self.bootable = bootable
self.attachments = attachments self.attachments = attachments
skipping to change at line 93 skipping to change at line 94
'addr': '10.0.0.21', 'addr': '10.0.0.21',
'version': 4} 'version': 4}
]}, ]},
availability_zone="nova", availability_zone="nova",
flavor={'id': 'flavor_id', flavor={'id': 'flavor_id',
'links': [ 'links': [
{'href': '', {'href': '',
'rel': 'bookmark'} 'rel': 'bookmark'}
]}, ]},
key_name=None, key_name=None,
security_groups="default"), security_groups="default",
status="ACTIVE"),
"vm_id_2": Server(id="vm_id_2", "vm_id_2": Server(id="vm_id_2",
addresses={'fake_net': [ addresses={'fake_net': [
{'OS-EXT-IPS-MAC:mac_addr': 'mac_address_2', {'OS-EXT-IPS-MAC:mac_addr': 'mac_address_2',
'OS-EXT-IPS:type': 'fixed', 'OS-EXT-IPS:type': 'fixed',
'addr': '10.0.0.22', 'addr': '10.0.0.22',
'version': 4} 'version': 4}
]}, ]},
availability_zone="nova", availability_zone="nova",
flavor={'id': 'flavor_id', flavor={'id': 'flavor_id',
'links': [ 'links': [
{'href': '', {'href': '',
'rel': 'bookmark'} 'rel': 'bookmark'}
]}, ]},
key_name=None, key_name=None,
security_groups="default") security_groups="default",
status="ACTIVE")
} }
FakeVolumes = { FakeVolumes = {
"vol_id_1": Volume(id="vol_id_1", "vol_id_1": Volume(id="vol_id_1",
volume_type="", volume_type="",
status="in-use", status="in-use",
bootable="", bootable="",
attachments=[{'server_id': 'vm_id_2', attachments=[{'server_id': 'vm_id_2',
'attachment_id': '', 'attachment_id': '',
'host_name': '', 'host_name': '',
skipping to change at line 445 skipping to change at line 448
"/resource_data/checkpoint_id/vm_id_1/data_0" "/resource_data/checkpoint_id/vm_id_1/data_0"
] = "image_data_1" ] = "image_data_1"
fake_bank._plugin._objects[ fake_bank._plugin._objects[
"/resource_data/checkpoint_id/vm_id_1/data_1" "/resource_data/checkpoint_id/vm_id_1/data_1"
] = "image_data_1" ] = "image_data_1"
call_hooks(delete_operation, self.checkpoint, resource, self.cntxt, call_hooks(delete_operation, self.checkpoint, resource, self.cntxt,
{}) {})
@mock.patch('karbor.services.protection.protection_plugins.utils.' @mock.patch('karbor.services.protection.protection_plugins.utils.'
'update_resource_restore_result')
@mock.patch('karbor.services.protection.clients.neutron.create')
@mock.patch('karbor.services.protection.clients.glance.create')
@mock.patch('karbor.services.protection.clients.nova.create')
@mock.patch('karbor.services.protection.clients.cinder.create')
def test_restore_backup_with_parameters(self, mock_cinder_client,
mock_nova_client,
mock_glance_client,
mock_neutron_client,
mock_update_result):
resource = Resource(id='vm_id_1',
type=constants.SERVER_RESOURCE_TYPE,
name='fake_vm')
fake_bank._plugin._objects[
"/resource_data/checkpoint_id/vm_id_1/metadata"] = {
"server_metadata": {
"availability_zone": "nova",
"key_name": None,
"floating_ips": [],
"flavor": "fake_flavor_id_1",
"networks": ["fake_net_id_1"],
"security_groups": [{"name": "default"}]},
"boot_metadata": {
"boot_image_id": "fake_image_id",
"boot_device_type": "image"},
"attach_metadata": {},
"resource_id": "vm_id_1"}
restore_operation = self.plugin.get_restore_operation(resource)
mock_cinder_client.return_value = self.cinder_client
mock_nova_client.return_value = self.nova_client
mock_glance_client.return_value = self.glance_client
mock_neutron_client.return_value = self.neutron_client
parameters = {'restore_net_id': 'fake_net_id_2',
'restore_flavor_id': 'fake_flavor_id_2'}
checkpoint = Checkpoint()
new_resources = {"new_resources": {"fake_image_id": "fake_image_id"}}
self.nova_client.servers.create = mock.MagicMock()
self.nova_client.servers.create.return_value = FakeServers['vm_id_2']
call_hooks(restore_operation, checkpoint, resource, self.cntxt,
parameters, **new_resources)
properties = {
"availability_zone": "nova",
"flavor": "fake_flavor_id_2",
"name": "karbor-restore-server",
"image": "fake_image_id",
"key_name": None,
"security_groups": ['default'],
"nics": [{'net-id': 'fake_net_id_2'}],
"userdata": None
}
self.nova_client.servers.create.assert_called_with(**properties)
@mock.patch('karbor.services.protection.protection_plugins.utils.'
'update_resource_verify_result') 'update_resource_verify_result')
def test_verify_backup(self, mock_update_verify): def test_verify_backup(self, mock_update_verify):
resource = Resource(id="123", resource = Resource(id="123",
type=constants.SERVER_RESOURCE_TYPE, type=constants.SERVER_RESOURCE_TYPE,
name='fake') name='fake')
fake_bank._plugin._objects[ fake_bank._plugin._objects[
"/resource_data/checkpoint_id/123/status" "/resource_data/checkpoint_id/123/status"
] = "available" ] = "available"
 End of changes. 5 change blocks. 
3 lines changed or deleted 59 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)