Exemple #1
0
 def test_process_lifecycle_exception_still_removes_working_dir(self, super_pl, mock_rmtree):
     step = PluginStep("foo", working_dir=self.working_dir, conduit=self.conduit)
     step._build_final_report = Mock()
     self.assertRaises(Exception, step.process_lifecycle)
     super_pl.assert_called_once_with()
     self.assertFalse(step._build_final_report.called)
     mock_rmtree.assert_called_once_with(self.working_dir, ignore_errors=True)
Exemple #2
0
 def test_process_lifecycle_non_existent_working_dir(self, mock_wd, mock_rmtree, mock_progress,
                                                     mock_build_report):
     new_dir = os.path.join(self.working_dir, 'test', 'bar')
     mock_wd.return_value = new_dir
     step = PluginStep("foo")
     step.process_lifecycle()
     self.assertTrue(os.path.exists(new_dir))
     mock_rmtree.assert_called_once_with(new_dir, ignore_errors=True)
Exemple #3
0
    def test_process_lifecycle_reports_on_error(self):
        # set working_dir and conduit. This is required by process_lifecycle
        step = PluginStep('parent', working_dir=self.working_dir, conduit=self.conduit)
        step.process = Mock(side_effect=Exception('Foo'))
        step.report_progress = Mock()

        self.assertRaises(Exception, step.process_lifecycle)

        step.report_progress.assert_called_once_with(force=True)
Exemple #4
0
 def test_process_step_failure_reported_on_metadata_finalized(self, mock_get_units):
     self.pluginstep.repo.content_unit_counts = {'FOO_TYPE': 1}
     mock_get_units.return_value = ['mock_unit']
     step = PluginStep('foo_step')
     step.parent = self.pluginstep
     step.finalize = Mock(side_effect=Exception())
     self.assertRaises(Exception, step.process)
     self.assertEquals(step.state, reporting_constants.STATE_FAILED)
     self.assertEquals(step.progress_successes, 1)
     self.assertEquals(step.progress_failures, 1)
     self.assertEquals(step.total_units, 1)
Exemple #5
0
    def test_record_failure(self):
        plugin_step = PluginStep('foo_step')
        plugin_step.parent = self.pluginstep

        error_msg = 'Too bad, so sad'

        try:
            raise Exception(error_msg)

        except Exception, e:
            tb = sys.exc_info()[2]
            plugin_step._record_failure(e, tb)
Exemple #6
0
 def test_process_lifecycle_no_working_dir(self, mock_wd):
     # we need to mock this to None instead of just setting
     # self.working_directory to None so that we don't go up the step repo
     # chain looking for working_dirs
     mock_wd.return_value = None
     step = PluginStep("foo")
     self.assertRaises(RuntimeError, step.process_lifecycle)
Exemple #7
0
 def test_get_progress_report_summary(self):
     parent_step = PluginStep('parent_step')
     step = PluginStep('foo_step')
     parent_step.add_child(step)
     step.state = reporting_constants.STATE_COMPLETE
     report = parent_step.get_progress_report_summary()
     target_report = {
         'foo_step': reporting_constants.STATE_COMPLETE
     }
     compare_dict(report, target_report)
Exemple #8
0
 def test_cancel_before_processing(self):
     self.pluginstep.repo.content_unit_counts = {'FOO_TYPE': 2}
     step = PluginStep('foo_step')
     step.is_skipped = Mock()
     step.cancel()
     step.process()
     self.assertEquals(0, step.is_skipped.call_count)
Exemple #9
0
    def test_process_child_on_error_notifies_parent(self):
        # set working_dir and conduit. This is required by process_lifecycle
        step = PluginStep('parent', working_dir=self.working_dir, conduit=self.conduit)
        child_step = PluginStep('child', working_dir=self.working_dir, conduit=self.conduit)
        child_step.initialize = Mock(side_effect=Exception('boo'))
        child_step.on_error = Mock(side_effect=Exception('flux'))
        step.on_error = Mock()

        step.add_child(child_step)

        self.assertRaises(Exception, step.process_lifecycle)

        self.assertEquals(reporting_constants.STATE_FAILED, step.state)
        self.assertEquals(reporting_constants.STATE_FAILED, child_step.state)
        self.assertTrue(step.on_error.called)
        self.assertTrue(child_step.on_error.called)
