add service/interface/region filter for endpoint v3
Change-Id: I7eac5b2ff5f5a6f3f08b22dd3a48a5ae7e2c056b Closes-Bug: #1281888
This commit is contained in:
parent
99ad9ef92e
commit
181f16da8a
@ -114,12 +114,38 @@ class ListEndpoint(lister.Lister):
|
|||||||
|
|
||||||
log = logging.getLogger(__name__ + '.ListEndpoint')
|
log = logging.getLogger(__name__ + '.ListEndpoint')
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListEndpoint, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'--service',
|
||||||
|
metavar='<service>',
|
||||||
|
help='Filter by a specific service')
|
||||||
|
parser.add_argument(
|
||||||
|
'--interface',
|
||||||
|
metavar='<interface>',
|
||||||
|
choices=['admin', 'public', 'internal'],
|
||||||
|
help='Filter by a specific interface, must be admin, public or'
|
||||||
|
' internal')
|
||||||
|
parser.add_argument(
|
||||||
|
'--region',
|
||||||
|
metavar='<region>',
|
||||||
|
help='Filter by a specific region')
|
||||||
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
columns = ('ID', 'Region', 'Service Name', 'Service Type',
|
columns = ('ID', 'Region', 'Service Name', 'Service Type',
|
||||||
'Enabled', 'Interface', 'URL')
|
'Enabled', 'Interface', 'URL')
|
||||||
data = identity_client.endpoints.list()
|
kwargs = {}
|
||||||
|
if parsed_args.service:
|
||||||
|
service = common.find_service(identity_client, parsed_args.service)
|
||||||
|
kwargs['service'] = service.id
|
||||||
|
if parsed_args.interface:
|
||||||
|
kwargs['interface'] = parsed_args.interface
|
||||||
|
if parsed_args.region:
|
||||||
|
kwargs['region'] = parsed_args.region
|
||||||
|
data = identity_client.endpoints.list(**kwargs)
|
||||||
|
|
||||||
for ep in data:
|
for ep in data:
|
||||||
service = common.find_service(identity_client, ep.service_id)
|
service = common.find_service(identity_client, ep.service_id)
|
||||||
|
@ -317,6 +317,102 @@ class TestEndpointList(TestEndpoint):
|
|||||||
),)
|
),)
|
||||||
self.assertEqual(datalist, tuple(data))
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_endpoint_list_service(self):
|
||||||
|
arglist = [
|
||||||
|
'--service', identity_fakes.service_name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('service', identity_fakes.service_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 = {
|
||||||
|
'service': identity_fakes.service_id,
|
||||||
|
}
|
||||||
|
self.endpoints_mock.list.assert_called_with(**kwargs)
|
||||||
|
|
||||||
|
collist = ('ID', 'Region', 'Service Name', 'Service Type',
|
||||||
|
'Enabled', 'Interface', 'URL')
|
||||||
|
self.assertEqual(collist, columns)
|
||||||
|
datalist = ((
|
||||||
|
identity_fakes.endpoint_id,
|
||||||
|
identity_fakes.endpoint_region,
|
||||||
|
identity_fakes.service_name,
|
||||||
|
identity_fakes.service_type,
|
||||||
|
True,
|
||||||
|
identity_fakes.endpoint_interface,
|
||||||
|
identity_fakes.endpoint_url,
|
||||||
|
),)
|
||||||
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_endpoint_list_interface(self):
|
||||||
|
arglist = [
|
||||||
|
'--interface', identity_fakes.endpoint_interface,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('interface', identity_fakes.endpoint_interface),
|
||||||
|
]
|
||||||
|
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 = {
|
||||||
|
'interface': identity_fakes.endpoint_interface,
|
||||||
|
}
|
||||||
|
self.endpoints_mock.list.assert_called_with(**kwargs)
|
||||||
|
|
||||||
|
collist = ('ID', 'Region', 'Service Name', 'Service Type',
|
||||||
|
'Enabled', 'Interface', 'URL')
|
||||||
|
self.assertEqual(collist, columns)
|
||||||
|
datalist = ((
|
||||||
|
identity_fakes.endpoint_id,
|
||||||
|
identity_fakes.endpoint_region,
|
||||||
|
identity_fakes.service_name,
|
||||||
|
identity_fakes.service_type,
|
||||||
|
True,
|
||||||
|
identity_fakes.endpoint_interface,
|
||||||
|
identity_fakes.endpoint_url,
|
||||||
|
),)
|
||||||
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_endpoint_list_region(self):
|
||||||
|
arglist = [
|
||||||
|
'--region', identity_fakes.endpoint_region,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('region', identity_fakes.endpoint_region),
|
||||||
|
]
|
||||||
|
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 = {
|
||||||
|
'region': identity_fakes.endpoint_region,
|
||||||
|
}
|
||||||
|
self.endpoints_mock.list.assert_called_with(**kwargs)
|
||||||
|
|
||||||
|
collist = ('ID', 'Region', 'Service Name', 'Service Type',
|
||||||
|
'Enabled', 'Interface', 'URL')
|
||||||
|
self.assertEqual(collist, columns)
|
||||||
|
datalist = ((
|
||||||
|
identity_fakes.endpoint_id,
|
||||||
|
identity_fakes.endpoint_region,
|
||||||
|
identity_fakes.service_name,
|
||||||
|
identity_fakes.service_type,
|
||||||
|
True,
|
||||||
|
identity_fakes.endpoint_interface,
|
||||||
|
identity_fakes.endpoint_url,
|
||||||
|
),)
|
||||||
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
|
||||||
class TestEndpointSet(TestEndpoint):
|
class TestEndpointSet(TestEndpoint):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user