Beispiel #1
0
    def _test_build_pxe_config_options_pxe(self, render_mock,
                                           whle_dsk_img=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385', group='conductor')

        driver_internal_info = self.node.driver_internal_info
        driver_internal_info['is_whole_disk_image'] = whle_dsk_img
        self.node.driver_internal_info = driver_internal_info
        self.node.save()

        tftp_server = CONF.pxe.tftp_server

        deploy_kernel = os.path.join(self.node.uuid, 'deploy_kernel')
        deploy_ramdisk = os.path.join(self.node.uuid, 'deploy_ramdisk')
        kernel = os.path.join(self.node.uuid, 'kernel')
        ramdisk = os.path.join(self.node.uuid, 'ramdisk')
        root_dir = CONF.pxe.tftp_root

        image_info = {
            'deploy_kernel': ('deploy_kernel',
                              os.path.join(root_dir,
                                           self.node.uuid,
                                           'deploy_kernel')),
            'deploy_ramdisk': ('deploy_ramdisk',
                               os.path.join(root_dir,
                                            self.node.uuid,
                                            'deploy_ramdisk'))
        }

        if (whle_dsk_img or
            deploy_utils.get_boot_option(self.node) == 'local'):
                ramdisk = 'no_ramdisk'
                kernel = 'no_kernel'
        else:
            image_info.update({
                'kernel': ('kernel_id',
                           os.path.join(root_dir,
                                        self.node.uuid,
                                        'kernel')),
                'ramdisk': ('ramdisk_id',
                            os.path.join(root_dir,
                                         self.node.uuid,
                                         'ramdisk'))
            })

        expected_options = {
            'ari_path': ramdisk,
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server,
            'ipxe_timeout': 0,
        }

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)
        self.assertEqual(expected_options, options)
Beispiel #2
0
    def test__build_pxe_config_options_pxe_no_kernel_no_ramdisk(self):
        del self.node.driver_internal_info['is_whole_disk_image']
        self.node.save()
        self.config(group='pxe', tftp_server='my-tftp-server')
        self.config(group='pxe', pxe_append_params='my-pxe-append-params')
        self.config(group='pxe', tftp_root='/tftp-path/')
        image_info = {
            'deploy_kernel': ('deploy_kernel',
                              os.path.join(CONF.pxe.tftp_root,
                                           'path-to-deploy_kernel')),
            'deploy_ramdisk': ('deploy_ramdisk',
                               os.path.join(CONF.pxe.tftp_root,
                                            'path-to-deploy_ramdisk'))
        }

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)

        expected_options = {
            'deployment_aki_path': 'path-to-deploy_kernel',
            'deployment_ari_path': 'path-to-deploy_ramdisk',
            'pxe_append_params': 'my-pxe-append-params',
            'tftp_server': 'my-tftp-server',
            'aki_path': 'no_kernel',
            'ari_path': 'no_ramdisk',
            'ipxe_timeout': 0
        }
        self.assertEqual(expected_options, options)
Beispiel #3
0
    def test__build_pxe_config_options_whole_disk_image(self,
                                                        build_pxe_mock,
                                                        ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='deploy')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            root_dir = CONF.deploy.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                          'deploy_ramdisk')
            root_dir = CONF.pxe.tftp_root

        expected_options = {
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server,
            'aki_path': 'no_kernel',
            'ari_path': 'no_ramdisk',
            'ipxe_timeout': 0,
        }

        image_info = {'deploy_kernel': ('deploy_kernel',
                                        os.path.join(root_dir,
                                                     self.node.uuid,
                                                     'deploy_kernel')),
                      'deploy_ramdisk': ('deploy_ramdisk',
                                         os.path.join(root_dir,
                                                      self.node.uuid,
                                                      'deploy_ramdisk')),
                      }
        driver_internal_info = self.node.driver_internal_info
        driver_internal_info['is_whole_disk_image'] = True
        self.node.driver_internal_info = driver_internal_info
        self.node.save()

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)
        self.assertEqual(expected_options, options)
