Skip to content

Commit

Permalink
Refactor docker CLI tests and utilities
Browse files Browse the repository at this point in the history
The previous commit added utility code for updating a docker repository
via the CLI. It did this by renaming a function called `repo_create`,
which executes `pulp-admin docker repo create`, to `repo_create_update`,
which can execute both the afore-mentioned command and `pulp-admin
docker repo update`. This change makes sense if trying to keep
implementation complexity to a low level, as the same set of flags are
accepted both when creating and updating a docker repository. However,
it raises interface complexity. Formerly, all `repo_*` functions map
directly to a `pulp-admin docker repo *` command, but after this change,
that pattern no longer holds true.

Split function `repo_create_update` into `repo_create` and
`repo_update`, in an attempt to keep interface complexity low. Also,
edit the test code added by the previous commit for formatting purposes.
Test results do not change as a result of this commit.
  • Loading branch information
Ichimonji10 committed Feb 25, 2016
1 parent af2e3a4 commit 10a38f3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 39 deletions.
12 changes: 6 additions & 6 deletions pulp_smash/tests/docker/cli/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ def setUpClass(cls):
super(CopyAllImagesTestCase, cls).setUpClass()

# Create a pair of repositories.
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
enable_v1='true',
enable_v2='false',
feed=DOCKER_V1_FEED_URL,
repo_id=cls.repo_ids[0],
upstream_name=_UPSTREAM_NAME,
)
docker_utils.repo_create_update(cls.cfg, repo_id=cls.repo_ids[1])
docker_utils.repo_create(cls.cfg, repo_id=cls.repo_ids[1])

# Sync the first and copy some content units to the second.
docker_utils.repo_sync(cls.cfg, cls.repo_ids[0])
Expand Down Expand Up @@ -154,15 +154,15 @@ def setUpClass(cls):
super(CopyAllManifestsTestCase, cls).setUpClass()

# Create a pair of repositories.
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
enable_v1='false',
enable_v2='true',
feed=DOCKER_V2_FEED_URL,
repo_id=cls.repo_ids[0],
upstream_name=_UPSTREAM_NAME,
)
docker_utils.repo_create_update(cls.cfg, repo_id=cls.repo_ids[1])
docker_utils.repo_create(cls.cfg, repo_id=cls.repo_ids[1])

# Sync the first and copy some content units to the second.
docker_utils.repo_sync(cls.cfg, cls.repo_ids[0])
Expand Down Expand Up @@ -208,15 +208,15 @@ def setUpClass(cls):
super(CopyAllTagsTestCase, cls).setUpClass()

# Create a pair of repositories.
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
enable_v1='false',
enable_v2='true',
feed=DOCKER_V2_FEED_URL,
repo_id=cls.repo_ids[0],
upstream_name=_UPSTREAM_NAME,
)
docker_utils.repo_create_update(cls.cfg, repo_id=cls.repo_ids[1])
docker_utils.repo_create(cls.cfg, repo_id=cls.repo_ids[1])

