Merge "Sets default service type for Nova V3 API"

This commit is contained in:
Jenkins 2013-12-08 13:27:40 +00:00 committed by Gerrit Code Review
commit fdee7c18a6
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

@ -211,3 +211,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',