Пример #1
0
    def test_deploy(
        self,
        mock_node_set_boot,
        mock_node_power_action,
        mock_update_neutron,
        mock_cache_instance_image,
        mock_get_image_file_path,
        mock_get_image_mb,
    ):
        fake_img_path = "/test/path/test.img"
        mock_get_image_file_path.return_value = fake_img_path
        mock_get_image_mb.return_value = 1

        with task_manager.acquire(self.context, self.node.uuid, shared=False) as task:
            state = task.driver.deploy.deploy(task)
            self.assertEqual(state, states.DEPLOYWAIT)
            mock_cache_instance_image.assert_called_once_with(self.context, task.node)
            mock_get_image_file_path.assert_called_once_with(task.node.uuid)
            mock_get_image_mb.assert_called_once_with(fake_img_path)
            mock_update_neutron.assert_called_once_with(task)
            mock_node_set_boot.assert_called_once_with(task, "pxe", persistent=True)
            mock_node_power_action.assert_called_once_with(task, states.REBOOT)

            # ensure token file created
            t_path = pxe._get_token_file_path(self.node.uuid)
            token = open(t_path, "r").read()
            self.assertEqual(self.context.auth_token, token)
Пример #2
0
    def test_deploy(self, mock_node_set_boot, mock_node_power_action,
                    mock_update_dhcp, mock_cache_instance_image,
                    mock_get_image_file_path, mock_get_image_mb, mock_expire):
        fake_img_path = '/test/path/test.img'
        mock_get_image_file_path.return_value = fake_img_path
        mock_get_image_mb.return_value = 1
        mock_expire.return_value = False
        self.config(deploy_callback_timeout=600, group='conductor')

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            dhcp_opts = pxe_utils.dhcp_options_for_instance(task)
            state = task.driver.deploy.deploy(task)
            self.assertEqual(state, states.DEPLOYWAIT)
            mock_cache_instance_image.assert_called_once_with(
                self.context, task.node)
            mock_get_image_file_path.assert_called_once_with(task.node.uuid)
            mock_get_image_mb.assert_called_once_with(fake_img_path)
            mock_update_dhcp.assert_called_once_with(task, dhcp_opts)
            mock_expire.assert_called_once_with(self.context.auth_token, 600)
            mock_node_set_boot.assert_called_once_with(task,
                                                       'pxe',
                                                       persistent=True)
            mock_node_power_action.assert_called_once_with(task, states.REBOOT)

            # ensure token file created
            t_path = pxe._get_token_file_path(self.node.uuid)
            token = open(t_path, 'r').read()
            self.assertEqual(self.context.auth_token, token)
Пример #3
0
    def setUp(self):
        super(CleanUpFullFlowTestCase, self).setUp()
        self.config(image_cache_size=0, group='pxe')

        # Configure node
        mgr_utils.mock_the_extension_manager(driver="fake_pxe")
        instance_info = INST_INFO_DICT
        instance_info['deploy_key'] = 'fake-56789'
        self.node = obj_utils.create_test_node(self.context,
                                               driver='fake_pxe',
                                               instance_info=instance_info,
                                               driver_info=DRV_INFO_DICT)
        self.dbapi = dbapi.get_instance()
        self.port = obj_utils.create_test_port(self.context,
                                               node_id=self.node.id)

        # Configure temporary directories
        pxe_temp_dir = tempfile.mkdtemp()
        self.config(tftp_root=pxe_temp_dir, group='pxe')
        tftp_master_dir = os.path.join(CONF.pxe.tftp_root, 'tftp_master')
        self.config(tftp_master_path=tftp_master_dir, group='pxe')
        os.makedirs(tftp_master_dir)

        instance_temp_dir = tempfile.mkdtemp()
        self.config(images_path=instance_temp_dir, group='pxe')
        instance_master_dir = os.path.join(CONF.pxe.images_path,
                                           'instance_master')
        self.config(instance_master_path=instance_master_dir, group='pxe')
        os.makedirs(instance_master_dir)
        self.pxe_config_dir = os.path.join(CONF.pxe.tftp_root, 'pxelinux.cfg')
        os.makedirs(self.pxe_config_dir)

        # Populate some file names
        self.master_kernel_path = os.path.join(CONF.pxe.tftp_master_path,
                                               'kernel')
        self.master_instance_path = os.path.join(CONF.pxe.instance_master_path,
                                                 'image_uuid')
        self.node_tftp_dir = os.path.join(CONF.pxe.tftp_root, self.node.uuid)
        os.makedirs(self.node_tftp_dir)
        self.kernel_path = os.path.join(self.node_tftp_dir, 'kernel')
        self.node_image_dir = iscsi_deploy._get_image_dir_path(self.node.uuid)
        os.makedirs(self.node_image_dir)
        self.image_path = iscsi_deploy._get_image_file_path(self.node.uuid)
        self.config_path = pxe_utils.get_pxe_config_file_path(self.node.uuid)
        self.mac_path = pxe_utils._get_pxe_mac_path(self.port.address)
        self.token_path = pxe._get_token_file_path(self.node.uuid)

        # Create files
        self.files = [
            self.config_path, self.master_kernel_path,
            self.master_instance_path, self.token_path
        ]
        for fname in self.files:
            # NOTE(dtantsur): files with 0 size won't be cleaned up
            with open(fname, 'w') as fp:
                fp.write('test')

        os.link(self.config_path, self.mac_path)
        os.link(self.master_kernel_path, self.kernel_path)
        os.link(self.master_instance_path, self.image_path)
