Skip to content

Commit afdec1d

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add image metadef resource type command 'list'"
2 parents 9846092 + 52bf194 commit afdec1d

File tree

6 files changed

+137
-1
lines changed

6 files changed

+137
-1
lines changed

doc/source/cli/data/glance.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ md-namespace-import,,Import a metadata definitions namespace from file or standa
2828
md-namespace-list,image metadef namespace list,List metadata definitions namespaces.
2929
md-namespace-objects-delete,,Delete all metadata definitions objects inside a specific namespace.
3030
md-namespace-properties-delete,,Delete all metadata definitions property inside a specific namespace.
31-
md-namespace-resource-type-list,,List resource types associated to specific namespace.
31+
md-namespace-resource-type-list,image metadef resource type list,List resource types associated to specific namespace.
3232
md-namespace-show,image metadef namespace show,Describe a specific metadata definitions namespace.
3333
md-namespace-tags-delete,,Delete all metadata definitions tags inside a specific namespace.
3434
md-namespace-update,,Update an existing metadata definitions namespace.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
"""Image V2 Action Implementations"""
14+
15+
from osc_lib.command import command
16+
from osc_lib import utils
17+
18+
from openstackclient.i18n import _
19+
20+
21+
class ListMetadefResourceTypes(command.Lister):
22+
_description = _("List metadef resource types")
23+
24+
def take_action(self, parsed_args):
25+
image_client = self.app.client_manager.image
26+
kwargs = {}
27+
data = image_client.metadef_resource_types(**kwargs)
28+
columns = ['Name']
29+
column_headers = columns
30+
return (
31+
column_headers,
32+
(
33+
utils.get_item_properties(
34+
s,
35+
columns,
36+
)
37+
for s in data
38+
),
39+
)

openstackclient/tests/unit/image/v2/fakes.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from openstack.image.v2 import image
2020
from openstack.image.v2 import member
2121
from openstack.image.v2 import metadef_namespace
22+
from openstack.image.v2 import metadef_resource_type
2223
from openstack.image.v2 import service_info as _service_info
2324
from openstack.image.v2 import task
2425

@@ -48,6 +49,7 @@ def __init__(self, **kwargs):
4849

4950
self.remove_tag = mock.Mock()
5051
self.metadef_namespaces = mock.Mock()
52+
self.metadef_resource_types = mock.Mock()
5153

5254
self.tasks = mock.Mock()
5355
self.tasks.resource_class = fakes.FakeResource(None, {})
@@ -285,3 +287,41 @@ def create_one_metadef_namespace(attrs=None):
285287
# Overwrite default attributes if there are some attributes set
286288
metadef_namespace_list.update(attrs)
287289
return metadef_namespace.MetadefNamespace(**metadef_namespace_list)
290+
291+
292+
def create_one_resource_type(attrs=None):
293+
"""Create a fake MetadefResourceType member.
294+
295+
:param attrs: A dictionary with all attributes of
296+
metadef_resource_type member
297+
:type attrs: dict
298+
:return: a fake MetadefResourceType object
299+
:rtype: A `metadef_resource_type.MetadefResourceType`
300+
"""
301+
attrs = attrs or {}
302+
303+
metadef_resource_type_info = {
304+
'name': 'OS::Compute::Quota',
305+
'properties_target': 'image',
306+
}
307+
308+
metadef_resource_type_info.update(attrs)
309+
return metadef_resource_type.MetadefResourceType(
310+
**metadef_resource_type_info
311+
)
312+
313+
314+
def create_resource_types(attrs=None, count=2):
315+
"""Create multiple fake resource types.
316+
317+
:param attrs: A dictionary with all attributes of
318+
metadef_resource_type member
319+
:type attrs: dict
320+
:return: A list of fake MetadefResourceType objects
321+
:rtype: list
322+
"""
323+
metadef_resource_types = []
324+
for n in range(0, count):
325+
metadef_resource_types.append(create_one_resource_type(attrs))
326+
327+
return metadef_resource_types
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstackclient.image.v2 import metadef_resource_types
14+
from openstackclient.tests.unit.image.v2 import fakes as resource_type_fakes
15+
16+
17+
class TestMetadefResourceTypes(resource_type_fakes.TestImagev2):
18+
def setUp(self):
19+
super().setUp()
20+
21+
self.client = self.app.client_manager.image
22+
23+
24+
class TestMetadefResourceTypeList(TestMetadefResourceTypes):
25+
resource_types = resource_type_fakes.create_resource_types()
26+
27+
columns = ['Name']
28+
29+
datalist = [(resource_type.name,) for resource_type in resource_types]
30+
31+
def setUp(self):
32+
super().setUp()
33+
34+
self.client.metadef_resource_types.side_effect = [
35+
self.resource_types,
36+
[],
37+
]
38+
39+
self.cmd = metadef_resource_types.ListMetadefResourceTypes(
40+
self.app, None
41+
)
42+
43+
def test_resource_type_list_no_options(self):
44+
arglist = []
45+
parsed_args = self.check_parser(self.cmd, arglist, [])
46+
47+
columns, data = self.cmd.take_action(parsed_args)
48+
49+
self.assertEqual(self.columns, columns)
50+
self.assertCountEqual(self.datalist, data)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Added ``image metadef resource type list`` command. This is equivalent to
5+
the ``+md-namespace-resource-type-list`` command in glanceclient.

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ openstack.image.v2 =
395395
image_metadef_namespace_set = openstackclient.image.v2.metadef_namespaces:SetMetadefNameSpace
396396
image_metadef_namespace_show = openstackclient.image.v2.metadef_namespaces:ShowMetadefNameSpace
397397

398+
image_metadef_resource_type_list = openstackclient.image.v2.metadef_resource_types:ListMetadefResourceTypes
399+
398400
openstack.network.v2 =
399401
address_group_create = openstackclient.network.v2.address_group:CreateAddressGroup
400402
address_group_delete = openstackclient.network.v2.address_group:DeleteAddressGroup

0 commit comments

Comments
 (0)