Exemple #10
0
    def setUp(self):
        self.working_dir = tempfile.mkdtemp(prefix='working_')

        self.repo_id = 'publish-test-repo'
        self.repo = Repository(self.repo_id, working_dir=self.working_dir)
        self.conduit = RepoPublishConduit(self.repo_id, 'test_plugin_id')
        self.conduit.get_repo_scratchpad = Mock(return_value={})

        self.config = PluginCallConfiguration(None, None)
        self.pluginstep = PluginStep("base-step", repo=self.repo, conduit=self.conduit,
                                     config=self.config, plugin_type='test_plugin_type')
Exemple #11
0
    def test_build_final_report_success(self):

        step_one = PluginStep('step_one')
        step_one.state = reporting_constants.STATE_COMPLETE
        step_two = PluginStep('step_two')
        step_two.state = reporting_constants.STATE_COMPLETE
        self.pluginstep.add_child(step_one)
        self.pluginstep.add_child(step_two)

        report = self.pluginstep._build_final_report()

        self.assertTrue(report.success_flag)
Exemple #12
0
    def test_get_progress_report_description(self):
        step = PluginStep('bar_step')
        step.description = 'bar'
        step.error_details = "foo"
        step.state = reporting_constants.STATE_COMPLETE
        step.total_units = 2
        step.progress_successes = 1
        step.progress_failures = 1
        report = step.get_progress_report()

        target_report = {
            reporting_constants.PROGRESS_STEP_TYPE_KEY: 'bar_step',
            reporting_constants.PROGRESS_NUM_SUCCESSES_KEY: 1,
            reporting_constants.PROGRESS_STATE_KEY: step.state,
            reporting_constants.PROGRESS_ERROR_DETAILS_KEY: step.error_details,
            reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 2,
            reporting_constants.PROGRESS_NUM_FAILURES_KEY: 1,
            reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 2,
            reporting_constants.PROGRESS_DESCRIPTION_KEY: 'bar',
            reporting_constants.PROGRESS_DETAILS_KEY: '',
            reporting_constants.PROGRESS_STEP_UUID: step.uuid
        }

        compare_dict(report[0], target_report)
Exemple #13
0
 def test_get_working_dir_already_calculated(self):
     step = PluginStep('foo_step')
     step.working_dir = 'foo'
     self.assertEquals('foo', step.get_working_dir())
Exemple #14
0
 def test_get_repo(self):
     step = PluginStep('foo_step')
     step.repo = 'foo'
     self.assertEquals('foo', step.get_repo())
Exemple #15
0
 def test_get_plugin_type(self):
     step = PluginStep('foo_step')
     step.plugin_type = 'foo'
     self.assertEquals('foo', step.get_plugin_type())
Exemple #16
0
 def test_get_plugin_type_none(self):
     step = PluginStep('foo_step')
     self.assertEquals(None, step.get_plugin_type())
Exemple #17
0
 def test_get_conduit(self):
     step = PluginStep('foo_step')
     step.conduit = 'foo'
     self.assertEquals('foo', step.get_conduit())
Exemple #18
0
    def test_process_lifecycle(self):
        # set working_dir and conduit. This is required by process_lifecycle
        step = PluginStep('parent', working_dir=self.working_dir, conduit=self.conduit)
        step.process = Mock()
        child_step = PluginStep('child', working_dir=self.working_dir, conduit=self.conduit)
        child_step.process = Mock()
        step.add_child(child_step)
        step.report_progress = Mock()

        step.process_lifecycle()

        step.process.assert_called_once_with()
        child_step.process.assert_called_once_with()
        step.report_progress.assert_called_once_with(force=True)
Exemple #19
0
 def test_get_conduit_from_parent(self):
     step = PluginStep('foo_step')
     step.conduit = 'foo'
     step.parent = Mock()
     step.parent.get_conduit.return_value = 'foo'
     self.assertEquals('foo', step.get_conduit())
Exemple #20
0
 def test_report_progress(self):
     plugin_step = PluginStep('foo_step')
     plugin_step.parent = Mock()
     plugin_step.report_progress()
     plugin_step.parent.report_progress.assert_called_once_with(False)
Exemple #21
0
 def test_get_working_dir_from_repo(self):
     step = PluginStep('foo_step')
     step.get_repo = Mock(return_value=Mock(working_dir='foo'))
     self.assertEquals('foo', step.get_working_dir())