Пример #4
0
    def test_start_deploy(self):
        with mock.patch.object(pxe, '_create_pxe_config') \
                as create_pxe_config_mock:
            with mock.patch.object(pxe, '_cache_images') as cache_images_mock:
                with mock.patch.object(pxe, '_get_tftp_image_info') \
                        as get_tftp_image_info_mock:
                    get_tftp_image_info_mock.return_value = None
                    create_pxe_config_mock.return_value = None
                    cache_images_mock.return_value = None

                    with task_manager.acquire(self.context,
                                    [self.node['uuid']], shared=False) as task:
                        state = task.resources[0].driver.deploy.deploy(task,
                                                                    self.node)
                        get_tftp_image_info_mock.assert_called_once_with(
                                                                  self.node)
                        create_pxe_config_mock.assert_called_once_with(task,
                                                                    self.node,
                                                                    None)
                        cache_images_mock.assert_called_once_with(self.node,
                                                                  None)
                        self.assertEqual(state, states.DEPLOYING)

                        t_path = pxe._get_token_file_path(self.node['uuid'])
                        token = open(t_path, 'r').read()
                        self.assertEqual(self.context.auth_token, token)
Пример #5
0
    def test_deploy(self, mock_node_set_boot, mock_node_power_action,
                    mock_update_dhcp, mock_cache_instance_image,
                    mock_get_image_file_path, mock_get_image_mb, mock_expire):
        fake_img_path = '/test/path/test.img'
        mock_get_image_file_path.return_value = fake_img_path
        mock_get_image_mb.return_value = 1
        mock_expire.return_value = False
        self.config(deploy_callback_timeout=600, group='conductor')

        with task_manager.acquire(self.context,
                                  self.node.uuid, shared=False) as task:
            dhcp_opts = pxe_utils.dhcp_options_for_instance(task)
            state = task.driver.deploy.deploy(task)
            self.assertEqual(state, states.DEPLOYWAIT)
            mock_cache_instance_image.assert_called_once_with(
                self.context, task.node)
            mock_get_image_file_path.assert_called_once_with(task.node.uuid)
            mock_get_image_mb.assert_called_once_with(fake_img_path)
            mock_update_dhcp.assert_called_once_with(task, dhcp_opts)
            mock_expire.assert_called_once_with(self.context.auth_token, 600)
            mock_node_set_boot.assert_called_once_with(task, 'pxe',
                                                       persistent=True)
            mock_node_power_action.assert_called_once_with(task, states.REBOOT)

            # ensure token file created
            t_path = pxe._get_token_file_path(self.node.uuid)
            token = open(t_path, 'r').read()
            self.assertEqual(self.context.auth_token, token)
Пример #6
0
 def test_clean_up(self, mock_image_info, mock_cache, mock_pxe_clean,
                   mock_iscsi_clean, mock_unlink):
     mock_image_info.return_value = {'label': ['', 'deploy_kernel']}
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.driver.deploy.clean_up(task)
         mock_image_info.assert_called_once_with(task.node, task.context)
         mock_pxe_clean.assert_called_once_with(task)
         mock_unlink.assert_any_call('deploy_kernel')
         mock_unlink.assert_any_call(
             pxe._get_token_file_path(task.node.uuid))
         mock_iscsi_clean.assert_called_once_with(task.node.uuid)
     mock_cache.return_value.clean_up.assert_called_once_with()
