add --project-domain option for user v3
user v3 create/set only support --project option, we need --project-domain to prevent collisions between project names exist. Change-Id: I2d62e5b9bb6df4c5c5a9542514faf2e4365bb18b Closes-Bug: #1475357
This commit is contained in:
		| @@ -14,7 +14,7 @@ Create new user | ||||
|  | ||||
|     os user create | ||||
|         [--domain <domain>] | ||||
|         [--project <project>] | ||||
|         [--project <project> [--project-domain <project-domain>]] | ||||
|         [--password <password>] | ||||
|         [--password-prompt] | ||||
|         [--email <email-address>] | ||||
| @@ -33,6 +33,11 @@ Create new user | ||||
|  | ||||
|     Default project (name or ID) | ||||
|  | ||||
| .. option:: --project-domain <project-domain> | ||||
|  | ||||
|     Domain the project belongs to (name or ID). | ||||
|     This can be used in case collisions between project names exist. | ||||
|  | ||||
| .. option:: --password <password> | ||||
|  | ||||
|     Set user password | ||||
| @@ -136,7 +141,7 @@ Set user properties | ||||
|  | ||||
|     os user set | ||||
|         [--name <name>] | ||||
|         [--project <project>] | ||||
|         [--project <project> [--project-domain <project-domain>]] | ||||
|         [--password <password>] | ||||
|         [--email <email-address>] | ||||
|         [--description <description>] | ||||
| @@ -151,6 +156,11 @@ Set user properties | ||||
|  | ||||
|     Set default project (name or ID) | ||||
|  | ||||
| .. option:: --project-domain <project-domain> | ||||
|  | ||||
|     Domain the project belongs to (name or ID). | ||||
|     This can be used in case collisions between project names exist. | ||||
|  | ||||
| .. option:: --password <password> | ||||
|  | ||||
|     Set user password | ||||
|   | ||||
| @@ -51,6 +51,7 @@ class CreateUser(show.ShowOne): | ||||
|             metavar='<project>', | ||||
|             help='Default project (name or ID)', | ||||
|         ) | ||||
|         common.add_project_domain_option_to_parser(parser) | ||||
|         parser.add_argument( | ||||
|             '--password', | ||||
|             metavar='<password>', | ||||
| @@ -96,10 +97,9 @@ class CreateUser(show.ShowOne): | ||||
|  | ||||
|         project_id = None | ||||
|         if parsed_args.project: | ||||
|             project_id = utils.find_resource( | ||||
|                 identity_client.projects, | ||||
|             project_id = common.find_project(identity_client, | ||||
|                                              parsed_args.project, | ||||
|             ).id | ||||
|                                              parsed_args.project_domain).id | ||||
|  | ||||
|         domain_id = None | ||||
|         if parsed_args.domain: | ||||
| @@ -301,6 +301,7 @@ class SetUser(command.Command): | ||||
|             metavar='<project>', | ||||
|             help='Set default project (name or ID)', | ||||
|         ) | ||||
|         common.add_project_domain_option_to_parser(parser) | ||||
|         parser.add_argument( | ||||
|             '--password', | ||||
|             metavar='<password>', | ||||
| @@ -367,8 +368,9 @@ class SetUser(command.Command): | ||||
|         if parsed_args.description: | ||||
|             kwargs['description'] = parsed_args.description | ||||
|         if parsed_args.project: | ||||
|             project_id = utils.find_resource( | ||||
|                 identity_client.projects, parsed_args.project).id | ||||
|             project_id = common.find_project(identity_client, | ||||
|                                              parsed_args.project, | ||||
|                                              parsed_args.project_domain).id | ||||
|             kwargs['default_project'] = project_id | ||||
|         kwargs['enabled'] = user.enabled | ||||
|         if parsed_args.enable: | ||||
|   | ||||
| @@ -320,6 +320,68 @@ class TestUserCreate(TestUser): | ||||
|         ) | ||||
|         self.assertEqual(datalist, data) | ||||
|  | ||||
|     def test_user_create_project_domain(self): | ||||
|         # Return the new project | ||||
|         self.projects_mock.get.return_value = fakes.FakeResource( | ||||
|             None, | ||||
|             copy.deepcopy(identity_fakes.PROJECT_2), | ||||
|             loaded=True, | ||||
|         ) | ||||
|         # Set up to return an updated user | ||||
|         USER_2 = copy.deepcopy(identity_fakes.USER) | ||||
|         USER_2['default_project_id'] = identity_fakes.PROJECT_2['id'] | ||||
|         self.users_mock.create.return_value = fakes.FakeResource( | ||||
|             None, | ||||
|             USER_2, | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--project', identity_fakes.PROJECT_2['name'], | ||||
|             '--project-domain', identity_fakes.PROJECT_2['domain_id'], | ||||
|             identity_fakes.user_name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('project', identity_fakes.PROJECT_2['name']), | ||||
|             ('project_domain', identity_fakes.PROJECT_2['domain_id']), | ||||
|             ('enable', False), | ||||
|             ('disable', False), | ||||
|             ('name', identity_fakes.user_name), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         # DisplayCommandBase.take_action() returns two tuples | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         # Set expected values | ||||
|         kwargs = { | ||||
|             'name': identity_fakes.user_name, | ||||
|             'default_project': identity_fakes.PROJECT_2['id'], | ||||
|             'description': None, | ||||
|             'domain': None, | ||||
|             'email': None, | ||||
|             'enabled': True, | ||||
|             'password': None, | ||||
|         } | ||||
|         # UserManager.create(name=, domain=, project=, password=, email=, | ||||
|         #   description=, enabled=, default_project=) | ||||
|         self.users_mock.create.assert_called_with( | ||||
|             **kwargs | ||||
|         ) | ||||
|  | ||||
|         collist = ('default_project_id', 'domain_id', 'email', | ||||
|                    'enabled', 'id', 'name') | ||||
|         self.assertEqual(collist, columns) | ||||
|         datalist = ( | ||||
|             identity_fakes.PROJECT_2['id'], | ||||
|             identity_fakes.domain_id, | ||||
|             identity_fakes.user_email, | ||||
|             True, | ||||
|             identity_fakes.user_id, | ||||
|             identity_fakes.user_name, | ||||
|         ) | ||||
|         self.assertEqual(datalist, data) | ||||
|  | ||||
|     def test_user_create_domain(self): | ||||
|         arglist = [ | ||||
|             '--domain', identity_fakes.domain_name, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Guojian Shao
					Guojian Shao