Exemple #1
0
 def test_render_and_save_ok(self, mock_open, mock_j_lo, mock_j_env):
     mock_render = mock.Mock()
     mock_render.render.return_value = 'fake_data'
     mock_j_env.get_template.return_value = mock_render
     utils.render_and_save('fake_dir', 'fake_tmpl_name', 'fake_data',
                           'fake_file_name')
     mock_open.assert_called_once_with('fake_file_name', 'w')
 def test_render_and_save_ok(self, mock_open, mock_j_lo, mock_j_env):
     mock_render = mock.Mock()
     mock_render.render.return_value = 'fake_data'
     mock_j_env.get_template.return_value = mock_render
     utils.render_and_save('fake_dir', 'fake_tmpl_name', 'fake_data',
                           'fake_file_name')
     mock_open.assert_called_once_with('fake_file_name', 'w')
Exemple #3
0
    def do_configdrive(self):
        LOG.debug('--- Creating configdrive (do_configdrive) ---')
        if CONF.prepare_configdrive:
            cc_output_path = os.path.join(CONF.tmp_path, 'cloud_config.txt')
            bh_output_path = os.path.join(CONF.tmp_path, 'boothook.txt')
            # NOTE:file should be strictly named as 'user-data'
            #      the same is for meta-data as well
            ud_output_path = os.path.join(CONF.tmp_path, 'user-data')
            md_output_path = os.path.join(CONF.tmp_path, 'meta-data')

            tmpl_dir = CONF.nc_template_path
            utils.render_and_save(
                tmpl_dir,
                self.driver.configdrive_scheme.template_names('cloud_config'),
                self.driver.configdrive_scheme.template_data(),
                cc_output_path
            )
            utils.render_and_save(
                tmpl_dir,
                self.driver.configdrive_scheme.template_names('boothook'),
                self.driver.configdrive_scheme.template_data(),
                bh_output_path
            )
            utils.render_and_save(
                tmpl_dir,
                self.driver.configdrive_scheme.template_names('meta_data'),
                self.driver.configdrive_scheme.template_data(),
                md_output_path
            )

            utils.execute(
                'write-mime-multipart', '--output=%s' % ud_output_path,
                '%s:text/cloud-boothook' % bh_output_path,
                '%s:text/cloud-config' % cc_output_path)
            utils.execute('genisoimage', '-output', CONF.config_drive_path,
                          '-volid', 'cidata', '-joliet', '-rock',
                          ud_output_path, md_output_path)

        if CONF.prepare_configdrive or os.path.isfile(CONF.config_drive_path):
            self._add_configdrive_image()
Exemple #4
0
    def _prepare_configdrive_files(self):
        # see data sources part of cloud-init documentation
        # for directory structure
        cd_root = tempfile.mkdtemp(dir=CONF.tmp_path)
        cd_latest = os.path.join(cd_root, 'openstack', 'latest')
        md_output_path = os.path.join(cd_latest, 'meta_data.json')
        ud_output_path = os.path.join(cd_latest, 'user_data')
        os.makedirs(cd_latest)

        cc_output_path = os.path.join(CONF.tmp_path, 'cloud_config.txt')
        bh_output_path = os.path.join(CONF.tmp_path, 'boothook.txt')

        tmpl_dir = CONF.nc_template_path
        utils.render_and_save(
            tmpl_dir,
            self.driver.configdrive_scheme.template_names('cloud_config'),
            self.driver.configdrive_scheme.template_data(),
            cc_output_path
        )
        utils.render_and_save(
            tmpl_dir,
            self.driver.configdrive_scheme.template_names('boothook'),
            self.driver.configdrive_scheme.template_data(),
            bh_output_path
        )
        utils.render_and_save(
            tmpl_dir,
            self.driver.configdrive_scheme.template_names('meta_data_json'),
            self.driver.configdrive_scheme.template_data(),
            md_output_path
        )

        utils.execute(
            'write-mime-multipart', '--output=%s' % ud_output_path,
            '%s:text/cloud-boothook' % bh_output_path,
            '%s:text/cloud-config' % cc_output_path)
        return [os.path.join(cd_root, 'openstack')]
Exemple #5
0
 def test_render_and_save_ok(self, mock_open, mock_j_lo, mock_j_env):
     mock_render = mock.Mock()
     mock_render.render.return_value = "fake_data"
     mock_j_env.get_template.return_value = mock_render
     utils.render_and_save("fake_dir", "fake_tmpl_name", "fake_data", "fake_file_name")
     mock_open.assert_called_once_with("fake_file_name", "w")