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 do_configdrive(self): 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.configdrive_scheme.template_names('cloud_config'), self.configdrive_scheme.template_data(), cc_output_path) utils.render_and_save( tmpl_dir, self.configdrive_scheme.template_names('boothook'), self.configdrive_scheme.template_data(), bh_output_path) utils.render_and_save( tmpl_dir, self.configdrive_scheme.template_names('meta-data'), self.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) configdrive_device = self.partition_scheme.configdrive_device() if configdrive_device is None: raise errors.WrongPartitionSchemeError( 'Error while trying to get configdrive device: ' 'configdrive device not found') self.image_scheme.add_image(uri='file://%s' % CONF.config_drive_path, target_device=configdrive_device, image_format='iso9660', container='raw')
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()
def do_configdrive(self): LOG.debug('--- Creating configdrive (do_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) configdrive_device = self.driver.partition_scheme.configdrive_device() if configdrive_device is None: raise errors.WrongPartitionSchemeError( 'Error while trying to get configdrive device: ' 'configdrive device not found') size = os.path.getsize(CONF.config_drive_path) md5 = utils.calculate_md5(CONF.config_drive_path, size) self.driver.image_scheme.add_image( uri='file://%s' % CONF.config_drive_path, target_device=configdrive_device, format='iso9660', container='raw', size=size, md5=md5, )
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()
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()
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")