Пример #7
0
 def test_clean_up_fail_get_image_info(self, mock_image_info, mock_cache,
                                       mock_pxe_clean, mock_iscsi_clean,
                                       mock_unlink):
     mock_image_info.side_effect = exception.MissingParameterValue('foo')
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.driver.deploy.clean_up(task)
         mock_image_info.assert_called_once_with(task.node, task.context)
         mock_pxe_clean.assert_called_once_with(task)
         mock_unlink.assert_called_once_with(
             pxe._get_token_file_path(task.node.uuid))
         mock_iscsi_clean.assert_called_once_with(task.node.uuid)
     mock_cache.return_value.clean_up.assert_called_once_with()
Пример #8
0
 def test_clean_up(self, mock_image_info, mock_cache, mock_pxe_clean,
                   mock_iscsi_clean, mock_unlink):
     mock_image_info.return_value = {'label': ['', 'deploy_kernel']}
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.driver.deploy.clean_up(task)
         mock_image_info.assert_called_once_with(task.node,
                                                 task.context)
         mock_pxe_clean.assert_called_once_with(task)
         mock_unlink.assert_any_call('deploy_kernel')
         mock_unlink.assert_any_call(pxe._get_token_file_path(
             task.node.uuid))
         mock_iscsi_clean.assert_called_once_with(task.node.uuid)
     mock_cache.return_value.clean_up.assert_called_once_with()
Пример #9
0
 def test_clean_up_fail_get_image_info(self, mock_image_info, mock_cache,
                                       mock_pxe_clean, mock_iscsi_clean,
                                       mock_unlink):
     mock_image_info.side_effect = exception.MissingParameterValue('foo')
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         task.driver.deploy.clean_up(task)
         mock_image_info.assert_called_once_with(task.node,
                                                 task.context)
         mock_pxe_clean.assert_called_once_with(task)
         mock_unlink.assert_called_once_with(pxe._get_token_file_path(
             task.node.uuid))
         mock_iscsi_clean.assert_called_once_with(task.node.uuid)
     mock_cache.return_value.clean_up.assert_called_once_with()
Пример #10
0
    def test_deploy(self):
        with mock.patch.object(pxe, '_update_neutron') as update_neutron_mock:
            with mock.patch.object(manager_utils,
                    'node_power_action') as node_power_mock:
                with task_manager.acquire(self.context,
                        self.node['uuid'], shared=False) as task:
                    state = task.driver.deploy.deploy(task, self.node)
                    self.assertEqual(state, states.DEPLOYWAIT)
                    update_neutron_mock.assert_called_once_with(task,
                                                                self.node)
                    node_power_mock.assert_called_once_with(task, self.node,
                                                            states.REBOOT)

                    # ensure token file created
                    t_path = pxe._get_token_file_path(self.node['uuid'])
                    token = open(t_path, 'r').read()
                    self.assertEqual(self.context.auth_token, token)
Пример #11
0
    def test_deploy(self):
        with mock.patch.object(pxe, '_update_neutron') as update_neutron_mock:
            with mock.patch.object(manager_utils,
                                   'node_power_action') as node_power_mock:
                with task_manager.acquire(self.context,
                                          self.node['uuid'],
                                          shared=False) as task:
                    state = task.driver.deploy.deploy(task, self.node)
                    self.assertEqual(state, states.DEPLOYWAIT)
                    update_neutron_mock.assert_called_once_with(
                        task, self.node)
                    node_power_mock.assert_called_once_with(
                        task, self.node, states.REBOOT)

                    # ensure token file created
                    t_path = pxe._get_token_file_path(self.node['uuid'])
                    token = open(t_path, 'r').read()
                    self.assertEqual(self.context.auth_token, token)
Пример #12
0
    def test_deploy_token_near_expiration(
            self, mock_node_set_boot, mock_node_power_action, mock_update_dhcp,
            mock_cache_instance_image, mock_get_image_file_path,
            mock_get_image_mb, mock_expire, mock_admin_token):
        mock_get_image_mb.return_value = 1
        mock_expire.return_value = True
        new_token = 'new_admin_token'
        mock_admin_token.return_value = new_token
        self.config(deploy_callback_timeout=600, group='conductor')

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            task.driver.deploy.deploy(task)

            mock_expire.assert_called_once_with(self.context.auth_token, 600)
            mock_admin_token.assert_called_once_with()
            # ensure token file created with new token
            t_path = pxe._get_token_file_path(self.node.uuid)
            token = open(t_path, 'r').read()
            self.assertEqual(new_token, token)
