Merge "Make set/unset command in identity and image pass normally when nothing specified"
This commit is contained in:
		@@ -189,13 +189,6 @@ class SetProject(command.Command):
 | 
			
		||||
    def take_action(self, parsed_args):
 | 
			
		||||
        identity_client = self.app.client_manager.identity
 | 
			
		||||
 | 
			
		||||
        if (not parsed_args.name
 | 
			
		||||
                and not parsed_args.description
 | 
			
		||||
                and not parsed_args.enable
 | 
			
		||||
                and not parsed_args.property
 | 
			
		||||
                and not parsed_args.disable):
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        project = utils.find_resource(
 | 
			
		||||
            identity_client.tenants,
 | 
			
		||||
            parsed_args.project,
 | 
			
		||||
@@ -295,7 +288,6 @@ class UnsetProject(command.Command):
 | 
			
		||||
            metavar='<key>',
 | 
			
		||||
            action='append',
 | 
			
		||||
            default=[],
 | 
			
		||||
            required=True,
 | 
			
		||||
            help=_('Unset a project property '
 | 
			
		||||
                   '(repeat option to unset multiple properties)'),
 | 
			
		||||
        )
 | 
			
		||||
@@ -307,11 +299,8 @@ class UnsetProject(command.Command):
 | 
			
		||||
            identity_client.tenants,
 | 
			
		||||
            parsed_args.project,
 | 
			
		||||
        )
 | 
			
		||||
        if not parsed_args.property:
 | 
			
		||||
            self.app.log.error(_("No changes requested\n"))
 | 
			
		||||
        else:
 | 
			
		||||
            kwargs = project._info
 | 
			
		||||
            for key in parsed_args.property:
 | 
			
		||||
                if key in kwargs:
 | 
			
		||||
                    kwargs[key] = None
 | 
			
		||||
            identity_client.tenants.update(project.id, **kwargs)
 | 
			
		||||
        kwargs = project._info
 | 
			
		||||
        for key in parsed_args.property:
 | 
			
		||||
            if key in kwargs:
 | 
			
		||||
                kwargs[key] = None
 | 
			
		||||
        identity_client.tenants.update(project.id, **kwargs)
 | 
			
		||||
 
 | 
			
		||||
@@ -287,15 +287,6 @@ class SetUser(command.Command):
 | 
			
		||||
        if parsed_args.password_prompt:
 | 
			
		||||
            parsed_args.password = utils.get_password(self.app.stdin)
 | 
			
		||||
 | 
			
		||||
        if (not parsed_args.name
 | 
			
		||||
                and not parsed_args.name
 | 
			
		||||
                and not parsed_args.password
 | 
			
		||||
                and not parsed_args.email
 | 
			
		||||
                and not parsed_args.project
 | 
			
		||||
                and not parsed_args.enable
 | 
			
		||||
                and not parsed_args.disable):
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        user = utils.find_resource(
 | 
			
		||||
            identity_client.users,
 | 
			
		||||
            parsed_args.user,
 | 
			
		||||
 
 | 
			
		||||
@@ -817,11 +817,6 @@ class SetImage(command.Command):
 | 
			
		||||
                parsed_args.project_domain,
 | 
			
		||||
            ).id
 | 
			
		||||
 | 
			
		||||
        # Checks if anything that requires getting the image
 | 
			
		||||
        if not (kwargs or parsed_args.deactivate or parsed_args.activate):
 | 
			
		||||
            msg = _("No arguments specified")
 | 
			
		||||
            raise exceptions.CommandError(msg)
 | 
			
		||||
 | 
			
		||||
        image = utils.find_resource(
 | 
			
		||||
            image_client.images, parsed_args.image)
 | 
			
		||||
 | 
			
		||||
@@ -833,10 +828,6 @@ class SetImage(command.Command):
 | 
			
		||||
            image_client.images.reactivate(image.id)
 | 
			
		||||
            activation_status = "activated"
 | 
			
		||||
 | 
			
		||||
        # Check if need to do the actual update
 | 
			
		||||
        if not kwargs:
 | 
			
		||||
            return {}, {}
 | 
			
		||||
 | 
			
		||||
        if parsed_args.tags:
 | 
			
		||||
            # Tags should be extended, but duplicates removed
 | 
			
		||||
            kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))
 | 
			
		||||
@@ -909,10 +900,6 @@ class UnsetImage(command.Command):
 | 
			
		||||
            parsed_args.image,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        if not (parsed_args.tags or parsed_args.properties):
 | 
			
		||||
            msg = _("No arguments specified")
 | 
			
		||||
            raise exceptions.CommandError(msg)
 | 
			
		||||
 | 
			
		||||
        kwargs = {}
 | 
			
		||||
        tagret = 0
 | 
			
		||||
        propret = 0
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
import copy
 | 
			
		||||
 | 
			
		||||
