コード例 #1
0
ファイル: test_cataloger_conduit.py プロジェクト: lzap/pulp
 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)
コード例 #2
0
ファイル: model.py プロジェクト: ashcrow/pulp
 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:
コード例 #3
0
 def get_conduit(self):
     """
     Get a plugin conduit.
     :return: A plugin conduit.
     :rtype CatalogerConduit
     """
     return CatalogerConduit(self.id, self.expires)
コード例 #4
0
ファイル: test_cataloger_conduit.py プロジェクト: lzap/pulp
 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)
コード例 #5
0
 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)
コード例 #6
0
ファイル: test_cataloger_conduit.py プロジェクト: lzap/pulp
 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)
コード例 #7
0
ファイル: test_yum.py プロジェクト: ulif/pulp_rpm
 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)
コード例 #8
0
 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)
コード例 #9
0
 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'])))
コード例 #10
0
 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)