def test_reset(self): conduit = CatalogerConduit(SOURCE_ID, EXPIRES) conduit.added_count = 10 conduit.deleted_count = 10 conduit.reset() self.assertEqual(conduit.added_count, 0) self.assertEqual(conduit.deleted_count, 0)
def refresh(self, cancel_event): """ Refresh the content catalog using the cataloger plugin as defined by the "type" descriptor property. :param cancel_event: An event that indicates the refresh has been canceled. :type cancel_event: threading.Event :return: The list of refresh reports. :rtype: list of: RefreshReport """ reports = [] plugin_id = self.descriptor[constants.TYPE] plugin, cfg = plugins.get_cataloger_by_id(plugin_id) conduit = CatalogerConduit(self.id, self.expires()) for url in self.urls(): if cancel_event.isSet(): break conduit.reset() report = RefreshReport(self.id, url) log.info(REFRESHING, self.id, url) try: plugin.refresh(conduit, self.descriptor, url) log.info(REFRESH_SUCCEEDED, self.id, conduit.added_count, conduit.deleted_count) report.succeeded = True report.added_count = conduit.added_count report.deleted_count = conduit.deleted_count except Exception, e: log.error(REFRESH_FAILED, self.id, url, e) report.errors.append(str(e)) finally:
def get_conduit(self): """ Get a plugin conduit. :return: A plugin conduit. :rtype CatalogerConduit """ return CatalogerConduit(self.id, self.expires)
def test_add(self): units = self.units(0, 10) conduit = CatalogerConduit(SOURCE_ID, EXPIRES) for unit_key, url in units: conduit.add_entry(TYPE_ID, unit_key, url) collection = ContentCatalog.get_collection() self.assertEqual(conduit.source_id, SOURCE_ID) self.assertEqual(conduit.expires, EXPIRES) self.assertEqual(len(units), collection.find().count()) self.assertEqual(conduit.added_count, len(units)) self.assertEqual(conduit.deleted_count, 0) for unit_key, url in units: locator = ContentCatalog.get_locator(TYPE_ID, unit_key) entry = collection.find_one({"locator": locator}) self.assertEqual(entry["type_id"], TYPE_ID) self.assertEqual(entry["unit_key"], unit_key) self.assertEqual(entry["url"], url)
def test_add(self): units = self.units(0, 10) conduit = CatalogerConduit(SOURCE_ID, EXPIRES) for unit_key, url in units: conduit.add_entry(TYPE_ID, unit_key, url) collection = ContentCatalog.get_collection() self.assertEqual(conduit.source_id, SOURCE_ID) self.assertEqual(conduit.expires, EXPIRES) self.assertEqual(len(units), collection.find().count()) self.assertEqual(conduit.added_count, len(units)) self.assertEqual(conduit.deleted_count, 0) for unit_key, url in units: locator = ContentCatalog.get_locator(TYPE_ID, unit_key) entry = collection.find_one({'locator': locator}) self.assertEqual(entry['type_id'], TYPE_ID) self.assertEqual(entry['unit_key'], unit_key) self.assertEqual(entry['url'], url)
def test_delete(self): units = self.units(0, 10) conduit = CatalogerConduit(SOURCE_ID, EXPIRES) for unit_key, url in units: conduit.add_entry(TYPE_ID, unit_key, url) collection = ContentCatalog.get_collection() self.assertEqual(len(units), collection.find().count()) unit_key, url = units[5] locator = ContentCatalog.get_locator(TYPE_ID, unit_key) entry = collection.find_one({"locator": locator}) self.assertEqual(entry["type_id"], TYPE_ID) self.assertEqual(entry["unit_key"], unit_key) self.assertEqual(entry["url"], url) conduit.delete_entry(TYPE_ID, unit_key) self.assertEqual(len(units) - 1, collection.find().count()) self.assertEqual(conduit.added_count, len(units)) self.assertEqual(conduit.deleted_count, 1) entry = collection.find_one({"locator": locator}) self.assertTrue(entry is None)
def test_json_serializable(self, mock_add): """ ensure the arguments are json serializable see https://pulp.plan.io/issues/2012 """ url = 'file://%s/' % self.tmp_dir conduit = CatalogerConduit(SOURCE_ID, EXPIRES) cataloger = YumCataloger() cataloger.refresh(conduit, {}, url) for call in mock_add.call_args_list: json.dumps(call)
def test_refresh(self, mock_add): url = 'file://%s/' % self.tmp_dir conduit = CatalogerConduit(SOURCE_ID, EXPIRES) cataloger = YumCataloger() cataloger.refresh(conduit, {}, url) with open(JSON_PATH) as fp: expected = json.load(fp) self.assertEqual(mock_add.call_count, len(expected)) for entry in expected: self.assertTrue( mock_add.called_with(SOURCE_ID, EXPIRES, entry['type_id'], entry['unit_key'], self._normalized(entry['url'])))
def test_delete(self): units = self.units(0, 10) conduit = CatalogerConduit(SOURCE_ID, EXPIRES) for unit_key, url in units: conduit.add_entry(TYPE_ID, unit_key, url) collection = ContentCatalog.get_collection() self.assertEqual(len(units), collection.find().count()) unit_key, url = units[5] locator = ContentCatalog.get_locator(TYPE_ID, unit_key) entry = collection.find_one({'locator': locator}) self.assertEqual(entry['type_id'], TYPE_ID) self.assertEqual(entry['unit_key'], unit_key) self.assertEqual(entry['url'], url) conduit.delete_entry(TYPE_ID, unit_key) self.assertEqual(len(units) - 1, collection.find().count()) self.assertEqual(conduit.added_count, len(units)) self.assertEqual(conduit.deleted_count, 1) entry = collection.find_one({'locator': locator}) self.assertTrue(entry is None)