class RepoGroupPublishConduitTests(base.PulpServerTests): def clean(self): super(RepoGroupPublishConduitTests, self).clean() RepoGroup.get_collection().remove() RepoGroupDistributor.get_collection().remove() def setUp(self): super(RepoGroupPublishConduitTests, self).setUp() mock_plugins.install() manager_factory.initialize() self.group_manager = manager_factory.repo_group_manager() self.distributor_manager = manager_factory.repo_group_distributor_manager() self.group_id = 'conduit-group' self.distributor_id = 'conduit-distributor' self.group_manager.create_repo_group(self.group_id) self.distributor_manager.add_distributor(self.group_id, 'mock-group-distributor', {}, distributor_id=self.distributor_id) self.conduit = RepoGroupPublishConduit(self.group_id, self.distributor_id) def tearDown(self): super(RepoGroupPublishConduitTests, self).tearDown() mock_plugins.reset() def test_str(self): str(self.conduit) # make sure no exception is raised def test_last_publish(self): # Test - Unpublished unpublished = self.conduit.last_publish() self.assertTrue(unpublished is None) # Setup - Publish last_publish = datetime.datetime.now() repo_group_dist = self.distributor_manager.get_distributor(self.group_id, self.distributor_id) repo_group_dist['last_publish'] = dateutils.format_iso8601_datetime(last_publish) RepoGroupDistributor.get_collection().save(repo_group_dist, safe=True) # Test found = self.conduit.last_publish() self.assertTrue(isinstance(found, datetime.datetime)) last_publish = dateutils.parse_iso8601_datetime(repo_group_dist['last_publish']) # simulate the DB encoding self.assertEqual(last_publish, found) @mock.patch('pulp.server.managers.repo.group.publish.RepoGroupPublishManager.last_publish') def test_last_publish_server_error(self, mock_call): # Setup mock_call.side_effect = Exception() # Test self.assertRaises(DistributorConduitException, self.conduit.last_publish)
class RepoGroupPublishConduitTests(base.PulpServerTests): def clean(self): super(RepoGroupPublishConduitTests, self).clean() RepoGroup.get_collection().remove() RepoGroupDistributor.get_collection().remove() def setUp(self): super(RepoGroupPublishConduitTests, self).setUp() mock_plugins.install() manager_factory.initialize() self.group_manager = manager_factory.repo_group_manager() self.distributor_manager = manager_factory.repo_group_distributor_manager() self.group_id = 'conduit-group' self.distributor_id = 'conduit-distributor' self.group_manager.create_repo_group(self.group_id) self.distributor_manager.add_distributor(self.group_id, 'mock-group-distributor', {}, distributor_id=self.distributor_id) self.conduit = RepoGroupPublishConduit(self.group_id, self.distributor_id) def test_str(self): str(self.conduit) # make sure no exception is raised def test_last_publish(self): # Test - Unpublished unpublished = self.conduit.last_publish() self.assertTrue(unpublished is None) # Setup - Publish last_publish = datetime.datetime.now() repo_group_dist = self.distributor_manager.get_distributor(self.group_id, self.distributor_id) repo_group_dist['last_publish'] = dateutils.format_iso8601_datetime(last_publish) RepoGroupDistributor.get_collection().save(repo_group_dist, safe=True) # Test found = self.conduit.last_publish() self.assertTrue(isinstance(found, datetime.datetime)) last_publish = dateutils.parse_iso8601_datetime(repo_group_dist['last_publish']) # simulate the DB encoding self.assertEqual(last_publish, found) @mock.patch('pulp.server.managers.repo.group.publish.RepoGroupPublishManager.last_publish') def test_last_publish_server_error(self, mock_call): # Setup mock_call.side_effect = Exception() # Test self.assertRaises(DistributorConduitException, self.conduit.last_publish)
def setUp(self): super(RepoGroupPublishConduitTests, self).setUp() mock_plugins.install() manager_factory.initialize() self.group_manager = manager_factory.repo_group_manager() self.distributor_manager = manager_factory.repo_group_distributor_manager() self.group_id = 'conduit-group' self.distributor_id = 'conduit-distributor' self.group_manager.create_repo_group(self.group_id) self.distributor_manager.add_distributor(self.group_id, 'mock-group-distributor', {}, distributor_id=self.distributor_id) self.conduit = RepoGroupPublishConduit(self.group_id, self.distributor_id)
def publish(self, group_id, distributor_id, distributor=None, distributor_instance=None, plugin_config=None, publish_config_override=None): """ Requests the given distributor publish the repository group. @param group_id: identifies the repo group @type group_id: str @param distributor_id: identifies the group's distributor @type distributor_id: str @param distributor: distributor metadata as associate with the repo group @type distributor: dict @param distributor_instance: instance of group's distributor to be used for publishing @type distributor_instance: GroupDistributor @param plugin_config: general configuration for the distributor instance @type plugin_config: dict or None @param publish_config_override: values to pass the plugin for this publish call alone @type publish_config_override: dict """ if None in (distributor, distributor_instance): raise MissingResource(repo_group=group_id, group_distributor=distributor_id) group_query_manager = manager_factory.repo_group_query_manager() # Validation group = group_query_manager.get_group(group_id) distributor_type_id = distributor['distributor_type_id'] # Assemble the data needed for publish conduit = RepoGroupPublishConduit(group_id, distributor_id) call_config = PluginCallConfiguration(plugin_config, distributor['config'], publish_config_override) transfer_group = common_utils.to_transfer_repo_group(group) transfer_group.working_dir = common_utils.group_distributor_working_dir( distributor_type_id, group_id) # TODO: Add events for group publish start/complete self._do_publish(transfer_group, distributor_id, distributor_instance, conduit, call_config)
def publish(group_id, distributor_id, publish_config_override=None): """ Requests the given distributor publish the repository group. :param group_id: identifies the repo group :type group_id: str :param distributor_id: identifies the group's distributor :type distributor_id: str :param publish_config_override: values to pass the plugin for this publish call alone :type publish_config_override: dict """ distributor_manager = manager_factory.repo_group_distributor_manager() distributor = distributor_manager.get_distributor( group_id, distributor_id) distributor_type_id = distributor['distributor_type_id'] distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id( distributor_type_id) group_query_manager = manager_factory.repo_group_query_manager() # Validation group = group_query_manager.get_group(group_id) distributor_type_id = distributor['distributor_type_id'] # Assemble the data needed for publish conduit = RepoGroupPublishConduit(group_id, distributor) call_config = PluginCallConfiguration(plugin_config, distributor['config'], publish_config_override) transfer_group = common_utils.to_transfer_repo_group(group) transfer_group.working_dir = common_utils.group_distributor_working_dir( distributor_type_id, group_id) # TODO: Add events for group publish start/complete RepoGroupPublishManager._do_publish(transfer_group, distributor_id, distributor_instance, conduit, call_config)