opam: Fix 'opam init' error when relisting an opam instance
When relisting an opam instance and the opam root directory is already populated, the '--set-default' parameter must be provided otherwise the following error is reported: No switch is currently set. Please use 'opam switch' to set or install a switch Related to swh/infra/sysadm-environment#4971.
This commit is contained in:
parent
01be6ce581
commit
8d7dccc54a
2 changed files with 29 additions and 18 deletions
|
@ -156,6 +156,7 @@ def opam_init(opam_root: str, instance: str, url: str, env: Dict[str, Any]) -> N
|
|||
opam(),
|
||||
"repository",
|
||||
"add",
|
||||
"--set-default",
|
||||
"--root",
|
||||
opam_root,
|
||||
instance,
|
||||
|
|
|
@ -163,30 +163,40 @@ def test_opam_multi_instance(datadir, swh_scheduler, tmp_path, mocker):
|
|||
# Patch opam_init to use the local directory
|
||||
mocker.patch("swh.lister.opam.lister.opam_init", side_effect=mock_opam_init)
|
||||
|
||||
lister = OpamLister(
|
||||
swh_scheduler,
|
||||
url=instance_url,
|
||||
instance="fake",
|
||||
opam_root=mkdtemp(dir=tmp_path, prefix="swh_opam_lister"),
|
||||
)
|
||||
opam_root = mkdtemp(dir=tmp_path, prefix="swh_opam_lister")
|
||||
|
||||
stats = lister.run()
|
||||
def check_listing():
|
||||
lister = OpamLister(
|
||||
swh_scheduler,
|
||||
url=instance_url,
|
||||
instance="fake",
|
||||
opam_root=opam_root,
|
||||
)
|
||||
|
||||
assert stats.pages == 4
|
||||
assert stats.origins == 4
|
||||
stats = lister.run()
|
||||
|
||||
scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results
|
||||
assert stats.pages == 4
|
||||
assert stats.origins == 4
|
||||
|
||||
expected_urls = [
|
||||
f"opam+{instance_url}/packages/agrid/",
|
||||
f"opam+{instance_url}/packages/calculon/",
|
||||
f"opam+{instance_url}/packages/directories/",
|
||||
f"opam+{instance_url}/packages/ocb/",
|
||||
]
|
||||
scheduler_origins = swh_scheduler.get_listed_origins(
|
||||
lister.lister_obj.id
|
||||
).results
|
||||
|
||||
result_urls = [origin.url for origin in scheduler_origins]
|
||||
expected_urls = [
|
||||
f"opam+{instance_url}/packages/agrid/",
|
||||
f"opam+{instance_url}/packages/calculon/",
|
||||
f"opam+{instance_url}/packages/directories/",
|
||||
f"opam+{instance_url}/packages/ocb/",
|
||||
]
|
||||
|
||||
assert expected_urls == result_urls
|
||||
result_urls = [origin.url for origin in scheduler_origins]
|
||||
|
||||
assert expected_urls == result_urls
|
||||
|
||||
# first listing
|
||||
check_listing()
|
||||
# check second listing works as expected
|
||||
check_listing()
|
||||
|
||||
|
||||
def test_opam_init_failure(swh_scheduler, mocker, tmp_path):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue