def test_get_floating_ips(self): vif = fake_network_cache_model.new_vif() vif['network']['subnets'][0]['ips'][0].add_floating_ip('192.168.1.1') ninfo = model.NetworkInfo([vif, fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'})]) self.assertEqual(['192.168.1.1'], ninfo.floating_ips())
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 test_get_floating_ips(self): vif = fake_network_cache_model.new_vif() vif['network']['subnets'][0]['ips'][0].add_floating_ip('192.168.1.1') ninfo = model.NetworkInfo([vif, fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'})]) self.assertEqual(ninfo.floating_ips(), ['192.168.1.1'])
def test_create_model(self): ninfo = model.NetworkInfo([ fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif({'address': 'bb:bb:bb:bb:bb:bb'}) ]) self.assertEqual([ fake_network_cache_model.new_fixed_ip({'address': '10.10.0.2'}), fake_network_cache_model.new_fixed_ip({'address': '10.10.0.3'}) ] * 4, ninfo.fixed_ips())
def test_create_model(self): ninfo = model.NetworkInfo([fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'})]) self.assertEqual( [fake_network_cache_model.new_fixed_ip( {'address': '10.10.0.2'}), fake_network_cache_model.new_fixed_ip( {'address': '10.10.0.3'})] * 4, ninfo.fixed_ips())
def test_hydrate(self): ninfo = model.NetworkInfo([fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'})]) model.NetworkInfo.hydrate(ninfo) self.assertEqual(ninfo.fixed_ips(), [fake_network_cache_model.new_fixed_ip( {'address': '10.10.0.2'}), fake_network_cache_model.new_fixed_ip( {'address': '10.10.0.3'})] * 4)
def test_hydrate(self): ninfo = model.NetworkInfo([ fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif({'address': 'bb:bb:bb:bb:bb:bb'}) ]) model.NetworkInfo.hydrate(ninfo) self.assertEqual(ninfo.fixed_ips(), [ fake_network_cache_model.new_fixed_ip({'address': '10.10.0.2'}), fake_network_cache_model.new_fixed_ip({'address': '10.10.0.3'}) ] * 4)
def test_create_model(self): ninfo = model.NetworkInfo( [fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif({"address": "bb:bb:bb:bb:bb:bb"})] ) self.assertEqual( ninfo.fixed_ips(), [ fake_network_cache_model.new_fixed_ip({"address": "10.10.0.2"}), fake_network_cache_model.new_fixed_ip({"address": "10.10.0.3"}), ] * 4, )
def test_add_floating_ip_policy(self, mock_add, mock_net): rule_name = "os_compute_api:os-floating-ips:add" ninfo = network_model.NetworkInfo([ fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif({'address': 'bb:bb:bb:bb:bb:bb'}) ]) mock_net.return_value = network_model.NetworkInfo.hydrate(ninfo) body = {'addFloatingIp': {'address': '1.2.3.4'}} self.common_policy_auth(self.project_member_authorized_contexts, rule_name, self.action_controller._add_floating_ip, self.req, self.instance.uuid, body=body)
def test_hydrate(self): fake_network_cache_model.new_network() vif = model.VIF.hydrate(fake_network_cache_model.new_vif()) self.assertEqual(1, vif['id']) self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address']) self.assertEqual(fake_network_cache_model.new_network(), vif['network'])
def test_vif_get_fixed_ips(self): vif = fake_network_cache_model.new_vif() fixed_ips = vif.fixed_ips() ips = [ fake_network_cache_model.new_fixed_ip(dict(address='10.10.0.2')), fake_network_cache_model.new_fixed_ip(dict(address='10.10.0.3')) ] * 2 self.assertEqual(fixed_ips, ips)
def test_hydrate_vif_with_type(self): vif_dict = dict( id=1, address="aa:aa:aa:aa:aa:aa", network=fake_network_cache_model.new_network(), type="bridge" ) vif = model.VIF.hydrate(fake_network_cache_model.new_vif(vif_dict)) self.assertEqual(vif["id"], 1) self.assertEqual(vif["address"], "aa:aa:aa:aa:aa:aa") self.assertEqual(vif["type"], "bridge") self.assertEqual(vif["network"], fake_network_cache_model.new_network())
def _setup_injected_network_scenario(self, should_inject=True, use_ipv4=True, use_ipv6=False, gateway=True, dns=True, two_interfaces=False, libvirt_virt_type=None): """Check that netutils properly decides whether to inject based on whether the supplied subnet is static or dynamic. """ network = fake_network_cache_model.new_network({'subnets': []}) subnet_dict = {} if not gateway: subnet_dict['gateway'] = None if not dns: subnet_dict['dns'] = None if not should_inject: subnet_dict['dhcp_server'] = '10.10.0.1' if use_ipv4: network.add_subnet( fake_network_cache_model.new_subnet(subnet_dict)) if should_inject and use_ipv6: gateway_ip = fake_network_cache_model.new_ip( dict(address='1234:567::1')) ip = fake_network_cache_model.new_ip(dict(address='1234:567::2')) ipv6_subnet_dict = dict( cidr='1234:567::/48', gateway=gateway_ip, dns=[ fake_network_cache_model.new_ip( dict(address='2001:4860:4860::8888')), fake_network_cache_model.new_ip( dict(address='2001:4860:4860::8844')) ], ips=[ip]) if not gateway: ipv6_subnet_dict['gateway'] = None network.add_subnet( fake_network_cache_model.new_subnet(ipv6_subnet_dict)) # Behave as though CONF.flat_injected is True network['meta']['injected'] = True vif = fake_network_cache_model.new_vif({'network': network}) vifs = [vif] if two_interfaces: vifs.append(vif) nwinfo = model.NetworkInfo(vifs) return netutils.get_injected_network_template( nwinfo, use_ipv6=use_ipv6, libvirt_virt_type=libvirt_virt_type)
def test_hydrate_vif_with_type(self): vif_dict = dict(id=1, address='aa:aa:aa:aa:aa:aa', network=fake_network_cache_model.new_network(), type='bridge') vif = model.VIF.hydrate(fake_network_cache_model.new_vif(vif_dict)) self.assertEqual(1, vif['id']) self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address']) self.assertEqual('bridge', vif['type']) self.assertEqual(fake_network_cache_model.new_network(), vif['network'])
def test_create_vif_with_type(self): vif_dict = dict(id=1, address='aa:aa:aa:aa:aa:aa', network=fake_network_cache_model.new_network(), type='bridge') vif = fake_network_cache_model.new_vif(vif_dict) self.assertEqual(vif['id'], 1) self.assertEqual(vif['address'], 'aa:aa:aa:aa:aa:aa') self.assertEqual(vif['type'], 'bridge') self.assertEqual(vif['network'], fake_network_cache_model.new_network())
def test_vif_get_labeled_ips(self): vif = fake_network_cache_model.new_vif() labeled_ips = vif.labeled_ips() ip_dict = { 'network_id': 1, 'ips': [fake_network_cache_model.new_ip( {'address': '10.10.0.2', 'type': 'fixed'}), fake_network_cache_model.new_ip( {'address': '10.10.0.3', 'type': 'fixed'})] * 2, 'network_label': 'public'} self.assertEqual(labeled_ips, ip_dict)
def test_create_vif_with_type(self): vif_dict = dict(id=uuids.vif_id, address='aa:aa:aa:aa:aa:aa', network=fake_network_cache_model.new_network(), type='bridge') vif = fake_network_cache_model.new_vif(vif_dict) self.assertEqual(uuids.vif_id, vif['id']) self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address']) self.assertEqual('bridge', vif['type']) self.assertEqual(fake_network_cache_model.new_network(), vif['network'])
def test_vif_get_labeled_ips(self): vif = fake_network_cache_model.new_vif() labeled_ips = vif.labeled_ips() ip_dict = { 'network_id': 1, 'ips': [fake_network_cache_model.new_ip( {'address': '10.10.0.2', 'type': 'fixed'}), fake_network_cache_model.new_ip( {'address': '10.10.0.3', 'type': 'fixed'})] * 2, 'network_label': 'public'} self.assertEqual(ip_dict, labeled_ips)
def fake_attach_interface(self, context, instance, network_id, port_id, requested_ip='192.168.1.3', tag=None): if not network_id: network_id = "fake_net_uuid" if not port_id: port_id = "fake_port_uuid" vif = fake_network_cache_model.new_vif() vif['id'] = port_id vif['network']['id'] = network_id vif['network']['subnets'][0]['ips'][0] = requested_ip return vif
def _setup_injected_network_scenario( self, should_inject=True, use_ipv4=True, use_ipv6=False, gateway=True, dns=True, two_interfaces=False, libvirt_virt_type=None, ): """Check that netutils properly decides whether to inject based on whether the supplied subnet is static or dynamic. """ network = fake_network_cache_model.new_network({"subnets": []}) subnet_dict = {} if not gateway: subnet_dict["gateway"] = None if not dns: subnet_dict["dns"] = None if not should_inject: subnet_dict["dhcp_server"] = "10.10.0.1" if use_ipv4: network.add_subnet(fake_network_cache_model.new_subnet(subnet_dict)) if should_inject and use_ipv6: gateway_ip = fake_network_cache_model.new_ip(dict(address="1234:567::1")) ip = fake_network_cache_model.new_ip(dict(address="1234:567::2")) ipv6_subnet_dict = dict( cidr="1234:567::/48", gateway=gateway_ip, dns=[ fake_network_cache_model.new_ip(dict(address="2001:4860:4860::8888")), fake_network_cache_model.new_ip(dict(address="2001:4860:4860::8844")), ], ips=[ip], ) if not gateway: ipv6_subnet_dict["gateway"] = None network.add_subnet(fake_network_cache_model.new_subnet(ipv6_subnet_dict)) # Behave as though CONF.flat_injected is True network["meta"]["injected"] = True vif = fake_network_cache_model.new_vif({"network": network}) vifs = [vif] if two_interfaces: vifs.append(vif) nwinfo = model.NetworkInfo(vifs) return netutils.get_injected_network_template(nwinfo, use_ipv6=use_ipv6, libvirt_virt_type=libvirt_virt_type)
def _new_netinfo(self, vif_type='ethernet'): netinfo = model.NetworkInfo([fake_network_cache_model.new_vif( {'type': vif_type})]) # Give this vif ipv4 and ipv6 dhcp subnets ipv4_subnet = fake_network_cache_model.new_subnet(version=4) ipv6_subnet = fake_network_cache_model.new_subnet(version=6) netinfo[0]['network']['subnets'][0] = ipv4_subnet netinfo[0]['network']['subnets'][1] = ipv6_subnet netinfo[0]['network']['meta']['mtu'] = 1500 return netinfo
def test_create_vif_with_type(self): vif_dict = dict( id=1, address='aa:aa:aa:aa:aa:aa', network=fake_network_cache_model.new_network(), type='bridge') vif = fake_network_cache_model.new_vif(vif_dict) self.assertEqual(vif['id'], 1) self.assertEqual(vif['address'], 'aa:aa:aa:aa:aa:aa') self.assertEqual(vif['type'], 'bridge') self.assertEqual(vif['network'], fake_network_cache_model.new_network())
def fake_attach_interface(self, context, instance, network_id, port_id, requested_ip='192.168.1.3'): if not network_id: network_id = "fake_net_uuid" if not port_id: port_id = "fake_port_uuid" vif = fake_network_cache_model.new_vif() vif['id'] = port_id vif['network']['id'] = network_id vif['network']['subnets'][0]['ips'][0] = requested_ip return vif
def setUp(self): super(TestNetworkMetadata, self).setUp() self.netinfo = model.NetworkInfo( [fake_network_cache_model.new_vif({'type': 'ethernet'})]) # Give this vif ipv4 and ipv6 dhcp subnets ipv4_subnet = fake_network_cache_model.new_subnet(version=4) ipv6_subnet = fake_network_cache_model.new_subnet(version=6) self.netinfo[0]['network']['subnets'][0] = ipv4_subnet self.netinfo[0]['network']['subnets'][1] = ipv6_subnet self.netinfo[0]['network']['meta']['mtu'] = 1500
def test_hydrate_vif_with_type(self): vif_dict = dict( id=1, address='aa:aa:aa:aa:aa:aa', network=fake_network_cache_model.new_network(), type='bridge') vif = model.VIF.hydrate(fake_network_cache_model.new_vif(vif_dict)) self.assertEqual(1, vif['id']) self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address']) self.assertEqual('bridge', vif['type']) self.assertEqual(fake_network_cache_model.new_network(), vif['network'])
def setUp(self): super(TestNetworkMetadata, self).setUp() self.netinfo = model.NetworkInfo([fake_network_cache_model.new_vif( {'type': 'ethernet'})]) # Give this vif ipv4 and ipv6 dhcp subnets ipv4_subnet = fake_network_cache_model.new_subnet(version=4) ipv6_subnet = fake_network_cache_model.new_subnet(version=6) self.netinfo[0]['network']['subnets'][0] = ipv4_subnet self.netinfo[0]['network']['subnets'][1] = ipv6_subnet self.netinfo[0]['network']['mtu'] = 1500
def _setup_injected_network_scenario(self, should_inject=True, use_ipv4=True, use_ipv6=False, gateway=True, dns=True, two_interfaces=False, libvirt_virt_type=None): """Check that netutils properly decides whether to inject based on whether the supplied subnet is static or dynamic. """ network = fake_network_cache_model.new_network({'subnets': []}) subnet_dict = {} if not gateway: subnet_dict['gateway'] = None if not dns: subnet_dict['dns'] = None if not should_inject: subnet_dict['dhcp_server'] = '10.10.0.1' if use_ipv4: network.add_subnet( fake_network_cache_model.new_subnet(subnet_dict)) if should_inject and use_ipv6: gateway_ip = fake_network_cache_model.new_ip(dict( address='1234:567::1')) ip = fake_network_cache_model.new_ip(dict( address='1234:567::2')) ipv6_subnet_dict = dict( cidr='1234:567::/48', gateway=gateway_ip, dns=[fake_network_cache_model.new_ip( dict(address='2001:4860:4860::8888')), fake_network_cache_model.new_ip( dict(address='2001:4860:4860::8844'))], ips=[ip]) if not gateway: ipv6_subnet_dict['gateway'] = None network.add_subnet(fake_network_cache_model.new_subnet( ipv6_subnet_dict)) # Behave as though CONF.flat_injected is True network['meta']['injected'] = True vif = fake_network_cache_model.new_vif({'network': network}) vifs = [vif] if two_interfaces: vifs.append(vif) nwinfo = model.NetworkInfo(vifs) return netutils.get_injected_network_template( nwinfo, use_ipv6=use_ipv6, libvirt_virt_type=libvirt_virt_type)
def test_vif_get_labeled_ips(self): vif = fake_network_cache_model.new_vif() labeled_ips = vif.labeled_ips() ip_dict = { "network_id": 1, "ips": [ fake_network_cache_model.new_ip({"address": "10.10.0.2", "type": "fixed"}), fake_network_cache_model.new_ip({"address": "10.10.0.3", "type": "fixed"}), ] * 2, "network_label": "public", } self.assertEqual(labeled_ips, ip_dict)
def fake_attach_interface(self, context, instance, network_id, port_id, requested_ip='192.168.1.3'): if not network_id: # if no network_id is given when add a port to an instance, use the # first default network. network_id = fake_networks[0] if network_id == FAKE_BAD_NET_ID: raise exception.NetworkNotFound(network_id=network_id) if not port_id: port_id = ports[fake_networks.index(network_id)]['id'] vif = fake_network_cache_model.new_vif() vif['id'] = port_id vif['network']['id'] = network_id vif['network']['subnets'][0]['ips'][0]['address'] = requested_ip return vif
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_attach_interface(self, context, instance, network_id, port_id, requested_ip="192.168.1.3"): if not network_id: # if no network_id is given when add a port to an instance, use the # first default network. network_id = fake_networks[0] if network_id == FAKE_BAD_NET_ID: raise exception.NetworkNotFound(network_id=network_id) if not port_id: port_id = ports[fake_networks.index(network_id)]["id"] if port_id == FAKE_NOT_FOUND_PORT_ID: raise exception.PortNotFound(port_id=port_id) vif = fake_network_cache_model.new_vif() vif["id"] = port_id vif["network"]["id"] = network_id vif["network"]["subnets"][0]["ips"][0]["address"] = requested_ip return vif
def fake_attach_interface(self, context, instance, network_id, port_id, requested_ip='192.168.1.3'): if not network_id: # if no network_id is given when add a port to an instance, use the # first default network. network_id = fake_networks[0] if network_id == FAKE_BAD_NET_ID: raise exception.NetworkNotFound(network_id=network_id) if not port_id: port_id = ports[fake_networks.index(network_id)]['id'] if port_id == FAKE_NOT_FOUND_PORT_ID: raise exception.PortNotFound(port_id=port_id) vif = fake_network_cache_model.new_vif() vif['id'] = port_id vif['network']['id'] = network_id vif['network']['subnets'][0]['ips'][0]['address'] = requested_ip return vif
def test_vif_get_floating_ips(self): vif = fake_network_cache_model.new_vif() vif['network']['subnets'][0]['ips'][0].add_floating_ip('192.168.1.1') floating_ips = vif.floating_ips() self.assertEqual(['192.168.1.1'], floating_ips)
def test_create_vif(self): vif = fake_network_cache_model.new_vif() self.assertEqual(vif['id'], 1) self.assertEqual(vif['address'], 'aa:aa:aa:aa:aa:aa') self.assertEqual(vif['network'], fake_network_cache_model.new_network())
def async_wrapper(): return model.NetworkInfo([ fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'}) ])
def test_create_vif(self): vif = fake_network_cache_model.new_vif() self.assertEqual(vif["id"], 1) self.assertEqual(vif["address"], "aa:aa:aa:aa:aa:aa") self.assertEqual(vif["network"], fake_network_cache_model.new_network())
def test_vif_get_floating_ips(self): vif = fake_network_cache_model.new_vif() vif["network"]["subnets"][0]["ips"][0].add_floating_ip("192.168.1.1") floating_ips = vif.floating_ips() self.assertEqual(floating_ips, ["192.168.1.1"])
def _test_schedule_provider_network(self, scheduler_hints, mock_get_all, mock_by_host, mock_get_by_binary, mock_get_all_states): vif_dict = dict(vif_model='virtio') fake_vif1 = fake_network_cache_model.new_vif(vif_dict) fake_vif2 = fake_network_cache_model.new_vif(vif_dict) fake_vif2['network']['id'] = 2 fake_vif3 = fake_network_cache_model.new_vif(vif_dict) fake_vif3['network']['id'] = 3 fake_vif4 = fake_network_cache_model.new_vif(vif_dict) fake_vif4['network']['id'] = 4 fake_nw_info = network_model.NetworkInfo([fake_vif1, fake_vif2, fake_vif3, fake_vif4]) fake_info_cache = objects.InstanceInfoCache(network_info=fake_nw_info) fake_inst = objects.Instance(info_cache=fake_info_cache) fake_build_req = objects.BuildRequest(instance=fake_inst) @staticmethod def _fake_get_by_instance_uuid(context, instance_uuid): return fake_build_req @staticmethod def _fake_get_by_uuid(context, instance_uuid): return fake_inst self.stub_out('nova.objects.BuildRequest.get_by_instance_uuid', _fake_get_by_instance_uuid) self.stub_out('nova.objects.Instance.get_by_uuid', _fake_get_by_uuid) def _fake_net_get_dict(context, network_uuid): if network_uuid == 1: return {'provider:physical_network': 'physnet0'} elif network_uuid == 2: return {'provider:physical_network': 'physnet1'} elif network_uuid == 3: return {'provider:physical_network': 'physnet1'} else: return {} from nova.network.neutronv2 import api as neutronapi self.driver.network_api = neutronapi.API() self.stubs.Set(self.driver.network_api, 'get_dict', _fake_net_get_dict) spec_obj = objects.RequestSpec( num_instances=1, flavor=objects.Flavor(memory_mb=512, root_gb=512, ephemeral_gb=0, vcpus=1, extra_specs={}), project_id=1, os_type='Linux', instance_uuid='00000000-aaaa-bbbb-cccc-000000000000', pci_requests=None, numa_topology=None, instance_group=None, scheduler_hints=scheduler_hints, # WRS extension display_name = 'fake-vm', name = 'instance-00000001', image=objects.ImageMeta(properties=objects.ImageMetaProps())) host_state = mock.Mock(spec=host_manager.HostState, host=mock.sentinel.host, uuid=uuids.cn1, numa_topology=None) all_host_states = [host_state] mock_get_all_states.return_value = all_host_states instance_uuids = [uuids.instance] allocs = \ [{'allocations': [ {'resources': {'VCPU': 1, 'MEMORY_MB': 512, 'DISK_GB': 512}, 'resource_provider': {'uuid': uuids.cn1}} ] }] alloc_reqs_by_rp_uuid = { uuids.cn1: allocs, } with mock.patch.object(self.driver.host_manager, 'get_filtered_hosts') as mock_get_hosts: mock_get_hosts.side_effect = fake_get_filtered_hosts hosts = self.driver._schedule(self.context, spec_obj, instance_uuids, alloc_reqs_by_rp_uuid, mock.sentinel.provider_summaries) self.assertEqual(len(hosts), 1) return spec_obj
def test_create_vif(self): vif = fake_network_cache_model.new_vif() self.assertEqual(1, vif['id']) self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address']) self.assertEqual(fake_network_cache_model.new_network(), vif['network'])
def test_get_floating_ips(self): vif = fake_network_cache_model.new_vif() vif["network"]["subnets"][0]["ips"][0].add_floating_ip("192.168.1.1") ninfo = model.NetworkInfo([vif, fake_network_cache_model.new_vif({"address": "bb:bb:bb:bb:bb:bb"})]) self.assertEqual(ninfo.floating_ips(), ["192.168.1.1"])
def test_hydrate(self): fake_network_cache_model.new_network() vif = model.VIF.hydrate(fake_network_cache_model.new_vif()) self.assertEqual(vif["id"], 1) self.assertEqual(vif["address"], "aa:aa:aa:aa:aa:aa") self.assertEqual(vif["network"], fake_network_cache_model.new_network())
def async_wrapper(): return model.NetworkInfo( [fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'})])
def async_wrapper(): return model.NetworkInfo( [fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif({"address": "bb:bb:bb:bb:bb:bb"})] )
def test_get_network_metadata(self): expected_json = { "links": [ { "ethernet_mac_address": "aa:aa:aa:aa:aa:aa", "id": "interface0", "type": "phy", "vif_id": 1, "mtu": 1500 }, { "ethernet_mac_address": "aa:aa:aa:aa:aa:ab", "id": "interface1", "type": "phy", "vif_id": 1, "mtu": 1500 }, ], "networks": [{ "id": "network0", "ip_address": "10.10.0.2", "link": "interface0", "netmask": "255.255.255.0", "network_id": "00000000-0000-0000-0000-000000000000", "routes": [{ "gateway": "10.10.0.1", "netmask": "0.0.0.0", "network": "0.0.0.0" }, { "gateway": "192.168.1.1", "netmask": "255.255.255.0", "network": "0.0.0.0" }], "type": "ipv4" }, { 'id': 'network1', 'ip_address': 'fd00::2', 'link': 'interface0', 'netmask': 'ffff:ffff:ffff::', 'network_id': '00000000-0000-0000-0000-000000000000', 'routes': [{ 'gateway': 'fd00::1', 'netmask': '::', 'network': '::' }, { 'gateway': 'fd00::1:1', 'netmask': 'ffff:ffff:ffff::', 'network': '::' }], 'type': 'ipv6' }, { "id": "network2", "ip_address": "192.168.0.2", "link": "interface1", "netmask": "255.255.255.0", "network_id": "11111111-1111-1111-1111-111111111111", "routes": [{ "gateway": "192.168.0.1", "netmask": "0.0.0.0", "network": "0.0.0.0" }], "type": "ipv4" }], 'services': [{ 'address': '1.2.3.4', 'type': 'dns' }, { 'address': '2.3.4.5', 'type': 'dns' }, { 'address': '1:2:3:4::', 'type': 'dns' }, { 'address': '2:3:4:5::', 'type': 'dns' }] } self.netinfo[0]['network']['id'] = ( '00000000-0000-0000-0000-000000000000') # Add a second NIC self.netinfo.append( fake_network_cache_model.new_vif({ 'type': 'ethernet', 'address': 'aa:aa:aa:aa:aa:ab' })) address = fake_network_cache_model.new_ip({'address': '192.168.0.2'}) gateway_address = fake_network_cache_model.new_ip( {'address': '192.168.0.1'}) ipv4_subnet = fake_network_cache_model.new_subnet({ 'cidr': '192.168.0.0/24', 'gateway': gateway_address, 'ips': [address], 'routes': [] }) self.netinfo[1]['network']['id'] = ( '11111111-1111-1111-1111-111111111111') self.netinfo[1]['network']['subnets'][0] = ipv4_subnet self.netinfo[1]['network']['meta']['mtu'] = 1500 network_json = netutils.get_network_metadata(self.netinfo) self.assertEqual(expected_json, network_json)
def test_get_network_metadata(self): expected_json = { "links": [ { "ethernet_mac_address": "aa:aa:aa:aa:aa:aa", "id": "interface0", "type": "phy", "vif_id": 1, "mtu": 1500 }, { "ethernet_mac_address": "aa:aa:aa:aa:aa:ab", "id": "interface1", "type": "phy", "vif_id": 1, "mtu": 1500 }, ], "networks": [ { "id": "network0", "ip_address": "10.10.0.2", "link": "interface0", "netmask": "255.255.255.0", "network_id": "00000000-0000-0000-0000-000000000000", "routes": [ { "gateway": "10.10.0.1", "netmask": "0.0.0.0", "network": "0.0.0.0" }, { "gateway": "192.168.1.1", "netmask": "255.255.255.0", "network": "0.0.0.0" } ], "type": "ipv4" }, { 'id': 'network1', 'ip_address': 'fd00::2', 'link': 'interface0', 'netmask': 'ffff:ffff:ffff::', 'network_id': '00000000-0000-0000-0000-000000000000', 'routes': [{'gateway': 'fd00::1', 'netmask': '::', 'network': '::'}, {'gateway': 'fd00::1:1', 'netmask': 'ffff:ffff:ffff::', 'network': '::'}], 'type': 'ipv6' }, { "id": "network2", "ip_address": "192.168.0.2", "link": "interface1", "netmask": "255.255.255.0", "network_id": "11111111-1111-1111-1111-111111111111", "routes": [ { "gateway": "192.168.0.1", "netmask": "0.0.0.0", "network": "0.0.0.0" } ], "type": "ipv4" } ], 'services': [ {'address': '1.2.3.4', 'type': 'dns'}, {'address': '2.3.4.5', 'type': 'dns'}, {'address': '1:2:3:4::', 'type': 'dns'}, {'address': '2:3:4:5::', 'type': 'dns'} ] } self.netinfo[0]['network']['id'] = ( '00000000-0000-0000-0000-000000000000') # Add a second NIC self.netinfo.append(fake_network_cache_model.new_vif({ 'type': 'ethernet', 'address': 'aa:aa:aa:aa:aa:ab'})) address = fake_network_cache_model.new_ip({'address': '192.168.0.2'}) gateway_address = fake_network_cache_model.new_ip( {'address': '192.168.0.1'}) ipv4_subnet = fake_network_cache_model.new_subnet( {'cidr': '192.168.0.0/24', 'gateway': gateway_address, 'ips': [address], 'routes': []}) self.netinfo[1]['network']['id'] = ( '11111111-1111-1111-1111-111111111111') self.netinfo[1]['network']['subnets'][0] = ipv4_subnet self.netinfo[1]['network']['mtu'] = 1500 network_json = netutils.get_network_metadata(self.netinfo) self.assertEqual(expected_json, network_json)