Пример #13
0
    def test_deploy_token_near_expiration(self, mock_node_set_boot,
                    mock_node_power_action, mock_update_dhcp,
                    mock_cache_instance_image, mock_get_image_file_path,
                    mock_get_image_mb, mock_expire, mock_admin_token):
        mock_get_image_mb.return_value = 1
        mock_expire.return_value = True
        new_token = 'new_admin_token'
        mock_admin_token.return_value = new_token
        self.config(deploy_callback_timeout=600, group='conductor')

        with task_manager.acquire(self.context,
                                  self.node.uuid, shared=False) as task:
            task.driver.deploy.deploy(task)

            mock_expire.assert_called_once_with(self.context.auth_token, 600)
            mock_admin_token.assert_called_once_with()
            # ensure token file created with new token
            t_path = pxe._get_token_file_path(self.node.uuid)
            token = open(t_path, 'r').read()
            self.assertEqual(new_token, token)
Пример #14
0
 def _create_token_file(self):
     token_path = pxe._get_token_file_path(self.node['uuid'])
     open(token_path, 'w').close()
     return token_path
Пример #15
0
 def test_get_token_file_path(self):
     node_uuid = self.node['uuid']
     self.assertEqual('/tftpboot/token-' + node_uuid,
                      pxe._get_token_file_path(node_uuid))
Пример #16
0
    def setUp(self):
        super(CleanUpFullFlowTestCase, self).setUp()
        self.config(image_cache_size=0, group='pxe')

        # Configure node
        mgr_utils.mock_the_extension_manager(driver="fake_pxe")
        instance_info = INST_INFO_DICT
        instance_info['deploy_key'] = 'fake-56789'
        self.node = obj_utils.create_test_node(self.context,
                                               driver='fake_pxe',
                                               instance_info=instance_info,
                                               driver_info=DRV_INFO_DICT)
        self.port = obj_utils.create_test_port(self.context,
                                               node_id=self.node.id)

        # Configure temporary directories
        pxe_temp_dir = tempfile.mkdtemp()
        self.config(tftp_root=pxe_temp_dir, group='pxe')
        tftp_master_dir = os.path.join(CONF.pxe.tftp_root,
                                       'tftp_master')
        self.config(tftp_master_path=tftp_master_dir, group='pxe')
        os.makedirs(tftp_master_dir)

        instance_temp_dir = tempfile.mkdtemp()
        self.config(images_path=instance_temp_dir,
                    group='pxe')
        instance_master_dir = os.path.join(CONF.pxe.images_path,
                                           'instance_master')
        self.config(instance_master_path=instance_master_dir,
                    group='pxe')
        os.makedirs(instance_master_dir)
        self.pxe_config_dir = os.path.join(CONF.pxe.tftp_root, 'pxelinux.cfg')
        os.makedirs(self.pxe_config_dir)

        # Populate some file names
        self.master_kernel_path = os.path.join(CONF.pxe.tftp_master_path,
                                               'kernel')
        self.master_instance_path = os.path.join(CONF.pxe.instance_master_path,
                                                'image_uuid')
        self.node_tftp_dir = os.path.join(CONF.pxe.tftp_root,
                                          self.node.uuid)
        os.makedirs(self.node_tftp_dir)
        self.kernel_path = os.path.join(self.node_tftp_dir,
                                        'kernel')
        self.node_image_dir = iscsi_deploy._get_image_dir_path(self.node.uuid)
        os.makedirs(self.node_image_dir)
        self.image_path = iscsi_deploy._get_image_file_path(self.node.uuid)
        self.config_path = pxe_utils.get_pxe_config_file_path(self.node.uuid)
        self.mac_path = pxe_utils._get_pxe_mac_path(self.port.address)
        self.token_path = pxe._get_token_file_path(self.node.uuid)

        # Create files
        self.files = [self.config_path, self.master_kernel_path,
                      self.master_instance_path, self.token_path]
        for fname in self.files:
            # NOTE(dtantsur): files with 0 size won't be cleaned up
            with open(fname, 'w') as fp:
                fp.write('test')

        os.link(self.config_path, self.mac_path)
        os.link(self.master_kernel_path, self.kernel_path)
        os.link(self.master_instance_path, self.image_path)
Пример #17
0
 def test_get_token_file_path(self):
     node_uuid = self.node['uuid']
     self.assertEqual(pxe._get_token_file_path(node_uuid),
                      '/tftpboot/token-' + node_uuid)
Пример #18
0
 def _create_token_file(self):
     token_path = pxe._get_token_file_path(self.node.uuid)
     open(token_path, 'w').close()
     return token_path
Пример #19
0
 def test_get_token_file_path(self):
     node_uuid = self.node.uuid
     self.assertEqual('/tftpboot/token-' + node_uuid,
                      pxe._get_token_file_path(node_uuid))