Пример #1
0
    def test_deactivate_bootloader_for_nonexistent_instance(self):
        self._create_node()
        self.instance['uuid'] = 'fake-uuid'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)

        self.mox.StubOutWithMock(utils, 'unlink_without_raise')
        self.mox.StubOutWithMock(utils, 'rmtree_without_raise')
        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses')

        extra_specs = dict(extra_specs={
            'baremetal:deploy_ramdisk_id': 'ignore',
            'baremetal:deploy_kernel_id': 'ignore'})
        pxe.get_tftp_image_info(self.instance, extra_specs).\
                AndRaise(exception.NovaException)
        utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndRaise(db_exc.DBError)
        utils.rmtree_without_raise(
                os.path.join(CONF.baremetal.tftp_root, 'fake-uuid'))
        self.mox.ReplayAll()

        self.driver.deactivate_bootloader(
            self.context, self.node, self.instance)
        self.mox.VerifyAll()
Пример #2
0
    def test_cache_images(self):
        self._create_node()
        self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get')
        self.mox.StubOutWithMock(pxe, "get_tftp_image_info")
        self.mox.StubOutWithMock(self.driver, "_cache_tftp_images")
        self.mox.StubOutWithMock(self.driver, "_cache_image")
        self.mox.StubOutWithMock(self.driver, "_inject_into_image")

        self.driver.virtapi.instance_type_get(
            self.context, self.instance['instance_type_id']).AndReturn({})
        pxe.get_tftp_image_info(self.instance, {}).AndReturn([])
        self.driver._cache_tftp_images(self.context, self.instance, [])
        self.driver._cache_image(self.context, self.instance, [])
        self.driver._inject_into_image(self.context, self.node, self.instance,
                self.test_network_info, None, '')
        self.mox.ReplayAll()

        self.driver.cache_images(
                self.context, self.node, self.instance,
                admin_password='',
                image_meta=[],
                injected_files=None,
                network_info=self.test_network_info,
            )
        self.mox.VerifyAll()
Пример #3
0
    def test_deactivate_bootloader_for_nonexistent_instance(self):
        self._create_node()
        self.instance['uuid'] = 'fake-uuid'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)

        self.mox.StubOutWithMock(utils, 'unlink_without_raise')
        self.mox.StubOutWithMock(utils, 'rmtree_without_raise')
        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses')

        extra_specs = dict(extra_specs={
            'baremetal:deploy_ramdisk_id': 'ignore',
            'baremetal:deploy_kernel_id': 'ignore'})
        pxe.get_tftp_image_info(self.instance, extra_specs).\
                AndRaise(exception.NovaException)
        utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndRaise(db_exc.DBError)
        utils.rmtree_without_raise(
                os.path.join(CONF.baremetal.tftp_root, 'fake-uuid'))
        self.mox.ReplayAll()

        self.driver.deactivate_bootloader(
            self.context, self.node, self.instance)
        self.mox.VerifyAll()
Пример #4
0
    def test_cache_images(self):
        self._create_node()
        self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get')
        self.mox.StubOutWithMock(pxe, "get_tftp_image_info")
        self.mox.StubOutWithMock(self.driver, "_cache_tftp_images")
        self.mox.StubOutWithMock(self.driver, "_cache_image")
        self.mox.StubOutWithMock(self.driver, "_inject_into_image")

        self.driver.virtapi.instance_type_get(
            self.context, self.instance['instance_type_id']).AndReturn({})
        pxe.get_tftp_image_info(self.instance, {}).AndReturn([])
        self.driver._cache_tftp_images(self.context, self.instance, [])
        self.driver._cache_image(self.context, self.instance, [])
        self.driver._inject_into_image(self.context, self.node, self.instance,
                self.test_network_info, None, '')
        self.mox.ReplayAll()

        self.driver.cache_images(
                self.context, self.node, self.instance,
                admin_password='',
                image_meta=[],
                injected_files=None,
                network_info=self.test_network_info,
            )
        self.mox.VerifyAll()
Пример #5
0
    def test_activate_bootloader_passes_details(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.sort()
        image_info = {
                'deploy_kernel': [None, 'aaaa'],
                'deploy_ramdisk': [None, 'bbbb'],
                'kernel': [None, 'cccc'],
                'ramdisk': [None, 'dddd'],
            }
        self.instance['uuid'] = 'fake-uuid'
        iqn = "iqn-%s" % self.instance['uuid']
        pxe_config = 'this is a fake pxe config'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)
        pxe.get_image_file_path(self.instance)

        self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get')
        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(pxe, 'get_partition_sizes')
        self.mox.StubOutWithMock(utils, 'random_alnum')
        self.mox.StubOutWithMock(pxe, 'build_pxe_config')
        self.mox.StubOutWithMock(utils, 'write_to_file')
        self.mox.StubOutWithMock(utils, 'create_link_without_raise')

        self.driver.virtapi.instance_type_get(
            self.context, self.instance['instance_type_id']).AndReturn({})
        pxe.get_tftp_image_info(self.instance, {}).AndReturn(image_info)
        pxe.get_partition_sizes(self.instance).AndReturn((0, 0))
        utils.random_alnum(32).AndReturn('alnum')
        pxe.build_pxe_config(
                self.node['id'], 'alnum', iqn,
                'aaaa', 'bbbb', 'cccc', 'dddd').AndReturn(pxe_config)
        utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            utils.create_link_without_raise(
                    pxe_path, pxe.get_pxe_mac_path(mac))

        self.mox.ReplayAll()

        self.driver.activate_bootloader(self.context, self.node, self.instance)

        self.mox.VerifyAll()
