예제 #1
0
파일: publisher.py 프로젝트: pieska/pulp
 def write_manifest(self, units):
     """
     Write the manifest (units.json) for the specified list of units.
     :param units: A list of units.
     :type units: list
     :return: The absolute path to the written manifest file.
     :rtype: str
     """
     manifest = Manifest()
     dir_path = join(self.publish_dir, self.repo_id)
     mkdir(dir_path)
     return manifest.write(dir_path, units)
예제 #2
0
파일: strategies.py 프로젝트: pieska/pulp
 def _units_upstream(self):
     """
     Fetch the list of units published by the upstream citrus distributor.
     This is performed by reading the manifest at the URL defined in
     the configuration.
     :param repo_id: The repository ID.
     :type repo_id: str
     :return: A dictionary of units keyed by UnitKey.
     :rtype: dict
     """
     url = self.config.get("manifest_url")
     manifest = Manifest()
     units = manifest.read(url, self.downloader)
     return unit_dictionary(units)
예제 #3
0
 def test_write(self):
     # Test
     manifest = Manifest()
     units = []
     for i in range(0, self.NUM_UNITS):
         units.append({i:i+1})
     manifest.write(self.tmp_dir, units)
     # Verify
     path = os.path.join(self.tmp_dir, Manifest.FILE_NAME)
     self.assertTrue(os.path.exists(path))
     fp = gzip.open(path)
     s = fp.read()
     units_in = json.loads(s)
     self.verify(units, units_in)
예제 #4
0
 def test_round_trip(self):
     # Test
     manifest = Manifest()
     units = []
     for i in range(0, self.NUM_UNITS):
         units.append({i:i+1})
     manifest.write(self.tmp_dir, units)
     cfg = DownloaderConfig('http')
     downloader = factory.get_downloader(cfg)
     manifest = Manifest()
     path = os.path.join(self.tmp_dir, Manifest.FILE_NAME)
     url = 'file://%s' % path
     units_in = manifest.read(url, downloader)
     # Verify
     self.verify(units, units_in)
예제 #5
0
 def test_read(self):
     # Setup
     units = []
     for i in range(0, self.NUM_UNITS):
         units.append({i:i+1})
     s = json.dumps(units)
     path = os.path.join(self.tmp_dir, Manifest.FILE_NAME)
     fp = gzip.open(path, 'wb')
     fp.write(s)
     fp.close()
     # Test
     cfg = DownloaderConfig('http')
     downloader = factory.get_downloader(cfg)
     manifest = Manifest()
     path = os.path.join(self.tmp_dir, Manifest.FILE_NAME)
     url = 'file://%s' % path
     units_in = manifest.read(url, downloader)
     # Verify
     self.verify(units, units_in)
예제 #6
0
 def test_publisher(self):
     # setup
     units = []
     for n in range(0, 3):
         fn = "test_%d" % n
         path = os.path.join(self.unit_dir, fn)
         fp = open(path, "w")
         fp.write(fn)
         fp.close()
         unit = {"type_id": "unit", "unit_key": {"n": n}, "storage_path": path}
         units.append(unit)
     # test
     # publish
     repo_id = "test_repo"
     base_url = "file://"
     publish_dir = os.path.join(self.tmpdir, "citrus/repos")
     virtual_host = (publish_dir, publish_dir)
     p = HttpPublisher(base_url, virtual_host, repo_id)
     p.publish(units)
     # verify
     conf = DownloaderConfig("http")
     downloader = factory.get_downloader(conf)
     manifest_path = p.manifest_path()
     manifest = Manifest()
     url = "file://" + manifest_path
     units = manifest.read(url, downloader)
     n = 0
     for unit in units:
         file_content = "test_%d" % n
         _download = unit["_download"]
         url = _download["url"]
         self.assertEqual(url.rsplit("/", 1)[0], "/".join((base_url, publish_dir[1:], repo_id, "content")))
         path = url.split("//", 1)[1]
         self.assertTrue(os.path.islink(path))
         f = open(path)
         s = f.read()
         f.close()
         self.assertEqual(s, file_content)
         self.assertEqual(unit["unit_key"]["n"], n)
         n += 1
예제 #7
0
파일: test_plugins.py 프로젝트: pieska/pulp
 def test_publish(self):
     # Setup
     self.populate()
     pulp_conf.set('server', 'storage_dir', self.upfs)
     # Test
     dist = CitrusHttpDistributor()
     repo = Repository(self.REPO_ID)
     conduit = RepoPublishConduit(self.REPO_ID, CITRUS_DISTRUBUTOR)
     dist.publish_repo(repo, conduit, self.dist_conf())
     # Verify
     conf = DownloaderConfig('http')
     downloader = factory.get_downloader(conf)
     manifest = Manifest()
     pub = dist.publisher(repo, self.dist_conf())
     url = '/'.join((pub.base_url, pub.manifest_path()))
     units = manifest.read(url, downloader)
     self.assertEqual(len(units), self.NUM_UNITS)
     for n in range(0, self.NUM_UNITS):
         unit = units[n]
         created = self.units[n]
         for p, v in unit['metadata'].items():
             if p.startswith('_'):
                 continue
             self.assertEqual(created[p], v)