Ejemplo n.º 1
0
    def test__plug_vifs_count_mismatch(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(uuid=node_uuid)
        port = ironic_utils.get_test_port()

        mock_uvifs = mock.patch.object(self.driver, '_unplug_vifs').start()
        self.addCleanup(mock_uvifs.stop)
        mock_port_udt = mock.patch.object(FAKE_CLIENT.port, 'update').start()
        self.addCleanup(mock_port_udt.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'list_ports') as mock_lp:
            mock_lp.return_value = [port]

            instance = fake_instance.fake_instance_obj(self.ctx,
                                                       node=node_uuid)
            # len(network_info) > len(ports)
            network_info = (utils.get_test_network_info() +
                            utils.get_test_network_info())
            self.assertRaises(exception.NovaException, self.driver._plug_vifs,
                              node, instance, network_info)

            # asserts
            mock_uvifs.assert_called_once_with(node, instance, network_info)
            mock_lp.assert_called_once_with(node_uuid)
            # assert port.update() was not called
            assert not mock_port_udt.called
Ejemplo n.º 2
0
    def test__plug_vifs_count_mismatch(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(uuid=node_uuid)
        port = ironic_utils.get_test_port()

        mock_uvifs = mock.patch.object(self.driver, '_unplug_vifs').start()
        self.addCleanup(mock_uvifs.stop)
        mock_port_udt = mock.patch.object(FAKE_CLIENT.port, 'update').start()
        self.addCleanup(mock_port_udt.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'list_ports') as mock_lp:
            mock_lp.return_value = [port]

            instance = fake_instance.fake_instance_obj(self.ctx,
                                                       node=node_uuid)
            # len(network_info) > len(ports)
            network_info = (utils.get_test_network_info() +
                            utils.get_test_network_info())
            self.assertRaises(exception.NovaException,
                              self.driver._plug_vifs, node, instance,
                              network_info)

            # asserts
            mock_uvifs.assert_called_once_with(node, instance, network_info)
            mock_lp.assert_called_once_with(node_uuid)
            # assert port.update() was not called
            assert not mock_port_udt.called
Ejemplo n.º 3
0
    def test_build_network_config(self):
        net = utils.get_test_network_info(1, legacy_model=False)
        config = tilera.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertNotIn('eth1', config)

        net = utils.get_test_network_info(2, legacy_model=False)
        config = tilera.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertIn('eth1', config)
Ejemplo n.º 4
0
    def test_build_network_config(self):
        net = utils.get_test_network_info(1)
        config = pxe.build_network_config(net)
        self.assertIn("eth0", config)
        self.assertNotIn("eth1", config)

        net = utils.get_test_network_info(2)
        config = pxe.build_network_config(net)
        self.assertIn("eth0", config)
        self.assertIn("eth1", config)
Ejemplo n.º 5
0
    def test_build_network_config(self):
        net = utils.get_test_network_info(1)
        config = tilera.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertNotIn('eth1', config)

        net = utils.get_test_network_info(2)
        config = tilera.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertIn('eth1', config)
Ejemplo n.º 6
0
    def test_build_pxe_network_config(self):
        self.flags(pxe_network_config=True, group="baremetal")
        net = utils.get_test_network_info(1)
        config = pxe.build_pxe_network_config(net)
        self.assertIn("eth0:off", config)
        self.assertNotIn("eth1", config)

        net = utils.get_test_network_info(2)
        config = pxe.build_pxe_network_config(net)
        self.assertIn("eth0:off", config)
        self.assertIn("eth1:off", config)
Ejemplo n.º 7
0
    def test_build_pxe_network_config(self):
        self.flags(
                pxe_network_config=True,
                group='baremetal',
            )
        net = utils.get_test_network_info(1, legacy_model=False)
        config = pxe.build_pxe_network_config(net)
        self.assertIn('eth0:off', config)
        self.assertNotIn('eth1', config)

        net = utils.get_test_network_info(2, legacy_model=False)
        config = pxe.build_pxe_network_config(net)
        self.assertIn('eth0:off', config)
        self.assertIn('eth1:off', config)
Ejemplo n.º 8
0
    def test_build_pxe_network_config(self):
        self.flags(
            pxe_network_config=True,
            group='baremetal',
        )
        net = utils.get_test_network_info(1)
        config = pxe.build_pxe_network_config(net)
        self.assertIn('eth0:off', config)
        self.assertNotIn('eth1', config)

        net = utils.get_test_network_info(2)
        config = pxe.build_pxe_network_config(net)
        self.assertIn('eth0:off', config)
        self.assertIn('eth1:off', config)
Ejemplo n.º 9
0
    def _create_node(self, node_info=None, nic_info=None):
        result = {}
        if node_info is None:
            node_info = bm_db_utils.new_bm_node(id=123, service_host="test_host", cpus=2, memory_mb=2048)
        if nic_info is None:
            nic_info = [
                {"address": "01:23:45:67:89:01", "datapath_id": "0x1", "port_no": 1},
                {"address": "01:23:45:67:89:02", "datapath_id": "0x2", "port_no": 2},
            ]
        result["node_info"] = node_info
        result["nic_info"] = nic_info
        result["node"] = db.bm_node_create(self.context, node_info)

        for nic in nic_info:
            db.bm_interface_create(
                self.context, result["node"]["id"], nic["address"], nic["datapath_id"], nic["port_no"]
            )
        result["instance"] = utils.get_test_instance()
        result["instance"]["node"] = result["node"]["uuid"]
        result["spawn_params"] = dict(
            admin_password="******",
            block_device_info=None,
            context=self.context,
            image_meta=utils.get_test_image_info(None, result["instance"]),
            injected_files=[("/fake/path", "hello world")],
            instance=result["instance"],
            network_info=utils.get_test_network_info(),
        )
        result["destroy_params"] = dict(
            instance=result["instance"],
            network_info=result["spawn_params"]["network_info"],
            block_device_info=result["spawn_params"]["block_device_info"],
        )

        return result
Ejemplo n.º 10
0
 def test_unrescue_rescued_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.connection.rescue(self.ctxt, instance_ref, lambda x: None,
                            network_info)
     self.connection.unrescue(instance_ref, lambda x: None, network_info)
Ejemplo n.º 11
0
 def test_inject_file(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.connection.inject_file(instance_ref,
                                 base64.b64encode('/testfile'),
                                 base64.b64encode('testcontents'))
Ejemplo n.º 12
0
    def setUp(self):
        super(BareMetalVPDTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
            id=123,
            service_host='test_host',
            cpus=2,
            memory_mb=2048,
            prov_mac_address='aa:bb:cc:dd:ee:ff',
        )
        self.nic_info = [
            {
                'address': '11:11:11:11:11:11',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '22:22:22:22:22:22',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
        self.addCleanup(fake_image.FakeImageService_reset)
Ejemplo n.º 13
0
    def test_build_network_config(self):
        net = utils.get_test_network_info(1)
        config = pxe.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertNotIn('eth1', config)
        self.assertIn('hwaddress ether fake', config)
        self.assertNotIn('hwaddress ether aa:bb:cc:dd', config)

        net[0][1]['mac'] = 'aa:bb:cc:dd'
        config = pxe.build_network_config(net)
        self.assertIn('hwaddress ether aa:bb:cc:dd', config)

        net = utils.get_test_network_info(2)
        config = pxe.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertIn('eth1', config)
Ejemplo n.º 14
0
 def test_cannot_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'] = []
     self.assertRaises(exception.InstanceDeployFailure,
                       network.find_fixed_ip, instance, first_net)
Ejemplo n.º 15
0
    def test_build_network_config_static_parameters(self):
        self.flags(use_ipv6=True)
        self.flags(net_config_template='$pybasedir/nova/virt/baremetal/'
                   'net-static.ubuntu.template',
                   group='baremetal')

        net = utils.get_test_network_info()
        net[0]['network']['subnets'][0]['cidr'] = '10.1.1.0/24'
        net[0]['network']['subnets'][0]['gateway']['address'] = '10.1.1.1'
        net[0]['network']['subnets'][0]['dns'][0]['address'] = '10.1.1.2'
        net[0]['network']['subnets'][0]['dns'][1]['address'] = '10.1.1.3'

        net[0]['network']['subnets'][1]['cidr'] = 'fc00::/7'
        net[0]['network']['subnets'][1]['ips'][0]['address'] = 'fc00::1'
        net[0]['network']['subnets'][1]['gateway']['address'] = 'fc00::2'
        config = pxe.build_network_config(net)

        self.assertIn('iface eth0 inet static', config)
        self.assertIn('gateway 10.1.1.1', config)
        self.assertIn('dns-nameservers 10.1.1.2 10.1.1.3', config)

        self.assertIn('iface eth0 inet6 static', config)
        self.assertIn('address fc00::1', config)
        self.assertIn('netmask 7', config)
        self.assertIn('gateway fc00::2', config)
Ejemplo n.º 16
0
    def test_build_network_config(self):
        net = utils.get_test_network_info(1)
        config = pxe.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertNotIn('eth1', config)
        self.assertIn('hwaddress ether fake', config)
        self.assertNotIn('hwaddress ether aa:bb:cc:dd', config)

        net[0][1]['mac'] = 'aa:bb:cc:dd'
        config = pxe.build_network_config(net)
        self.assertIn('hwaddress ether aa:bb:cc:dd', config)

        net = utils.get_test_network_info(2)
        config = pxe.build_network_config(net)
        self.assertIn('eth0', config)
        self.assertIn('eth1', config)
Ejemplo n.º 17
0
    def test__plug_vifs(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(uuid=node_uuid)
        port = ironic_utils.get_test_port()

        mock_uvifs = mock.patch.object(self.driver, '_unplug_vifs').start()
        self.addCleanup(mock_uvifs.stop)

        mock_port_udt = mock.patch.object(FAKE_CLIENT.port, 'update').start()
        self.addCleanup(mock_port_udt.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'list_ports') as mock_lp:
            mock_lp.return_value = [port]

            instance = fake_instance.fake_instance_obj(self.ctx,
                                                       node=node_uuid)
            network_info = utils.get_test_network_info()

            port_id = unicode(network_info[0]['id'])
            expected_patch = [{
                'op': 'add',
                'path': '/extra/vif_port_id',
                'value': port_id
            }]
            self.driver._plug_vifs(node, instance, network_info)

            # asserts
            mock_uvifs.assert_called_once_with(node, instance, network_info)
            mock_lp.assert_called_once_with(node_uuid)
            mock_port_udt.assert_called_with(port.uuid, expected_patch)
Ejemplo n.º 18
0
 def _get_running_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
Ejemplo n.º 19
0
 def test__stop_firewall(self):
     fake_inst = 'fake-inst'
     fake_net_info = utils.get_test_network_info()
     with mock.patch.object(self.driver.firewall_driver,
                            'unfilter_instance') as mock_ui:
         self.driver._stop_firewall(fake_inst, fake_net_info)
         mock_ui.assert_called_once_with(fake_inst, fake_net_info)
Ejemplo n.º 20
0
 def test__stop_firewall(self):
     fake_inst = 'fake-inst'
     fake_net_info = utils.get_test_network_info()
     with mock.patch.object(self.driver.firewall_driver,
                            'unfilter_instance') as mock_ui:
         self.driver._stop_firewall(fake_inst, fake_net_info)
         mock_ui.assert_called_once_with(fake_inst, fake_net_info)
Ejemplo n.º 21
0
    def test_build_network_config_static_parameters(self):
        self.flags(use_ipv6=True)
        self.flags(
                net_config_template='$pybasedir/nova/virt/baremetal/'
                                    'net-static.ubuntu.template',
                group='baremetal'
            )

        net = utils.get_test_network_info()
        net[0]['network']['subnets'][0]['cidr'] = '10.1.1.0/24'
        net[0]['network']['subnets'][0]['gateway']['address'] = '10.1.1.1'
        net[0]['network']['subnets'][0]['dns'][0]['address'] = '10.1.1.2'
        net[0]['network']['subnets'][0]['dns'][1]['address'] = '10.1.1.3'

        net[0]['network']['subnets'][1]['cidr'] = 'fc00::/7'
        net[0]['network']['subnets'][1]['ips'][0]['address'] = 'fc00::1'
        net[0]['network']['subnets'][1]['gateway']['address'] = 'fc00::2'
        config = pxe.build_network_config(net)

        self.assertIn('iface eth0 inet static', config)
        self.assertIn('gateway 10.1.1.1', config)
        self.assertIn('dns-nameservers 10.1.1.2 10.1.1.3', config)

        self.assertIn('iface eth0 inet6 static', config)
        self.assertIn('address fc00::1', config)
        self.assertIn('netmask 7', config)
        self.assertIn('gateway fc00::2', config)
Ejemplo n.º 22
0
    def setUp(self):
        super(BareMetalTileraTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = tilera.Tilera(fake_virt.FakeVirtAPI())

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info()
        self.node_info = bm_db_utils.new_bm_node(
            service_host='test_host',
            cpus=4,
            memory_mb=2048,
        )
        self.nic_info = [
            {
                'address': '22:22:22:22:22:22',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '33:33:33:33:33:33',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
Ejemplo n.º 23
0
    def test_inject_into_image(self):
        self._create_node()
        files = []
        self.instance["hostname"] = "fake hostname"
        files.append(("/etc/hostname", "fake hostname"))
        self.instance["key_data"] = "fake ssh key"
        net_info = utils.get_test_network_info(1)
        net = tilera.build_network_config(net_info)
        admin_password = "******"

        self.mox.StubOutWithMock(os.path, "exists")
        os.path.exists(mox.IgnoreArg()).AndReturn(True)

        self.mox.StubOutWithMock(disk_api, "inject_data")
        disk_api.inject_data(
            admin_password=admin_password,
            image=tilera.get_image_file_path(self.instance),
            key="fake ssh key",
            metadata=None,
            partition=None,
            net=net,
            files=files,
        ).AndReturn(True)
        self.mox.ReplayAll()

        self.driver._inject_into_image(
            self.context,
            self.node,
            self.instance,
            network_info=net_info,
            admin_password=admin_password,
            injected_files=None,
        )
        self.mox.VerifyAll()
Ejemplo n.º 24
0
 def _get_running_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
Ejemplo n.º 25
0
    def setUp(self):
        super(VMwareAPIVMTestCase, self).setUp()
        self.context = context.RequestContext("fake", "fake", is_admin=False)
        self.flags(
            host_ip="test_url",
            host_username="******",
            host_password="******",
            use_linked_clone=False,
            group="vmware",
        )
        self.flags(vnc_enabled=False)
        self.user_id = "fake"
        self.project_id = "fake"
        self.node_name = "test_url"
        self.context = context.RequestContext(self.user_id, self.project_id)
        vmwareapi_fake.reset()
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.set_stubs(self.stubs)
        self.conn = driver.VMwareESXDriver(fake.FakeVirtAPI)
        # NOTE(vish): none of the network plugging code is actually
        #             being tested
        self.network_info = utils.get_test_network_info()

        self.image = {"id": "c1c8ce3d-c2e0-4247-890c-ccf5cc1c004c", "disk_format": "vhd", "size": 512}
        nova.tests.image.fake.stub_out_image_service(self.stubs)
Ejemplo n.º 26
0
    def setUp(self):
        super(VMwareAPIVMTestCase, self).setUp()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        self.flags(host_ip='test_url',
                   host_username='******',
                   host_password='******',
                   cluster_name='test_cluster',
                   use_linked_clone=False, group='vmware')
        self.flags(vnc_enabled=False)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.node_name = 'test_url'
        self.context = context.RequestContext(self.user_id, self.project_id)
        vmwareapi_fake.reset()
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.set_stubs(self.stubs)
        self.conn = driver.VMwareESXDriver(fake.FakeVirtAPI)
        # NOTE(vish): none of the network plugging code is actually
        #             being tested
        self.network_info = utils.get_test_network_info()

        self.image = {
            'id': 'c1c8ce3d-c2e0-4247-890c-ccf5cc1c004c',
            'disk_format': 'vhd',
            'size': 512,
        }
        nova.tests.image.fake.stub_out_image_service(self.stubs)
Ejemplo n.º 27
0
    def setUp(self):
        super(BareMetalPXETestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = pxe.PXE()

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
                id=123,
                service_host='test_host',
                cpus=2,
                memory_mb=2048,
                prov_mac_address='11:11:11:11:11:11',
            )
        self.nic_info = [
                {'address': '22:22:22:22:22:22', 'datapath_id': '0x1',
                    'port_no': 1},
                {'address': '33:33:33:33:33:33', 'datapath_id': '0x2',
                    'port_no': 2},
            ]
Ejemplo n.º 28
0
 def test_power_on(self):
     node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
     instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
     with mock.patch.object(FAKE_CLIENT.node, 'set_power_state') as mock_sp:
         self.driver.power_on(self.ctx, instance,
                              utils.get_test_network_info())
         mock_sp.assert_called_once_with(node_uuid, 'on')
Ejemplo n.º 29
0
 def test_inject_file(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.connection.inject_file(instance_ref,
                                 base64.b64encode('/testfile'),
                                 base64.b64encode('testcontents'))
Ejemplo n.º 30
0
    def setUp(self):
        super(VMwareAPIVMTestCase, self).setUp()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        self.flags(host_ip='test_url',
                   host_username='******',
                   host_password='******',
                   cluster_name='test_cluster',
                   use_linked_clone=False, group='vmware')
        self.flags(vnc_enabled=False)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.node_name = 'test_url'
        self.context = context.RequestContext(self.user_id, self.project_id)
        vmwareapi_fake.reset()
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.set_stubs(self.stubs)
        self.conn = driver.VMwareESXDriver(fake.FakeVirtAPI)
        # NOTE(vish): none of the network plugging code is actually
        #             being tested
        self.network_info = utils.get_test_network_info()

        self.image = {
            'id': 'c1c8ce3d-c2e0-4247-890c-ccf5cc1c004c',
            'disk_format': 'vhd',
            'size': 512,
        }
        nova.tests.image.fake.stub_out_image_service(self.stubs)
        self.vnc_host = 'test_url'
Ejemplo n.º 31
0
 def test_ensure_filtering_rules_for_instance(self, mock_pif, mock_sbf):
     instance = fake_instance.fake_instance_obj(self.ctx)
     network_info = utils.get_test_network_info()
     self.driver.ensure_filtering_rules_for_instance(instance,
                                                     network_info)
     mock_sbf.assert_called_once_with(instance, network_info)
     mock_pif.assert_called_once_with(instance, network_info)
Ejemplo n.º 32
0
    def test_inject_into_image(self):
        # NOTE(deva): we could also test this method by stubbing
        #             nova.virt.disk.api._inject_*_into_fs
        self._create_node()
        files = []
        self.instance['hostname'] = 'fake hostname'
        files.append(('/etc/hostname', 'fake hostname'))
        self.instance['key_data'] = 'fake ssh key'
        net_info = utils.get_test_network_info(1)
        net = pxe.build_network_config(net_info)
        admin_password = '******'

        self.mox.StubOutWithMock(disk_api, 'inject_data')
        disk_api.inject_data(
                admin_password=admin_password,
                image=pxe.get_image_file_path(self.instance),
                key='fake ssh key',
                metadata=None,
                partition=None,
                net=net,
                files=files,    # this is what we're really testing
            ).AndReturn(True)
        self.mox.ReplayAll()

        self.driver._inject_into_image(
                self.context, self.node, self.instance,
                network_info=net_info,
                admin_password=admin_password,
                injected_files=None)
        self.mox.VerifyAll()
Ejemplo n.º 33
0
    def test__plug_vifs(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(uuid=node_uuid)
        port = ironic_utils.get_test_port()

        mock_uvifs = mock.patch.object(self.driver, '_unplug_vifs').start()
        self.addCleanup(mock_uvifs.stop)

        mock_port_udt = mock.patch.object(FAKE_CLIENT.port, 'update').start()
        self.addCleanup(mock_port_udt.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'list_ports') as mock_lp:
            mock_lp.return_value = [port]

            instance = fake_instance.fake_instance_obj(self.ctx,
                                                       node=node_uuid)
            network_info = utils.get_test_network_info()

            port_id = unicode(network_info[0]['id'])
            expected_patch = [{'op': 'add',
                               'path': '/extra/vif_port_id',
                               'value': port_id}]
            self.driver._plug_vifs(node, instance, network_info)

            # asserts
            mock_uvifs.assert_called_once_with(node, instance, network_info)
            mock_lp.assert_called_once_with(node_uuid)
            mock_port_udt.assert_called_with(port.uuid, expected_patch)
Ejemplo n.º 34
0
 def test_cannot_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'] = []
     self.assertRaises(exception.InstanceDeployFailure,
                       network.find_fixed_ip, instance, first_net)
Ejemplo n.º 35
0
    def test_inject_into_image(self):
        self._create_node()
        files = []
        self.instance['hostname'] = 'fake hostname'
        files.append(('/etc/hostname', 'fake hostname'))
        self.instance['key_data'] = 'fake ssh key'
        net_info = utils.get_test_network_info(1)
        net = tilera.build_network_config(net_info)
        admin_password = '******'

        self.mox.StubOutWithMock(disk_api, 'inject_data')
        disk_api.inject_data(
                admin_password=admin_password,
                image=tilera.get_image_file_path(self.instance),
                key='fake ssh key',
                metadata=None,
                partition=None,
                net=net,
                files=files,
            ).AndReturn(True)
        self.mox.ReplayAll()

        self.driver._inject_into_image(
                self.context, self.node, self.instance,
                network_info=net_info,
                admin_password=admin_password,
                injected_files=None)
        self.mox.VerifyAll()
Ejemplo n.º 36
0
    def test_inject_into_image(self):
        # NOTE(deva): we could also test this method by stubbing
        #             nova.virt.disk.api._inject_*_into_fs
        self._create_node()
        files = []
        self.instance['hostname'] = 'fake hostname'
        files.append(('/etc/hostname', 'fake hostname'))
        self.instance['key_data'] = 'fake ssh key'
        net_info = utils.get_test_network_info(1)
        net = pxe.build_network_config(net_info)
        admin_password = '******'

        self.mox.StubOutWithMock(disk_api, 'inject_data')
        disk_api.inject_data(
            admin_password=admin_password,
            image=pxe.get_image_file_path(self.instance),
            key='fake ssh key',
            metadata=None,
            partition=None,
            net=net,
            files=files,  # this is what we're really testing
        ).AndReturn(True)
        self.mox.ReplayAll()

        self.driver._inject_into_image(self.context,
                                       self.node,
                                       self.instance,
                                       network_info=net_info,
                                       admin_password=admin_password,
                                       injected_files=None)
        self.mox.VerifyAll()
Ejemplo n.º 37
0
 def test_unrescue_rescued_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.connection.rescue(self.ctxt, instance_ref,
                            lambda x: None, network_info)
     self.connection.unrescue(instance_ref, lambda x: None, network_info)
Ejemplo n.º 38
0
    def test_build_network_config_static_parameters(self):
        self.flags(use_ipv6=True)
        self.flags(
            net_config_template="$pybasedir/nova/virt/baremetal/" "net-static.ubuntu.template", group="baremetal"
        )

        net = utils.get_test_network_info()
        net[0]["network"]["subnets"][0]["cidr"] = "10.1.1.0/24"
        net[0]["network"]["subnets"][0]["gateway"]["address"] = "10.1.1.1"
        net[0]["network"]["subnets"][0]["dns"][0]["address"] = "10.1.1.2"
        net[0]["network"]["subnets"][0]["dns"][1]["address"] = "10.1.1.3"

        net[0]["network"]["subnets"][1]["cidr"] = "fc00::/7"
        net[0]["network"]["subnets"][1]["ips"][0]["address"] = "fc00::1"
        net[0]["network"]["subnets"][1]["gateway"]["address"] = "fc00::2"
        config = pxe.build_network_config(net)

        self.assertIn("iface eth0 inet static", config)
        self.assertIn("gateway 10.1.1.1", config)
        self.assertIn("dns-nameservers 10.1.1.2 10.1.1.3", config)

        self.assertIn("iface eth0 inet6 static", config)
        self.assertIn("address fc00::1", config)
        self.assertIn("netmask 7", config)
        self.assertIn("gateway fc00::2", config)
Ejemplo n.º 39
0
    def test_unplug_vifs(self):
        node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
        node = ironic_utils.get_test_node(uuid=node_uuid)
        port = ironic_utils.get_test_port()

        mock_update = mock.patch.object(FAKE_CLIENT.port, 'update').start()
        self.addCleanup(mock_update.stop)
        mock_get = mock.patch.object(FAKE_CLIENT.node, 'get').start()
        mock_get.return_value = node
        self.addCleanup(mock_get.stop)

        with mock.patch.object(FAKE_CLIENT.node, 'list_ports') as mock_lp:
            mock_lp.return_value = [port]

            instance = fake_instance.fake_instance_obj(self.ctx,
                                                       node=node_uuid)
            expected_patch = [{'op': 'remove', 'path':
                               '/extra/vif_port_id'}]
            self.driver.unplug_vifs(instance,
                                    utils.get_test_network_info())

            # asserts
            mock_get.assert_called_once_with(node_uuid)
            mock_lp.assert_called_once_with(node_uuid)
            mock_update.assert_called_once_with(port.uuid, expected_patch)
Ejemplo n.º 40
0
 def _get_running_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     network_info[0]["network"]["subnets"][0]["meta"]["dhcp_server"] = "1.1.1.1"
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info, [], "herp", network_info=network_info)
     return instance_ref, network_info
Ejemplo n.º 41
0
 def test_build_network_config_dhcp(self):
     self.flags(net_config_template="$pybasedir/nova/virt/baremetal/" "net-dhcp.ubuntu.template", group="baremetal")
     net = utils.get_test_network_info()
     net[0][1]["ips"][0]["ip"] = "1.2.3.4"
     config = pxe.build_network_config(net)
     self.assertIn("iface eth0 inet dhcp", config)
     self.assertNotIn("address 1.2.3.4", config)
Ejemplo n.º 42
0
 def test_get_vnc_console(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     vnc_console = self.connection.get_vnc_console(instance_ref)
     self.assertIn('token', vnc_console)
     self.assertIn('host', vnc_console)
     self.assertIn('port', vnc_console)
Ejemplo n.º 43
0
 def test_attach_detach_volume(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.connection.attach_volume(instance_ref['name'], '/dev/null',
                                   '/mnt/nova/something')
     self.connection.detach_volume(instance_ref['name'],
                                   '/mnt/nova/something')
Ejemplo n.º 44
0
 def test_get_console_pool_info(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     console_pool = self.connection.get_console_pool_info(instance_ref)
     self.assertIn('address', console_pool)
     self.assertIn('username', console_pool)
     self.assertIn('password', console_pool)
Ejemplo n.º 45
0
 def test_get_vnc_console(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     vnc_console = self.connection.get_vnc_console(instance_ref)
     self.assertIn('token', vnc_console)
     self.assertIn('host', vnc_console)
     self.assertIn('port', vnc_console)
Ejemplo n.º 46
0
 def test_attach_detach_volume(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.connection.attach_volume(instance_ref['name'],
                                   '/dev/null', '/mnt/nova/something')
     self.connection.detach_volume(instance_ref['name'],
                                   '/mnt/nova/something')
Ejemplo n.º 47
0
 def test_get_console_pool_info(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     console_pool = self.connection.get_console_pool_info(instance_ref)
     self.assertIn('address', console_pool)
     self.assertIn('username', console_pool)
     self.assertIn('password', console_pool)
Ejemplo n.º 48
0
    def test__start_firewall(self, mock_aif, mock_sbf, mock_pif):
        fake_inst = 'fake-inst'
        fake_net_info = utils.get_test_network_info()
        self.driver._start_firewall(fake_inst, fake_net_info)

        mock_aif.assert_called_once_with(fake_inst, fake_net_info)
        mock_sbf.assert_called_once_with(fake_inst, fake_net_info)
        mock_pif.assert_called_once_with(fake_inst, fake_net_info)
Ejemplo n.º 49
0
    def test__start_firewall(self, mock_aif, mock_sbf, mock_pif):
        fake_inst = 'fake-inst'
        fake_net_info = utils.get_test_network_info()
        self.driver._start_firewall(fake_inst, fake_net_info)

        mock_aif.assert_called_once_with(fake_inst, fake_net_info)
        mock_sbf.assert_called_once_with(fake_inst, fake_net_info)
        mock_pif.assert_called_once_with(fake_inst, fake_net_info)
Ejemplo n.º 50
0
 def test_destroy_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     self.assertIn(instance_ref['name'], self.connection.list_instances())
     self.connection.destroy(instance_ref, network_info)
     self.assertNotIn(instance_ref['name'],
                      self.connection.list_instances())
Ejemplo n.º 51
0
 def test_destroy_instance_nonexistent(self):
     fake_instance = {
         'id': 42,
         'name': 'I just made this up!',
         'uuid': 'bda5fb9e-b347-40e8-8256-42397848cb00'
     }
     network_info = test_utils.get_test_network_info()
     self.connection.destroy(self.ctxt, fake_instance, network_info)
Ejemplo n.º 52
0
    def _create_node(self, node_info=None, nic_info=None, ephemeral=True):
        result = {}
        if node_info is None:
            node_info = bm_db_utils.new_bm_node(
                id=123,
                service_host='test_host',
                cpus=2,
                memory_mb=2048,
            )
        if nic_info is None:
            nic_info = [
                {
                    'address': '01:23:45:67:89:01',
                    'datapath_id': '0x1',
                    'port_no': 1
                },
                {
                    'address': '01:23:45:67:89:02',
                    'datapath_id': '0x2',
                    'port_no': 2
                },
            ]
        result['node_info'] = node_info
        result['nic_info'] = nic_info
        result['node'] = db.bm_node_create(self.context, node_info)

        for nic in nic_info:
            db.bm_interface_create(
                self.context,
                result['node']['id'],
                nic['address'],
                nic['datapath_id'],
                nic['port_no'],
            )
        if ephemeral:
            result['instance'] = utils.get_test_instance()
        else:
            flavor = utils.get_test_flavor(options={'ephemeral_gb': 0})
            result['instance'] = utils.get_test_instance(flavor=flavor)
        result['instance']['node'] = result['node']['uuid']
        result['spawn_params'] = dict(
            admin_password='******',
            block_device_info=None,
            context=self.context,
            image_meta=utils.get_test_image_info(None, result['instance']),
            injected_files=[('/fake/path', 'hello world')],
            instance=result['instance'],
            network_info=utils.get_test_network_info(),
        )
        result['destroy_params'] = dict(
            context=self.context,
            instance=result['instance'],
            network_info=result['spawn_params']['network_info'],
            block_device_info=result['spawn_params']['block_device_info'],
        )

        return result
Ejemplo n.º 53
0
 def test_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'][0]['cidr'] = '10.0.0.0/24'
     first_net['subnets'][0]['ips'][0]['type'] = 'fixed'
     first_net['subnets'][0]['ips'][0]['address'] = '10.0.1.13'
     self.assertEqual('10.0.1.13/24',
                      network.find_fixed_ip(instance, first_net))
Ejemplo n.º 54
0
 def _get_running_instance(self, obj=False):
     instance_ref = test_utils.get_test_instance(obj=obj)
     network_info = test_utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = \
         '1.1.1.1'
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
Ejemplo n.º 55
0
    def test_spawn(self):
        instance_ref = test_utils.get_test_instance()
        network_info = test_utils.get_test_network_info()
        self.connection.spawn(self.ctxt, instance_ref, network_info)

        domains = self.connection.list_instances()
        self.assertIn(instance_ref['name'], domains)

        domains_details = self.connection.list_instances_detail()
        self.assertIn(instance_ref['name'], [i.name for i in domains_details])
 def _get_running_instance(self):
     instance_ref = test_utils.get_test_instance()
     instance_ref['instance_type_id'] = self.router_type_id
     network_info = test_utils.get_test_network_info()
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt,
                           instance=instance_ref,
                           image_meta=image_info,
                           network_info=network_info)
     return instance_ref, network_info
Ejemplo n.º 57
0
 def test_get_info(self):
     network_info = test_utils.get_test_network_info()
     instance_ref = test_utils.get_test_instance()
     self.connection.spawn(self.ctxt, instance_ref, network_info)
     info = self.connection.get_info(instance_ref['name'])
     self.assertIn('state', info)
     self.assertIn('max_mem', info)
     self.assertIn('mem', info)
     self.assertIn('num_cpu', info)
     self.assertIn('cpu_time', info)