Beispiel #4
0
    def test_build_pxe_config_options(self, build_pxe_mock, random_alnum_mock):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385/', group='conductor')
        pxe_template = 'pxe_config_template'
        self.config(pxe_config_template=pxe_template, group='pxe')

        fake_key = '0123456789ABCDEFGHIJKLMNOPQRSTUV'
        random_alnum_mock.return_value = fake_key

        expected_options = {
            'deployment_key': '0123456789ABCDEFGHIJKLMNOPQRSTUV',
            'ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                        u'ramdisk',
            'deployment_iscsi_iqn': u'iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33'
                                    u'c123',
            'deployment_ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7'
                                   u'f33c123/deploy_ramdisk',
            'pxe_append_params': 'test_param',
            'aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                        u'kernel',
            'deployment_id': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
            'ironic_api_url': 'http://192.168.122.184:6385',
            'deployment_aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-'
                                   u'c02d7f33c123/deploy_kernel'
        }
        image_info = {'deploy_kernel': ('deploy_kernel',
                                        os.path.join(CONF.pxe.tftp_root,
                                                     self.node.uuid,
                                                     'deploy_kernel')),
                      'deploy_ramdisk': ('deploy_ramdisk',
                                         os.path.join(CONF.pxe.tftp_root,
                                                      self.node.uuid,
                                                      'deploy_ramdisk')),
                      'kernel': ('kernel_id',
                                 os.path.join(CONF.pxe.tftp_root,
                                              self.node.uuid,
                                              'kernel')),
                      'ramdisk': ('ramdisk_id',
                                  os.path.join(CONF.pxe.tftp_root,
                                               self.node.uuid,
                                               'ramdisk'))
                      }
        options = pxe._build_pxe_config_options(self.node,
                                                image_info,
                                                self.context)
        self.assertEqual(expected_options, options)

        random_alnum_mock.assert_called_once_with(32)

        # test that deploy_key saved
        db_node = self.dbapi.get_node_by_uuid(self.node.uuid)
        db_key = db_node.instance_info.get('deploy_key')
        self.assertEqual(fake_key, db_key)
Beispiel #5
0
    def test_build_pxe_config_options(self, build_pxe_mock, random_alnum_mock):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385/', group='conductor')
        pxe_template = 'pxe_config_template'
        self.config(pxe_config_template=pxe_template, group='pxe')

        fake_key = '0123456789ABCDEFGHIJKLMNOPQRSTUV'
        random_alnum_mock.return_value = fake_key

        expected_options = {
            'deployment_key': '0123456789ABCDEFGHIJKLMNOPQRSTUV',
            'ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                        u'ramdisk',
            'deployment_iscsi_iqn': u'iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33'
                                    u'c123',
            'deployment_ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7'
                                   u'f33c123/deploy_ramdisk',
            'pxe_append_params': 'test_param',
            'aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                        u'kernel',
            'deployment_id': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
            'ironic_api_url': 'http://192.168.122.184:6385',
            'deployment_aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-'
                                   u'c02d7f33c123/deploy_kernel'
        }
        image_info = {'deploy_kernel': ('deploy_kernel',
                                        os.path.join(CONF.pxe.tftp_root,
                                                     self.node.uuid,
                                                     'deploy_kernel')),
                      'deploy_ramdisk': ('deploy_ramdisk',
                                         os.path.join(CONF.pxe.tftp_root,
                                                      self.node.uuid,
                                                      'deploy_ramdisk')),
                      'kernel': ('kernel_id',
                                 os.path.join(CONF.pxe.tftp_root,
                                              self.node.uuid,
                                              'kernel')),
                      'ramdisk': ('ramdisk_id',
                                  os.path.join(CONF.pxe.tftp_root,
                                               self.node.uuid,
                                               'ramdisk'))
                      }
        options = pxe._build_pxe_config_options(self.node,
                                                image_info,
                                                self.context)
        self.assertEqual(expected_options, options)

        random_alnum_mock.assert_called_once_with(32)

        # test that deploy_key saved
        db_node = self.dbapi.get_node_by_uuid(self.node.uuid)
        db_key = db_node.instance_info.get('deploy_key')
        self.assertEqual(fake_key, db_key)
