|
15 | 15 | # You should have received a copy of the Apache License |
16 | 16 | # along with Galaxy. If not, see <http://www.apache.org/licenses/>. |
17 | 17 |
|
| 18 | +import os |
18 | 19 | import shutil |
19 | | -from subprocess import Popen, PIPE, STDOUT |
| 20 | +from subprocess import PIPE, STDOUT, Popen |
20 | 21 |
|
21 | | -from galaxy_importer import config |
22 | | -from galaxy_importer import exceptions |
23 | | -from galaxy_importer.ansible_test.builders.local_image_build import Build |
| 22 | +from galaxy_importer import config, exceptions |
24 | 23 | from galaxy_importer.ansible_test.runners.base import BaseTestRunner |
25 | 24 |
|
26 | 25 |
|
27 | 26 | class LocalImageTestRunner(BaseTestRunner): |
28 | | - """Run image locally with docker or podman.""" |
| 27 | + """ |
| 28 | + Run `ansible-test sanity` in container defined in repo and hosted on quay. |
29 | 29 |
|
30 | | - def run(self): |
31 | | - cfg = config.Config(config_data=config.ConfigFile.load()) |
| 30 | + Container defined at galaxy_importer/ansible_test/container |
32 | 31 |
|
33 | | - build = Build( |
34 | | - self.filepath, |
35 | | - f"{self.metadata.namespace}-{self.metadata.name}-{self.metadata.version}", |
36 | | - cfg, |
37 | | - self.log, |
38 | | - ) |
| 32 | + Image used is hosted on quay: quay.io/cloudservices/automation-hub-ansible-test |
| 33 | + """ |
39 | 34 |
|
40 | | - container_engine = build.get_container_engine(cfg) |
| 35 | + def run(self): |
| 36 | + cfg = config.Config(config_data=config.ConfigFile.load()) |
41 | 37 |
|
| 38 | + # Get preferred container image and check if installed |
| 39 | + container_engine = "podman" |
| 40 | + if cfg.local_image_docker is True: |
| 41 | + container_engine = "docker" |
42 | 42 | if not shutil.which(container_engine): |
43 | 43 | self.log.warning(f'"{container_engine}" not found, skipping ansible-test sanity') |
44 | 44 | return |
45 | 45 |
|
46 | | - image_id = build.build_image() |
| 46 | + # Copy user-provided archive into path that can be used as volume |
| 47 | + archive_path = os.path.join(self.dir, "archive.tar.gz") |
| 48 | + self.log.debug(f"archive_path={archive_path}") |
| 49 | + shutil.copy(self.filepath, archive_path) |
| 50 | + volume = f"{archive_path}:/archive/archive.tar.gz" |
47 | 51 |
|
48 | 52 | self.log.info("Running image...") |
49 | | - self._run_image(image_id=image_id, container_engine=container_engine) |
| 53 | + self._run_image(container_engine=container_engine, volume=volume) |
50 | 54 |
|
51 | | - build.cleanup() |
| 55 | + def _run_image(self, container_engine, volume): |
| 56 | + cmd = [ |
| 57 | + container_engine, "run", |
| 58 | + "-v", volume, |
| 59 | + "quay.io/cloudservices/automation-hub-ansible-test", |
| 60 | + "LOCAL_IMAGE_RUNNER", |
| 61 | + ] # fmt: skip |
| 62 | + self.log.debug(f"cmd={cmd}") |
52 | 63 |
|
53 | | - def _run_image(self, image_id, container_engine): |
54 | | - cmd = [container_engine, "run", image_id, "LOCAL_IMAGE_RUNNER"] |
55 | 64 | proc = Popen( |
56 | 65 | cmd, |
57 | 66 | stdout=PIPE, |
|
0 commit comments