Add support for extension list

- Add support in the common section for extension list. This only
   supports Identity for now. Once the APIs for volume and compute
   are supported in the respective APIs, they will be added. Once
   network is added to this client, it will be added (the API already
   supports it).
 - Include extension fakes for volume and compute for pre-enablement.

Change-Id: Iebb0156a779887d2ab06488a2a27b70b56369376
Closes-Bug: #1319115
This commit is contained in:
Matt Fischer 2014-05-13 13:04:02 -04:00
parent 7f6a901d01
commit 4ae4dc35bd
6 changed files with 272 additions and 0 deletions
openstackclient
common
tests
common
compute/v2
identity/v2_0
volume/v1
setup.cfg

@ -0,0 +1,78 @@
# Copyright 2012-2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Extension action implementations"""
import logging
from cliff import lister
from openstackclient.common import exceptions as exc
from openstackclient.common import utils
class ListExtension(lister.Lister):
"""List extension command"""
# TODO(mfisch): add support for volume and compute
# when the underlying APIs support it. Add support
# for network when it's added to openstackclient.
log = logging.getLogger(__name__ + '.ListExtension')
def get_parser(self, prog_name):
parser = super(ListExtension, self).get_parser(prog_name)
parser.add_argument(
'--long',
action='store_true',
default=False,
help='List additional fields in output')
parser.add_argument(
'--identity',
action='store_true',
default=False,
help='List extensions for the Identity API')
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
if parsed_args.long:
columns = ('Name', 'Namespace', 'Description',
'Alias', 'Updated', 'Links')
else:
columns = ('Name', 'Alias', 'Description')
data = []
# by default we want to show everything, unless the
# user specifies one or more of the APIs to show
# for now, only identity is supported
show_all = (not parsed_args.identity)
if parsed_args.identity or show_all:
identity_client = self.app.client_manager.identity
try:
data += identity_client.extensions.list()
except Exception:
raise exc.CommandError(
"Extensions list not supported by"
" identity API")
return (columns,
(utils.get_item_properties(
s, columns,
formatters={},
) for s in data))