Beispiel #6
0
    def _test_build_pxe_config_options(self, build_pxe_mock, whle_dsk_img=False, ipxe_enabled=False):
        self.config(pxe_append_params="test_param", group="pxe")
        # NOTE: right '/' should be removed from url string
        self.config(api_url="http://192.168.122.184:6385", group="conductor")
        self.config(disk_devices="sda", group="pxe")

        driver_internal_info = self.node.driver_internal_info
        driver_internal_info["is_whole_disk_image"] = whle_dsk_img
        self.node.driver_internal_info = driver_internal_info
        self.node.save()

        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = "http://192.1.2.3:1234"
            self.config(ipxe_enabled=True, group="pxe")
            self.config(http_url=http_url, group="deploy")

            deploy_kernel = os.path.join(http_url, self.node.uuid, "deploy_kernel")
            deploy_ramdisk = os.path.join(http_url, self.node.uuid, "deploy_ramdisk")
            kernel = os.path.join(http_url, self.node.uuid, "kernel")
            ramdisk = os.path.join(http_url, self.node.uuid, "ramdisk")
            root_dir = CONF.deploy.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid, "deploy_kernel")
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid, "deploy_ramdisk")
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid, "kernel")
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid, "ramdisk")
            root_dir = CONF.pxe.tftp_root

        if whle_dsk_img:
            ramdisk = "no_ramdisk"
            kernel = "no_kernel"

        expected_options = {
            "ari_path": ramdisk,
            "deployment_ari_path": deploy_ramdisk,
            "pxe_append_params": "test_param",
            "aki_path": kernel,
            "deployment_aki_path": deploy_kernel,
            "tftp_server": tftp_server,
        }

        image_info = {
            "deploy_kernel": ("deploy_kernel", os.path.join(root_dir, self.node.uuid, "deploy_kernel")),
            "deploy_ramdisk": ("deploy_ramdisk", os.path.join(root_dir, self.node.uuid, "deploy_ramdisk")),
            "kernel": ("kernel_id", os.path.join(root_dir, self.node.uuid, "kernel")),
            "ramdisk": ("ramdisk_id", os.path.join(root_dir, self.node.uuid, "ramdisk")),
        }

        with task_manager.acquire(self.context, self.node.uuid, shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)
        self.assertEqual(expected_options, options)
Beispiel #7
0
    def _test_build_pxe_config_options_pxe(self, render_mock, whle_dsk_img=False):
        self.config(pxe_append_params="test_param", group="pxe")
        # NOTE: right '/' should be removed from url string
        self.config(api_url="http://192.168.122.184:6385", group="conductor")

        driver_internal_info = self.node.driver_internal_info
        driver_internal_info["is_whole_disk_image"] = whle_dsk_img
        self.node.driver_internal_info = driver_internal_info
        self.node.save()

        tftp_server = CONF.pxe.tftp_server

        deploy_kernel = os.path.join(self.node.uuid, "deploy_kernel")
        deploy_ramdisk = os.path.join(self.node.uuid, "deploy_ramdisk")
        kernel = os.path.join(self.node.uuid, "kernel")
        ramdisk = os.path.join(self.node.uuid, "ramdisk")
        root_dir = CONF.pxe.tftp_root

        image_info = {
            "deploy_kernel": ("deploy_kernel", os.path.join(root_dir, self.node.uuid, "deploy_kernel")),
            "deploy_ramdisk": ("deploy_ramdisk", os.path.join(root_dir, self.node.uuid, "deploy_ramdisk")),
        }

        if whle_dsk_img or deploy_utils.get_boot_option(self.node) == "local":
            ramdisk = "no_ramdisk"
            kernel = "no_kernel"
        else:
            image_info.update(
                {
                    "kernel": ("kernel_id", os.path.join(root_dir, self.node.uuid, "kernel")),
                    "ramdisk": ("ramdisk_id", os.path.join(root_dir, self.node.uuid, "ramdisk")),
                }
            )

        expected_options = {
            "ari_path": ramdisk,
            "deployment_ari_path": deploy_ramdisk,
            "pxe_append_params": "test_param",
            "aki_path": kernel,
            "deployment_aki_path": deploy_kernel,
            "tftp_server": tftp_server,
            "ipxe_timeout": 0,
        }

        with task_manager.acquire(self.context, self.node.uuid, shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)
        self.assertEqual(expected_options, options)
Beispiel #8
0
    def test__build_pxe_config_options_no_kernel_no_ramdisk(self):
        del self.node.driver_internal_info["is_whole_disk_image"]
        self.node.save()
        self.config(group="pxe", tftp_server="my-tftp-server")
        self.config(group="pxe", pxe_append_params="my-pxe-append-params")
        image_info = {
            "deploy_kernel": ("deploy_kernel", "path-to-deploy_kernel"),
            "deploy_ramdisk": ("deploy_ramdisk", "path-to-deploy_ramdisk"),
        }

        with task_manager.acquire(self.context, self.node.uuid, shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)

        expected_options = {
            "deployment_aki_path": "path-to-deploy_kernel",
            "deployment_ari_path": "path-to-deploy_ramdisk",
            "pxe_append_params": "my-pxe-append-params",
            "tftp_server": "my-tftp-server",
            "aki_path": "no_kernel",
            "ari_path": "no_ramdisk",
        }
        self.assertEqual(expected_options, options)
