Пример #1
0
    def fetch_image_sha(self, image, arch):
        """Use skopeo to obtain the SHA of a given image

        We want the image manifest shasum because internal registry/cri-o can't handle manifest lists yet.
        More info: http://post-office.corp.redhat.com/archives/aos-team-art/2019-October/msg02010.html

        :param string image: Image name + version (format: openshift/my-image:v4.1.16-201901010000)
        :param string arch: Same image has different SHAs per architecture
        :return string Digest (format: sha256:a1b2c3d4...)
        """
        registry = self.runtime.group_config.urls.brew_image_host.rstrip("/")
        ns = self.runtime.group_config.urls.brew_image_namespace
        if ns:
            image = "{}/{}".format(ns, image.replace('/', '-'))

        if arch == 'manifest-list':
            cmd = 'skopeo inspect docker://{}/{}'.format(registry, image)
            rc, out, err = exectools.retry(
                retries=3, task_f=lambda *_: exectools.cmd_gather(cmd))
            return json.loads(out)['Digest']

        cmd = 'skopeo inspect --raw docker://{}/{}'.format(registry, image)
        rc, out, err = exectools.retry(
            retries=3, task_f=lambda *_: exectools.cmd_gather(cmd))

        arch = 'amd64' if arch == 'x86_64' else arch  # x86_64 is called amd64 in skopeo

        def select_arch(manifests):
            return manifests['platform']['architecture'] == arch

        return filter(select_arch, json.loads(out)['manifests'])[0]['digest']
Пример #2
0
 def test_success(self):
     """
     Given a function that passes, make sure it returns successfully with
     a single retry or greater.
     """
     pass_function = lambda: True
     self.assertTrue(exectools.retry(1, pass_function))
     self.assertTrue(exectools.retry(2, pass_function))
Пример #3
0
 def test_return(self):
     """
     Verify that the retry task return value is passed back out faithfully.
     """
     obj = {}
     func = lambda: obj
     self.assertIs(exectools.retry(1, func, check_f=lambda _: True), obj)
Пример #4
0
    def clone_repo(self, repo, branch):
        """Clone a repository using rhpkg

        :param string repo: Name of the repository to be cloned
        :param string branch: Which branch of the repository should be cloned
        """
        def delete_and_clone():
            self.delete_repo(repo)

            cmd = 'timeout 600 rhpkg '
            cmd += '--user {} '.format(
                self.rhpkg_user) if self.rhpkg_user else ''
            cmd += 'clone containers/{} --branch {}'.format(repo, branch)
            return exectools.cmd_assert(cmd)

        with pushd.Dir(self.working_dir):
            exectools.retry(retries=3, task_f=delete_and_clone)
Пример #5
0
 def commit_and_push_metadata_repo(self):
     """Commit and push changes made on the metadata repository, using rhpkg
     """
     with pushd.Dir('{}/{}'.format(self.working_dir, self.metadata_repo)):
         try:
             exectools.cmd_assert('git add .')
             user_option = '--user {} '.format(
                 self.rhpkg_user) if self.rhpkg_user else ''
             exectools.cmd_assert(
                 'rhpkg {} {}commit -m "Update operator metadata"'.format(
                     self.runtime.rhpkg_config, user_option))
             exectools.retry(
                 retries=3,
                 task_f=lambda: exectools.cmd_assert(
                     'timeout 600 rhpkg {}push'.format(user_option)))
             return True
         except Exception:
             # The metadata repo might be already up to date, so we don't have anything new to commit
             return False
Пример #6
0
 def get_latest_build(self):
     cmd = 'brew latest-build {} {} --quiet'.format(
         self.target, self.metadata_component_name)
     _rc, stdout, _stderr = exectools.retry(
         retries=3, task_f=lambda *_: exectools.cmd_gather(cmd))
     return stdout.split(' ')[0]
Пример #7
0
 def get_brew_buildinfo(self):
     """Output of this command is used to extract the operator name and its commit hash
     """
     cmd = 'brew buildinfo {}'.format(self.nvr)
     return exectools.retry(retries=3,
                            task_f=lambda *_: exectools.cmd_gather(cmd))