Exemple #1
0
 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'])
Exemple #2
0
 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_ip({'address': '10.10.0.2'}),
              fake_network_cache_model.new_ip(
                 {'address': '10.10.0.3'})] * 4)
Exemple #3
0
 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'})])
     deserialized = model.NetworkInfo.hydrate(ninfo)
     self.assertEqual(ninfo.fixed_ips(),
             [fake_network_cache_model.new_ip({'address': '10.10.0.2'}),
              fake_network_cache_model.new_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_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,
        )
Exemple #6
0
 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())
Exemple #7
0
 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())
Exemple #8
0
 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_ip(dict(address='10.10.0.2')),
             fake_network_cache_model.new_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 _test_injected_network_template(self, should_inject, use_ipv6=False,
                                        gateway=True):
        """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 should_inject:
            subnet_dict['dhcp_server'] = '10.10.0.1'

        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,
                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})
        ninfo = model.NetworkInfo([vif])

        template = netutils.get_injected_network_template(ninfo,
                                                          use_ipv6=use_ipv6)

        # will just ignore the improper behavior.
        if not should_inject:
            self.assertTrue(template is None)
        else:
            self.assertTrue('auto eth0' in template)
            self.assertTrue('iface eth0 inet static' in template)
            self.assertTrue('address 10.10.0.2' in template)
            self.assertTrue('netmask 255.255.255.0' in template)
            self.assertTrue('broadcast 10.10.0.255' in template)
            if gateway:
                self.assertTrue('gateway 10.10.0.1' in template)
            else:
                self.assertFalse('gateway' in template)
            self.assertTrue('dns-nameservers 1.2.3.4 2.3.4.5' in template)
            if use_ipv6:
                self.assertTrue('iface eth0 inet6 static' in template)
                self.assertTrue('address 1234:567::2' in template)
                self.assertTrue('netmask 48' in template)
                if gateway:
                    self.assertTrue('gateway 1234:567::1' in template)
Exemple #11
0
 def test_hydrate(self):
     new_vif = dict(id=1,
                    address='127.0.0.1',
                    network=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())
Exemple #12
0
    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)
Exemple #13
0
 def test_hydrate(self):
     new_vif = dict(
         id=1,
         address='127.0.0.1',
         network=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())
Exemple #14
0
 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())
Exemple #15
0
 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'}),
                 fake_network_cache_model.new_ip(
                     {'address': '10.10.0.3'})] * 2,
         'network_label': 'public'}
     self.assertEqual(labeled_ips, ip_dict)
Exemple #16
0
 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
Exemple #17
0
 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())
Exemple #18
0
    def _test_injected_network_template(self, should_inject, use_ipv6=False,
                                        legacy=False):
        """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': []})
        if should_inject:
            network.add_subnet(fake_network_cache_model.new_subnet())
            if 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'))
                subnet_dict = dict(
                        cidr='1234:567::/48',
                        gateway=gateway_ip,
                        ips=[ip])
                network.add_subnet(fake_network_cache_model.new_subnet(
                        subnet_dict))
        else:
            subnet_dict = dict(dhcp_server='10.10.0.1')
            network.add_subnet(fake_network_cache_model.new_subnet(
                    subnet_dict))
        # Behave as though CONF.flat_injected is True
        network['meta']['injected'] = True
        vif = fake_network_cache_model.new_vif({'network': network})
        ninfo = model.NetworkInfo([vif])
        if legacy:
            ninfo = ninfo.legacy()

        template = netutils.get_injected_network_template(ninfo,
                                                          use_ipv6=use_ipv6)

        # NOTE(bnemec): There is a bug with legacy network info that causes
        # it to inject regardless of whether the network is static or dynamic.
        # This can't be fixed without changes that would potentially break
        # existing code, so until legacy network info goes away this test
        # will just ignore the improper behavior.
        if not should_inject and not legacy:
            self.assertTrue(template is None)
        else:
            self.assertTrue('auto eth0' in template)
            self.assertTrue('iface eth0 inet static' in template)
            self.assertTrue('address 10.10.0.2' in template)
            self.assertTrue('netmask 255.255.255.0' in template)
            self.assertTrue('broadcast 10.10.0.255' in template)
            self.assertTrue('gateway 10.10.0.1' in template)
            self.assertTrue('dns-nameservers 1.2.3.4 2.3.4.5' in template)
            if use_ipv6:
                self.assertTrue('iface eth0 inet6 static' in template)
                self.assertTrue('address 1234:567::2' in template)
                self.assertTrue('netmask 48' in template)
                self.assertTrue('gateway 1234:567::1' in template)
 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
Exemple #20
0
    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 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 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_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)
Exemple #23
0
 def test_spawn_create_lpar_fail(self):
     self.flags(powervm_img_local_path='/images/')
     self.stubs.Set(images, 'fetch', lambda *x, **y: None)
     self.stubs.Set(
         self.powervm_connection._powervm, 'get_host_stats',
         lambda *x, **y: raise_(
             (processutils.ProcessExecutionError('instance_name'))))
     fake_net_info = network_model.NetworkInfo(
         [fake_network_cache_model.new_vif()])
     self.assertRaises(exception.PowerVMLPARCreationFailed,
                       self.powervm_connection.spawn,
                       context.get_admin_context(), self.instance,
                       {'id': 'ANY_ID'}, [], 's3cr3t', fake_net_info)
Exemple #24
0
    def test_spawn(self):
        def fake_image_fetch(context, image_id, file_path, user_id, project_id):
            pass

        self.flags(powervm_img_local_path="/images/")
        self.stubs.Set(images, "fetch", fake_image_fetch)
        image_meta = {}
        image_meta["id"] = "666"
        fake_net_info = network_model.NetworkInfo([fake_network_cache_model.new_vif()])
        self.powervm_connection.spawn(
            context.get_admin_context(), self.instance, image_meta, [], "s3cr3t", fake_net_info
        )
        state = self.powervm_connection.get_info(self.instance)["state"]
        self.assertEqual(state, power_state.RUNNING)
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 == "bad_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
Exemple #26
0
 def test_spawn(self):
     def fake_image_fetch(context, image_id, file_path,
                                 user_id, project_id):
         pass
     self.flags(powervm_img_local_path='/images/')
     self.stubs.Set(images, 'fetch', fake_image_fetch)
     image_meta = {}
     image_meta['id'] = '666'
     fake_net_info = network_model.NetworkInfo([
                                  fake_network_cache_model.new_vif()])
     self.powervm_connection.spawn(context.get_admin_context(),
                                   self.instance, image_meta, [], 's3cr3t',
                                   fake_net_info)
     state = self.powervm_connection.get_info(self.instance)['state']
     self.assertEqual(state, power_state.RUNNING)
Exemple #27
0
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 == 'bad_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
Exemple #28
0
 def test_spawn(self):
     def fake_image_fetch(context, image_id, file_path,
                                 user_id, project_id):
         pass
     self.flags(powervm_img_local_path='/images/')
     self.stubs.Set(images, 'fetch', fake_image_fetch)
     image_meta = {}
     image_meta['id'] = '666'
     fake_net_info = network_model.NetworkInfo([
                                  fake_network_cache_model.new_vif()])
     self.powervm_connection.spawn(context.get_admin_context(),
                                   self.instance, image_meta, [], 's3cr3t',
                                   fake_net_info)
     state = self.powervm_connection.get_info(self.instance)['state']
     self.assertEqual(state, power_state.RUNNING)
Exemple #29
0
 def test_spawn_create_lpar_fail(self):
     self.flags(powervm_img_local_path='/images/')
     self.stubs.Set(images, 'fetch', lambda *x, **y: None)
     self.stubs.Set(
         self.powervm_connection._powervm,
         'get_host_stats',
         lambda *x, **y: raise_(
             (processutils.ProcessExecutionError('instance_name'))))
     fake_net_info = network_model.NetworkInfo([
                                  fake_network_cache_model.new_vif()])
     self.assertRaises(exception.PowerVMLPARCreationFailed,
                       self.powervm_connection.spawn,
                       context.get_admin_context(),
                       self.instance,
                       {'id': 'ANY_ID'}, [], 's3cr3t', fake_net_info)
Exemple #30
0
 def test_spawn_cleanup_on_fail(self):
     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)
Exemple #31
0
 def test_spawn_cleanup_on_fail(self):
     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 _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, 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)
Exemple #33
0
 def test_spawn_create_lpar_fail(self):
     self.flags(powervm_img_local_path="/images/")
     self.stubs.Set(images, "fetch", lambda *x, **y: None)
     self.stubs.Set(
         self.powervm_connection._powervm,
         "get_host_stats",
         lambda *x, **y: raise_((processutils.ProcessExecutionError("instance_name"))),
     )
     fake_net_info = network_model.NetworkInfo([fake_network_cache_model.new_vif()])
     self.assertRaises(
         exception.PowerVMLPARCreationFailed,
         self.powervm_connection.spawn,
         context.get_admin_context(),
         self.instance,
         {"id": "ANY_ID"},
         [],
         "s3cr3t",
         fake_net_info,
     )
Exemple #34
0
    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)
Exemple #35
0
    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 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_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"])
Exemple #38
0
 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'})])
Exemple #39
0
    def _test_injected_network_template(self,
                                        should_inject,
                                        use_ipv4=True,
                                        use_ipv6=False,
                                        gateway=True):
        """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 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,
                                    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})
        ninfo = model.NetworkInfo([vif])

        template = netutils.get_injected_network_template(ninfo,
                                                          use_ipv6=use_ipv6)

        # will just ignore the improper behavior.
        if not should_inject:
            self.assertTrue(template is None)
        else:
            if use_ipv4:
                self.assertIn('auto eth0', template)
                self.assertIn('iface eth0 inet static', template)
                self.assertIn('address 10.10.0.2', template)
                self.assertIn('netmask 255.255.255.0', template)
                self.assertIn('broadcast 10.10.0.255', template)
                if gateway:
                    self.assertIn('gateway 10.10.0.1', template)
                else:
                    self.assertNotIn('gateway', template)
                self.assertIn('dns-nameservers 1.2.3.4 2.3.4.5', template)
            if use_ipv6:
                self.assertIn('iface eth0 inet6 static', template)
                self.assertIn('address 1234:567::2', template)
                self.assertIn('netmask 48', template)
                if gateway:
                    self.assertIn('gateway 1234:567::1', template)
            if not use_ipv4 and not use_ipv6:
                self.assertTrue(template is None)
Exemple #40
0
 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())
Exemple #41
0
 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'])