# Sync the first and copy some content units to the second.
docker_utils.repo_sync(cls.cfg, cls.repo_ids[0])
Expand Down
58 changes: 36 additions & 22 deletions pulp_smash/tests/docker/cli/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_basic(self):
Assert the return code is 0.
"""
completed_proc = docker_utils.repo_create_update(
completed_proc = docker_utils.repo_create(
self.cfg,
repo_id=self.repo_id
)
Expand All @@ -46,7 +46,7 @@ def test_with_feed_upstream_name(self):
Assert the return code is 0.
"""
completed_proc = docker_utils.repo_create_update(
completed_proc = docker_utils.repo_create(
self.cfg,
feed=_FEED,
repo_id=self.repo_id,
Expand All @@ -71,8 +71,8 @@ class UpdateEnableV1TestCase(unittest2.TestCase):
"""Update a docker repository's --enable-v1 flag.
There was a bug in pulp-admin wherein the --enable-v1 flag could be set
during repository creation, but not while updating repositories. This
test ensures that behavior functions correctly.
during repository creation, but not while updating repositories. This test
ensures that behavior functions correctly.
"""

@classmethod
Expand All @@ -88,10 +88,16 @@ def setUpClass(cls):
docker_utils.login(cls.cfg)

cls.repo_id = utils.uuid4()
docker_utils.repo_create_update(cls.cfg, repo_id=cls.repo_id,
enable_v1='false')
cls.update_response = docker_utils.repo_create_update(
cls.cfg, repo_id=cls.repo_id, enable_v1='true', action='update')
docker_utils.repo_create(
cls.cfg,
repo_id=cls.repo_id,
enable_v1='false'
)
cls.update_response = docker_utils.repo_update(
cls.cfg,
repo_id=cls.repo_id,
enable_v1='true',
)

@classmethod
def tearDownClass(cls):
Expand All @@ -100,13 +106,14 @@ def tearDownClass(cls):

def test_change_enable_v1_flag(self):
"""Test that the the --enable-v1 flag was successful."""
repo_details = docker_utils.repo_list(self.cfg, repo_id=self.repo_id,
details=True).stdout
repo_details = docker_utils.repo_list(
self.cfg,
repo_id=self.repo_id,
details=True,
).stdout

# Enable V1: True should appear in the output of the repo list
match = re.search(r'(?:Enable V1:)\s*(.*)', repo_details)

# The match should have found a group with the word "True"
self.assertEqual(match.group(1), 'True')

def test_success(self):
Expand All @@ -118,8 +125,8 @@ class UpdateEnableV2TestCase(unittest2.TestCase):
"""Update a docker repository's --enable-v2 flag.
There was a bug in pulp-admin wherein the --enable-v2 flag could be set
during repository creation, but not while updating repositories. This
test ensures that behavior functions correctly.
during repository creation, but not while updating repositories. This test
ensures that behavior functions correctly.
"""

@classmethod
Expand All @@ -135,10 +142,16 @@ def setUpClass(cls):
docker_utils.login(cls.cfg)

cls.repo_id = utils.uuid4()
docker_utils.repo_create_update(cls.cfg, repo_id=cls.repo_id,
enable_v2='false')
cls.update_response = docker_utils.repo_create_update(
cls.cfg, repo_id=cls.repo_id, enable_v2='true', action='update')
docker_utils.repo_create(
cls.cfg,
repo_id=cls.repo_id,
enable_v2='false',
)
cls.update_response = docker_utils.repo_update(
cls.cfg,
repo_id=cls.repo_id,
enable_v2='true',
)

@classmethod
def tearDownClass(cls):
Expand All @@ -147,13 +160,14 @@ def tearDownClass(cls):

def test_change_enable_v2_flag(self):
"""Test that the the --enable-v2 flag was successful."""
repo_details = docker_utils.repo_list(self.cfg, repo_id=self.repo_id,
details=True).stdout
repo_details = docker_utils.repo_list(
self.cfg,
repo_id=self.repo_id,
details=True
).stdout

# Enable V2: True should appear in the output of the repo list
match = re.search(r'(?:Enable V2:)\s*(.*)', repo_details)

# The match should have found a group with the word "True"
self.assertEqual(match.group(1), 'True')

def test_success(self):
Expand Down
8 changes: 4 additions & 4 deletions pulp_smash/tests/docker/cli/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SyncV1TestCase(_SuccessMixin, _BaseTestCase):
def setUpClass(cls):
"""Create and sync a docker repository with a v1 registry."""
super(SyncV1TestCase, cls).setUpClass()
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
feed=DOCKER_V1_FEED_URL,
repo_id=cls.repo_id,
Expand All @@ -71,7 +71,7 @@ def setUpClass(cls):
super(SyncV2TestCase, cls).setUpClass()
if cls.cfg.version < Version('2.8'):
raise unittest2.SkipTest('These tests require Pulp 2.8 or above.')
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
feed=DOCKER_V2_FEED_URL,
repo_id=cls.repo_id,
Expand All @@ -93,7 +93,7 @@ def setUpClass(cls):
super(SyncUnnamespacedV2TestCase, cls).setUpClass()
if cls.cfg.version < Version('2.8'):
raise unittest2.SkipTest('These tests require Pulp 2.8 or above.')
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
feed=DOCKER_V2_FEED_URL,
repo_id=cls.repo_id,
Expand All @@ -109,7 +109,7 @@ class InvalidFeedTestCase(_BaseTestCase):
def setUpClass(cls):
"""Create a docker repo with an invalid feed and sync it."""
super(InvalidFeedTestCase, cls).setUpClass()
docker_utils.repo_create_update(
docker_utils.repo_create(
cls.cfg,
feed='https://docker.example.com',
repo_id=cls.repo_id,
Expand Down
33 changes: 26 additions & 7 deletions pulp_smash/tests/docker/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ def repo_copy(server_config, unit_type, from_repo_id=None, to_repo_id=None):
return cli.Client(server_config).run(cmd)


# Yes, this function has an annoying number of arguments. It may be better to
# adopt some other solution such as providing a string for interpolation.
def repo_create_update( # pylint:disable=too-many-arguments
def repo_create( # pylint:disable=too-many-arguments
server_config,
enable_v1=None,
enable_v2=None,
feed=None,
repo_id=None,
upstream_name=None,
action='create'):
"""Execute ``pulp-admin docker repo create/update``."""
cmd = 'pulp-admin docker repo {}'.format(action).split()
upstream_name=None):
"""Execute ``pulp-admin docker repo create``."""
cmd = 'pulp-admin docker repo create'.split()
if enable_v1 is not None:
cmd.extend(('--enable-v1', enable_v1))
if enable_v2 is not None:
Expand Down Expand Up @@ -85,3 +82,25 @@ def repo_sync(server_config, repo_id):
cmd = 'pulp-admin docker repo sync run'.split()
cmd.extend(('--repo-id', repo_id))
return cli.Client(server_config).run(cmd)


def repo_update( # pylint:disable=too-many-arguments
server_config,
enable_v1=None,
enable_v2=None,
feed=None,
repo_id=None,
upstream_name=None):
"""Execute ``pulp-admin docker repo update``."""
cmd = 'pulp-admin docker repo update'.split()
if enable_v1 is not None:
cmd.extend(('--enable-v1', enable_v1))
if enable_v2 is not None:
cmd.extend(('--enable-v2', enable_v2))
if feed is not None:
cmd.extend(('--feed', feed))
if repo_id is not None:
cmd.extend(('--repo-id', repo_id))
if upstream_name is not None:
cmd.extend(('--upstream-name', upstream_name))
return cli.Client(server_config).run(cmd)

0 comments on commit 10a38f3

Please sign in to comment.