Exemplo n.º 1
0
 def test_log_and_exit_exception(self, log):
     with self.assertRaises(SystemExit):
         terminator.log_and_exit('image failed',
                                 terminator.buildinfo.BuildInfo(),
                                 exception=Exception('FakeException'),
                                 collect=False)
     log.critical.assert_called_with(
         f'image failed\n\nException] FakeException\n\n'
         f'{_HELP_MSG}#4000')
Exemplo n.º 2
0
 def test_log_and_exit_(self, wpe, log):
     wpe.return_value = True
     with self.assertRaises(SystemExit):
         terminator.log_and_exit('image failed',
                                 terminator.buildinfo.BuildInfo())
     log.critical.assert_called_with(
         f'image failed\n\nSee {terminator.constants.WINPE_BUILD_LOG} for more '
         f'info. Need help? Visit {terminator.constants.HELP_URI}#4000')
     self.assertTrue(log.debug.called)
Exemplo n.º 3
0
    def RunBuild(self):
        """Perform the build."""
        try:
            title.set_title()
            self._build_info.BeyondCorp()

            task_list = self._SetupTaskList()

            if not os.path.exists(task_list):
                root_path = FLAGS.config_root_path or '/'
                try:
                    b = builder.ConfigBuilder(self._build_info)
                    b.Start(out_file=task_list, in_path=root_path)
                except builder.ConfigBuilderError as e:
                    # TODO: Migrate to GlazierError
                    terminator.log_and_exit('Failed to build the task list',
                                            self._build_info, 4302, e)

            try:
                r = runner.ConfigRunner(self._build_info)
                r.Start(task_list=task_list)
            except runner.ConfigRunnerError as e:
                # TODO: Migrate to GlazierError
                terminator.log_and_exit('Failed to execute the task list',
                                        self._build_info, 4304, e)
        except KeyboardInterrupt:
            logging.info('KeyboardInterrupt detected, exiting.')
            sys.exit(1)
        except errors.GlazierError as e:
            terminator.log_and_exit(e.message, self._build_info, e.code,
                                    e.exception)
        except Exception as e:  # pylint: disable=broad-except
            terminator.log_and_exit('Unknown Exception', self._build_info,
                                    4000, e)
Exemplo n.º 4
0
 def _SetupTaskList(self):
     """Determines the location of the task list and erases if necessary."""
     location = constants.SYS_TASK_LIST
     if winpe.check_winpe():
         location = constants.WINPE_TASK_LIST
     logging.debug('Using task list at %s', location)
     if not FLAGS.preserve_tasks and os.path.exists(location):
         logging.debug('Purging old task list.')
         try:
             os.remove(location)
         except OSError as e:
             # TODO: Migrate to GlazierError
             terminator.log_and_exit('Unable to remove task list',
                                     self._build_info, 4303, e)
     return location
Exemplo n.º 5
0
 def test_log_and_exit_code(self, log):
     with self.assertRaises(SystemExit):
         terminator.log_and_exit('image failed',
                                 terminator.buildinfo.BuildInfo(), 1234,
                                 False)
     log.critical.assert_called_with(f'image failed\n\n{_HELP_MSG}#1234')