Exemplo n.º 1
0
    def test_get_progress_report_description(self):
        step = PublishStep('bar_step')
        step.description = 'bar'
        step.progress_details = 'baz'
        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: 'baz',
            reporting_constants.PROGRESS_STEP_UUID: step.uuid
        }

        compare_dict(report[0], target_report)
Exemplo n.º 2
0
    def test_process_lifecycle_reports_on_error(self):
        step = PublishStep('parent')
        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)
Exemplo n.º 3
0
    def test_create_symlink_no_link_parent(self):
        source_path = os.path.join(self.working_dir, 'source')
        link_path = os.path.join(self.published_dir, 'foo/bar/baz/link')

        touch(source_path)
        self.assertFalse(os.path.exists(os.path.dirname(link_path)))

        PublishStep._create_symlink(source_path, link_path)

        self.assertTrue(os.path.exists(link_path))
Exemplo n.º 4
0
 def test_process_step_failure_reported_on_metadata_finalized(self, mock_get_units):
     self.publisher.repo.content_unit_counts = {'FOO_TYPE': 1}
     mock_get_units.return_value = ['mock_unit']
     step = PublishStep('foo_step')
     step.parent = self.publisher
     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)
Exemplo n.º 5
0
    def test_publish_exception_still_removes_working_dir(self, mock_rmtree):
        step = PublishStep("foo")
        work_dir = os.path.join(self.working_dir, 'foo')
        step.working_dir = work_dir
        step.process_lifecycle = Mock(side_effect=Exception('foo'))
        step._build_final_report = Mock()

        self.assertRaises(Exception, step.publish)
        self.assertTrue(step.process_lifecycle.called)
        self.assertFalse(step._build_final_report.called)
        mock_rmtree.assert_called_once_with(work_dir, ignore_errors=True)
Exemplo n.º 6
0
 def test_publish_distribution_packages_link_with_packagedir_delete_existing_packages(self):
     packages_dir = os.path.join(self.working_dir, 'Packages')
     old_directory = os.path.join(self.working_dir, "foo")
     os.mkdir(old_directory)
     PublishStep._create_symlink(old_directory, packages_dir)
     self.assertEquals(os.path.realpath(packages_dir), old_directory)
     unit = self._generate_distribution_unit('one', {'packagedir': 'Packages'})
     step = publish.PublishDistributionStep()
     step.parent = self.publisher
     step._publish_distribution_packages_link(unit)
     self.assertFalse(os.path.islink(packages_dir))
Exemplo n.º 7
0
 def test_publish_distribution_packages_link_with_packagedir_delete_existing_packages(self):
     packages_dir = os.path.join(self.working_dir, 'Packages')
     old_directory = os.path.join(self.working_dir, "foo")
     os.mkdir(old_directory)
     PublishStep._create_symlink(old_directory, packages_dir)
     self.assertEquals(os.path.realpath(packages_dir), old_directory)
     unit = self._generate_distribution_unit('one', {'packagedir': 'Packages'})
     step = publish.PublishDistributionStep()
     step.parent = self.publisher
     step._publish_distribution_packages_link(unit)
     self.assertFalse(os.path.islink(packages_dir))
Exemplo n.º 8
0
    def test_record_failure(self):
        publish_step = PublishStep('foo_step')
        publish_step.parent = self.publisher

        error_msg = 'Too bad, so sad'

        try:
            raise Exception(error_msg)

        except Exception, e:
            tb = sys.exc_info()[2]
            publish_step._record_failure(e, tb)
Exemplo n.º 9
0
    def test_clear_directory(self):

        for file_name in ('one', 'two', 'three'):
            touch(os.path.join(self.working_dir, file_name))

        os.makedirs(os.path.join(self.working_dir, 'four'))
        self.assertEqual(len(os.listdir(self.working_dir)), 4)
        step = PublishStep("foo")

        step._clear_directory(self.working_dir, ['two'])

        self.assertEqual(len(os.listdir(self.working_dir)), 1)