Beispiel #9
0
    def prepare_ramdisk(self, task, ramdisk_params):
        node = task.node

        # TODO(deva): optimize this if rerun on existing files
        if CONF.pxe.ipxe_enabled:
            # Copy the iPXE boot script to HTTP root directory
            bootfile_path = os.path.join(
                CONF.deploy.http_root,
                os.path.basename(CONF.pxe.ipxe_boot_script))
            shutil.copyfile(CONF.pxe.ipxe_boot_script, bootfile_path)

        prov_ip = self._plug_provisioning(task)

        task.ports = objects.Port.list_by_node_id(task.context, node.id)

        pxe_info = pxe._get_deploy_image_info(node)

        # NODE: Try to validate and fetch instance images only
        # if we are in DEPLOYING state.
        if node.provision_state == states.DEPLOYING:
            pxe_info.update(pxe._get_instance_image_info(node, task.context))

        pxe_options = pxe._build_pxe_config_options(task, pxe_info)
        pxe_options.update(ramdisk_params)
        pxe_options['advertise_host'] = prov_ip

        if deploy_utils.get_boot_mode_for_deploy(node) == 'uefi':
            pxe_config_template = CONF.pxe.uefi_pxe_config_template
        else:
            pxe_config_template = CONF.pxe.pxe_config_template

        pxe_utils.create_pxe_config(task, pxe_options,
                                    pxe_config_template)
        deploy_utils.try_set_boot_device(task, boot_devices.PXE)

        # FIXME(lucasagomes): If it's local boot we should not cache
        # the image kernel and ramdisk (Or even require it).
        pxe._cache_ramdisk_kernel(task.context, node, pxe_info)
Beispiel #10
0
    def test__build_pxe_config_options_no_kernel_no_ramdisk(self):
        del self.node.driver_internal_info['is_whole_disk_image']
        self.node.save()
        self.config(group='pxe', tftp_server='my-tftp-server')
        self.config(group='pxe', pxe_append_params='my-pxe-append-params')
        image_info = {
            'deploy_kernel': ('deploy_kernel',
                              'path-to-deploy_kernel'),
            'deploy_ramdisk': ('deploy_ramdisk',
                               'path-to-deploy_ramdisk')}

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)

        expected_options = {
            'deployment_aki_path': 'path-to-deploy_kernel',
            'deployment_ari_path': 'path-to-deploy_ramdisk',
            'pxe_append_params': 'my-pxe-append-params',
            'tftp_server': 'my-tftp-server',
            'aki_path': 'no_kernel',
            'ari_path': 'no_ramdisk'}
        self.assertEqual(expected_options, options)
Beispiel #11
0
    def test_build_pxe_config_options(self, build_pxe_mock, random_alnum_mock):
        self.config(pxe_append_params="test_param", group="pxe")
        # NOTE: right '/' should be removed from url string
        self.config(api_url="http://192.168.122.184:6385/", group="conductor")
        pxe_template = "pxe_config_template"
        self.config(pxe_config_template=pxe_template, group="pxe")

        fake_key = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
        random_alnum_mock.return_value = fake_key

        expected_options = {
            "deployment_key": "0123456789ABCDEFGHIJKLMNOPQRSTUV",
            "ari_path": u"/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/" u"ramdisk",
            "deployment_iscsi_iqn": u"iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33" u"c123",
            "deployment_ari_path": u"/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7" u"f33c123/deploy_ramdisk",
            "pxe_append_params": "test_param",
            "aki_path": u"/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/" u"kernel",
            "deployment_id": u"1be26c0b-03f2-4d2e-ae87-c02d7f33c123",
            "ironic_api_url": "http://192.168.122.184:6385",
            "deployment_aki_path": u"/tftpboot/1be26c0b-03f2-4d2e-ae87-" u"c02d7f33c123/deploy_kernel",
        }
        image_info = {
            "deploy_kernel": ("deploy_kernel", os.path.join(CONF.pxe.tftp_root, self.node.uuid, "deploy_kernel")),
            "deploy_ramdisk": ("deploy_ramdisk", os.path.join(CONF.pxe.tftp_root, self.node.uuid, "deploy_ramdisk")),
            "kernel": ("kernel_id", os.path.join(CONF.pxe.tftp_root, self.node.uuid, "kernel")),
            "ramdisk": ("ramdisk_id", os.path.join(CONF.pxe.tftp_root, self.node.uuid, "ramdisk")),
        }
        options = pxe._build_pxe_config_options(self.node, image_info, self.context)
        self.assertEqual(expected_options, options)

        random_alnum_mock.assert_called_once_with(32)

        # test that deploy_key saved
        db_node = self.dbapi.get_node_by_uuid(self.node.uuid)
        db_key = db_node.instance_info.get("deploy_key")
        self.assertEqual(fake_key, db_key)
