Example #1
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()
Example #2
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()
Example #3
0
File: pxe.py Project: chiehwen/nova
    def activate_bootloader(self, context, node, instance):
        """Configure PXE boot loader for an instance

        Kernel and ramdisk images are downloaded by cache_tftp_images,
        and stored in /tftpboot/{uuid}/

        This method writes the instances config file, and then creates
        symlinks for each MAC address in the instance.

        By default, the complete layout looks like this:

        /tftpboot/
            ./{uuid}/
                 kernel
                 ramdisk
                 deploy_kernel
                 deploy_ramdisk
                 config
            ./pxelinux.cfg/
                 {mac} -> ../{uuid}/config

        """
        image_info = get_tftp_image_info(instance)
        (root_mb, swap_mb) = get_partition_sizes(instance)
        pxe_config_file_path = get_pxe_config_file_path(instance)
        image_file_path = get_image_file_path(instance)

        deployment_key = bm_utils.random_alnum(32)
        deployment_iscsi_iqn = "iqn-%s" % instance['uuid']
        deployment_id = db.bm_deployment_create(
                            context,
                            deployment_key,
                            image_file_path,
                            pxe_config_file_path,
                            root_mb,
                            swap_mb
                        )
        pxe_config = build_pxe_config(
                    deployment_id,
                    deployment_key,
                    deployment_iscsi_iqn,
                    image_info['deploy_kernel'][1],
                    image_info['deploy_ramdisk'][1],
                    image_info['kernel'][1],
                    image_info['ramdisk'][1],
                )
        bm_utils.write_to_file(pxe_config_file_path, pxe_config)

        macs = self._collect_mac_addresses(context, node)
        for mac in macs:
            mac_path = get_pxe_mac_path(mac)
            bm_utils.unlink_without_raise(mac_path)
            bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
Example #4
0
File: pxe.py Project: ameade/nova
    def activate_bootloader(self, context, node, instance):
        """Configure PXE boot loader for an instance

        Kernel and ramdisk images are downloaded by cache_tftp_images,
        and stored in /tftpboot/{uuid}/

        This method writes the instances config file, and then creates
        symlinks for each MAC address in the instance.

        By default, the complete layout looks like this:

        /tftpboot/
            ./{uuid}/
                 kernel
                 ramdisk
                 deploy_kernel
                 deploy_ramdisk
                 config
            ./pxelinux.cfg/
                 {mac} -> ../{uuid}/config

        """
        image_info = get_tftp_image_info(instance)
        (root_mb, swap_mb) = get_partition_sizes(instance)
        pxe_config_file_path = get_pxe_config_file_path(instance)
        image_file_path = get_image_file_path(instance)

        deployment_key = bm_utils.random_alnum(32)
        deployment_iscsi_iqn = "iqn-%s" % instance['uuid']
        deployment_id = db.bm_deployment_create(
                            context,
                            deployment_key,
                            image_file_path,
                            pxe_config_file_path,
                            root_mb,
                            swap_mb
                        )
        pxe_config = build_pxe_config(
                    deployment_id,
                    deployment_key,
                    deployment_iscsi_iqn,
                    image_info['deploy_kernel'][1],
                    image_info['deploy_ramdisk'][1],
                    image_info['kernel'][1],
                    image_info['ramdisk'][1],
                )
        bm_utils.write_to_file(pxe_config_file_path, pxe_config)

        macs = self._collect_mac_addresses(context, node)
        for mac in macs:
            mac_path = get_pxe_mac_path(mac)
            bm_utils.unlink_without_raise(mac_path)
            bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