Exemplo n.º 10
0
    def test_create_symlink(self):
        source_path = os.path.join(self.working_dir, 'source')
        link_path = os.path.join(self.published_dir, 'link')

        touch(source_path)
        self.assertFalse(os.path.exists(link_path))

        PublishStep._create_symlink(source_path, link_path)

        self.assertTrue(os.path.exists(link_path))
        self.assertTrue(os.path.islink(link_path))
        self.assertEqual(os.readlink(link_path), source_path)
Exemplo n.º 11
0
    def test_create_symlink_link_exists_and_is_correct(self):
        new_source_path = os.path.join(self.working_dir, 'new_source')
        link_path = os.path.join(self.published_dir, 'link')

        touch(new_source_path)

        os.symlink(new_source_path, link_path)

        self.assertEqual(os.readlink(link_path), new_source_path)

        PublishStep._create_symlink(new_source_path, link_path)

        self.assertEqual(os.readlink(link_path), new_source_path)
    def __init__(self, repo, publish_conduit, config):
        """
        :param repo: Pulp managed Yum repository
        :type  repo: pulp.plugins.model.Repository
        :param publish_conduit: Conduit providing access to relative Pulp functionality
        :type  publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit
        :param config: Pulp configuration for the distributor
        :type  config: pulp.plugins.config.PluginCallConfiguration
        """
        super(GlancePublisher, self).__init__(constants.PUBLISH_STEP_GLANCE_PUBLISHER,
                                              repo, publish_conduit, config)

        publish_step = PublishStep(constants.PUBLISH_STEP_OVER_GLANCE_REST)
        publish_step.description = _('Pushing files to Glance.')
        self.add_child(PublishImagesStep())
Exemplo n.º 13
0
    def __init__(self, repo, publish_conduit, config):
        """
        :param repo: Pulp managed Yum repository
        :type  repo: pulp.plugins.model.Repository
        :param publish_conduit: Conduit providing access to relative Pulp functionality
        :type  publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit
        :param config: Pulp configuration for the distributor
        :type  config: pulp.plugins.config.PluginCallConfiguration
        """
        super(GlancePublisher,
              self).__init__(constants.PUBLISH_STEP_GLANCE_PUBLISHER, repo,
                             publish_conduit, config)

        publish_step = PublishStep(constants.PUBLISH_STEP_OVER_GLANCE_REST)
        publish_step.description = _('Pushing files to Glance.')
        self.add_child(PublishImagesStep())
Exemplo n.º 14
0
    def test_process_lifecycle(self):
        step = PublishStep('parent')
        step.process = Mock()
        child_step = PublishStep('child')
        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)
Exemplo n.º 15
0
    def test_create_symlink_link_exists(self):
        old_source_path = os.path.join(self.working_dir, 'old_source')
        new_source_path = os.path.join(self.working_dir, 'new_source')
        link_path = os.path.join(self.published_dir, 'link')

        touch(old_source_path)
        touch(new_source_path)

        os.symlink(old_source_path, link_path)

        self.assertEqual(os.readlink(link_path), old_source_path)

        link_path_with_slash = link_path + '/'

        PublishStep._create_symlink(new_source_path, link_path_with_slash)

        self.assertEqual(os.readlink(link_path), new_source_path)
Exemplo n.º 16
0
 def test_get_progress_report_summary(self):
     parent_step = PublishStep('parent_step')
     step = PublishStep('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)
Exemplo n.º 17
0
 def test_cancel_before_processing(self):
     self.publisher.repo.content_unit_counts = {'FOO_TYPE': 2}
     step = PublishStep('foo_step')
     step.is_skipped = Mock()
     step.cancel()
     step.process()
     self.assertEquals(0, step.is_skipped.call_count)
Exemplo n.º 18
0
    def test_process_child_on_error_notifies_parent(self):
        step = PublishStep('parent')
        child_step = PublishStep('child')
        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)
Exemplo n.º 19
0
 def setUp(self):
     self.temp_dir = tempfile.mkdtemp()
     self.working_directory = os.path.join(self.temp_dir, 'working')
     self.publish_directory = os.path.join(self.temp_dir, 'publish')
     self.content_directory = os.path.join(self.temp_dir, 'content')
     os.makedirs(self.working_directory)
     os.makedirs(self.publish_directory)
     os.makedirs(self.content_directory)
     repo = Repository('foo_repo_id', working_dir=self.working_directory)
     config = PluginCallConfiguration(None, None)
     conduit = RepoPublishConduit(repo.id, 'foo_repo')
     self.parent = PublishStep('test-step', repo, conduit, config)