@ -0,0 +1,128 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import copy
from openstackclient.common import extension
from openstackclient.tests import fakes
from openstackclient.tests import utils
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
class TestExtension(utils.TestCommand):
def setUp(self):
super(TestExtension, self).setUp()
self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)
# Get shortcuts to the ExtensionManager Mocks
self.identity_extensions_mock = (
self.app.client_manager.identity.extensions)
self.identity_extensions_mock.reset_mock()
class TestExtensionList(TestExtension):
def setUp(self):
super(TestExtensionList, self).setUp()
self.identity_extensions_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.EXTENSION),
loaded=True,
),
]
# Get the command object to test
self.cmd = extension.ListExtension(self.app, None)
def test_extension_list_no_options(self):
arglist = []
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# no args should output from all services
self.identity_extensions_mock.list.assert_called_with()
collist = ('Name', 'Alias', 'Description')
self.assertEqual(columns, collist)
datalist = (
(
identity_fakes.extension_name,
identity_fakes.extension_alias,
identity_fakes.extension_description,
),
)
self.assertEqual(tuple(data), datalist)
def test_extension_list_long(self):
arglist = [
'--long',
]
verifylist = [
('long', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# no args should output from all services
self.identity_extensions_mock.list.assert_called_with()
collist = ('Name', 'Namespace', 'Description', 'Alias', 'Updated',
'Links')
self.assertEqual(columns, collist)
datalist = (
(
identity_fakes.extension_name,
identity_fakes.extension_namespace,
identity_fakes.extension_description,
identity_fakes.extension_alias,
identity_fakes.extension_updated,
identity_fakes.extension_links,
),
)
self.assertEqual(tuple(data), datalist)
def test_extension_list_identity(self):
arglist = [
'--identity',
]
verifylist = [
('identity', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.identity_extensions_mock.list.assert_called_with()
collist = ('Name', 'Alias', 'Description')
self.assertEqual(columns, collist)
datalist = ((
identity_fakes.extension_name,
identity_fakes.extension_alias,
identity_fakes.extension_description,
), )
self.assertEqual(tuple(data), datalist)

@ -28,6 +28,25 @@ SERVER = {
'name': server_name,
}
extension_name = 'Multinic'
extension_namespace = 'http://docs.openstack.org/compute/ext/'\
'multinic/api/v1.1'
extension_description = 'Multiple network support'
extension_updated = '2014-01-07T12:00:0-00:00'
extension_alias = 'NMN'
extension_links = '[{"href":'\
'"https://github.com/openstack/compute-api", "type":'\
' "text/html", "rel": "describedby"}]'
EXTENSION = {
'name': extension_name,
'namespace': extension_namespace,
'description': extension_description,
'updated': extension_updated,
'alias': extension_alias,
'links': extension_links,
}
class FakeComputev2Client(object):
def __init__(self, **kwargs):
@ -35,6 +54,8 @@ class FakeComputev2Client(object):
self.images.resource_class = fakes.FakeResource(None, {})
self.servers = mock.Mock()
self.servers.resource_class = fakes.FakeResource(None, {})
self.extensions = mock.Mock()
self.extensions.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']

@ -100,6 +100,26 @@ ENDPOINT = {
'service_id': endpoint_service_id,
}
extension_name = 'OpenStack Keystone User CRUD'
extension_namespace = 'http://docs.openstack.org/identity/'\
'api/ext/OS-KSCRUD/v1.0'
extension_description = 'OpenStack extensions to Keystone v2.0 API'\
' enabling User Operations.'
extension_updated = '2013-07-07T12:00:0-00:00'
extension_alias = 'OS-KSCRUD'
extension_links = '[{"href":'\
'"https://github.com/openstack/identity-api", "type":'\
' "text/html", "rel": "describedby"}]'
EXTENSION = {
'name': extension_name,
'namespace': extension_namespace,
'description': extension_description,
'updated': extension_updated,
'alias': extension_alias,
'links': extension_links,
}
class FakeIdentityv2Client(object):
def __init__(self, **kwargs):
@ -116,6 +136,8 @@ class FakeIdentityv2Client(object):
self.ec2.resource_class = fakes.FakeResource(None, {})
self.endpoints = mock.Mock()
self.endpoints.resource_class = fakes.FakeResource(None, {})
self.extensions = mock.Mock()
self.extensions.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']

@ -45,6 +45,26 @@ VOLUME = {
'metadata': volume_metadata,
}
extension_name = 'SchedulerHints'
extension_namespace = 'http://docs.openstack.org/'\
'block-service/ext/scheduler-hints/api/v2'
extension_description = 'Pass arbitrary key/value'\
'pairs to the scheduler.'
extension_updated = '2014-02-07T12:00:0-00:00'
extension_alias = 'OS-SCH-HNT'
extension_links = '[{"href":'\
'"https://github.com/openstack/block-api", "type":'\
' "text/html", "rel": "describedby"}]'
EXTENSION = {
'name': extension_name,
'namespace': extension_namespace,
'description': extension_description,
'updated': extension_updated,
'alias': extension_alias,
'links': extension_links,
}
class FakeVolumev1Client(object):
def __init__(self, **kwargs):
@ -52,6 +72,8 @@ class FakeVolumev1Client(object):
self.volumes.resource_class = fakes.FakeResource(None, {})
self.services = mock.Mock()
self.services.resource_class = fakes.FakeResource(None, {})
self.extensions = mock.Mock()
self.extensions.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']

@ -38,6 +38,7 @@ openstack.common =
limits_show = openstackclient.common.limits:ShowLimits
quota_set = openstackclient.common.quota:SetQuota
quota_show = openstackclient.common.quota:ShowQuota
extension_list = openstackclient.common.extension:ListExtension
openstack.compute.v2 =
compute_agent_create = openstackclient.compute.v2.agent:CreateAgent