Make set/unset commands pass normally when nothing specified in identityv3

Change-Id: I554b41969f96b62a2c6d37024caa56b1441d5ed1
Partial-bug: #1588588
This commit is contained in:
Huanxuan Ao 2016-07-13 19:28:11 +08:00
parent 5a21eb2555
commit e5a3c403e5
19 changed files with 32 additions and 94 deletions

View File

@ -15,8 +15,6 @@
"""Identity v3 Consumer action implementations"""
import sys
from osc_lib.command import command
from osc_lib import utils
import six
@ -102,10 +100,6 @@ class SetConsumer(command.Command):
if parsed_args.description:
kwargs['description'] = parsed_args.description
if not len(kwargs):
sys.stdout.write(_('Consumer not updated, no arguments present\n'))
return
consumer = identity_client.oauth1.consumers.update(
consumer.id, **kwargs)

View File

@ -16,7 +16,6 @@
"""Identity v3 Domain action implementations"""
import logging
import sys
from keystoneauth1 import exceptions as ks_exc
from osc_lib.command import command
@ -168,9 +167,6 @@ class SetDomain(command.Command):
if parsed_args.disable:
kwargs['enabled'] = False
if not kwargs:
sys.stdout.write(_("Domain not updated, no arguments present\n"))
return
identity_client.domains.update(domain.id, **kwargs)

View File

@ -15,8 +15,6 @@
"""Identity v3 Endpoint action implementations"""
import sys
from osc_lib.command import command
from osc_lib import utils
import six
@ -212,12 +210,6 @@ class SetEndpoint(command.Command):
endpoint = utils.find_resource(identity_client.endpoints,
parsed_args.endpoint)
if (not parsed_args.interface and not parsed_args.url
and not parsed_args.service and not parsed_args.region
and not parsed_args.enabled and not parsed_args.disabled):
sys.stdout.write(_("Endpoint not updated, no arguments present\n"))
return
service_id = None
if parsed_args.service:
service = common.find_service(identity_client, parsed_args.service)

View File

@ -149,10 +149,6 @@ class SetProtocol(command.Command):
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
if not parsed_args.mapping:
LOG.error(_("No changes requested"))
return
protocol = identity_client.federation.protocols.update(
parsed_args.identity_provider, parsed_args.federation_protocol,
parsed_args.mapping)

View File

@ -343,9 +343,6 @@ class SetGroup(command.Command):
if parsed_args.description:
kwargs['description'] = parsed_args.description
if not len(kwargs):
sys.stderr.write("Group not updated, no arguments present\n")
return
identity_client.groups.update(group.id, **kwargs)

View File