Beispiel #12
0
    def _test_build_pxe_config_options_ipxe(
        self, render_mock, glance_mock, whle_dsk_img=False, ipxe_timeout=0, ipxe_use_swift=False
    ):
        self.config(pxe_append_params="test_param", group="pxe")
        # NOTE: right '/' should be removed from url string
        self.config(api_url="http://192.168.122.184:6385", group="conductor")
        self.config(ipxe_timeout=ipxe_timeout, group="pxe")
        root_dir = CONF.deploy.http_root

        driver_internal_info = self.node.driver_internal_info
        driver_internal_info["is_whole_disk_image"] = whle_dsk_img
        self.node.driver_internal_info = driver_internal_info
        self.node.save()

        tftp_server = CONF.pxe.tftp_server

        http_url = "http://192.1.2.3:1234"
        self.config(ipxe_enabled=True, group="pxe")
        self.config(http_url=http_url, group="deploy")
        if ipxe_use_swift:
            self.config(ipxe_use_swift=True, group="pxe")
            glance = mock.Mock()
            glance_mock.return_value = glance
            glance.swift_temp_url.side_effect = [deploy_kernel, deploy_ramdisk] = ["swift_kernel", "swift_ramdisk"]
            image_info = {
                "deploy_kernel": (uuidutils.generate_uuid(), os.path.join(root_dir, self.node.uuid, "deploy_kernel")),
                "deploy_ramdisk": (uuidutils.generate_uuid(), os.path.join(root_dir, self.node.uuid, "deploy_ramdisk")),
            }
        else:
            deploy_kernel = os.path.join(http_url, self.node.uuid, "deploy_kernel")
            deploy_ramdisk = os.path.join(http_url, self.node.uuid, "deploy_ramdisk")
            image_info = {
                "deploy_kernel": ("deploy_kernel", os.path.join(root_dir, self.node.uuid, "deploy_kernel")),
                "deploy_ramdisk": ("deploy_ramdisk", os.path.join(root_dir, self.node.uuid, "deploy_ramdisk")),
            }

        kernel = os.path.join(http_url, self.node.uuid, "kernel")
        ramdisk = os.path.join(http_url, self.node.uuid, "ramdisk")
        if whle_dsk_img or deploy_utils.get_boot_option(self.node) == "local":
            ramdisk = "no_ramdisk"
            kernel = "no_kernel"
        else:
            image_info.update(
                {
                    "kernel": ("kernel_id", os.path.join(root_dir, self.node.uuid, "kernel")),
                    "ramdisk": ("ramdisk_id", os.path.join(root_dir, self.node.uuid, "ramdisk")),
                }
            )

        ipxe_timeout_in_ms = ipxe_timeout * 1000

        expected_options = {
            "ari_path": ramdisk,
            "deployment_ari_path": deploy_ramdisk,
            "pxe_append_params": "test_param",
            "aki_path": kernel,
            "deployment_aki_path": deploy_kernel,
            "tftp_server": tftp_server,
            "ipxe_timeout": ipxe_timeout_in_ms,
        }

        with task_manager.acquire(self.context, self.node.uuid, shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)
        self.assertEqual(expected_options, options)
