Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run ansible-test sanity from quay image not from build #180

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/1884.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove use of docker build, instead use quay image to run ansible-test sanity
75 changes: 56 additions & 19 deletions galaxy_importer/ansible_test/runners/local_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,80 @@
# You should have received a copy of the Apache License
# along with Galaxy. If not, see <http://www.apache.org/licenses/>.

import os
import shutil
from subprocess import Popen, PIPE, STDOUT
from subprocess import PIPE, STDOUT, Popen

from galaxy_importer import config
from galaxy_importer import exceptions
from galaxy_importer.ansible_test.builders.local_image_build import Build
from galaxy_importer import config, exceptions
from galaxy_importer.ansible_test.runners.base import BaseTestRunner


class LocalImageTestRunner(BaseTestRunner):
"""Run image locally with docker or podman."""
"""
Run `ansible-test sanity` in container defined in repo and hosted on quay.

def run(self):
cfg = config.Config(config_data=config.ConfigFile.load())
Container defined at galaxy_importer/ansible_test/container

build = Build(
self.filepath,
f"{self.metadata.namespace}-{self.metadata.name}-{self.metadata.version}",
cfg,
self.log,
)
Image used is hosted on quay: quay.io/cloudservices/automation-hub-ansible-test
"""

container_engine = build.get_container_engine(cfg)
def run(self):
cfg = config.Config(config_data=config.ConfigFile.load())

# Get preferred container image and check if installed
container_engine = "podman"
if cfg.local_image_docker is True:
container_engine = "docker"
if not shutil.which(container_engine):
self.log.warning(f'"{container_engine}" not found, skipping ansible-test sanity')
return

image_id = build.build_image()
# Copy user-provided archive into path that can be used as volume
archive_path = os.path.join(self.dir, "archive.tar.gz")
self.log.debug(f"archive_path={archive_path}")
shutil.copy(self.filepath, archive_path)
volume = f"{archive_path}:/archive/archive.tar.gz"

self.log.info("Pulling image...")
self._pull_image(container_engine=container_engine)

self.log.info("Running image...")
self._run_image(image_id=image_id, container_engine=container_engine)
self._run_image(container_engine=container_engine, volume=volume)

def _pull_image(self, container_engine):
# TODO: use a separate image repo, repo or org is private
cmd = [
container_engine,
"pull",
"quay.io/cloudservices/automation-hub-ansible-test",
]
self.log.debug(f"cmd={cmd}")

proc = Popen(
cmd,
stdout=PIPE,
stderr=STDOUT,
encoding="utf-8",
)

for line in proc.stdout:
self.log.info(line.strip())

return_code = proc.wait()
if return_code != 0:
raise exceptions.AnsibleTestError(
"An exception occurred in {}, returncode={}".format(" ".join(cmd), return_code)
)

build.cleanup()
def _run_image(self, container_engine, volume):
cmd = [
container_engine, "run",
"-v", volume,
"quay.io/cloudservices/automation-hub-ansible-test",
"LOCAL_IMAGE_RUNNER",
] # fmt: skip
self.log.debug(f"cmd={cmd}")

def _run_image(self, image_id, container_engine):
cmd = [container_engine, "run", image_id, "LOCAL_IMAGE_RUNNER"]
proc = Popen(
cmd,
stdout=PIPE,
Expand Down