Example #1
0
 def _call_script_no_chroot(
     self, name, option_list, working_directory
 ):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name])
     )
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&',
             'bash', '--norc', script_path, ' '.join(option_list)
         ]
         if log.getLogFlags().get('run-scripts-in-screen'):
             # Run scripts in a screen session if requested
             config_script = Command.call(
                 ['screen', '-t', '-X', 'bash', '-c', ' '.join(bash_command)]
             )
         else:
             # In standard mode run script through bash
             config_script = Command.call(
                 ['bash', '-c', ' '.join(bash_command)]
             )
         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)
             )
Example #2
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)
             )
Example #3
0
 def _call_script_no_chroot(self, name, option_list, working_directory):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name]))
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&', 'bash', '--norc', script_path,
             ' '.join(option_list)
         ]
         if log.getLogLevel() == logging.DEBUG and not \
            Defaults.is_buildservice_worker():
             # In debug mode run scripts in a screen session to
             # allow attaching and debugging
             config_script = Command.call([
                 'screen', '-t', '-X', 'bash', '-c', ' '.join(bash_command)
             ])
         else:
             # In standard mode run script through bash
             config_script = Command.call(
                 ['bash', '-c', ' '.join(bash_command)])
         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))
Example #4
0
 def _call_script(self, name):
     if os.path.exists(self.root_dir + '/image/' + name):
         config_script = Command.call(
             ['chroot', self.root_dir, 'bash', '/image/' + name])
         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)))
Example #5
0
 def _call_script(self, name):
     if os.path.exists(self.root_dir + '/image/' + name):
         config_script = Command.call(
             ['chroot', self.root_dir, 'bash', '/image/' + name]
         )
         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))
             )
Example #6
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)))
Example #7
0
 def test_poll_and_watch(self, mock_command):
     process = CommandProcess(mock_command)
     process.command.command.process.poll = self.flow
     process.command.command.output_available = self.flow_out_available
     process.command.command.error_available = self.flow_err_available
     process.command.command.output.read = self.flow_out
     process.command.command.error.read = self.flow_err
     process.command.command.process.returncode = 1
     with self._caplog.at_level(logging.DEBUG):
         result = process.poll_and_watch()
         assert '--------------out start-------------' in self._caplog.text
         assert 'data' in self._caplog.text
         assert '--------------out stop--------------' in self._caplog.text
         assert result.stderr == 'error'
Example #8
0
 def _call_script_no_chroot(self, name, option_list, working_directory):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name]))
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&', 'bash', '--norc', script_path,
             ' '.join(option_list)
         ]
         config_script = Command.call(
             ['bash', '-c', ' '.join(bash_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)))
Example #9
0
 def test_poll_and_watch(self, mock_log_debug, mock_command):
     process = CommandProcess(mock_command)
     process.command.command.process.poll = self.flow
     process.command.command.output_available = self.flow_out_available
     process.command.command.error_available = self.flow_err_available
     process.command.command.output.read = self.flow_out
     process.command.command.error.read = self.flow_err
     process.command.command.process.returncode = 1
     result = process.poll_and_watch()
     call = mock_log_debug.call_args_list[0]
     assert mock_log_debug.call_args_list[0] == \
         call('--------------out start-------------')
     call = mock_log_debug.call_args_list[1]
     assert mock_log_debug.call_args_list[1] == \
         call('data')
     call = mock_log_debug.call_args_list[2]
     assert mock_log_debug.call_args_list[2] == \
         call('--------------out stop--------------')
     assert result.stderr == 'error'
Example #10
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))
Example #11
0
 def test_poll_and_watch(self, mock_log_debug, mock_command):
     process = CommandProcess(mock_command)
     process.command.command.process.poll = self.flow
     process.command.command.output_available = self.flow_out_available
     process.command.command.error_available = self.flow_err_available
     process.command.command.output.read = self.flow_out
     process.command.command.error.read = self.flow_err
     process.command.command.process.returncode = 1
     result = process.poll_and_watch()
     call = mock_log_debug.call_args_list[0]
     assert mock_log_debug.call_args_list[0] == \
         call('--------------out start-------------')
     call = mock_log_debug.call_args_list[1]
     assert mock_log_debug.call_args_list[1] == \
         call('data')
     call = mock_log_debug.call_args_list[2]
     assert mock_log_debug.call_args_list[2] == \
         call('--------------out stop--------------')
     assert result.stderr == 'error'
Example #12
0
 def _call_script_no_chroot(
     self, name, option_list, working_directory
 ):
     if not working_directory:
         working_directory = self.root_dir
     script_path = os.path.abspath(
         os.sep.join([self.root_dir, 'image', name])
     )
     if os.path.exists(script_path):
         bash_command = [
             'cd', working_directory, '&&',
             'bash', '--norc', script_path, ' '.join(option_list)
         ]
         config_script = Command.call(
             ['bash', '-c', ' '.join(bash_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))
             )