Beispiel #13
0
    def _test_build_pxe_config_options(self, build_pxe_mock, deploy_opts_mock,
                                        ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385/', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        fake_deploy_opts = {'iscsi_target_iqn': 'fake-iqn',
                            'deployment_id': 'fake-deploy-id',
                            'deployment_key': 'fake-deploy-key',
                            'disk': 'fake-disk',
                            'ironic_api_url': 'fake-api-url',
                            'boot_option': 'netboot'}

        deploy_opts_mock.return_value = fake_deploy_opts

        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='pxe')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(http_url, self.node.uuid, 'kernel')
            ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
            root_dir = CONF.pxe.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_ramdisk')
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                  'kernel')
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                   'ramdisk')
            root_dir = CONF.pxe.tftp_root

        expected_options = {
            'ari_path': ramdisk,
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server,
            'boot_option': 'netboot'
        }

        expected_options.update(fake_deploy_opts)

        image_info = {'deploy_kernel': ('deploy_kernel',
                                        os.path.join(root_dir,
                                                     self.node.uuid,
                                                     'deploy_kernel')),
                      'deploy_ramdisk': ('deploy_ramdisk',
                                         os.path.join(root_dir,
                                                      self.node.uuid,
                                                      'deploy_ramdisk')),
                      'kernel': ('kernel_id',
                                 os.path.join(root_dir,
                                              self.node.uuid,
                                              'kernel')),
                      'ramdisk': ('ramdisk_id',
                                  os.path.join(root_dir,
                                               self.node.uuid,
                                               'ramdisk'))
                      }
        options = pxe._build_pxe_config_options(self.node,
                                                image_info,
                                                self.context)
        self.assertEqual(expected_options, options)
Beispiel #14
0
    def _test_build_pxe_config_options(self, build_pxe_mock, random_alnum_mock,
                                        ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385/', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        fake_key = '0123456789ABCDEFGHIJKLMNOPQRSTUV'
        random_alnum_mock.return_value = fake_key
        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='pxe')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(http_url, self.node.uuid, 'kernel')
            ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
            root_dir = CONF.pxe.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_ramdisk')
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                  'kernel')
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                   'ramdisk')
            root_dir = CONF.pxe.tftp_root

        expected_options = {
            'deployment_key': '0123456789ABCDEFGHIJKLMNOPQRSTUV',
            'ari_path': ramdisk,
            'iscsi_target_iqn': u'iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33'
                                    u'c123',
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_id': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
            'ironic_api_url': 'http://192.168.122.184:6385',
            'deployment_aki_path': deploy_kernel,
            'disk': 'sda',
            'tftp_server': tftp_server
        }

        image_info = {'deploy_kernel': ('deploy_kernel',
                                        os.path.join(root_dir,
                                                     self.node.uuid,
                                                     'deploy_kernel')),
                      'deploy_ramdisk': ('deploy_ramdisk',
                                         os.path.join(root_dir,
                                                      self.node.uuid,
                                                      'deploy_ramdisk')),
                      'kernel': ('kernel_id',
                                 os.path.join(root_dir,
                                              self.node.uuid,
                                              'kernel')),
                      'ramdisk': ('ramdisk_id',
                                  os.path.join(root_dir,
                                               self.node.uuid,
                                               'ramdisk'))
                      }
        options = pxe._build_pxe_config_options(self.node,
                                                image_info,
                                                self.context)
        self.assertEqual(expected_options, options)

        random_alnum_mock.assert_called_once_with(32)

        # test that deploy_key saved
        db_node = self.dbapi.get_node_by_uuid(self.node.uuid)
        db_key = db_node.instance_info.get('deploy_key')
        self.assertEqual(fake_key, db_key)
Beispiel #15
0
    def _test_build_pxe_config_options(self,
                                       build_pxe_mock,
                                       deploy_opts_mock,
                                       ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385/', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        fake_deploy_opts = {
            'iscsi_target_iqn': 'fake-iqn',
            'deployment_id': 'fake-deploy-id',
            'deployment_key': 'fake-deploy-key',
            'disk': 'fake-disk',
            'ironic_api_url': 'fake-api-url'
        }

        deploy_opts_mock.return_value = fake_deploy_opts

        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='pxe')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(http_url, self.node.uuid, 'kernel')
            ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
            root_dir = CONF.pxe.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid, 'kernel')
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                   'ramdisk')
            root_dir = CONF.pxe.tftp_root

        expected_options = {
            'ari_path': ramdisk,
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server
        }

        expected_options.update(fake_deploy_opts)

        image_info = {
            'deploy_kernel': ('deploy_kernel',
                              os.path.join(root_dir, self.node.uuid,
                                           'deploy_kernel')),
            'deploy_ramdisk': ('deploy_ramdisk',
                               os.path.join(root_dir, self.node.uuid,
                                            'deploy_ramdisk')),
            'kernel':
            ('kernel_id', os.path.join(root_dir, self.node.uuid, 'kernel')),
            'ramdisk':
            ('ramdisk_id', os.path.join(root_dir, self.node.uuid, 'ramdisk'))
        }
        options = pxe._build_pxe_config_options(self.node, image_info,
                                                self.context)
        self.assertEqual(expected_options, options)
