Merge "Adds CLI support for `glance md-namespace-properties-delete`"

This commit is contained in:
Zuul
2025-08-15 13:37:13 +00:00
committed by Gerrit Code Review
4 changed files with 39 additions and 13 deletions

View File

@@ -27,7 +27,7 @@ md-namespace-delete,image metadef namespace delete,Delete specified metadata def
md-namespace-import,WONTFIX,Import a metadata definitions namespace from file or standard input.
md-namespace-list,image metadef namespace list,List metadata definitions namespaces.
md-namespace-objects-delete,image metadef object 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-properties-delete,image metadef property delete,Delete all metadata definitions property inside a specific namespace.
md-namespace-resource-type-list,image metadef resource type association 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.
1 cache-clear cached image clear Clear all images from cache, queue or both.
27 md-namespace-import WONTFIX Import a metadata definitions namespace from file or standard input.
28 md-namespace-list image metadef namespace list List metadata definitions namespaces.
29 md-namespace-objects-delete image metadef object delete Delete all metadata definitions objects inside a specific namespace.
30 md-namespace-properties-delete image metadef property delete Delete all metadata definitions property inside a specific namespace.
31 md-namespace-resource-type-list image metadef resource type association 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.

View File

@@ -124,14 +124,21 @@ class DeleteMetadefProperty(command.Command):
parser.add_argument(
"properties",
metavar="<property>",
nargs="+",
help=_("Metadef propert(ies) to delete (name)"),
nargs="*",
help=_(
"Metadef properties to delete (name) "
"(omit this argument to delete all properties in the namespace)"
),
)
return parser
def take_action(self, parsed_args):
image_client = self.app.client_manager.image
if not parsed_args.properties:
image_client.delete_all_metadef_properties(parsed_args.namespace)
return
result = 0
for prop in parsed_args.properties:
try:

View File

@@ -91,6 +91,7 @@ class TestMetadefPropertyDelete(image_fakes.TestImagev2):
super().setUp()
self.cmd = metadef_properties.DeleteMetadefProperty(self.app, None)
self.image_client.delete_all_metadef_properties.return_value = None
def test_metadef_property_delete(self):
arglist = ['namespace', 'property']
@@ -100,6 +101,10 @@ class TestMetadefPropertyDelete(image_fakes.TestImagev2):
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.image_client.delete_metadef_property.assert_called_with(
'property', 'namespace', ignore_missing=False
)
self.image_client.delete_all_metadef_properties.assert_not_called()
def test_metadef_property_delete_missing_arguments(self):
arglist = []
@@ -110,21 +115,13 @@ class TestMetadefPropertyDelete(image_fakes.TestImagev2):
arglist,
[],
)
arglist = ['namespace']
self.assertRaises(
tests_utils.ParserException,
self.check_parser,
self.cmd,
arglist,
[],
)
self.image_client.delete_all_metadef_properties.assert_not_called()
self.image_client.delete_metadef_property.assert_not_called()
def test_metadef_property_delete_exception(self):
arglist = ['namespace', 'property']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.image_client.delete_metadef_property.side_effect = (
sdk_exceptions.ResourceNotFound
)
@@ -132,6 +129,23 @@ class TestMetadefPropertyDelete(image_fakes.TestImagev2):
self.assertRaises(
exceptions.CommandError, self.cmd.take_action, parsed_args
)
self.image_client.delete_metadef_property.assert_called_with(
'property', 'namespace', ignore_missing=False
)
self.image_client.delete_all_metadef_properties.assert_not_called()
def test_metadef_property_delete_all(self):
arglist = ['namespace']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
self.image_client.delete_all_metadef_properties.assert_called_with(
'namespace'
)
self.image_client.delete_metadef_property.assert_not_called()
class TestMetadefPropertyList(image_fakes.TestImagev2):

View File

@@ -0,0 +1,5 @@
---
features:
- |
The ``image property delete`` command will now delete all properties in
the provided namespace if no property is provided.