def _test(mock_bind_ports_to_host, mock_supports_port_binding, mock_check_can_live_migrate_dest): nwinfo = network_model.NetworkInfo([ network_model.VIF(uuids.port1), network_model.VIF(uuids.port2) ]) self.instance.info_cache = objects.InstanceInfoCache( network_info=nwinfo) self.task._call_livem_checks_on_host('dest-host') # Assert the migrate_data set on the task based on the port # bindings created. self.assertIn('vifs', data) self.assertEqual(2, len(data.vifs)) for vif in data.vifs: self.assertIn('source_vif', vif) self.assertEqual('dest-host', vif.host) self.assertEqual(vif.port_id, vif.source_vif['id'])
def test_get_neutron_network_ovs_integration_bridge(self, mock_check): self.flags(integration_bridge='fake-bridge-id', group='vmware') vif_info = network_model.NetworkInfo([ network_model.VIF(type=network_model.VIF_TYPE_OVS, address='DE:AD:BE:EF:00:00', network=self._network)] )[0] network_ref = vif._get_neutron_network('fake-session', 'fake-cluster', vif_info) expected_ref = {'type': 'OpaqueNetwork', 'network-id': 'fake-bridge-id', 'network-type': 'opaque', 'use-external-id': False} self.assertEqual(expected_ref, network_ref) mock_check.assert_called_once_with('fake-session')
def _test_refresh_cache(self, method, *args, **kwargs): # This test verifies that no call to get_instance_nw_info() is made # from the @refresh_cache decorator for the tested method. with contextlib.nested( mock.patch.object(self.network_api.network_rpcapi, method), mock.patch.object(self.network_api.network_rpcapi, 'get_instance_nw_info'), mock.patch.object(network_model.NetworkInfo, 'hydrate'), ) as ( method_mock, nwinfo_mock, hydrate_mock ): nw_info = network_model.NetworkInfo([]) method_mock.return_value = nw_info hydrate_mock.return_value = nw_info getattr(self.network_api, method)(*args, **kwargs) hydrate_mock.assert_called_once_with(nw_info) self.assertFalse(nwinfo_mock.called)
def _build_network_info_model(self, context, instance, networks=None): search_opts = { 'tenant_id': instance['project_id'], 'device_id': instance['uuid'], } data = quantumv2.get_client(context).list_ports(**search_opts) ports = data.get('ports', []) if not networks: search_opts = {} if instance['project_id']: search_opts.update({"tenant_id": instance['project_id']}) data = quantumv2.get_client(context).list_networks(**search_opts) networks = data.get('networks', []) nw_info = network_model.NetworkInfo() for port in ports: network_name = None for net in networks: if port['network_id'] == net['id']: network_name = net['name'] break subnets = self._get_subnets_from_port(context, port) network_IPs = [ network_model.FixedIP(address=ip_address) for ip_address in [ip['ip_address'] for ip in port['fixed_ips']] ] # TODO(gongysh) get floating_ips for each fixed_ip for subnet in subnets: subnet['ips'] = [ fixed_ip for fixed_ip in network_IPs if fixed_ip.is_in_subnet(subnet) ] network = network_model.Network( id=port['network_id'], bridge='', # Quantum ignores this field injected=FLAGS.flat_injected, label=network_name, tenant_id=net['tenant_id']) network['subnets'] = subnets nw_info.append( network_model.VIF(id=port['id'], address=port['mac_address'], network=network)) return nw_info
def test_get_neutron_network_dvs(self, mock_network_name): fake_network_obj = { 'type': 'DistributedVirtualPortgroup', 'dvpg': 'fake-key', 'dvsw': 'fake-props' } mock_network_name.return_value = fake_network_obj vif_info = network_model.NetworkInfo([ network_model.VIF(type=network_model.VIF_TYPE_DVS, address='DE:AD:BE:EF:00:00', network=self._network) ])[0] network_ref = vif._get_neutron_network('fake-session', 'fake-cluster', vif_info) mock_network_name.assert_called_once_with('fake-session', 'fa0', 'fake-cluster') self.assertEqual(fake_network_obj, network_ref)
def test_get_neutron_network_ovs_logical_switch_id(self, mock_check): vif_info = network_model.NetworkInfo([ network_model.VIF(type=network_model.VIF_TYPE_OVS, address='DE:AD:BE:EF:00:00', network=self._network, details={'nsx-logical-switch-id': 'fake-nsx-id'}) ])[0] network_ref = vif._get_neutron_network('fake-session', 'fake-cluster', vif_info) expected_ref = { 'type': 'OpaqueNetwork', 'network-id': 'fake-nsx-id', 'network-type': 'nsx.LogicalSwitch', 'use-external-id': True } self.assertEqual(expected_ref, network_ref) mock_check.assert_called_once_with('fake-session')
def _build_network_info_model(self, context, instance_id, tenant_id, networks=None, port_ids=None): search_opts = {'tenant_id': tenant_id, 'device_id': instance_id, } client = neutronv2.get_client(context, admin=True) data = client.list_ports(**search_opts) current_neutron_ports = data.get('ports', []) nw_info = network_model.NetworkInfo() current_neutron_port_map = {} for current_neutron_port in current_neutron_ports: current_neutron_port_map[current_neutron_port['id']] = ( current_neutron_port) for port_id in port_ids: current_neutron_port = current_neutron_port_map.get(port_id) if current_neutron_port: vif_active = False if (current_neutron_port['admin_state_up'] is False or current_neutron_port['status'] == 'ACTIVE'): vif_active = True network_IPs = self._nw_info_get_ips(client, current_neutron_port) subnets = self._nw_info_get_subnets(context, current_neutron_port, network_IPs) devname = "tap" + current_neutron_port['id'] devname = devname[:network_model.NIC_NAME_LEN] network, ovs_interfaceid = ( self._nw_info_build_network(current_neutron_port, networks, subnets)) nw_info.append(network_model.VIF( id=current_neutron_port['id'], address=current_neutron_port['mac_address'], network=network, vnic_type=current_neutron_port.get('binding:vnic_type', network_model.VNIC_TYPE_NORMAL), type=current_neutron_port.get('binding:vif_type'), profile=current_neutron_port.get('binding:profile'), details=current_neutron_port.get('binding:vif_details'), ovs_interfaceid=ovs_interfaceid, devname=devname, active=vif_active)) return nw_info
def get_test_network_info(count=1): ipv6 = CONF.use_ipv6 fake = 'fake' fake_ip = '0.0.0.0' fake_netmask = '255.255.255.255' fake_vlan = 100 fake_bridge_interface = 'eth0' def current(): subnet_4 = network_model.Subnet(cidr=fake_ip, dns=[network_model.IP(fake_ip), network_model.IP(fake_ip)], gateway=network_model.IP(fake_ip), ips=[network_model.IP(fake_ip), network_model.IP(fake_ip)], routes=None, dhcp_server=fake_ip) subnet_6 = network_model.Subnet(cidr=fake_ip, gateway=network_model.IP(fake_ip), ips=[network_model.IP(fake_ip), network_model.IP(fake_ip), network_model.IP(fake_ip)], routes=None, version=6) subnets = [subnet_4] if ipv6: subnets.append(subnet_6) network = network_model.Network(id=None, bridge=fake, label=None, subnets=subnets, vlan=fake_vlan, bridge_interface=fake_bridge_interface, injected=False) vif = network_model.VIF(id='vif-xxx-yyy-zzz', address=fake, network=network, type=network_model.VIF_TYPE_BRIDGE, devname=None, ovs_interfaceid=None) return vif return network_model.NetworkInfo([current() for x in xrange(0, count)])
def _build_network_info_model(self, context, instance, networks=None): search_opts = { 'tenant_id': instance['project_id'], 'device_id': instance['uuid'], } client = neutronv2.get_client(context, admin=True) data = client.list_ports(**search_opts) ports = data.get('ports', []) if networks is None: # retrieve networks from info_cache to get correct nic order network_cache = self.conductor_api.instance_get_by_uuid( context, instance['uuid'])['info_cache']['network_info'] network_cache = jsonutils.loads(network_cache) net_ids = [iface['network']['id'] for iface in network_cache] networks = self._get_available_networks(context, instance['project_id']) # ensure ports are in preferred network order, and filter out # those not attached to one of the provided list of networks else: net_ids = [n['id'] for n in networks] ports = [port for port in ports if port['network_id'] in net_ids] _ensure_requested_network_ordering(lambda x: x['network_id'], ports, net_ids) nw_info = network_model.NetworkInfo() for port in ports: network_IPs = self._nw_info_get_ips(client, port) subnets = self._nw_info_get_subnets(context, port, network_IPs) devname = "tap" + port['id'] devname = devname[:network_model.NIC_NAME_LEN] network, ovs_interfaceid = self._nw_info_build_network( port, networks, subnets) nw_info.append( network_model.VIF(id=port['id'], address=port['mac_address'], network=network, type=port.get('binding:vif_type'), ovs_interfaceid=ovs_interfaceid, devname=devname)) return nw_info
def get_test_network_info(count=1): def current(): subnet_4 = network_model.Subnet( cidr=FAKE_NETWORK_IP4_CIDR, dns=[ network_model.IP(FAKE_NETWORK_DNS_IP4_ADDR1), network_model.IP(FAKE_NETWORK_DNS_IP4_ADDR2) ], gateway=network_model.IP(FAKE_NETWORK_IP4_GATEWAY), ips=[ network_model.IP(FAKE_NETWORK_IP4_ADDR1), network_model.IP(FAKE_NETWORK_IP4_ADDR2) ], routes=None, dhcp_server=FAKE_NETWORK_DHCP_IP4_ADDR) subnet_6 = network_model.Subnet( cidr=FAKE_NETWORK_IP6_CIDR, gateway=network_model.IP(FAKE_NETWORK_IP6_GATEWAY), ips=[ network_model.IP(FAKE_NETWORK_IP6_ADDR1), network_model.IP(FAKE_NETWORK_IP6_ADDR2), network_model.IP(FAKE_NETWORK_IP6_ADDR3) ], routes=None, version=6) subnets = [subnet_4, subnet_6] network = network_model.Network( id=FAKE_NETWORK_UUID, bridge=FAKE_NETWORK_BRIDGE, label=None, subnets=subnets, vlan=FAKE_NETWORK_VLAN, bridge_interface=FAKE_NETWORK_INTERFACE, injected=False) vif = network_model.VIF(id=FAKE_VIF_UUID, address=FAKE_VIF_MAC, network=network, type=network_model.VIF_TYPE_OVS, devname=None, ovs_interfaceid=None) return vif return network_model.NetworkInfo([current() for x in range(0, count)])
def deallocate_for_instance(self, context, instance, **kwargs): """Deallocate all network resources related to the instance.""" LOG.debug('deallocate_for_instance()', instance=instance) # This used to get a list of ports matching this device from Neutron and free them all. # We could instead list the port IDs of the VIFs and unbound the ones we know about. #search_opts = {'device_id': instance.uuid} client = self.client data = client.list_ports(owner=SERVICE_NAME, device=instance.uuid) ports = data.keys() # Reset device_id and device_owner for ports self._unbind_ports(context, ports) # NOTE(arosen): This clears out the network_cache only if the instance # hasn't already been deleted. This is needed when an instance fails to # launch and is rescheduled onto another compute node. If the instance # has already been deleted this call does nothing. base_api.update_instance_cache_with_nw_info( self, context, instance, network_model.NetworkInfo([]))
def test_has_port_with_allocation(self): network_info = model.NetworkInfo([]) self.assertFalse(network_info.has_port_with_allocation()) network_info.append(model.VIF(id=uuids.port_without_profile)) self.assertFalse(network_info.has_port_with_allocation()) network_info.append( model.VIF(id=uuids.port_no_allocation, profile={'foo': 'bar'})) self.assertFalse(network_info.has_port_with_allocation()) network_info.append( model.VIF(id=uuids.port_empty_alloc, profile={'allocation': None})) self.assertFalse(network_info.has_port_with_allocation()) network_info.append( model.VIF(id=uuids.port_with_alloc, profile={'allocation': uuids.rp})) self.assertTrue(network_info.has_port_with_allocation())
def test_get_network_ref_bridge(self, mock_ensure_vlan_bridge): network = network_model.Network(id=0, bridge='fa0', label='fake', vlan=3, bridge_interface='eth0', injected=True, should_create_vlan=True) self.vif = network_model.NetworkInfo([ network_model.VIF(id=None, address='DE:AD:BE:EF:00:00', network=network, type=None, devname=None, ovs_interfaceid=None, rxtx_cap=3) ])[0] vif.get_network_ref(self.session, self.cluster, self.vif, False) mock_ensure_vlan_bridge.assert_called_once_with( self.session, self.vif, cluster=self.cluster, create_vlan=True)
def _after_reboot(self): """Perform sync operation after host reboot.""" context = nova.context.get_admin_context() instances = objects.InstanceList.get_by_host( context, self.host, expected_attrs=['info_cache', 'metadata']) for instance in instances: if (instance.vm_state != vm_states.STOPPED): continue try: network_info = self.network_api.get_instance_nw_info( context, instance) except exception.InstanceNotFound: network_info = network_model.NetworkInfo() self.plug_vifs(instance, network_info) self.firewall_driver.setup_basic_filtering(instance, network_info) self.firewall_driver.prepare_instance_filter( instance, network_info) self.firewall_driver.apply_instance_filter(instance, network_info)
def test_get_neutron_network_dvs_provider(self, mock_network_name): fake_network_obj = { 'type': 'DistributedVirtualPortgroup', 'dvpg': 'fake-key', 'dvsw': 'fake-props' } mock_network_name.side_effect = [None, fake_network_obj] vif_info = network_model.NetworkInfo([ network_model.VIF(type=network_model.VIF_TYPE_DVS, address='DE:AD:BE:EF:00:00', network=self._network) ])[0] network_ref = vif._get_neutron_network('fake-session', 'fake-cluster', vif_info) calls = [ mock.call('fake-session', 'fa0', 'fake-cluster'), mock.call('fake-session', 'fake', 'fake-cluster') ] mock_network_name.assert_has_calls(calls) self.assertEqual(fake_network_obj, network_ref)
def setUp(self): super(VMwareVifTestCase, self).setUp() network = network_model.Network(id=0, bridge='fa0', label='fake', vlan=3, bridge_interface='eth0', injected=True) self._network = network self.vif = network_model.NetworkInfo([ network_model.VIF(id=None, address='DE:AD:BE:EF:00:00', network=network, type=None, devname=None, ovs_interfaceid=None, rxtx_cap=3) ])[0] self.session = fake.FakeSession() self.cluster = None
def stub_out_modules(self): # NOTE: if simulation mode is enabled, the virt driver will be replaced # by a fake driver. if CONF_BENCH.nova_patcher.enable_simulation: _SchedulerFakeDriver.setup() self.patch('nova.virt.fake.SchedulerFakeDriver', _SchedulerFakeDriver, add=True) fake_async_networkinfo = \ lambda *args, **kwargs: network_model.NetworkInfoAsyncWrapper( lambda *args, **kwargs: network_model.NetworkInfo()) fake_deallocate_networkinfo = lambda *args, **kwargs: None fake_check_requested_networks = lambda *args, **kwargs: 1 self.patch('nova.compute.manager.ComputeManager._allocate_network', fake_async_networkinfo) self.patch('nova.compute.manager.ComputeManager._deallocate_network', fake_deallocate_networkinfo) self.patch('nova.compute.api.API._check_requested_networks', fake_check_requested_networks)
def test_get_events(self): network_info = model.NetworkInfo([ model.VIF(id=uuids.hybrid_vif, details={'ovs_hybrid_plug': True}), model.VIF(id=uuids.normal_vif, details={'ovs_hybrid_plug': False}) ]) same_host = objects.Migration(source_compute='fake-host', dest_compute='fake-host') diff_host = objects.Migration(source_compute='fake-host1', dest_compute='fake-host2') # Same-host migrations will have all events be plug-time. self.assertCountEqual([('network-vif-plugged', uuids.normal_vif), ('network-vif-plugged', uuids.hybrid_vif)], network_info.get_plug_time_events(same_host)) # Same host migration will have no plug-time events. self.assertEqual([], network_info.get_bind_time_events(same_host)) # Diff-host migration + OVS hybrid plug = bind-time events self.assertEqual([('network-vif-plugged', uuids.hybrid_vif)], network_info.get_bind_time_events(diff_host)) # Diff-host migration + normal OVS = plug-time events self.assertEqual([('network-vif-plugged', uuids.normal_vif)], network_info.get_plug_time_events(diff_host))
def test_create_with_special_things(self): self.mox.StubOutWithMock(db, 'instance_create') fake_inst = fake_instance.fake_db_instance() db.instance_create(self.context, {'host': 'foo-host', 'security_groups': ['foo', 'bar'], 'info_cache': {'network_info': '[]'}, } ).AndReturn(fake_inst) self.mox.ReplayAll() secgroups = security_group.SecurityGroupList() secgroups.objects = [] for name in ('foo', 'bar'): secgroup = security_group.SecurityGroup() secgroup.name = name secgroups.objects.append(secgroup) info_cache = instance_info_cache.InstanceInfoCache() info_cache.network_info = network_model.NetworkInfo() inst = instance.Instance(host='foo-host', security_groups=secgroups, info_cache=info_cache) inst.create(self.context)
def setUp(self): super(VMwareVifTestCase, self).setUp() self.flags(vlan_interface='vmnet0', group='vmware') network = network_model.Network(id=0, bridge='fa0', label='fake', vlan=3, bridge_interface='eth0', injected=True) self.vif = network_model.NetworkInfo([ network_model.VIF(id=None, address='DE:AD:BE:EF:00:00', network=network, type=None, devname=None, ovs_interfaceid=None, rxtx_cap=3) ])[0] self.session = test_vmwareapi_vm_util.fake_session() self.cluster = None
def test_spawn_cleanup_on_fail(self): # Verify on a failed spawn, we get the original exception raised. # helper function def raise_(ex): raise ex self.flags(powervm_img_local_path='/images/') self.stubs.Set(images, 'fetch', lambda *x, **y: None) self.stubs.Set( self.powervm_connection._powervm._disk_adapter, 'create_volume_from_image', lambda *x, **y: raise_(exception.PowerVMImageCreationFailed())) self.stubs.Set( self.powervm_connection._powervm, '_cleanup', lambda *x, **y: raise_(Exception('This should be logged.'))) fake_net_info = network_model.NetworkInfo( [fake_network_cache_model.new_vif()]) self.assertRaises(exception.PowerVMImageCreationFailed, self.powervm_connection.spawn, context.get_admin_context(), self.instance, {'id': 'ANY_ID'}, [], 's3cr3t', fake_net_info)
def _allocate_provider_port(self, context, instance, network_info, instance_mac=None): api_port_mac = None tunnel_port_mac = None if instance_mac: api_port_mac = \ instance_mac[CONF.vtepdriver.provider_api_network_name] tunnel_port_mac = \ instance_mac[CONF.vtepdriver.provider_tunnel_network_name] provider_api_port = ProviderPort( CONF.vtepdriver.provider_api_network_id, api_port_mac) provider_tunnel_port = ProviderPort( CONF.vtepdriver.provider_tunnel_network_id, tunnel_port_mac, self._get_tunnel_network_name(network_info)) api_nwinfo = self._allocate_provider_port_for_instance( context, instance, provider_api_port) tunnel_nwinfo = self.\ _allocate_provider_port_for_instance(context, instance, provider_tunnel_port) if api_nwinfo is None or len(api_nwinfo) != 1 or \ tunnel_nwinfo is None or len(tunnel_nwinfo) != 1: raise exception.NovaException("Allocate provider port error ," + "driver allocate port return None") nwinfo = network_model.NetworkInfo() for vif in tunnel_nwinfo: nwinfo.append(vif) for vif in api_nwinfo: nwinfo.append(vif) return nwinfo
def _test_init_instance_reverts_crashed_migrations(self, old_vm_state=None): power_on = True if (not old_vm_state or old_vm_state == vm_states.ACTIVE) else False sys_meta = { 'old_vm_state': old_vm_state } instance = { 'uuid': 'foo', 'vm_state': vm_states.ERROR, 'task_state': task_states.RESIZE_MIGRATING, 'power_state': power_state.SHUTDOWN, 'system_metadata': sys_meta } fixed = dict(instance, task_state=None) self.mox.StubOutWithMock(compute_utils, 'get_nw_info_for_instance') self.mox.StubOutWithMock(utils, 'instance_sys_meta') self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') self.mox.StubOutWithMock(self.compute.driver, 'finish_revert_migration') self.mox.StubOutWithMock(self.compute, '_get_instance_volume_block_device_info') self.mox.StubOutWithMock(self.compute.driver, 'get_info') self.mox.StubOutWithMock(self.compute, '_instance_update') compute_utils.get_nw_info_for_instance(instance).AndReturn( network_model.NetworkInfo()) self.compute.driver.plug_vifs(instance, []) utils.instance_sys_meta(instance).AndReturn(sys_meta) self.compute._get_instance_volume_block_device_info( self.context, instance).AndReturn([]) self.compute.driver.finish_revert_migration(instance, [], [], power_on) self.compute._instance_update(self.context, instance['uuid'], task_state=None).AndReturn(fixed) self.compute.driver.get_info(fixed).AndReturn( {'state': power_state.SHUTDOWN}) self.mox.ReplayAll() self.compute._init_instance(self.context, instance)
def test_get_network_ref_bridge(self): self.mox.StubOutWithMock(vif, 'ensure_vlan_bridge') vif.ensure_vlan_bridge(self.session, self.vif, cluster=self.cluster, create_vlan=True) self.mox.ReplayAll() network = network_model.Network(id=0, bridge='fa0', label='fake', vlan=3, bridge_interface='eth0', injected=True, should_create_vlan=True) self.vif = network_model.NetworkInfo([ network_model.VIF(id=None, address='DE:AD:BE:EF:00:00', network=network, type=None, devname=None, ovs_interfaceid=None, rxtx_cap=3) ])[0] vif.get_network_ref(self.session, self.cluster, self.vif, False)
def _test_init_instance_update_nw_info_cache_helper(self, legacy_nwinfo): self.compute.driver.legacy_nwinfo = lambda *a, **k: legacy_nwinfo cached_nw_info = fake_network_cache_model.new_vif() cached_nw_info = network_model.NetworkInfo([cached_nw_info]) old_cached_nw_info = copy.deepcopy(cached_nw_info) # Folsom has no 'type' in network cache info. del old_cached_nw_info[0]['type'] fake_info_cache = {'network_info': old_cached_nw_info.json()} instance = { 'uuid': 'a-foo-uuid', 'vm_state': vm_states.ACTIVE, 'task_state': None, 'power_state': power_state.RUNNING, 'info_cache': fake_info_cache, } self.mox.StubOutWithMock(self.compute, '_get_power_state') self.compute._get_power_state(mox.IgnoreArg(), instance).AndReturn(power_state.RUNNING) if legacy_nwinfo: self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') # Call network API to get instance network info, and force # an update to instance's info_cache. self.compute._get_instance_nw_info( self.context, instance).AndReturn(cached_nw_info) self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') self.compute.driver.plug_vifs(instance, cached_nw_info.legacy()) else: self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') self.compute.driver.plug_vifs(instance, cached_nw_info) self.mox.ReplayAll() self.compute._init_instance(self.context, instance)
def create_instance(context, user_id='fake', project_id='fake', params=None): """Create a test instance.""" flavor = flavors.get_flavor_by_name('m1.tiny') net_info = model.NetworkInfo([]) info_cache = objects.InstanceInfoCache(network_info=net_info) inst = objects.Instance(context=context, image_ref=uuids.fake_image_ref, reservation_id='r-fakeres', user_id=user_id, project_id=project_id, instance_type_id=flavor.id, flavor=flavor, old_flavor=None, new_flavor=None, system_metadata={}, ami_launch_index=0, root_gb=0, ephemeral_gb=0, info_cache=info_cache) if params: inst.update(params) inst.create() return inst
def test_send_version_instance_update_uses_flavor(self, mock_emit): # Make sure that the notification payload chooses the values in # instance.flavor.$value instead of instance.$value test_keys = ['memory_mb', 'vcpus', 'root_gb', 'ephemeral_gb'] flavor_values = {k: 123 for k in test_keys} instance_values = {k: 456 for k in test_keys} flavor = objects.Flavor(**flavor_values) info_cache = objects.InstanceInfoCache( network_info=network_model.NetworkInfo()) instance = objects.Instance(flavor=flavor, info_cache=info_cache, **instance_values) payload = { 'bandwidth': {}, 'audit_period_ending': timeutils.utcnow(), 'audit_period_beginning': timeutils.utcnow(), } notification_base._send_versioned_instance_update( mock.MagicMock(), instance, payload, 'host', 'compute') payload = mock_emit.call_args_list[0][1]['payload']['nova_object.data'] flavor_payload = payload['flavor']['nova_object.data'] data = {k: flavor_payload[k] for k in test_keys} self.assertEqual(flavor_values, data)
def setUp(self): super(TestInstanceNotification, self).setUp() self.test_keys = ['memory_mb', 'vcpus', 'root_gb', 'ephemeral_gb', 'swap'] self.flavor_values = {k: 123 for k in self.test_keys} instance_values = {k: 456 for k in self.test_keys} flavor = objects.Flavor(flavorid='test-flavor', name='test-flavor', disabled=False, projects=[], is_public=True, extra_specs={}, **self.flavor_values) info_cache = objects.InstanceInfoCache( network_info=network_model.NetworkInfo()) self.instance = objects.Instance( flavor=flavor, info_cache=info_cache, metadata={}, uuid=uuids.instance1, locked=False, **instance_values) self.payload = { 'bandwidth': {}, 'audit_period_ending': timeutils.utcnow(), 'audit_period_beginning': timeutils.utcnow(), }
def test_ensure_network_metadata(self): network_a = fake_network_cache_model.new_network({ 'physical_network': 'foo', 'tunneled': False }) vif_a = fake_network_cache_model.new_vif({'network': network_a}) network_b = fake_network_cache_model.new_network({ 'physical_network': 'foo', 'tunneled': False }) vif_b = fake_network_cache_model.new_vif({'network': network_b}) network_c = fake_network_cache_model.new_network({ 'physical_network': 'bar', 'tunneled': False }) vif_c = fake_network_cache_model.new_vif({'network': network_c}) network_d = fake_network_cache_model.new_network({ 'physical_network': None, 'tunneled': True }) vif_d = fake_network_cache_model.new_vif({'network': network_d}) nw_info = network_model.NetworkInfo([vif_a, vif_b, vif_c, vif_d]) info_cache = objects.InstanceInfoCache(network_info=nw_info, instance_uuid=uuids.instance) instance = objects.Instance(id=3, uuid=uuids.instance, info_cache=info_cache) spec = objects.RequestSpec() self.assertNotIn('network_metadata', spec) spec.ensure_network_metadata(instance) self.assertIn('network_metadata', spec) self.assertIsInstance(spec.network_metadata, objects.NetworkMetadata) self.assertEqual(spec.network_metadata.physnets, set(['foo', 'bar'])) self.assertTrue(spec.network_metadata.tunneled)
def fake_networkinfo(*args, **kwargs): return network_model.NetworkInfo()