Exemplo n.º 1
0
    def test_dhcp_options_for_instance(self):
        node = self._create_node()
        fake_path = "/a/b/c"
        self.mox.StubOutWithMock(pxe, 'get_pxe_config_file_path')
        pxe.get_pxe_config_file_path(mox.IgnoreArg()).AndReturn(fake_path)
        self.mox.ReplayAll()
        expected = [{'opt_name': 'bootfile-name', 'opt_value': fake_path},
                    {'opt_name': 'server-ip-address', 'opt_value': CONF.my_ip},
                    {'opt_name': 'tftp-server', 'opt_value': CONF.my_ip}]

        res = self.driver.dhcp_options_for_instance(node['instance'])
        self.assertEqual(expected.sort(), res.sort())
        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_deactivate_bootloader(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.append(self.node_info['prov_mac_address'])
        macs.sort()
        image_info = {
                'deploy_kernel': [None, 'aaaa'],
                'deploy_ramdisk': [None, 'bbbb'],
                'kernel': [None, 'cccc'],
                'ramdisk': [None, 'dddd'],
            }
        self.instance['uuid'] = 'fake-uuid'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)

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

        pxe.get_tftp_image_info(self.instance).AndReturn(image_info)
        for uuid, path in [image_info[label] for label in image_info]:
            bm_utils.unlink_without_raise(path)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndReturn(macs)
        for mac in macs:
            bm_utils.unlink_without_raise(pxe.get_pxe_mac_path(mac))
        bm_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()
Exemplo n.º 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(bm_utils, 'unlink_without_raise')
        self.mox.StubOutWithMock(bm_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)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndRaise(db_exc.DBError)
        bm_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()
Exemplo n.º 4
0
    def test_deactivate_bootloader_for_nonexistent_instance(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.append(self.node_info['prov_mac_address'])
        macs.sort()
        image_info = {
                'deploy_kernel': [None, 'aaaa'],
                'deploy_ramdisk': [None, 'bbbb'],
                'kernel': [None, 'cccc'],
                'ramdisk': [None, 'dddd'],
            }
        self.instance['uuid'] = 'fake-uuid'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)

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

        pxe.get_tftp_image_info(self.instance).\
                AndRaise(exception.NovaException)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndRaise(exception.DBError)
        bm_utils.unlink_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()
Exemplo n.º 5
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(bm_utils, 'unlink_without_raise')
        self.mox.StubOutWithMock(bm_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)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndRaise(db_exc.DBError)
        bm_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()
Exemplo n.º 6
0
    def test_deactivate_bootloader_for_nonexistent_instance(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.append(self.node_info['prov_mac_address'])
        macs.sort()
        image_info = {
                'deploy_kernel': [None, 'aaaa'],
                'deploy_ramdisk': [None, 'bbbb'],
                'kernel': [None, 'cccc'],
                'ramdisk': [None, 'dddd'],
            }
        self.instance['uuid'] = 'fake-uuid'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)

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

        pxe.get_tftp_image_info(self.instance).\
                AndRaise(exception.NovaException)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndRaise(db_session.DBError)
        bm_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()
Exemplo n.º 7
0
    def test_deactivate_bootloader(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.append(self.node_info['prov_mac_address'])
        macs.sort()
        image_info = {
                'deploy_kernel': [None, 'aaaa'],
                'deploy_ramdisk': [None, 'bbbb'],
                'kernel': [None, 'cccc'],
                'ramdisk': [None, 'dddd'],
            }
        self.instance['uuid'] = 'fake-uuid'
        pxe_path = pxe.get_pxe_config_file_path(self.instance)

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

        pxe.get_tftp_image_info(self.instance).AndReturn(image_info)
        for uuid, path in [image_info[label] for label in image_info]:
            bm_utils.unlink_without_raise(path)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).\
                AndReturn(macs)
        for mac in macs:
            bm_utils.unlink_without_raise(pxe.get_pxe_mac_path(mac))
        bm_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()