Example #5
0
    def activate_bootloader(self, var, context, node, instance):
        tftp_root = var['tftp_root']
        image_path = var['image_path']

        deploy_aki_id = FLAGS.baremetal_deploy_kernel
        deploy_ari_id = FLAGS.baremetal_deploy_ramdisk
        aki_id = str(instance['kernel_id'])
        ari_id = str(instance['ramdisk_id'])

        images = [
            (deploy_aki_id, 'deploy_kernel'),
            (deploy_ari_id, 'deploy_ramdisk'),
            (aki_id, 'kernel'),
            (ari_id, 'ramdisk'),
        ]

        utils.ensure_tree(tftp_root)
        if FLAGS.baremetal_pxe_vlan_per_host:
            tftp_paths = [i[1] for i in images]
        else:
            tftp_paths = [
                os.path.join(str(instance['uuid']), i[1]) for i in images
            ]
            utils.ensure_tree(os.path.join(tftp_root, str(instance['uuid'])))

        LOG.debug("tftp_paths=%s", tftp_paths)

        def _cache_image_b(image_id, target):
            LOG.debug("fetching id=%s target=%s", image_id, target)
            _cache_image_x(context=context,
                           image_id=image_id,
                           target=target,
                           user_id=instance['user_id'],
                           project_id=instance['project_id'])

        for image, path in zip(images, tftp_paths):
            target = os.path.join(tftp_root, path)
            _cache_image_b(image[0], target)

        pxe_config_dir = os.path.join(tftp_root, 'pxelinux.cfg')
        pxe_config_path = os.path.join(pxe_config_dir,
                                       self._pxe_cfg_name(node))

        root_mb = instance['root_gb'] * 1024

        inst_type_id = instance['instance_type_id']
        inst_type = instance_types.get_instance_type(inst_type_id)
        swap_mb = inst_type['swap']
        if swap_mb < 1024:
            swap_mb = 1024

        pxe_ip = None
        if FLAGS.baremetal_pxe_vlan_per_host:
            pxe_ip_id = bmdb.bm_pxe_ip_associate(context, node['id'])
            pxe_ip = bmdb.bm_pxe_ip_get(context, pxe_ip_id)

        deployment_key = _random_alnum(32)
        deployment_id = bmdb.bm_deployment_create(context, deployment_key,
                                                  image_path, pxe_config_path,
                                                  root_mb, swap_mb)
        deployment_iscsi_iqn = "iqn-%s" % str(instance['uuid'])
        iscsi_portal = None
        if FLAGS.baremetal_pxe_append_iscsi_portal:
            if pxe_ip:
                iscsi_portal = pxe_ip['server_address']
        pxeconf = _build_pxe_config(deployment_id,
                                    deployment_key,
                                    deployment_iscsi_iqn,
                                    deployment_aki_path=tftp_paths[0],
                                    deployment_ari_path=tftp_paths[1],
                                    aki_path=tftp_paths[2],
                                    ari_path=tftp_paths[3],
                                    iscsi_portal=iscsi_portal)
        utils.ensure_tree(pxe_config_dir)
        libvirt_utils.write_to_file(pxe_config_path, pxeconf)

        if FLAGS.baremetal_pxe_vlan_per_host:
            vlan_id = node['prov_vlan_id']
            server_address = pxe_ip['server_address']
            client_address = pxe_ip['address']
            _start_per_host_pxe_server(tftp_root, vlan_id, server_address,
                                       client_address)
Example #6
0
    def activate_bootloader(self, var, context, node, instance):
        tftp_root = var['tftp_root']
        image_path = var['image_path']

        deploy_aki_id = FLAGS.baremetal_deploy_kernel
        deploy_ari_id = FLAGS.baremetal_deploy_ramdisk
        aki_id = str(instance['kernel_id'])
        ari_id = str(instance['ramdisk_id'])

        images = [(deploy_aki_id, 'deploy_kernel'),
                  (deploy_ari_id, 'deploy_ramdisk'),
                  (aki_id, 'kernel'),
                  (ari_id, 'ramdisk'),
                  ]

        utils.ensure_tree(tftp_root)
        if FLAGS.baremetal_pxe_vlan_per_host:
            tftp_paths = [i[1] for i in images]
        else:
            tftp_paths = [os.path.join(str(instance['uuid']), i[1])
                    for i in images]
            utils.ensure_tree(
                    os.path.join(tftp_root, str(instance['uuid'])))

        LOG.debug("tftp_paths=%s", tftp_paths)

        def _cache_image_b(image_id, target):
            LOG.debug("fetching id=%s target=%s", image_id, target)
            _cache_image_x(context=context,
                           image_id=image_id,
                           target=target,
                           user_id=instance['user_id'],
                           project_id=instance['project_id'])

        for image, path in zip(images, tftp_paths):
            target = os.path.join(tftp_root, path)
            _cache_image_b(image[0], target)

        pxe_config_dir = os.path.join(tftp_root, 'pxelinux.cfg')
        pxe_config_path = os.path.join(pxe_config_dir,
                                       self._pxe_cfg_name(node))

        root_mb = instance['root_gb'] * 1024

        inst_type_id = instance['instance_type_id']
        inst_type = instance_types.get_instance_type(inst_type_id)
        swap_mb = inst_type['swap']
        if swap_mb < 1024:
            swap_mb = 1024

        pxe_ip = None
        if FLAGS.baremetal_pxe_vlan_per_host:
            pxe_ip_id = bmdb.bm_pxe_ip_associate(context, node['id'])
            pxe_ip = bmdb.bm_pxe_ip_get(context, pxe_ip_id)

        deployment_key = _random_alnum(32)
        deployment_id = bmdb.bm_deployment_create(context, deployment_key,
                                                  image_path, pxe_config_path,
                                                  root_mb, swap_mb)
        deployment_iscsi_iqn = "iqn-%s" % str(instance['uuid'])
        iscsi_portal = None
        if FLAGS.baremetal_pxe_append_iscsi_portal:
            if pxe_ip:
                iscsi_portal = pxe_ip['server_address']
        pxeconf = _build_pxe_config(deployment_id,
                                    deployment_key,
                                    deployment_iscsi_iqn,
                                    deployment_aki_path=tftp_paths[0],
                                    deployment_ari_path=tftp_paths[1],
                                    aki_path=tftp_paths[2],
                                    ari_path=tftp_paths[3],
                                    iscsi_portal=iscsi_portal)
        utils.ensure_tree(pxe_config_dir)
        libvirt_utils.write_to_file(pxe_config_path, pxeconf)

        if FLAGS.baremetal_pxe_vlan_per_host:
            vlan_id = node['prov_vlan_id']
            server_address = pxe_ip['server_address']
            client_address = pxe_ip['address']
            _start_per_host_pxe_server(tftp_root, vlan_id,
                                       server_address, client_address)