本文整理汇总了Python中pulp_node.manifest.Manifest类的典型用法代码示例。如果您正苦于以下问题:Python Manifest类的具体用法?Python Manifest怎么用?Python Manifest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manifest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publish
def publish(self, units):
"""
Publish the specified units.
Writes the units.json file and symlinks each of the files associated
to the unit.storage_path. Publishing is staged in a temporary directory and
must use commit() to make the publishing permanent.
:param units: A list of units to publish.
:type units: iterable
:return: The absolute path to the manifest.
:rtype: str
"""
# make the parent dir and a temp dir within it
parent_path = os.path.normpath(os.path.join(self.publish_dir, '../'))
pathlib.mkdir(parent_path)
self.tmp_dir = mkdtemp(dir=parent_path)
with UnitWriter(self.tmp_dir) as writer:
for unit in units:
self.publish_unit(unit)
writer.add(unit)
manifest_id = str(uuid4())
manifest = Manifest(self.tmp_dir, manifest_id)
manifest.units_published(writer)
manifest.write()
self.staged = True
return manifest.path
示例2: publish
def publish(self, units):
"""
Publish the specified units.
Writes the units.json file and symlinks each of the files associated
to the unit.storage_path. Publishing is staged in a temporary directory and
must use commit() to make the publishing permanent.
:param units: A list of units to publish.
:type units: iterable
:return: The absolute path to the manifest.
:rtype: str
"""
pathlib.mkdir(self.publish_dir)
self.tmp_dir = mkdtemp(dir=self.publish_dir)
units_path = pathlib.join(self.tmp_dir, UNITS_FILE_NAME)
manifest_path = pathlib.join(self.tmp_dir, MANIFEST_FILE_NAME)
with UnitWriter(units_path) as writer:
for unit in units:
self.publish_unit(unit)
writer.add(unit)
manifest_id = str(uuid4())
manifest = Manifest(manifest_id)
manifest.set_units(writer)
manifest_path = manifest.write(manifest_path)
self.staged = True
return manifest_path
示例3: test_import_cached_manifest_missing_units
def test_import_cached_manifest_missing_units(self, *unused):
# Setup
self.populate()
with mock_config.patch({'server': {'storage_dir': self.parentfs}}):
dist = NodesHttpDistributor()
working_dir = os.path.join(self.childfs, 'working_dir')
os.makedirs(working_dir)
repo = Repository(self.REPO_ID, working_dir)
configuration = self.dist_conf()
conduit = RepoPublishConduit(self.REPO_ID, constants.HTTP_DISTRIBUTOR)
dist.publish_repo(repo, conduit, configuration)
model.Distributor.objects.delete()
RepoContentUnit.get_collection().remove()
unit_db.clean()
self.define_plugins()
publisher = dist.publisher(repo, configuration)
manifest_path = publisher.manifest_path()
manifest = Manifest(manifest_path)
manifest.read()
shutil.copy(manifest_path, os.path.join(working_dir, MANIFEST_FILE_NAME))
# Test
importer = NodesHttpImporter()
manifest_url = pathlib.url_join(publisher.base_url, manifest_path)
configuration = {
constants.MANIFEST_URL_KEYWORD: manifest_url,
constants.STRATEGY_KEYWORD: constants.MIRROR_STRATEGY,
}
configuration = PluginCallConfiguration(configuration, {})
conduit = RepoSyncConduit(self.REPO_ID, constants.HTTP_IMPORTER, Mock())
with mock_config.patch({'server': {'storage_dir': self.childfs}}):
with patch('pulp_node.constants.CONTENT_PATH', self.parentfs):
importer.sync_repo(repo, conduit, configuration)
# Verify
units = conduit.get_units()
self.assertEquals(len(units), self.NUM_UNITS)
示例4: _unit_inventory
def _unit_inventory(self, request):
"""
Build the unit inventory.
:param request: A synchronization request.
:type request: SyncRequest
:return: The built inventory.
:rtype: UnitInventory
"""
# fetch child units
try:
conduit = NodesConduit()
child_units = conduit.get_units(request.repo_id)
except NodeError:
raise
except Exception:
log.exception(request.repo_id)
raise GetChildUnitsError(request.repo_id)
# fetch parent units
try:
request.progress.begin_manifest_download()
url = request.config.get(constants.MANIFEST_URL_KEYWORD)
manifest = Manifest()
manifest.fetch(url, request.working_dir, request.downloader)
manifest.fetch_units(url, request.downloader)
except NodeError:
raise
except Exception:
log.exception(request.repo_id)
raise GetParentUnitsError(request.repo_id)
return UnitInventory(manifest, child_units)
示例5: write_manifest
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)
示例6: test_write
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)
示例7: _parent_units
def _parent_units(self):
"""
Fetch the list of units published by the parent nodes 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)
示例8: test_round_trip
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)
示例9: publish
def publish(self, units):
"""
Publish the specified units.
Writes the units.json file and symlinks each of the
files associated to the unit.storage_path.
:param units: A list of units to publish.
:type units: iterable
:return: The path to the written manifest.
:rtype: str
"""
manifest_path = super(self.__class__, self).publish(units)
manifest = Manifest()
manifest.read(manifest_path)
manifest.publishing_details[constants.BASE_URL] = \
pathlib.url_join(self.base_url, self.alias[0], self.repo_id)
manifest.write(manifest_path)
return manifest_path
示例10: test_read
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)
示例11: test_import_cached_manifest_matched
def test_import_cached_manifest_matched(self, mock_fetch, *unused):
# Setup
self.populate()
pulp_conf.set('server', 'storage_dir', self.parentfs)
dist = NodesHttpDistributor()
working_dir = os.path.join(self.childfs, 'working_dir')
os.makedirs(working_dir)
repo = Repository(self.REPO_ID, working_dir)
configuration = self.dist_conf()
conduit = RepoPublishConduit(self.REPO_ID, constants.HTTP_DISTRIBUTOR)
dist.publish_repo(repo, conduit, configuration)
Repo.get_collection().remove()
RepoDistributor.get_collection().remove()
RepoContentUnit.get_collection().remove()
unit_db.clean()
self.define_plugins()
publisher = dist.publisher(repo, configuration)
manifest_path = publisher.manifest_path()
units_path = os.path.join(os.path.dirname(manifest_path), UNITS_FILE_NAME)
manifest = Manifest(manifest_path)
manifest.read()
shutil.copy(manifest_path, os.path.join(working_dir, MANIFEST_FILE_NAME))
shutil.copy(units_path, os.path.join(working_dir, UNITS_FILE_NAME))
# Test
importer = NodesHttpImporter()
manifest_url = pathlib.url_join(publisher.base_url, manifest_path)
configuration = {
constants.MANIFEST_URL_KEYWORD: manifest_url,
constants.STRATEGY_KEYWORD: constants.MIRROR_STRATEGY,
}
configuration = PluginCallConfiguration(configuration, {})
conduit = RepoSyncConduit(
self.REPO_ID,
constants.HTTP_IMPORTER,
RepoContentUnit.OWNER_TYPE_IMPORTER,
constants.HTTP_IMPORTER)
pulp_conf.set('server', 'storage_dir', self.childfs)
importer.sync_repo(repo, conduit, configuration)
# Verify
units = conduit.get_units()
self.assertEquals(len(units), self.NUM_UNITS)
self.assertFalse(mock_fetch.called)
示例12: test_publisher
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, 'nodes/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
示例13: publish
def publish(self, units):
"""
Publish the specified units.
Writes the units.json file and symlinks each of the
files associated to the unit.storage_path.
:param units: A list of units to publish.
:type units: iterable
"""
dir_path = join(self.publish_dir, self.repo_id)
units_path = os.path.join(dir_path, UNITS_FILE_NAME)
manifest_path = os.path.join(dir_path, MANIFEST_FILE_NAME)
mkdir(dir_path)
with UnitWriter(units_path) as writer:
for unit in units:
self.link_unit(unit)
writer.add(unit)
manifest_id = str(uuid4())
manifest = Manifest(manifest_id)
manifest.set_units(writer)
manifest_path = manifest.write(manifest_path)
return manifest_path
示例14: test_write
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()
fp.close()
manifest = json.loads(s)
units_in = []
for unit_file in manifest['unit_files']:
path = os.path.join(self.tmp_dir, unit_file)
fp = gzip.open(path)
units_in.extend(json.load(fp))
fp.close()
self.assertEqual(manifest['total_units'], self.NUM_UNITS)
self.verify(units, units_in)
示例15: test_publish
def test_publish(self):
# Setup
self.populate()
pulp_conf.set('server', 'storage_dir', self.parentfs)
# Test
dist = NodesHttpDistributor()
repo = Repository(self.REPO_ID)
conduit = RepoPublishConduit(self.REPO_ID, constants.HTTP_DISTRIBUTOR)
dist.publish_repo(repo, conduit, self.dist_conf())
# Verify
conf = DownloaderConfig()
downloader = HTTPSCurlDownloader(conf)
manifest = Manifest()
pub = dist.publisher(repo, self.dist_conf())
url = '/'.join((pub.base_url, pub.manifest_path()))
units = list(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)