Exemplo n.º 8
0
    def test_dhcp_options_for_instance(self):
        node = self._create_node()
        fake_path = "/a/b/c"
        self.mox.StubOutWithMock(pxe, 'get_pxe_config_file_path')
        pxe.get_pxe_config_file_path(mox.IgnoreArg()).AndReturn(fake_path)
        self.mox.ReplayAll()
        expected = [{
            'opt_name': 'bootfile-name',
            'opt_value': fake_path
        }, {
            'opt_name': 'server-ip-address',
            'opt_value': CONF.my_ip
        }, {
            'opt_name': 'tftp-server',
            'opt_value': CONF.my_ip
        }]

        res = self.driver.dhcp_options_for_instance(node['instance'])
        self.assertEqual(expected.sort(), res.sort())
        self.mox.VerifyAll()
Exemplo n.º 9
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)
        image_path = pxe.get_image_file_path(self.instance)

        self.mox.StubOutWithMock(flavor_obj.Flavor, 'get_by_id')
        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(pxe, 'get_partition_sizes')
        self.mox.StubOutWithMock(bm_utils, 'random_alnum')
        self.mox.StubOutWithMock(pxe, 'build_pxe_config')
        self.mox.StubOutWithMock(bm_utils, 'write_to_file')
        self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise')

        flavor_obj.Flavor.get_by_id(
            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, 0))
        bm_utils.random_alnum(32).AndReturn('alnum')
        pxe.build_pxe_config(self.node['id'], 'alnum', iqn, 'aaaa', 'bbbb',
                             'cccc', 'dddd',
                             self.test_network_info).AndReturn(pxe_config)
        bm_utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            bm_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,
                                        network_info=self.test_network_info)

        self.mox.VerifyAll()
Exemplo n.º 10
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(flavor_obj.Flavor, 'get_by_id')
        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(pxe, 'get_partition_sizes')
        self.mox.StubOutWithMock(bm_utils, 'random_alnum')
        self.mox.StubOutWithMock(pxe, 'build_pxe_config')
        self.mox.StubOutWithMock(bm_utils, 'write_to_file')
        self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise')

        flavor_obj.Flavor.get_by_id(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, 0))
        bm_utils.random_alnum(32).AndReturn('alnum')
        pxe.build_pxe_config(
                self.node['id'], 'alnum', iqn,
                'aaaa', 'bbbb', 'cccc', 'dddd',
                self.test_network_info).AndReturn(pxe_config)
        bm_utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            bm_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,
                                        network_info=self.test_network_info)

        self.mox.VerifyAll()
Exemplo n.º 11
0
    def test_activate_bootloader(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.append(self.node_info['prov_mac_address'])
        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)
        image_path = pxe.get_image_file_path(self.instance)

        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(pxe, 'get_partition_sizes')
        self.mox.StubOutWithMock(bm_utils, 'random_alnum')
        self.mox.StubOutWithMock(db, 'bm_deployment_create')
        self.mox.StubOutWithMock(pxe, 'build_pxe_config')
        self.mox.StubOutWithMock(bm_utils, 'write_to_file')
        self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise')

        pxe.get_tftp_image_info(self.instance).AndReturn(image_info)
        pxe.get_partition_sizes(self.instance).AndReturn((0, 0))
        bm_utils.random_alnum(32).AndReturn('alnum')
        db.bm_deployment_create(
                self.context, 'alnum', image_path, pxe_path, 0, 0).\
                        AndReturn(1234)
        pxe.build_pxe_config(
                1234, 'alnum', iqn, 'aaaa', 'bbbb', 'cccc', 'dddd').\
                        AndReturn(pxe_config)
        bm_utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            bm_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()
Exemplo n.º 12
0
    def dhcp_options_for_instance(self, instance):
        # NOTE(deva): This only works for PXE driver currently.
        try:
            bootfile_path = pxe.get_pxe_config_file_path(instance)
        except AttributeError as ex:
            # NOTE: not all drivers are going to support PXE boot capability
            LOG.exception(_("Exception no pxe bootfile-name path: %s"),
                          unicode(ex))
            return None

        opts = [{'opt_name': 'bootfile-name',
                 'opt_value': bootfile_path},
                {'opt_name': 'server-ip-address',
                 'opt_value': CONF.my_ip},
                {'opt_name': 'tftp-server',
                 'opt_value': CONF.my_ip}
               ]

        return opts