from keystoneauth1 import exceptions as ks_exc
 | 
			
		||||
from osc_lib import exceptions
 | 
			
		||||
 | 
			
		||||
from openstackclient.identity.v2_0 import project
 | 
			
		||||
from openstackclient.tests import fakes
 | 
			
		||||
@@ -410,6 +411,26 @@ class TestProjectSet(TestProject):
 | 
			
		||||
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_project_set_unexist_project(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            "unexist-project",
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('project', "unexist-project"),
 | 
			
		||||
            ('name', None),
 | 
			
		||||
            ('description', None),
 | 
			
		||||
            ('enable', False),
 | 
			
		||||
            ('disable', False),
 | 
			
		||||
            ('property', None),
 | 
			
		||||
        ]
 | 
			
		||||
        self.projects_mock.get.side_effect = exceptions.NotFound(None)
 | 
			
		||||
        self.projects_mock.find.side_effect = exceptions.NotFound(None)
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exceptions.CommandError, self.cmd.take_action, parsed_args)
 | 
			
		||||
 | 
			
		||||
    def test_project_set_name(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--name', 'qwerty',
 | 
			
		||||
@@ -604,6 +625,19 @@ class TestProjectUnset(TestProject):
 | 
			
		||||
        # Get the command object to test
 | 
			
		||||
        self.cmd = project.UnsetProject(self.app, None)
 | 
			
		||||
 | 
			
		||||
    def test_project_unset_no_options(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            identity_fakes.project_name,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('project', identity_fakes.project_name),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_project_unset_key(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--property', 'fee',
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ import copy
 | 
			
		||||
import mock
 | 
			
		||||
 | 
			
		||||
from keystoneauth1 import exceptions as ks_exc
 | 
			
		||||
from osc_lib import exceptions
 | 
			
		||||
 | 
			
		||||
from openstackclient.identity.v2_0 import user
 | 
			
		||||
from openstackclient.tests import fakes
 | 
			
		||||
@@ -563,6 +564,27 @@ class TestUserSet(TestUser):
 | 
			
		||||
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_user_set_unexist_user(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            "unexist-user",
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('name', None),
 | 
			
		||||
            ('password', None),
 | 
			
		||||
            ('email', None),
 | 
			
		||||
            ('project', None),
 | 
			
		||||
            ('enable', False),
 | 
			
		||||
            ('disable', False),
 | 
			
		||||
            ('user', "unexist-user"),
 | 
			
		||||
        ]
 | 
			
		||||
        self.users_mock.get.side_effect = exceptions.NotFound(None)
 | 
			
		||||
        self.users_mock.find.side_effect = exceptions.NotFound(None)
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exceptions.CommandError, self.cmd.take_action, parsed_args)
 | 
			
		||||
 | 
			
		||||
    def test_user_set_name(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--name', 'qwerty',
 | 
			
		||||
 
 | 
			
		||||
@@ -842,6 +842,19 @@ class TestImageSet(TestImage):
 | 
			
		||||
        # Get the command object to test
 | 
			
		||||
        self.cmd = image.SetImage(self.app, None)
 | 
			
		||||
 | 
			
		||||
    def test_image_set_no_options(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            image_fakes.image_id,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('image', image_fakes.image_id)
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_image_set_options(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            '--name', 'new-name',
 | 
			
		||||
@@ -1242,6 +1255,19 @@ class TestImageUnset(TestImage):
 | 
			
		||||
        # Get the command object to test
 | 
			
		||||
        self.cmd = image.UnsetImage(self.app, None)
 | 
			
		||||
 | 
			
		||||
    def test_image_unset_no_options(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            image_fakes.image_id,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ('image', image_fakes.image_id)
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_image_unset_tag_option(self):
 | 
			
		||||
 | 
			
		||||
        arglist = [
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
---
 | 
			
		||||
upgrade:
 | 
			
		||||
  - All ``set`` and ``unset`` commands in network and volume now return
 | 
			
		||||
    normally when nothing specified to modify. This will become the default
 | 
			
		||||
  - All ``set`` and ``unset`` commands in network, identity, image, and volume now
 | 
			
		||||
    return normally when nothing specified to modify. This will become the default
 | 
			
		||||
    behavior of OSC ``set`` and ``unset`` commands.
 | 
			
		||||
    [Bug `1588588 <https://bugs.launchpad.net/python-openstackclient/+bug/1588588>`_]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user