def test_images_complete_lifecycle( helper: Helper, image: str, tag: str, loop: asyncio.AbstractEventLoop, docker: aiodocker.Docker, ) -> None: # Let`s push image captured = helper.run_cli(["image", "push", image]) # stderr has "Used image ..." lines # assert not captured.err image_full_str = f"image://{helper.cluster_name}/{helper.username}/{image}" assert captured.out.endswith(image_full_str) image_url = URL(image_full_str) # Check if image available on registry captured = helper.run_cli(["image", "ls", "--full-uri"]) image_urls = [URL(line) for line in captured.out.splitlines() if line] for url in image_urls: assert url.scheme == "image" image_url_without_tag = image_url.with_path( image_url.path.replace(f":{tag}", "")) assert image_url_without_tag in image_urls # delete local loop.run_until_complete(docker.images.delete(image, force=True)) docker_ls_output = loop.run_until_complete(docker.images.list()) local_images = parse_docker_ls_output(docker_ls_output) assert image not in local_images # Pull image as with another tag captured = helper.run_cli(["image", "pull", f"image:{image}"]) # stderr has "Used image ..." lines # assert not captured.err assert captured.out.endswith(image) # check pulled locally, delete for cleanup docker_ls_output = loop.run_until_complete(docker.images.list()) local_images = parse_docker_ls_output(docker_ls_output) assert image in local_images # Execute image and check result captured = helper.run_cli([ "-q", "submit", *JOB_TINY_CONTAINER_PARAMS, "--non-preemptible", "--no-wait-start", str(image_url), ]) assert not captured.err job_id = captured.out assert job_id.startswith("job-") helper.wait_job_change_state_to(job_id, JobStatus.SUCCEEDED, JobStatus.FAILED) helper.check_job_output(job_id, re.escape(tag))
def test_docker_helper(helper: Helper, image: str, tag: str, nmrc_path: Path, monkeypatch: Any) -> None: monkeypatch.setenv(CONFIG_ENV_NAME, str(nmrc_path or DEFAULT_CONFIG_PATH)) helper.run_cli(["config", "docker"]) registry = helper.registry_url.host username = helper.username full_tag = f"{registry}/{username}/{image}" tag_cmd = f"docker tag {image} {full_tag}" result = subprocess.run(tag_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) assert ( not result.returncode ), f"Command {tag_cmd} failed: {result.stdout!r} {result.stderr!r} " push_cmd = f"docker push {full_tag}" result = subprocess.run(push_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) assert ( not result.returncode ), f"Command {push_cmd} failed: {result.stdout!r} {result.stderr!r} " # Run image and check output image_url = f"image://{helper.cluster_name}/{username}/{image}" job_id = helper.run_job_and_wait_state(image_url, "", wait_state=JobStatus.SUCCEEDED, stop_state=JobStatus.FAILED) helper.check_job_output(job_id, re.escape(tag))