Exemplo n.º 13
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(bm_utils, "unlink_without_raise")
        self.mox.StubOutWithMock(bm_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=dict(deploy_ramdisk_id="ignore", deploy_kernel_id="ignore"))
        pxe.get_tftp_image_info(self.instance, extra_specs).AndRaise(exception.NovaException)
        bm_utils.unlink_without_raise(pxe_path)
        self.driver._collect_mac_addresses(self.context, self.node).AndRaise(db_exc.DBError)
        bm_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()
Exemplo n.º 14
0
    def test_activate_bootloader(self):
        self._create_node()
        macs = [nic['address'] for nic in self.nic_info]
        macs.append(self.node_info['prov_mac_address'])
        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)
        image_path = pxe.get_image_file_path(self.instance)

        self.mox.StubOutWithMock(pxe, 'get_tftp_image_info')
        self.mox.StubOutWithMock(pxe, 'get_partition_sizes')
        self.mox.StubOutWithMock(bm_utils, 'random_alnum')
        self.mox.StubOutWithMock(db, 'bm_deployment_create')
        self.mox.StubOutWithMock(pxe, 'build_pxe_config')
        self.mox.StubOutWithMock(bm_utils, 'write_to_file')
        self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise')

        pxe.get_tftp_image_info(self.instance).AndReturn(image_info)
        pxe.get_partition_sizes(self.instance).AndReturn((0, 0))
        bm_utils.random_alnum(32).AndReturn('alnum')
        db.bm_deployment_create(
                self.context, 'alnum', image_path, pxe_path, 0, 0).\
                        AndReturn(1234)
        pxe.build_pxe_config(
                1234, 'alnum', iqn, 'aaaa', 'bbbb', 'cccc', 'dddd').\
                        AndReturn(pxe_config)
        bm_utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            bm_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()
Exemplo n.º 15
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)
        image_path = 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(bm_utils, "random_alnum")
        self.mox.StubOutWithMock(pxe, "build_pxe_config")
        self.mox.StubOutWithMock(bm_utils, "write_to_file")
        self.mox.StubOutWithMock(bm_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))
        bm_utils.random_alnum(32).AndReturn("alnum")
        pxe.build_pxe_config(
            self.node["id"], "alnum", iqn, "aaaa", "bbbb", "cccc", "dddd", self.test_network_info
        ).AndReturn(pxe_config)
        bm_utils.write_to_file(pxe_path, pxe_config)
        for mac in macs:
            bm_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, network_info=self.test_network_info)

        self.mox.VerifyAll()
Exemplo n.º 16
0
    def dhcp_options_for_instance(self, instance):
        # NOTE(deva): This only works for PXE driver currently.
        try:
            bootfile_path = pxe.get_pxe_config_file_path(instance)
        except AttributeError as ex:
            # NOTE: not all drivers are going to support PXE boot capability
            LOG.exception(_("Exception no pxe bootfile-name path: %s"),
                          unicode(ex))
            return None

        opts = [{
            'opt_name': 'bootfile-name',
            'opt_value': bootfile_path
        }, {
            'opt_name': 'server-ip-address',
            'opt_value': CONF.my_ip
        }, {
            'opt_name': 'tftp-server',
            'opt_value': CONF.my_ip
        }]

        return opts
Exemplo n.º 17
0
 def test_pxe_config_file_path(self):
     self.instance['uuid'] = 'aaaa-bbbb-cccc'
     self.assertEqual(
             pxe.get_pxe_config_file_path(self.instance),
             os.path.join(CONF.baremetal.tftp_root,
                 'aaaa-bbbb-cccc', 'config'))
Exemplo n.º 18
0
 def test_pxe_config_file_path(self):
     self.instance["uuid"] = "aaaa-bbbb-cccc"
     self.assertEqual(
         pxe.get_pxe_config_file_path(self.instance),
         os.path.join(CONF.baremetal.tftp_root, "aaaa-bbbb-cccc", "config"),
     )
Exemplo n.º 19
0
 def test_pxe_config_file_path(self):
     self.instance['uuid'] = 'aaaa-bbbb-cccc'
     self.assertEqual(
         os.path.join(CONF.baremetal.tftp_root, 'aaaa-bbbb-cccc', 'config'),
         pxe.get_pxe_config_file_path(self.instance))