Пример #6
0
    def test_activate_bootloader_passes_details(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.sort()
        image_info = {
                'deploy_kernel': [None, 'aaaa'],
                'deploy_ramdisk': [None, 'bbbb'],
                'kernel': [None, 'cccc'],
                'ramdisk': [None, 'dddd'],
            }
        self.instance['uuid'] = 'fake-uuid'
        iqn = "iqn-%s" % self.instance['uuid']
        pxe_config = 'this is a fake pxe config'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)
        pxe.get_image_file_path(self.instance)

        self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get')
        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(pxe, 'get_partition_sizes')
        self.mox.StubOutWithMock(utils, 'random_alnum')
        self.mox.StubOutWithMock(pxe, 'build_pxe_config')
        self.mox.StubOutWithMock(utils, 'write_to_file')
        self.mox.StubOutWithMock(utils, 'create_link_without_raise')

        self.driver.virtapi.instance_type_get(
            self.context, self.instance['instance_type_id']).AndReturn({})
        pxe.get_tftp_image_info(self.instance, {}).AndReturn(image_info)
        pxe.get_partition_sizes(self.instance).AndReturn((0, 0))
        utils.random_alnum(32).AndReturn('alnum')
        pxe.build_pxe_config(
                self.node['id'], 'alnum', iqn,
                'aaaa', 'bbbb', 'cccc', 'dddd').AndReturn(pxe_config)
        utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            utils.create_link_without_raise(
                    pxe_path, pxe.get_pxe_mac_path(mac))

        self.mox.ReplayAll()

        self.driver.activate_bootloader(self.context, self.node, self.instance)

        self.mox.VerifyAll()
Пример #7
0
    def test_cache_tftp_images(self):
        self.instance['kernel_id'] = 'aaaa'
        self.instance['ramdisk_id'] = 'bbbb'
        instance_type = utils.get_test_instance_type()
        extra_specs = {
                'baremetal:deploy_kernel_id': 'cccc',
                'baremetal:deploy_ramdisk_id': 'dddd',
            }
        instance_type['extra_specs'] = extra_specs
        image_info = pxe.get_tftp_image_info(self.instance, instance_type)

        self.mox.StubOutWithMock(os, 'makedirs')
        self.mox.StubOutWithMock(os.path, 'exists')
        os.makedirs(os.path.join(CONF.baremetal.tftp_root,
                                 self.instance['uuid'])).AndReturn(True)
        for uuid, path in [image_info[label] for label in image_info]:
            os.path.exists(path).AndReturn(True)
        self.mox.ReplayAll()

        self.driver._cache_tftp_images(
                self.context, self.instance, image_info)
        self.mox.VerifyAll()
Пример #8
0
    def test_cache_tftp_images(self):
        self.instance['kernel_id'] = 'aaaa'
        self.instance['ramdisk_id'] = 'bbbb'
        instance_type = utils.get_test_instance_type()
        extra_specs = {
                'baremetal:deploy_kernel_id': 'cccc',
                'baremetal:deploy_ramdisk_id': 'dddd',
            }
        instance_type['extra_specs'] = extra_specs
        image_info = pxe.get_tftp_image_info(self.instance, instance_type)

        self.mox.StubOutWithMock(os, 'makedirs')
        self.mox.StubOutWithMock(os.path, 'exists')
        os.makedirs(os.path.join(CONF.baremetal.tftp_root,
                                 self.instance['uuid'])).AndReturn(True)
        for uuid, path in [image_info[label] for label in image_info]:
            os.path.exists(path).AndReturn(True)
        self.mox.ReplayAll()

        self.driver._cache_tftp_images(
                self.context, self.instance, image_info)
        self.mox.VerifyAll()
Пример #9
0
    def test_get_tftp_image_info(self):
        instance_type = utils.get_test_instance_type()
        # Raises an exception when options are neither specified
        # on the instance nor in configuration file
        CONF.baremetal.deploy_kernel = None
        CONF.baremetal.deploy_ramdisk = None
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)

        # Test that other non-true values also raise an exception
        CONF.baremetal.deploy_kernel = ""
        CONF.baremetal.deploy_ramdisk = ""
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)

        # Even if the instance includes kernel_id and ramdisk_id,
        # we still need deploy_kernel_id and deploy_ramdisk_id.
        # If those aren't present in instance[], and not specified in
        # config file, then we raise an exception.
        self.instance['kernel_id'] = 'aaaa'
        self.instance['ramdisk_id'] = 'bbbb'
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)

        # If an instance doesn't specify deploy_kernel_id or deploy_ramdisk_id,
        # but defaults are set in the config file, we should use those.

        # Here, we confirm both that all four values were set
        # and that the proper paths are getting set for all of them
        CONF.baremetal.deploy_kernel = 'cccc'
        CONF.baremetal.deploy_ramdisk = 'dddd'
        base = os.path.join(CONF.baremetal.tftp_root, self.instance['uuid'])
        res = pxe.get_tftp_image_info(self.instance, instance_type)
        expected = {
                'kernel': ['aaaa', os.path.join(base, 'kernel')],
                'ramdisk': ['bbbb', os.path.join(base, 'ramdisk')],
                'deploy_kernel': ['cccc', os.path.join(base, 'deploy_kernel')],
                'deploy_ramdisk': ['dddd',
                                    os.path.join(base, 'deploy_ramdisk')],
                }
        self.assertEqual(res, expected)

        # If deploy_kernel_id and deploy_ramdisk_id are specified on
        # image extra_specs, this should override any default configuration.
        # Note that it is passed on the 'instance' object, despite being
        # inherited from the instance_types_extra_specs table.
        extra_specs = {
                'baremetal:deploy_kernel_id': 'eeee',
                'baremetal:deploy_ramdisk_id': 'ffff',
            }
        instance_type['extra_specs'] = extra_specs
        res = pxe.get_tftp_image_info(self.instance, instance_type)
        self.assertEqual(res['deploy_kernel'][0], 'eeee')
        self.assertEqual(res['deploy_ramdisk'][0], 'ffff')

        # However, if invalid values are passed on the image extra_specs,
        # this should still raise an exception.
        extra_specs = {
                'baremetal:deploy_kernel_id': '',
                'baremetal:deploy_ramdisk_id': '',
            }
        instance_type['extra_specs'] = extra_specs
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)
Пример #10
0
    def test_get_tftp_image_info(self):
        instance_type = utils.get_test_instance_type()
        # Raises an exception when options are neither specified
        # on the instance nor in configuration file
        CONF.baremetal.deploy_kernel = None
        CONF.baremetal.deploy_ramdisk = None
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)

        # Test that other non-true values also raise an exception
        CONF.baremetal.deploy_kernel = ""
        CONF.baremetal.deploy_ramdisk = ""
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)

        # Even if the instance includes kernel_id and ramdisk_id,
        # we still need deploy_kernel_id and deploy_ramdisk_id.
        # If those aren't present in instance[], and not specified in
        # config file, then we raise an exception.
        self.instance['kernel_id'] = 'aaaa'
        self.instance['ramdisk_id'] = 'bbbb'
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)

        # If an instance doesn't specify deploy_kernel_id or deploy_ramdisk_id,
        # but defaults are set in the config file, we should use those.

        # Here, we confirm both that all four values were set
        # and that the proper paths are getting set for all of them
        CONF.baremetal.deploy_kernel = 'cccc'
        CONF.baremetal.deploy_ramdisk = 'dddd'
        base = os.path.join(CONF.baremetal.tftp_root, self.instance['uuid'])
        res = pxe.get_tftp_image_info(self.instance, instance_type)
        expected = {
                'kernel': ['aaaa', os.path.join(base, 'kernel')],
                'ramdisk': ['bbbb', os.path.join(base, 'ramdisk')],
                'deploy_kernel': ['cccc', os.path.join(base, 'deploy_kernel')],
                'deploy_ramdisk': ['dddd',
                                    os.path.join(base, 'deploy_ramdisk')],
                }
        self.assertEqual(res, expected)

        # If deploy_kernel_id and deploy_ramdisk_id are specified on
        # image extra_specs, this should override any default configuration.
        # Note that it is passed on the 'instance' object, despite being
        # inherited from the instance_types_extra_specs table.
        extra_specs = {
                'baremetal:deploy_kernel_id': 'eeee',
                'baremetal:deploy_ramdisk_id': 'ffff',
            }
        instance_type['extra_specs'] = extra_specs
        res = pxe.get_tftp_image_info(self.instance, instance_type)
        self.assertEqual(res['deploy_kernel'][0], 'eeee')
        self.assertEqual(res['deploy_ramdisk'][0], 'ffff')

        # However, if invalid values are passed on the image extra_specs,
        # this should still raise an exception.
        extra_specs = {
                'baremetal:deploy_kernel_id': '',
                'baremetal:deploy_ramdisk_id': '',
            }
        instance_type['extra_specs'] = extra_specs
        self.assertRaises(exception.NovaException,
                pxe.get_tftp_image_info,
                self.instance, instance_type)