Add run_apollo_tree function

This commit is contained in:
Mustafa Gezen 2023-02-04 00:54:16 +01:00
parent aecc8c3823
commit a686b921ae
2 changed files with 92 additions and 13 deletions

View File

@ -270,14 +270,40 @@ async def update_repomd_xml(repomd_xml_path: str, updateinfo: dict):
os.remove(existing_updateinfo_path)
async def main(args):
base_paths = await scan_path(
args.path,
args.base_format,
args.ignore,
async def run_apollo_tree(
base_format: str,
manual: bool,
auto_scan: bool,
path: str,
ignore: list,
product_name: str,
):
if manual:
raise Exception("Manual mode not implemented yet")
if auto_scan:
repos = await scan_path(
path,
base_format,
ignore,
)
for _, repo_variants in repos.items():
for repo in repo_variants:
updateinfo = await fetch_updateinfo_from_apollo(
repo,
product_name,
)
gzipped = await gzip_updateinfo(updateinfo)
await write_updateinfo_to_file(
repo["found_path"],
gzipped,
)
await update_repomd_xml(
repo["found_path"],
gzipped,
)
print(args)
pass
if __name__ == "__main__":
@ -343,4 +369,13 @@ if __name__ == "__main__":
if p_args.auto_scan and not p_args.path:
parser.error("Must specify path to scan for repos in auto-scan mode")
asyncio.run(main(p_args))
asyncio.run(
run_apollo_tree(
p_args.base_format,
p_args.manual,
p_args.auto_scan,
p_args.path,
p_args.ignore,
p_args.product_name,
)
)

View File

@ -332,7 +332,6 @@ async def test_fetch_updateinfo_from_apollo_mock(mocker):
updateinfo = await apollo_tree.fetch_updateinfo_from_apollo(
repo,
"Rocky Linux 8 x86_64",
True,
)
assert updateinfo == updateinfo_xml
@ -363,7 +362,6 @@ async def test_gzip_updateinfo(mocker):
updateinfo = await apollo_tree.fetch_updateinfo_from_apollo(
repo,
"Rocky Linux 8 x86_64",
True,
)
assert updateinfo == updateinfo_xml
@ -399,7 +397,6 @@ async def test_write_updateinfo_to_file(mocker):
updateinfo = await apollo_tree.fetch_updateinfo_from_apollo(
repo,
"Rocky Linux 8 x86_64",
True,
)
assert updateinfo == updateinfo_xml
@ -452,7 +449,6 @@ async def test_update_repomd_xml(mocker):
updateinfo = await apollo_tree.fetch_updateinfo_from_apollo(
repo,
"Rocky Linux 8 x86_64",
True,
)
assert updateinfo == updateinfo_xml
@ -496,3 +492,51 @@ async def test_update_repomd_xml(mocker):
actual_repomd_xml = f.read()
assert actual_repomd_xml == expected_repomd_xml
@pytest.mark.asyncio
async def test_run_apollo_tree(mocker):
with tempfile.TemporaryDirectory() as directory:
repos = await _setup_test_baseos(directory)
# Read data/updateinfo__test__1.xml
with open(
path.join(
path.dirname(__file__), "data", "updateinfo__test__1.xml"
),
"r",
encoding="utf-8",
) as f:
updateinfo_xml = f.read()
resp = MockResponse(updateinfo_xml, 200)
mocker.patch("aiohttp.ClientSession.get", return_value=resp)
mocker.patch("time.time", return_value=1674284973)
await apollo_tree.run_apollo_tree(
"$reponame/$arch/os/repodata/repomd.xml",
False,
True,
directory,
[],
"Rocky Linux 8 x86_64",
)
for _, repo_variants in repos.items():
for repo in repo_variants:
# Check that the repomd.xml file matches baseos__base__repomd__x86_64_with_updateinfo.xml from data
with open(
path.join(
path.dirname(__file__),
"data",
"baseos__base__repomd__x86_64_with_updateinfo.xml",
),
"r",
encoding="utf-8",
) as f:
expected_repomd_xml = f.read()
with open(repo["found_path"], "r", encoding="utf-8") as f:
actual_repomd_xml = f.read()
assert actual_repomd_xml == expected_repomd_xml