@ -169,14 +169,6 @@ class SetIdentityProvider(command.Command):
def take_action(self, parsed_args):
federation_client = self.app.client_manager.identity.federation
# Basic argument checking
if (not parsed_args.enable and not parsed_args.disable and
not parsed_args.remote_id and
not parsed_args.remote_id_file and
not parsed_args.description):
LOG.error(_('No changes requested'))
return (None, None)
# Always set remote_ids if either is passed in
if parsed_args.remote_id_file:
file_content = utils.read_blob_file_contents(

View File

@ -162,10 +162,6 @@ class SetMapping(command.Command, _RulesReader):
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
if not parsed_args.rules:
LOG.error(_("No changes requested"))
return
rules = self._read_rules(parsed_args.rules)
mapping = identity_client.federation.mappings.update(

View File

@ -15,8 +15,6 @@
"""Identity v3 Policy action implementations"""
import sys
from osc_lib.command import command
from osc_lib import utils
import six
@ -136,9 +134,6 @@ class SetPolicy(command.Command):
if parsed_args.type:
kwargs['type'] = parsed_args.type
if not kwargs:
sys.stdout.write(_('Policy not updated, no arguments present\n'))
return
identity_client.policies.update(parsed_args.policy, **kwargs)

View File

@ -263,13 +263,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.domain
and not parsed_args.description
and not parsed_args.enable
and not parsed_args.property
and not parsed_args.disable):
return
project = common.find_project(identity_client,
parsed_args.project,
parsed_args.domain)

View File

@ -132,8 +132,6 @@ class SetRegion(command.Command):
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
if not parsed_args.parent_region and not parsed_args.description:
return
kwargs = {}
if parsed_args.description:
kwargs['description'] = parsed_args.description

View File

@ -357,10 +357,6 @@ class SetRole(command.Command):
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
if not parsed_args.name:
sys.stderr.write(_("Incorrect set of arguments provided. "
"See openstack --help for more details\n"))
return
role = utils.find_resource(
identity_client.roles,
parsed_args.role,

View File

@ -15,8 +15,6 @@
"""Identity v3 Service action implementations"""
import sys
from osc_lib.command import command
from osc_lib import utils
import six
@ -163,14 +161,6 @@ class SetService(command.Command):
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
if (not parsed_args.name
and not parsed_args.type
and not parsed_args.description
and not parsed_args.enable
and not parsed_args.disable):
sys.stderr.write(_("Incorrect set of arguments provided. "
"See openstack --help for more details\n"))
return
service = common.find_service(identity_client,
parsed_args.service)
kwargs = {}

View File

@ -13,8 +13,6 @@
"""Service Provider action implementations"""
import sys
from osc_lib.command import command
from osc_lib import utils
import six
@ -164,13 +162,6 @@ class SetServiceProvider(command.Command):
elif parsed_args.disable is True:
enabled = False
if not any((enabled is not None, parsed_args.description,
parsed_args.service_provider_url,
parsed_args.auth_url)):
sys.stdout.write(_("Service Provider not updated, no arguments "
"present\n"))
return (None, None)
service_provider = federation_client.service_providers.update(
parsed_args.service_provider, enabled=enabled,
description=parsed_args.description,

View File

@ -17,7 +17,6 @@
import copy
import logging
import sys
from keystoneauth1 import exceptions as ks_exc
from osc_lib.command import command
@ -330,18 +329,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.description
and not parsed_args.enable
and not parsed_args.disable):
sys.stderr.write(_("Incorrect set of arguments provided. "
"See openstack --help for more details\n"))
return
user = utils.find_resource(
identity_client.users,
parsed_args.user,

View File

@ -253,7 +253,11 @@ class TestDomainSet(TestDomain):
result = self.cmd.take_action(parsed_args)
self.assertNotCalled(self.domains_mock.update)
kwargs = {}
self.domains_mock.update.assert_called_with(
self.domain.id,
**kwargs
)
self.assertIsNone(result)
def test_domain_set_name(self):

View File

@ -485,7 +485,17 @@ class TestEndpointSet(TestEndpoint):
result = self.cmd.take_action(parsed_args)
self.assertNotCalled(self.endpoints_mock.update)
kwargs = {
'enabled': None,
'interface': None,
'region': None,
'service': None,
'url': None,
}
self.endpoints_mock.update.assert_called_with(
identity_fakes.endpoint_id,
**kwargs
)
self.assertIsNone(result)
def test_endpoint_set_interface(self):

View File

@ -585,8 +585,8 @@ class TestIdentityProviderSet(TestIdentityProvider):
# expect take_action() to return (None, None) as
# neither --enable nor --disable was specified
self.assertIsNone(columns)
self.assertIsNone(data)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, data)
class TestIdentityProviderShow(TestIdentityProvider):

View File

@ -253,7 +253,11 @@ class TestRegionSet(TestRegion):
result = self.cmd.take_action(parsed_args)
self.assertNotCalled(self.regions_mock.update)
kwargs = {}
self.regions_mock.update.assert_called_with(
identity_fakes.region_id,
**kwargs
)
self.assertIsNone(result)
def test_region_set_description(self):

View File

@ -377,8 +377,15 @@ class TestServiceProviderSet(TestServiceProvider):
# expect take_action() to return (None, None) as none of --disabled,
# --enabled, --description, --service-provider-url, --auth_url option
# was set.
self.assertIsNone(columns)
self.assertIsNone(data)
self.assertEqual(self.columns, columns)
datalist = (
service_fakes.sp_auth_url,
service_fakes.sp_description,
True,
service_fakes.sp_id,
service_fakes.service_provider_url
)
self.assertEqual(datalist, data)
class TestServiceProviderShow(TestServiceProvider):