mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Fix problems with the package() function
This commit is contained in:
@@ -85,20 +85,29 @@ def package(target, data, timestamp):
|
|||||||
manifest = {}
|
manifest = {}
|
||||||
with tarfile.open(target.joinpath(tarname), 'w:gz') as f:
|
with tarfile.open(target.joinpath(tarname), 'w:gz') as f:
|
||||||
for name, (item, version) in data.items():
|
for name, (item, version) in data.items():
|
||||||
manifest[name] = version
|
try:
|
||||||
if isinstance(item, str):
|
if isinstance(item, str):
|
||||||
info = f.gettarinfo(item, arcname=name)
|
info = f.gettarinfo(item, arcname=f'./{name}')
|
||||||
f.addfile(info)
|
f.addfile(info)
|
||||||
else:
|
else:
|
||||||
info = tarfile.TarInfo(name)
|
fileobj = io.BytesIO(json.dumps(item).encode('utf-8'))
|
||||||
fileobj = io.BytesIO(json.dumps(item).encode('utf-8'))
|
info = tarfile.TarInfo(f'./{name}')
|
||||||
fileobj.size = len(fileobj.getvalue())
|
info.size = len(fileobj.getvalue())
|
||||||
f.addfile(info, fileobj=fileobj)
|
info.mtime = timestamp.timestamp()
|
||||||
|
f.addfile(info, fileobj=fileobj)
|
||||||
|
manifest[name] = version
|
||||||
|
except Exception:
|
||||||
|
logger.exception(f"Could not generate metric {name}")
|
||||||
|
|
||||||
info = tarfile.TarInfo('manifest.json')
|
try:
|
||||||
fileobj = io.BytesIO(json.dumps(manifest).encode('utf-8'))
|
fileobj = io.BytesIO(json.dumps(manifest).encode('utf-8'))
|
||||||
fileobj.size = len(fileobj.getvalue())
|
info = tarfile.TarInfo('./manifest.json')
|
||||||
f.addfile(info, fileobj=fileobj)
|
info.size = len(fileobj.getvalue())
|
||||||
|
info.mtime = timestamp.timestamp()
|
||||||
|
f.addfile(info, fileobj=fileobj)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Could not generate manifest.json")
|
||||||
|
return None
|
||||||
|
|
||||||
return f.name
|
return f.name
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def mock_valid_license():
|
|||||||
def test_gather(mock_valid_license):
|
def test_gather(mock_valid_license):
|
||||||
settings.INSIGHTS_TRACKING_STATE = True
|
settings.INSIGHTS_TRACKING_STATE = True
|
||||||
|
|
||||||
tgzfiles = gather(module=importlib.import_module(__name__))
|
tgzfiles = gather(module=importlib.import_module(__name__), collection_type='dry-run')
|
||||||
files = {}
|
files = {}
|
||||||
with tarfile.open(tgzfiles[0], "r:gz") as archive:
|
with tarfile.open(tgzfiles[0], "r:gz") as archive:
|
||||||
for member in archive.getmembers():
|
for member in archive.getmembers():
|
||||||
|
|||||||
Reference in New Issue
Block a user