Beispiel #16
0
    def _test_build_pxe_config_options(self, build_pxe_mock,
                                       whle_dsk_img=False,
                                       ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        self.node.driver_internal_info['is_whole_disk_image'] = whle_dsk_img

        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='deploy')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(http_url, self.node.uuid, 'kernel')
            ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
            root_dir = CONF.deploy.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                  'kernel')
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                   'ramdisk')
            root_dir = CONF.pxe.tftp_root

        if whle_dsk_img:
            ramdisk = 'no_ramdisk'
            kernel = 'no_kernel'

        expected_options = {
            'ari_path': ramdisk,
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server,
        }

        image_info = {'deploy_kernel': ('deploy_kernel',
                                        os.path.join(root_dir,
                                                     self.node.uuid,
                                                     'deploy_kernel')),
                      'deploy_ramdisk': ('deploy_ramdisk',
                                         os.path.join(root_dir,
                                                      self.node.uuid,
                                                      'deploy_ramdisk')),
                      'kernel': ('kernel_id',
                                 os.path.join(root_dir,
                                              self.node.uuid,
                                              'kernel')),
                      'ramdisk': ('ramdisk_id',
                                  os.path.join(root_dir,
                                               self.node.uuid,
                                               'ramdisk'))}
        options = pxe._build_pxe_config_options(self.node,
                                                image_info,
                                                self.context)
        self.assertEqual(expected_options, options)
Beispiel #17
0
    def _test_build_pxe_config_options(self,
                                       build_pxe_mock,
                                       random_alnum_mock,
                                       ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385/', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        fake_key = '0123456789ABCDEFGHIJKLMNOPQRSTUV'
        random_alnum_mock.return_value = fake_key
        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='pxe')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(http_url, self.node.uuid, 'kernel')
            ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
            root_dir = CONF.pxe.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid, 'kernel')
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                   'ramdisk')
            root_dir = CONF.pxe.tftp_root

        expected_options = {
            'deployment_key': '0123456789ABCDEFGHIJKLMNOPQRSTUV',
            'ari_path': ramdisk,
            'iscsi_target_iqn': u'iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33'
            u'c123',
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_id': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
            'ironic_api_url': 'http://192.168.122.184:6385',
            'deployment_aki_path': deploy_kernel,
            'disk': 'sda',
            'tftp_server': tftp_server
        }

        image_info = {
            'deploy_kernel': ('deploy_kernel',
                              os.path.join(root_dir, self.node.uuid,
                                           'deploy_kernel')),
            'deploy_ramdisk': ('deploy_ramdisk',
                               os.path.join(root_dir, self.node.uuid,
                                            'deploy_ramdisk')),
            'kernel':
            ('kernel_id', os.path.join(root_dir, self.node.uuid, 'kernel')),
            'ramdisk':
            ('ramdisk_id', os.path.join(root_dir, self.node.uuid, 'ramdisk'))
        }
        options = pxe._build_pxe_config_options(self.node, image_info,
                                                self.context)
        self.assertEqual(expected_options, options)

        random_alnum_mock.assert_called_once_with(32)

        # test that deploy_key saved
        db_node = self.dbapi.get_node_by_uuid(self.node.uuid)
        db_key = db_node.instance_info.get('deploy_key')
        self.assertEqual(fake_key, db_key)
