Merge "Implement tripleo container image list command"
This commit is contained in:
commit
91f6210810
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
With the new podman container setup comes an Apache served local image
|
||||
registry.
|
||||
|
||||
`openstack tripleo container image list` gives you insight into your
|
||||
images.
|
@ -103,6 +103,7 @@ openstack.tripleoclient.v1 =
|
||||
overcloud_ffwd-upgrade_converge = tripleoclient.v1.overcloud_ffwd_upgrade:FFWDUpgradeConverge
|
||||
overcloud_execute = tripleoclient.v1.overcloud_execute:RemoteExecute
|
||||
overcloud_generate_fencing = tripleoclient.v1.overcloud_parameters:GenerateFencingParameters
|
||||
tripleo_container_image_list = tripleoclient.v1.container_image:TripleOContainerImageList
|
||||
tripleo_container_image_prepare = tripleoclient.v1.container_image:TripleOImagePrepare
|
||||
tripleo_container_image_prepare_default = tripleoclient.v1.container_image:TripleOImagePrepareDefault
|
||||
undercloud_deploy = tripleoclient.v1.undercloud_deploy:DeployUndercloud
|
||||
|
@ -80,6 +80,71 @@ class TestContainerImageUpload(TestPluginV1):
|
||||
mock_manager.return_value.upload.assert_called_once_with()
|
||||
|
||||
|
||||
class TestContainerImageList(TestPluginV1):
|
||||
|
||||
def setUp(self):
|
||||
super(TestContainerImageList, self).setUp()
|
||||
self.cmd = container_image.TripleOContainerImageList(self.app, None)
|
||||
|
||||
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager')
|
||||
def test_take_action(self, mock_manager):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
mock_manager.return_value.uploader.return_value.list.return_value = \
|
||||
['a', 'b']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
rv = self.cmd.take_action(parsed_args)
|
||||
actual = (('Image Name',), [('a',), ('b',)])
|
||||
self.assertEqual(actual, rv)
|
||||
|
||||
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager')
|
||||
def test_take_action_auth(self, mock_manager):
|
||||
# check arg parsing items
|
||||
arglist = ['--registry-url', 'reg-url',
|
||||
'--username', 'foo',
|
||||
'--password', 'bar']
|
||||
verifylist = [('registry_url', 'reg-url'),
|
||||
('username', 'foo'),
|
||||
('password', 'bar')]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# mock manager object
|
||||
mock_mgr = mock.Mock()
|
||||
mock_manager.return_value = mock_mgr
|
||||
|
||||
# mock uploader object
|
||||
mock_uploader = mock.Mock()
|
||||
mock_mgr.uploader.return_value = mock_uploader
|
||||
|
||||
# mock return url object from uploader._image_to_url
|
||||
mock_url = mock.Mock()
|
||||
mock_url.geturl.return_value = 'munged-reg-url'
|
||||
|
||||
mock_uploader._image_to_url.return_value = mock_url
|
||||
|
||||
# mock return session object from uploader.authenticate
|
||||
mock_session = mock.Mock()
|
||||
mock_uploader.authenticate.return_value = mock_session
|
||||
|
||||
# mock image list function
|
||||
mock_uploader.list.return_value = ['a', 'b']
|
||||
|
||||
rv = self.cmd.take_action(parsed_args)
|
||||
|
||||
# check various functions are called with expected inputs
|
||||
mock_mgr.uploader.assert_called_with('python')
|
||||
mock_uploader._image_to_url.assert_called_with('reg-url')
|
||||
mock_uploader.authenticate.assert_called_with(mock_url, 'foo', 'bar')
|
||||
mock_uploader.list.assert_called_with('munged-reg-url',
|
||||
session=mock_session)
|
||||
|
||||
# check data format for lister
|
||||
actual = (('Image Name',), [('a',), ('b',)])
|
||||
self.assertEqual(actual, rv)
|
||||
|
||||
|
||||
class TestContainerImagePrepare(TestPluginV1):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -511,6 +511,51 @@ class DiscoverImageTag(command.Command):
|
||||
))
|
||||
|
||||
|
||||
class TripleOContainerImageList(command.Lister):
|
||||
"""List images discovered in registry."""
|
||||
|
||||
auth_required = False
|
||||
log = logging.getLogger(__name__ + ".TripleoContainerImageList")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(TripleOContainerImageList, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"--registry-url",
|
||||
dest="registry_url",
|
||||
metavar='<registry url>',
|
||||
default=image_uploader.get_undercloud_registry(),
|
||||
help=_("URL of registry images are to be listed from in the "
|
||||
"form <fqdn>:<port>.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--username",
|
||||
dest="username",
|
||||
metavar='<username>',
|
||||
help=_("Username for image registry.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--password",
|
||||
dest="password",
|
||||
metavar='<password>',
|
||||
help=_("Password for image registry.")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
||||
manager = image_uploader.ImageUploadManager()
|
||||
uploader = manager.uploader('python')
|
||||
url = uploader._image_to_url(parsed_args.registry_url)
|
||||
session = uploader.authenticate(url, parsed_args.username,
|
||||
parsed_args.password)
|
||||
results = uploader.list(url.geturl(), session=session)
|
||||
cliff_results = []
|
||||
for r in results:
|
||||
cliff_results.append((r,))
|
||||
return (("Image Name",), cliff_results)
|
||||
|
||||
|
||||
class TripleOImagePrepareDefault(command.Command):
|
||||
"""Generate a default ContainerImagePrepare parameter."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user