Merge "Add image metadef resource type command 'list'"

This commit is contained in:
Zuul 2023-08-09 19:01:33 +00:00 committed by Gerrit Code Review
commit afdec1d2ca
6 changed files with 137 additions and 1 deletions

View File

@ -28,7 +28,7 @@ md-namespace-import,,Import a metadata definitions namespace from file or standa
md-namespace-list,image metadef namespace list,List metadata definitions namespaces.
md-namespace-objects-delete,,Delete all metadata definitions objects inside a specific namespace.
md-namespace-properties-delete,,Delete all metadata definitions property inside a specific namespace.
md-namespace-resource-type-list,,List resource types associated to specific namespace.
md-namespace-resource-type-list,image metadef resource type list,List resource types associated to specific namespace.
md-namespace-show,image metadef namespace show,Describe a specific metadata definitions namespace.
md-namespace-tags-delete,,Delete all metadata definitions tags inside a specific namespace.
md-namespace-update,,Update an existing metadata definitions namespace.

1 cache-clear Clear all images from cache, queue or both.
28 md-namespace-list image metadef namespace list List metadata definitions namespaces.
29 md-namespace-objects-delete Delete all metadata definitions objects inside a specific namespace.
30 md-namespace-properties-delete Delete all metadata definitions property inside a specific namespace.
31 md-namespace-resource-type-list image metadef resource type list List resource types associated to specific namespace.
32 md-namespace-show image metadef namespace show Describe a specific metadata definitions namespace.
33 md-namespace-tags-delete Delete all metadata definitions tags inside a specific namespace.
34 md-namespace-update Update an existing metadata definitions namespace.

View File

@ -0,0 +1,39 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Image V2 Action Implementations"""
from osc_lib.command import command
from osc_lib import utils
from openstackclient.i18n import _
class ListMetadefResourceTypes(command.Lister):
_description = _("List metadef resource types")
def take_action(self, parsed_args):
image_client = self.app.client_manager.image
kwargs = {}
data = image_client.metadef_resource_types(**kwargs)
columns = ['Name']
column_headers = columns
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)

View File

@ -19,6 +19,7 @@ import uuid
from openstack.image.v2 import image
from openstack.image.v2 import member
from openstack.image.v2 import metadef_namespace
from openstack.image.v2 import metadef_resource_type
from openstack.image.v2 import service_info as _service_info
from openstack.image.v2 import task
@ -48,6 +49,7 @@ class FakeImagev2Client:
self.remove_tag = mock.Mock()
self.metadef_namespaces = mock.Mock()
self.metadef_resource_types = mock.Mock()
self.tasks = mock.Mock()
self.tasks.resource_class = fakes.FakeResource(None, {})
@ -285,3 +287,41 @@ def create_one_metadef_namespace(attrs=None):
# Overwrite default attributes if there are some attributes set
metadef_namespace_list.update(attrs)
return metadef_namespace.MetadefNamespace(**metadef_namespace_list)
def create_one_resource_type(attrs=None):
"""Create a fake MetadefResourceType member.
:param attrs: A dictionary with all attributes of
metadef_resource_type member
:type attrs: dict
:return: a fake MetadefResourceType object
:rtype: A `metadef_resource_type.MetadefResourceType`
"""
attrs = attrs or {}
metadef_resource_type_info = {
'name': 'OS::Compute::Quota',
'properties_target': 'image',
}
metadef_resource_type_info.update(attrs)
return metadef_resource_type.MetadefResourceType(
**metadef_resource_type_info
)
def create_resource_types(attrs=None, count=2):
"""Create multiple fake resource types.
:param attrs: A dictionary with all attributes of
metadef_resource_type member
:type attrs: dict
:return: A list of fake MetadefResourceType objects
:rtype: list
"""
metadef_resource_types = []
for n in range(0, count):
metadef_resource_types.append(create_one_resource_type(attrs))
return metadef_resource_types

View File

@ -0,0 +1,50 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstackclient.image.v2 import metadef_resource_types
from openstackclient.tests.unit.image.v2 import fakes as resource_type_fakes
class TestMetadefResourceTypes(resource_type_fakes.TestImagev2):
def setUp(self):
super().setUp()
self.client = self.app.client_manager.image
class TestMetadefResourceTypeList(TestMetadefResourceTypes):
resource_types = resource_type_fakes.create_resource_types()
columns = ['Name']
datalist = [(resource_type.name,) for resource_type in resource_types]
def setUp(self):
super().setUp()
self.client.metadef_resource_types.side_effect = [
self.resource_types,
[],
]
self.cmd = metadef_resource_types.ListMetadefResourceTypes(
self.app, None
)
def test_resource_type_list_no_options(self):
arglist = []
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.datalist, data)

View File

@ -0,0 +1,5 @@
---
features:
- |
Added ``image metadef resource type list`` command. This is equivalent to
the ``+md-namespace-resource-type-list`` command in glanceclient.

View File

@ -395,6 +395,8 @@ openstack.image.v2 =
image_metadef_namespace_set = openstackclient.image.v2.metadef_namespaces:SetMetadefNameSpace
image_metadef_namespace_show = openstackclient.image.v2.metadef_namespaces:ShowMetadefNameSpace
image_metadef_resource_type_list = openstackclient.image.v2.metadef_resource_types:ListMetadefResourceTypes
openstack.network.v2 =
address_group_create = openstackclient.network.v2.address_group:CreateAddressGroup
address_group_delete = openstackclient.network.v2.address_group:DeleteAddressGroup