Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulp_sync: don't rely on syncRepo() return value #524

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions atomic_reactor/plugins/post_pulp_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions tests/dockpulp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 23 additions & 31 deletions tests/plugins/test_pulp_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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']),
Expand Down Expand Up @@ -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)
Expand Down