Add "image metadef property delete" command

Change-Id: I2e13b26139424c421ae609804c546a6b42add5a4
This commit is contained in:
Cyril Roelandt 2023-10-16 11:27:54 +00:00
parent d9c4c43a40
commit 9094e540b5
5 changed files with 94 additions and 1 deletions

View File

@ -39,7 +39,7 @@ md-object-property-show,,Describe a specific metadata definitions property insid
md-object-show,,Describe a specific metadata definitions object inside a namespace.
md-object-update,,Update metadata definitions object inside a namespace.
md-property-create,image metadef property create,Create a new metadata definitions property inside a namespace.
md-property-delete,,Delete a specific metadata definitions property inside a namespace.
md-property-delete,image metadef property delete,Delete a specific metadata definitions property inside a namespace.
md-property-list,image metadef property list,List metadata definitions properties inside a specific namespace.
md-property-show,image metadef property show,Describe a specific metadata definitions property inside a namespace.
md-property-update,,Update metadata definitions property inside a namespace.

1 cache-clear Clear all images from cache, queue or both.
39 md-object-show Describe a specific metadata definitions object inside a namespace.
40 md-object-update Update metadata definitions object inside a namespace.
41 md-property-create image metadef property create Create a new metadata definitions property inside a namespace.
42 md-property-delete image metadef property delete Delete a specific metadata definitions property inside a namespace.
43 md-property-list image metadef property list List metadata definitions properties inside a specific namespace.
44 md-property-show image metadef property show Describe a specific metadata definitions property inside a namespace.
45 md-property-update Update metadata definitions property inside a namespace.

View File

@ -107,6 +107,44 @@ class CreateMetadefProperty(command.ShowOne):
return zip(*sorted(info.items()))
class DeleteMetadefProperty(command.Command):
_description = _("Delete a metadef property")
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument(
"namespace_name",
help=_("An identifier (a name) for the namespace"),
)
parser.add_argument(
"property_name",
help=_("Property to delete"),
)
return parser
def take_action(self, parsed_args):
image_client = self.app.client_manager.image
try:
image_client.delete_metadef_property(
parsed_args.property_name,
parsed_args.namespace_name,
ignore_missing=False,
)
except Exception as e:
raise exceptions.CommandError(
_(
"Failed to delete property with name or "
"ID '%(property)s' from namespace '%(namespace)s': %(e)s"
)
% {
'property': parsed_args.property_name,
'namespace': parsed_args.namespace_name,
'e': e,
}
)
class ListMetadefProperties(command.Lister):
_description = _("List metadef properties")

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from openstack import exceptions as sdk_exceptions
from osc_lib import exceptions
from openstackclient.image.v2 import metadef_properties
@ -85,6 +86,54 @@ class TestMetadefPropertyCreate(image_fakes.TestImagev2):
)
class TestMetadefPropertyDelete(image_fakes.TestImagev2):
def setUp(self):
super().setUp()
self.cmd = metadef_properties.DeleteMetadefProperty(self.app, None)
def test_metadef_property_delete(self):
arglist = ['namespace', 'property']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertIsNone(result)
def test_metadef_property_delete_missing_arguments(self):
arglist = []
self.assertRaises(
tests_utils.ParserException,
self.check_parser,
self.cmd,
arglist,
[],
)
arglist = ['namespace']
self.assertRaises(
tests_utils.ParserException,
self.check_parser,
self.cmd,
arglist,
[],
)
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
)
self.assertRaises(
exceptions.CommandError, self.cmd.take_action, parsed_args
)
class TestMetadefPropertyList(image_fakes.TestImagev2):
_metadef_property = [image_fakes.create_one_metadef_property()]

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``image metadef property delete`` command to delete a
metadef property inside a specific namespace.

View File

@ -398,6 +398,7 @@ openstack.image.v2 =
image_metadef_namespace_show = openstackclient.image.v2.metadef_namespaces:ShowMetadefNameSpace
image_metadef_property_create = openstackclient.image.v2.metadef_properties:CreateMetadefProperty
image_metadef_property_delete = openstackclient.image.v2.metadef_properties:DeleteMetadefProperty
image_metadef_property_list = openstackclient.image.v2.metadef_properties:ListMetadefProperties
image_metadef_property_show = openstackclient.image.v2.metadef_properties:ShowMetadefProperty