From 66598609b8eb8befd6f29702936f4c539fb113cb Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Wed, 22 Jun 2016 23:58:46 +0100 Subject: [PATCH] pulp_sync: don't rely on syncRepo() return value The dockpulp syncRepo() method no longer returns the prefixed repository ID. As pulp_sync can be told what the prefix is, let's just use that to work out what the prefixed repository ID is. dockpulp change: https://github.com/release-engineering/dockpulp/pull/59 --- atomic_reactor/plugins/post_pulp_sync.py | 20 +++++---- tests/dockpulp/__init__.py | 4 +- tests/plugins/test_pulp_sync.py | 54 ++++++++++-------------- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/atomic_reactor/plugins/post_pulp_sync.py b/atomic_reactor/plugins/post_pulp_sync.py index 104e4278e..a00dda298 100644 --- a/atomic_reactor/plugins/post_pulp_sync.py +++ b/atomic_reactor/plugins/post_pulp_sync.py @@ -164,12 +164,14 @@ def create_repo_if_missing(self, pulp, repo_id, registry_id): repo = missing_repos.pop() except KeyError: # Already exists - return + pass else: self.log.info("creating repo %s", repo) - pulp.createRepo(repo, None, registry_id=registry_id, + pulp.createRepo(prefixed_repo_id, None, registry_id=registry_id, prefix_with=self.pulp_repo_prefix) + return prefixed_repo_id + def run(self): pulp = dockpulp.Pulp(env=self.pulp_registry_name) self.set_auth(pulp) @@ -197,12 +199,14 @@ def run(self): repos = {} # pulp repo -> repo id for image in self.workflow.tag_conf.primary_images: if image.pulp_repo not in repos: - self.create_repo_if_missing(pulp, image.pulp_repo, image.repo) - self.log.info("syncing %s", image.pulp_repo) - repoinfo = pulp.syncRepo(repo=image.pulp_repo, - feed=self.docker_registry, - **kwargs) - repos[image.pulp_repo] = repoinfo[0]['id'] + repo_id = self.create_repo_if_missing(pulp, + image.pulp_repo, + image.repo) + self.log.info("syncing %s", repo_id) + pulp.syncRepo(repo=repo_id, + feed=self.docker_registry, + **kwargs) + repos[image.pulp_repo] = repo_id images.append(ImageName(registry=pulp_registry, repo=image.repo)) diff --git a/tests/dockpulp/__init__.py b/tests/dockpulp/__init__.py index 374da3dd6..5794948bf 100644 --- a/tests/dockpulp/__init__.py +++ b/tests/dockpulp/__init__.py @@ -27,8 +27,8 @@ def login(self, username, password): def set_certs(self, cer, key): pass - def syncRepo(self, feed=None, repo=None, - basic_auth_username=None, basic_auth_password=None, + def syncRepo(self, env=None, repo=None, config_file=None, prefix_with=None, + feed=None, basic_auth_username=None, basic_auth_password=None, ssl_validation=None): pass diff --git a/tests/plugins/test_pulp_sync.py b/tests/plugins/test_pulp_sync.py index 24f4786a4..1446f4425 100644 --- a/tests/plugins/test_pulp_sync.py +++ b/tests/plugins/test_pulp_sync.py @@ -51,8 +51,8 @@ def login(self, username, password): def set_certs(self, cer, key): pass - def syncRepo(self, feed=None, repo=None, - basic_auth_username=None, basic_auth_password=None, + def syncRepo(self, env=None, repo=None, config_file=None, prefix_with=None, + feed=None, basic_auth_username=None, basic_auth_password=None, ssl_validation=None): pass @@ -107,15 +107,14 @@ def test_auth_none(self): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .with_args(object, - repo=pulp_repoid, + .with_args(repo=prefixed_pulp_repoid, feed=docker_registry) - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(mockpulp) .should_receive('crane') - .with_args([pulp_repoid], wait=True) + .with_args([prefixed_pulp_repoid], wait=True) .once() .ordered()) (flexmock(dockpulp) @@ -166,15 +165,14 @@ def test_pulp_auth(self, tmpdir, cer_exists, key_exists): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .with_args(object, - repo=pulp_repoid, + .with_args(repo=prefixed_pulp_repoid, feed=docker_registry) - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(mockpulp) .should_receive('crane') - .with_args([pulp_repoid], wait=True) + .with_args([prefixed_pulp_repoid], wait=True) .once() .ordered()) else: @@ -260,10 +258,9 @@ def test_dockercfg_registry_not_present(self, tmpdir): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .with_args(object, - repo=pulp_repoid, + .with_args(repo=prefixed_pulp_repoid, feed=docker_registry) - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(dockpulp) @@ -310,12 +307,11 @@ def test_dockercfg(self, tmpdir, scheme): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .with_args(object, - repo=pulp_repoid, + .with_args(repo=prefixed_pulp_repoid, feed=docker_registry, basic_auth_username=user, basic_auth_password=pw) - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(dockpulp) @@ -351,17 +347,15 @@ def test_insecure_registry(self, insecure_registry, ssl_validation): .ordered()) sync_exp = flexmock(mockpulp).should_receive('syncRepo') if ssl_validation is None: - sync_exp = sync_exp.with_args(object, - repo=pulp_repoid, + sync_exp = sync_exp.with_args(repo=prefixed_pulp_repoid, feed=docker_registry) else: - sync_exp = sync_exp.with_args(object, - repo=pulp_repoid, + sync_exp = sync_exp.with_args(repo=prefixed_pulp_repoid, feed=docker_registry, ssl_validation=ssl_validation) (sync_exp - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(dockpulp) @@ -384,7 +378,7 @@ def test_dockpulp_loglevel(self, fail, caplog): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .and_return([{'id':''}])) + .and_return(([], []))) flexmock(dockpulp).should_receive('Pulp').and_return(mockpulp) logger = flexmock() expectation = (logger @@ -439,15 +433,14 @@ def test_store_registry(self, already_exists): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .with_args(object, - repo=pulp_repoid, + .with_args(repo=prefixed_pulp_repoid, feed=docker_registry) - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(mockpulp) .should_receive('crane') - .with_args([pulp_repoid], wait=True) + .with_args([prefixed_pulp_repoid], wait=True) .once() .ordered()) (flexmock(dockpulp) @@ -482,7 +475,7 @@ def test_delete_not_implemented(self, caplog): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .and_return([{'id':''}])) + .and_return(([], []))) flexmock(dockpulp).should_receive('Pulp').and_return(mockpulp) plugin = PulpSyncPlugin(tasker=None, workflow=self.workflow(['prod/myrepository']), @@ -525,15 +518,14 @@ def test_create_missing_repo(self): .ordered()) (flexmock(mockpulp) .should_receive('syncRepo') - .with_args(object, - repo=pulp_repoid, + .with_args(repo=prefixed_pulp_repoid, feed=docker_registry) - .and_return([{'id': pulp_repoid}]) + .and_return(([], [])) .once() .ordered()) (flexmock(mockpulp) .should_receive('crane') - .with_args([pulp_repoid], wait=True) + .with_args([prefixed_pulp_repoid], wait=True) .once() .ordered()) (flexmock(dockpulp)