Esempio n. 1
0
 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)
             )
Esempio n. 2
0
    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)
Esempio n. 3
0
 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)))
Esempio n. 4
0
 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))
Esempio n. 5
0
 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
Esempio n. 6
0
 def test_access_invalid_mode(self):
     with raises(ValueError) as issue:
         Path.access("/some/non-existent-file/", 128)
     assert '0x80' in format(issue.value)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)