Skip to content

Commit

Permalink
Run ansible-test sanity from quay image not from build
Browse files Browse the repository at this point in the history
No-Issue
  • Loading branch information
awcrosby committed Aug 23, 2022
1 parent 05712d1 commit 62ab225
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 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,52 @@
# 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("Running image...")
self._run_image(image_id=image_id, container_engine=container_engine)
self._run_image(container_engine=container_engine, volume=volume)

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

0 comments on commit 62ab225

Please sign in to comment.