Sets default service type for Nova V3 API

Set the default service type when talking to the Nova V3 API to
computev3 rather than compute. Although it is rather ugly to have
a different service type for a different version of a service,
this is necessary for the medium term because traditionally the
compute service endpoint has pointed to the V2 API rather than
the root and then version discovery done.

This change allows progression of the V3 API support in
novaclient and although devstack too currently points computev3
directly to the V3 API, the intent is to change this to point to
the root and implement version discovery during the Icehouse
development cycle.

Longer term when the V2 API support is eventually removed we can
reclaim the 'compute' service type and point it to the root.

Partially implements blueprint v3-api

Change-Id: If5d6a0d8af037cde7bf253d71aac2823b89f8066
This commit is contained in:
Chris Yeoh 2013-12-02 23:09:03 +10:30
parent b99b25a6f1
commit fe7ac8800d
3 changed files with 46 additions and 3 deletions

View File

@ -60,7 +60,13 @@ from novaclient.v3 import shell as shell_v3
DEFAULT_OS_COMPUTE_API_VERSION = "1.1"
DEFAULT_NOVA_ENDPOINT_TYPE = 'publicURL'
DEFAULT_NOVA_SERVICE_TYPE = 'compute'
# NOTE(cyeoh): Having the service type dependent on the API version
# is pretty ugly, but we have to do this because traditionally the
# catalog entry for compute points directly to the V2 API rather than
# the root, and then doing version discovery.
DEFAULT_NOVA_SERVICE_TYPE_MAP = {'1.1': 'compute',
'2': 'compute',
'3': 'computev3'}
logger = logging.getLogger(__name__)
@ -557,7 +563,14 @@ class OpenStackComputeShell(object):
endpoint_type = DEFAULT_NOVA_ENDPOINT_TYPE
if not service_type:
service_type = DEFAULT_NOVA_SERVICE_TYPE
os_compute_api_version = (options.os_compute_api_version or
DEFAULT_OS_COMPUTE_API_VERSION)
try:
service_type = DEFAULT_NOVA_SERVICE_TYPE_MAP[
os_compute_api_version]
except KeyError:
service_type = DEFAULT_NOVA_SERVICE_TYPE_MAP[
DEFAULT_OS_COMPUTE_API_VERSION]
service_type = utils.get_service_type(args.func) or service_type
#FIXME(usrleon): Here should be restrict for project id same as

View File

@ -198,3 +198,33 @@ class ShellTest(utils.TestCase):
self.assertEqual(required, message.args)
else:
self.fail('CommandError not raised')
def _test_service_type(self, version, service_type, mock_client):
if version is None:
cmd = 'list'
else:
cmd = '--os-compute-api-version %s list' % version
self.make_env()
self.shell(cmd)
_, client_kwargs = mock_client.call_args
self.assertEqual(service_type, client_kwargs['service_type'])
@mock.patch('novaclient.client.Client')
def test_default_service_type(self, mock_client):
self._test_service_type(None, 'compute', mock_client)
@mock.patch('novaclient.client.Client')
def test_v1_1_service_type(self, mock_client):
self._test_service_type('1.1', 'compute', mock_client)
@mock.patch('novaclient.client.Client')
def test_v2_service_type(self, mock_client):
self._test_service_type('2', 'compute', mock_client)
@mock.patch('novaclient.client.Client')
def test_v3_service_type(self, mock_client):
self._test_service_type('3', 'computev3', mock_client)
@mock.patch('novaclient.client.Client')
def test_v_unknown_service_type(self, mock_client):
self._test_service_type('unknown', 'compute', mock_client)

View File

@ -40,7 +40,7 @@ class Client(object):
insecure=False, timeout=None, proxy_tenant_id=None,
proxy_token=None, region_name=None,
endpoint_type='publicURL', extensions=None,
service_type='compute', service_name=None,
service_type='computev3', service_name=None,
volume_service_name=None, timings=False,
bypass_url=None, os_cache=False, no_cache=True,
http_log_debug=False, auth_system='keystone',