Exemplo n.º 20
0
    def test_publish(self, mock_rmtree):
        step = PublishStep("foo")
        work_dir = os.path.join(self.working_dir, 'foo')
        step.working_dir = work_dir
        step.process_lifecycle = Mock()
        step._build_final_report = Mock()

        step.publish()
        self.assertTrue(step.process_lifecycle.called)
        self.assertTrue(step._build_final_report.called)
        mock_rmtree.assert_called_once_with(work_dir, ignore_errors=True)
Exemplo n.º 21
0
    def setUp(self):
        self.working_dir = tempfile.mkdtemp(prefix='working_')
        self.published_dir = tempfile.mkdtemp(prefix='published_')
        self.master_dir = os.path.join(self.published_dir, 'master')

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

        self.config = PluginCallConfiguration(None, None)
        self.publisher = PublishStep("base-step", repo=self.repo, publish_conduit=self.conduit,
                                     config=self.config, distributor_type='test_distributor_type')
Exemplo n.º 22
0
    def test_build_final_report_success(self):

        step_one = PublishStep('step_one')
        step_one.state = reporting_constants.STATE_COMPLETE
        step_two = PublishStep('step_two')
        step_two.state = reporting_constants.STATE_COMPLETE
        self.publisher.add_child(step_one)
        self.publisher.add_child(step_two)

        report = self.publisher._build_final_report()

        self.assertTrue(report.success_flag)
Exemplo n.º 23
0
 def test_get_distributor_type_from_parent(self):
     step = PublishStep('foo_step')
     step.conduit = 'foo'
     step.parent = Mock()
     step.parent.get_plugin_type.return_value = 'foo'
     self.assertEquals('foo', step.get_distributor_type())
Exemplo n.º 24
0
 def test_get_distributor_type(self):
     step = PublishStep('foo_step')
     step.plugin_type = 'foo'
     self.assertEquals('foo', step.get_distributor_type())
Exemplo n.º 25
0
 def test_publish(self):
     # just test that process_lifecycle got called, that is where the functionality lives now
     step = PublishStep("foo")
     step.process_lifecycle = Mock()
     step.publish()
     self.assertTrue(step.process_lifecycle.called)
Exemplo n.º 26
0
 def test_get_total(self):
     step = PublishStep("foo")
     self.assertEquals(1, step._get_total())
Exemplo n.º 27
0
 def test_clear_children(self):
     step = PublishStep("foo")
     step.children = ['bar']
     step.clear_children()
     self.assertEquals(0, len(step.children))
Exemplo n.º 28
0
 def test_create_symlink(self, mock_symlink):
     step = PublishStep("foo")
     step._create_symlink('foo', 'bar')
     mock_symlink.assert_called_once_with('foo', 'bar')
Exemplo n.º 29
0
    def test_clear_directory(self, mock_clear):
        step = PublishStep("foo")

        step._clear_directory(self.working_dir, ['two'])
        mock_clear.assert_called_once_with(self.working_dir, ['two'])
Exemplo n.º 30
0
 def test_get_distributor_type_none(self):
     step = PublishStep('foo_step')
     self.assertEquals(None, step.get_distributor_type())
Exemplo n.º 31
0
 def test_get_conduit(self):
     step = PublishStep('foo_step')
     step.conduit = 'foo'
     self.assertEquals('foo', step.get_conduit())
Exemplo n.º 32
0
 def test_get_repo(self):
     step = PublishStep('foo_step')
     step.repo = 'foo'
     self.assertEquals('foo', step.get_repo())
Exemplo n.º 33
0
 def test_report_progress(self):
     publish_step = PublishStep('foo_step')
     publish_step.parent = Mock()
     publish_step.report_progress()
     publish_step.parent.report_progress.assert_called_once_with(False)
Exemplo n.º 34
0
 def test_get_conduit_from_parent(self):
     step = PublishStep('foo_step')
     step.conduit = 'foo'
     step.parent = Mock()
     step.parent.get_conduit.return_value = 'foo'
     self.assertEquals('foo', step.get_conduit())