Пример #1
0
    def test_call_run_once_with_retry_exception_and_pass(self):
        """
        Test call_run_once_with_retry duplicating a test that fails at first
        and later passes.
        """
        # Stubbed out for the write_keyval call.
        self.test.outputdir = '/tmp'
        self.test.job._tap = None

        num_to_fail = 2
        self.test.job.test_retry = 5
        self.god.stub_function(self.test, 'drop_caches_between_iterations')
        self.god.stub_function(self.test, 'run_once')
        before_hook = self.god.create_mock_function('before_hook')
        after_hook = self.god.create_mock_function('after_hook')
        self.god.stub_function(self.test, '_call_run_once')
        self.test.register_before_iteration_hook(before_hook)
        self.test.register_after_iteration_hook(after_hook)
        self.god.stub_function(self.test.job, 'record')
        # tests the test._call_run_once implementation
        error = common_lib_error.TestFailRetry('fail')
        self._setup_failed_test_calls(num_to_fail, error)
        # Passing call
        self.test._call_run_once.expect_call([], False, None, (1, 2),
                                             {'arg': 'val'})
        self.test._call_run_once_with_retry([], False, None, (1, 2),
                                            {'arg': 'val'})
        self.god.check_playback()
    def initialize(self):
        """Setup required DEPS and start the http listener."""
        dep = 'page_cycler_dep'
        dep_dir = os.path.join(self.autodir, 'deps', dep)
        self.job.install_pkg(dep, 'dep', dep_dir)

        try:
            self.listener = httpd.HTTPListener(HTTP_PORT, docroot=dep_dir)
            self.listener.run()
        except Exception as err:
            logging.info('Timeout starting HTTP listener')
            raise error.TestFailRetry(err)
    def run_once(self):
        self._ensure_tpm_ready()
        if cryptohome.get_login_status()['boot_lockbox_finalized']:
            raise error.TestFailRetry('Test needs to run on an unfinalized '
                                      'boot lockbox - reboot and retry.')

        if not self._sign_lockbox():
            raise error.TestFail('Boot lockbox could not be signed.')

        if cryptohome.get_login_status()['boot_lockbox_finalized']:
            raise error.TestFail('Boot lockbox is already finalized.')

        if not self._verify_lockbox():
            raise error.TestFail('Boot lockbox could not be verified.')

        # Setup a bad signature and make sure it doesn't verify.
        open(self.data_file, mode='w').write('test_lockbox_data2')
        if self._verify_lockbox():
            raise error.TestFail('Boot lockbox verified bad data.')
        open(self.data_file, mode='w').write('test_lockbox_data')

        self._set_boot_attribute()

        if self._get_boot_attribute():
            raise error.TestFail('Boot attributes already have data.')

        if not self._flush_and_sign_boot_attributes():
            raise error.TestFail('Boot attributes could not sign.')

        if not self._get_boot_attribute():
            raise error.TestFail('Boot attribute was not available.')

        # Check again to make sure nothing has tricked the finalize check.
        if cryptohome.get_login_status()['boot_lockbox_finalized']:
            raise error.TestFail('Boot lockbox prematurely finalized.')

        # Finalize and make sure we can verify but not sign.
        self._finalize_lockbox()

        if not cryptohome.get_login_status()['boot_lockbox_finalized']:
            raise error.TestFail('Boot lockbox finalize status did not change '
                                 'after finalization.')

        if self._flush_and_sign_boot_attributes():
            raise error.TestFail('Boot attributes signed after finalization.')

        if not self._verify_lockbox():
            raise error.TestFail('Boot lockbox could not be verified after '
                                 'finalization.')

        if self._sign_lockbox():
            raise error.TestFail('Boot lockbox signed after finalization.')
Пример #4
0
 def test_call_run_once_with_retry_exception(self):
     """
     Test call_run_once_with_retry duplicating a test that will always fail.
     """
     self.test.job.test_retry = 5
     self.god.stub_function(self.test, 'drop_caches_between_iterations')
     self.god.stub_function(self.test, 'run_once')
     before_hook = self.god.create_mock_function('before_hook')
     after_hook = self.god.create_mock_function('after_hook')
     self.test.register_before_iteration_hook(before_hook)
     self.test.register_after_iteration_hook(after_hook)
     error = common_lib_error.TestFailRetry('fail')
     self._setup_failed_test_calls(self.test.job.test_retry + 1, error)
     try:
         self.test._call_run_once_with_retry([], False, None, (1, 2),
                                             {'arg': 'val'})
     except Exception as err:
         if err != error:
             raise
     self.god.check_playback()
Пример #5
0
    def run_once(self, seconds=1):
        if random.randint(0, 1):
            raise error.TestFailRetry('Flaky test failed intentionally.')

        time.sleep(seconds)