Example #1
0
def test_copy_collection_file():
    with tempfile.TemporaryDirectory() as dir:
        f = tempfile.NamedTemporaryFile(delete=False)
        filepath = f.name
        Build._copy_collection_file(dir, filepath)
        assert os.path.exists(os.path.join(dir, 'archive.tar.gz'))
        os.remove(f.name)
Example #2
0
    def run(self):
        build = Build(
            self.filepath,
            f'{self.metadata.namespace}-{self.metadata.name}-{self.metadata.version}',
            self.log)

        image_id = build.build_image()

        self.log.info('Running image...')
        self._run_image(image_id=image_id)

        build.cleanup()
Example #3
0
def test_build_image(mocker, tmp_file):
    with open(tmp_file, 'w') as f:
        f.write('file contents go here')
        f.flush()
        build = Build(filepath=tmp_file,
                      collection_name='namespace-name-version')
        mocker.patch.object(Build, '_build_dockerfile')
        mocker.patch.object(Build, '_copy_collection_file')
        mocker.patch.object(Build, '_build_image_with_artifact')
        _ = build.build_image()
        assert build._build_dockerfile.called
        assert build._copy_collection_file.called
        assert build._build_image_with_artifact.called
Example #4
0
def test_build_image_with_artifact(mocked_popen, mocker):
    with tempfile.TemporaryDirectory() as dir:
        mocked_popen.return_value.stdout = ['sha256:1234', 'sha256:5678']
        mocked_popen.return_value.wait.return_value = 0
        result = Build._build_image_with_artifact(dir=dir)
        assert mocked_popen.called
        assert '5678' in result
Example #5
0
    def run(self):
        cfg = config.Config(config_data=config.ConfigFile.load())

        build = Build(
            self.filepath,
            f'{self.metadata.namespace}-{self.metadata.name}-{self.metadata.version}',
            cfg, self.log)

        container_engine = build.get_container_engine(cfg)

        if not shutil.which(container_engine):
            self.log.warning(
                f'"{container_engine}" not found, skipping ansible-test sanity'
            )
            return

        image_id = build.build_image()

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

        build.cleanup()
def build():
    return Build('/file/path/to/archive.tar.gz',
                 'namespace-name-0.0.1',
                 logger=None)
Example #7
0
def test_build_image_with_artifact_exception(mocked_popen, mocker):
    with tempfile.TemporaryDirectory() as dir:
        mocked_popen.return_value.stdout = ['sha256:1234', 'sha256:5678']
        mocked_popen.return_value.wait.return_value = 1
        with pytest.raises(exc.AnsibleTestError):
            Build._build_image_with_artifact(dir=dir)
Example #8
0
def test_build_dockerfile(mocker):
    with tempfile.TemporaryDirectory() as dir:
        Build._build_dockerfile(dir)
        with open(f'{dir}/Dockerfile') as f:
            assert 'COPY archive.tar.gz /archive/archive.tar.gz' in f.read()
Example #9
0
def build():
    return Build('/file/path/to/archive.tar.gz', 'name')
def build():
    return Build("/file/path/to/archive.tar.gz",
                 "namespace-name-0.0.1",
                 logger=None)