def _call_script(self, name, option_list=None): script_path = os.path.join(self.root_dir, 'image', name) if os.path.exists(script_path): options = option_list or [] if log.getLogFlags().get('run-scripts-in-screen'): # Run scripts in a screen session if requested command = ['screen', '-t', '-X', 'chroot', self.root_dir] else: # In standard mode run scripts without a terminal # associated to them command = ['chroot', self.root_dir] if not Path.access(script_path, os.X_OK): command.append('bash') command.append( os.path.join(defaults.IMAGE_METADATA_DIR, name) ) command.extend(options) profile = Profile(self.xml_state) caller_environment = copy.deepcopy(os.environ) caller_environment.update(profile.get_settings()) config_script = Command.call(command, caller_environment) process = CommandProcess( command=config_script, log_topic='Calling ' + name + ' script' ) result = process.poll_and_watch() if result.returncode != 0: raise KiwiScriptFailed( '{0} failed: {1}'.format(name, result.stderr) )
def test_access_with_args(self, mock_access, mock_stat): mock_access.return_value = True fname = "arbitrary" mode = os.R_OK assert Path.access(fname, mode, effective_ids=True) mock_stat.assert_called_once_with(fname) mock_access.assert_called_once_with(fname, mode, effective_ids=True)
def _call_script(self, name): script_path = os.path.join(self.root_dir, 'image', name) if os.path.exists(script_path): command = ['chroot', self.root_dir] if not Path.access(script_path, os.X_OK): command += ['bash'] command += ['/image/' + name] config_script = Command.call(command) process = CommandProcess(command=config_script, log_topic='Calling ' + name + ' script') result = process.poll_and_watch() if result.returncode != 0: raise KiwiScriptFailed('%s failed: %s' % (name, format(result.stderr)))
def _call_script(self, name, option_list=None): script_path = os.path.join(self.root_dir, 'image', name) if os.path.exists(script_path): options = option_list or [] command = ['chroot', self.root_dir] if not Path.access(script_path, os.X_OK): command.append('bash') command.append(os.path.join(defaults.IMAGE_METADATA_DIR, name)) command.extend(options) profile = Profile(self.xml_state) caller_environment = copy.deepcopy(os.environ) caller_environment.update(profile.get_settings()) config_script = Command.call(command, caller_environment) process = CommandProcess(command=config_script, log_topic='Calling ' + name + ' script') result = process.poll_and_watch() if result.returncode != 0: raise KiwiScriptFailed('{0} failed: {1}'.format( name, result.stderr))
def test_access_with_non_existent_file(self): non_existent = "/some/file/that/should/not/exist" with raises(KiwiFileAccessError) as issue: Path.access(non_existent, os.F_OK) assert non_existent in issue.value.message
def test_access_invalid_mode(self): with raises(ValueError) as issue: Path.access("/some/non-existent-file/", 128) assert '0x80' in format(issue.value)
def test_access_with_non_existent_file(self): non_existent = "/some/file/that/should/not/exist" with raises(KiwiFileAccessError) as kfae_exc: Path.access(non_existent, os.F_OK) assert non_existent in str(kfae_exc)
def test_access_invalid_mode(self): with raises(ValueError) as val_err_exc: Path.access("/some/non-existent-file/", 128) assert "0x80" in str(val_err_exc)