def sync_repo(self, repo, conduit, config): """ Synchronizes content into the given repository. This call is responsible for adding new content units to Pulp as well as associating them to the given repository. While this call may be implemented using multiple threads, its execution from the Pulp server's standpoint should be synchronous. This call should not return until the sync is complete. It is not expected that this call be atomic. Should an error occur, it is not the responsibility of the importer to rollback any unit additions or associations that have been made. The returned report object is used to communicate the results of the sync back to the user. Care should be taken to i18n the free text "log" attribute in the report if applicable. :param repo: metadata describing the repository :type repo: pulp.plugins.model.Repository :param conduit: provides access to relevant Pulp functionality :type conduit: pulp.plugins.conduits.repo_sync.RepoSyncConduit :param config: plugin configuration :type config: pulp.plugins.config.PluginCallConfiguration :return: report of the details of the sync :rtype: pulp.plugins.model.SyncReport """ step = Main(repo=repo, conduit=conduit, config=config) report = step.process_lifecycle() return report
def sync_repo(self, repo, conduit, config): """ Synchronizes content into the given repository. This call is responsible for adding new content units to Pulp as well as associating them to the given repository. While this call may be implemented using multiple threads, its execution from the Pulp server's standpoint should be synchronous. This call should not return until the sync is complete. It is not expected that this call be atomic. Should an error occur, it is not the responsibility of the importer to rollback any unit additions or associations that have been made. The returned report object is used to communicate the results of the sync back to the user. Care should be taken to i18n the free text "log" attribute in the report if applicable. :param repo: metadata describing the repository :type repo: pulp.plugins.model.Repository :param conduit: provides access to relevant Pulp functionality :type conduit: pulp.plugins.conduits.repo_sync.RepoSyncConduit :param config: plugin configuration :type config: pulp.plugins.config.PluginCallConfiguration :return: report of the details of the sync :rtype: pulp.plugins.model.SyncReport """ step = Main(repo=repo, conduit=conduit, config=config) report = step.process_lifecycle() return report
def test_init_no_feed(self): repo = Mock(id='id-123') url = None config = { importer_constants.KEY_FEED: url, constants.IMPORTER_CONFIG_KEY_BRANCHES: [] } # test and validation with self.assertRaises(PulpCodedException) as assertion: Main(repo=repo, config=config) self.assertEqual(assertion.exception.error_code, errors.OST0004)
def test_init_no_feed(self): repo = Mock(id='id-123') url = None config = { importer_constants.KEY_FEED: url, constants.IMPORTER_CONFIG_KEY_BRANCHES: [] } # test and validation try: Main(repo=repo, config=config) self.assertTrue(False, msg='Main.__init__() exception expected') except PulpCodedException, pe: self.assertEqual(pe.error_code, errors.OST0004)
def test_storage_dir(self, storage): url = 'url-123' repo = Mock(id='id-123') config = { importer_constants.KEY_FEED: url, } st = Mock() st.__enter__ = Mock(return_value=st) st.__exit__ = Mock() storage.return_value = st # test step = Main(repo=repo, config=config) path = step.storage_dir storage.assert_called_once_with(constants.STORAGE_PROVIDER, step.remote_id) st.__enter__.assert_called_once_with() st.__exit__.assert_called_once_with(None, None, None) self.assertEqual(path, st.content_dir)
def test_init(self, fake_generate): repo = Mock(id='id-123') conduit = Mock() working_dir = 'dir-123' url = 'url-123' branches = ['branch-1', 'branch-2'] depth = 3 digest = 'digest-123' fake_generate.return_value = digest config = { importer_constants.KEY_FEED: url, constants.IMPORTER_CONFIG_KEY_BRANCHES: branches, constants.IMPORTER_CONFIG_KEY_DEPTH: depth, constants.IMPORTER_CONFIG_REPAIR: True, } # test step = Main(repo=repo, conduit=conduit, config=config, working_dir=working_dir) # validation self.assertEqual(step.step_id, constants.IMPORT_STEP_MAIN) self.assertEqual(step.repo, repo) self.assertEqual(step.conduit, conduit) self.assertEqual(step.config, config) self.assertEqual(step.working_dir, working_dir) self.assertEqual(step.plugin_type, constants.WEB_IMPORTER_TYPE_ID) self.assertEqual(step.feed_url, url) self.assertEqual(step.remote_id, digest) self.assertEqual(step.branches, branches) self.assertEqual(step.depth, depth) self.assertEqual(step.repo_id, repo.id) self.assertEqual(len(step.children), 6) self.assertTrue(isinstance(step.children[0], Repair)) self.assertTrue(isinstance(step.children[1], Create)) self.assertTrue(isinstance(step.children[2], Summary)) self.assertTrue(isinstance(step.children[3], Pull)) self.assertTrue(isinstance(step.children[4], Add)) self.assertTrue(isinstance(step.children[5], Clean))
def test_init(self, fake_generate): repo = Mock() conduit = Mock() working_dir = 'dir-123' url = 'url-123' branches = ['branch-1', 'branch-2'] digest = 'digest-123' fake_generate.return_value = digest config = { importer_constants.KEY_FEED: url, constants.IMPORTER_CONFIG_KEY_BRANCHES: branches } # test step = Main(repo=repo, conduit=conduit, config=config, working_dir=working_dir) # validation self.assertEqual(step.step_id, constants.IMPORT_STEP_MAIN) self.assertEqual(step.repo, repo) self.assertEqual(step.conduit, conduit) self.assertEqual(step.config, config) self.assertEqual(step.working_dir, working_dir) self.assertEqual(step.plugin_type, constants.WEB_IMPORTER_TYPE_ID) self.assertEqual(step.feed_url, url) self.assertEqual(step.remote_id, digest) self.assertEqual(step.branches, branches) self.assertEqual( step.storage_path, os.path.join(constants.SHARED_STORAGE, digest, 'content')) self.assertEqual(len(step.children), 3) self.assertTrue(isinstance(step.children[0], Create)) self.assertTrue(isinstance(step.children[1], Pull)) self.assertTrue(isinstance(step.children[2], Add))