Beispiel #18
0
    def _test_build_pxe_config_options(self,
                                       build_pxe_mock,
                                       whle_dsk_img=False,
                                       ipxe_enabled=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385', group='conductor')
        self.config(disk_devices='sda', group='pxe')

        self.node.driver_internal_info['is_whole_disk_image'] = whle_dsk_img

        tftp_server = CONF.pxe.tftp_server

        if ipxe_enabled:
            http_url = 'http://192.1.2.3:1234'
            self.config(ipxe_enabled=True, group='pxe')
            self.config(http_url=http_url, group='deploy')

            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(http_url, self.node.uuid, 'kernel')
            ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
            root_dir = CONF.deploy.http_root
        else:
            deploy_kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                          'deploy_ramdisk')
            kernel = os.path.join(CONF.pxe.tftp_root, self.node.uuid, 'kernel')
            ramdisk = os.path.join(CONF.pxe.tftp_root, self.node.uuid,
                                   'ramdisk')
            root_dir = CONF.pxe.tftp_root

        if whle_dsk_img:
            ramdisk = 'no_ramdisk'
            kernel = 'no_kernel'

        expected_options = {
            'ari_path': ramdisk,
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server,
        }

        image_info = {
            'deploy_kernel': ('deploy_kernel',
                              os.path.join(root_dir, self.node.uuid,
                                           'deploy_kernel')),
            'deploy_ramdisk': ('deploy_ramdisk',
                               os.path.join(root_dir, self.node.uuid,
                                            'deploy_ramdisk')),
            'kernel':
            ('kernel_id', os.path.join(root_dir, self.node.uuid, 'kernel')),
            'ramdisk':
            ('ramdisk_id', os.path.join(root_dir, self.node.uuid, 'ramdisk'))
        }
        options = pxe._build_pxe_config_options(self.node, image_info,
                                                self.context)
        self.assertEqual(expected_options, options)
Beispiel #19
0
    def _test_build_pxe_config_options_ipxe(self,
                                            build_pxe_mock,
                                            glance_mock,
                                            whle_dsk_img=False,
                                            ipxe_timeout=0,
                                            ipxe_use_swift=False):
        self.config(pxe_append_params='test_param', group='pxe')
        # NOTE: right '/' should be removed from url string
        self.config(api_url='http://192.168.122.184:6385', group='conductor')
        self.config(ipxe_timeout=ipxe_timeout, group='pxe')
        root_dir = CONF.deploy.http_root

        driver_internal_info = self.node.driver_internal_info
        driver_internal_info['is_whole_disk_image'] = whle_dsk_img
        self.node.driver_internal_info = driver_internal_info
        self.node.save()

        tftp_server = CONF.pxe.tftp_server

        http_url = 'http://192.1.2.3:1234'
        self.config(ipxe_enabled=True, group='pxe')
        self.config(http_url=http_url, group='deploy')
        if ipxe_use_swift:
            self.config(ipxe_use_swift=True, group='pxe')
            glance = mock.Mock()
            glance_mock.return_value = glance
            glance.swift_temp_url.side_effect = [
                deploy_kernel, deploy_ramdisk
            ] = ['swift_kernel', 'swift_ramdisk']
            image_info = {
                'deploy_kernel': (uuidutils.generate_uuid(),
                                  os.path.join(root_dir, self.node.uuid,
                                               'deploy_kernel')),
                'deploy_ramdisk': (uuidutils.generate_uuid(),
                                   os.path.join(root_dir, self.node.uuid,
                                                'deploy_ramdisk'))
            }
        else:
            deploy_kernel = os.path.join(http_url, self.node.uuid,
                                         'deploy_kernel')
            deploy_ramdisk = os.path.join(http_url, self.node.uuid,
                                          'deploy_ramdisk')
            image_info = {
                'deploy_kernel': ('deploy_kernel',
                                  os.path.join(root_dir, self.node.uuid,
                                               'deploy_kernel')),
                'deploy_ramdisk': ('deploy_ramdisk',
                                   os.path.join(root_dir, self.node.uuid,
                                                'deploy_ramdisk'))
            }

        kernel = os.path.join(http_url, self.node.uuid, 'kernel')
        ramdisk = os.path.join(http_url, self.node.uuid, 'ramdisk')
        if (whle_dsk_img
                or deploy_utils.get_boot_option(self.node) == 'local'):
            ramdisk = 'no_ramdisk'
            kernel = 'no_kernel'
        else:
            image_info.update({
                'kernel': ('kernel_id',
                           os.path.join(root_dir, self.node.uuid, 'kernel')),
                'ramdisk':
                ('ramdisk_id', os.path.join(root_dir, self.node.uuid,
                                            'ramdisk'))
            })

        ipxe_timeout_in_ms = ipxe_timeout * 1000

        expected_options = {
            'ari_path': ramdisk,
            'deployment_ari_path': deploy_ramdisk,
            'pxe_append_params': 'test_param',
            'aki_path': kernel,
            'deployment_aki_path': deploy_kernel,
            'tftp_server': tftp_server,
            'ipxe_timeout': ipxe_timeout_in_ms,
        }

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=True) as task:
            options = pxe._build_pxe_config_options(task, image_info)
        self.assertEqual(expected_options, options)