Support getting instances for a project
Change-Id: I1b3e8dce864740221722070a710f5a2f867d6c4b
This commit is contained in:
		| @@ -134,12 +134,20 @@ class ListDatabaseInstances(command.Lister): | ||||
|             default=False, | ||||
|             help=_("Include database instances of all projects (admin only)") | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--project-id', | ||||
|             help=_("Include database instances of a specific project " | ||||
|                    "(admin only)") | ||||
|         ) | ||||
|         return parser | ||||
|  | ||||
|     def take_action(self, parsed_args): | ||||
|         if parsed_args.all_projects: | ||||
|         extra_params = {} | ||||
|         if parsed_args.all_projects or parsed_args.project_id: | ||||
|             db_instances = self.app.client_manager.database.mgmt_instances | ||||
|             cols = self.admin_columns | ||||
|             if parsed_args.project_id: | ||||
|                 extra_params['project_id'] = parsed_args.project_id | ||||
|         else: | ||||
|             db_instances = self.app.client_manager.database.instances | ||||
|             cols = self.columns | ||||
| @@ -147,7 +155,8 @@ class ListDatabaseInstances(command.Lister): | ||||
|         instances = db_instances.list( | ||||
|             limit=parsed_args.limit, | ||||
|             marker=parsed_args.marker, | ||||
|             include_clustered=parsed_args.include_clustered | ||||
|             include_clustered=parsed_args.include_clustered, | ||||
|             **extra_params | ||||
|         ) | ||||
|         if instances: | ||||
|             instances = set_attributes_for_print(instances) | ||||
|   | ||||
| @@ -12,10 +12,12 @@ | ||||
| # | ||||
|  | ||||
| import os | ||||
| import random | ||||
| import sys | ||||
| from unittest import mock | ||||
| import uuid | ||||
|  | ||||
| import fixtures | ||||
| import sys | ||||
| import testtools | ||||
|  | ||||
| from troveclient.tests.osc import fakes | ||||
| @@ -35,6 +37,30 @@ class TestCase(testtools.TestCase): | ||||
|             stderr = self.useFixture(fixtures.StringStream("stderr")).stream | ||||
|             self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr)) | ||||
|  | ||||
|     @classmethod | ||||
|     def random_name(cls, name='', prefix=None): | ||||
|         """Generate a random name that inclues a random number. | ||||
|  | ||||
|         :param str name: The name that you want to include | ||||
|         :param str prefix: The prefix that you want to include | ||||
|  | ||||
|         :return: a random name. The format is | ||||
|                  '<prefix>-<name>-<random number>'. | ||||
|                  (e.g. 'prefixfoo-namebar-154876201') | ||||
|         :rtype: string | ||||
|         """ | ||||
|         randbits = str(random.randint(1, 0x7fffffff)) | ||||
|         rand_name = randbits | ||||
|         if name: | ||||
|             rand_name = name + '-' + rand_name | ||||
|         if prefix: | ||||
|             rand_name = prefix + '-' + rand_name | ||||
|         return rand_name | ||||
|  | ||||
|     @classmethod | ||||
|     def random_uuid(cls): | ||||
|         return str(uuid.uuid4()) | ||||
|  | ||||
|  | ||||
| class TestCommand(TestCase): | ||||
|     """Test cliff command classes""" | ||||
|   | ||||
| @@ -88,6 +88,22 @@ class TestInstanceList(TestInstances): | ||||
|         ] | ||||
|         self.assertEqual(expected_instances, instances) | ||||
|  | ||||
|     def test_instance_list_for_project(self): | ||||
|         self.mgmt_client.list.return_value = common.Paginated(self.data) | ||||
|  | ||||
|         project_id = self.random_uuid() | ||||
|         parsed_args = self.check_parser(self.cmd, ["--project-id", project_id], | ||||
|                                         [("project_id", project_id)]) | ||||
|         self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         expected_params = { | ||||
|             'include_clustered': False, | ||||
|             'limit': None, | ||||
|             'marker': None, | ||||
|             'project_id': project_id | ||||
|         } | ||||
|         self.mgmt_client.list.assert_called_once_with(**expected_params) | ||||
|  | ||||
|  | ||||
| class TestInstanceShow(TestInstances): | ||||
|     values = ([{'address': '10.0.0.13', 'type': 'private'}], [], 'mysql', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lingxian Kong
					Lingxian Kong