Correct usage of API_MAX_VERSION and DEFAULT_OS_COMPUTE_API_VERSION

Commit d045019f0f use the variables
API_MAX_VERSION and DEFAULT_OS_COMPUTE_API_VERSION with wrong way.

API_MAX_VERSION means the max version of client supported. This
variable only be changed when client support the new version. And
it's must bumped sequentially.

DEFAULT_OS_COMPUTE_API_VERSION is default value of option
'--os-compute-api-version', this value decided the default behaviour
of nova client. The nova client CLI behaviour should be that client
negotiate with server side to find out most recent version betweeyn
client and server. So the value should be '2.latest'. And it won't
be changed except we decided to change the default behaviour of nova
client CLI.

Change-Id: Iba9bfa136245bd2899c427ac0c231a30c00bd7f3
Closes-Bug: #1508244
This commit is contained in:
He Jie Xu 2015-10-21 10:36:53 +08:00
parent 095d72f652
commit 28bf8ddb06
3 changed files with 35 additions and 24 deletions

View File

@ -21,9 +21,8 @@ __version__ = pbr.version.VersionInfo('python-novaclient').version_string()
API_MIN_VERSION = api_versions.APIVersion("2.1") API_MIN_VERSION = api_versions.APIVersion("2.1")
# The max version should be the latest version that is supported in the client, # The max version should be the latest version that is supported in the client,
# not necessarily the latest that the server can provide. This is what a user # not necessarily the latest that the server can provide. This is only bumped
# can opt into with the --os-compute-api-version option on the CLI. Note that # when client supported the max version, and bumped sequentially, otherwise
# there may be gaps in supported microversions before this max version which is # the client may break due to server side new version may include some
# why novaclient.shell.DEFAULT_OS_COMPUTE_API_VERSION is not 2.latest or # backward incompatible change.
# necessarily equal to API_MAX_VERSION. API_MAX_VERSION = api_versions.APIVersion("2.5")
API_MAX_VERSION = api_versions.APIVersion("2.11")

View File

@ -51,16 +51,11 @@ from novaclient.openstack.common import cliutils
from novaclient import utils from novaclient import utils
DEFAULT_MAJOR_OS_COMPUTE_API_VERSION = "2.0" DEFAULT_MAJOR_OS_COMPUTE_API_VERSION = "2.0"
# We default to the highest *incremental* version that we know we can support. # The default behaviour of nova client CLI is that CLI negotiates with server
# There should not be gaps in support for this version even if # to find out the most recent version between client and server, and
# novaclient.API_MAX_VERSION is higher. The difference is API_MAX_VERSION # '2.latest' means to that. This value never be changed until we decided to
# caps what the user can request (they are opting into something), whereas # change the default behaviour of nova client CLI.
# DEFAULT_OS_COMPUTE_API_VERSION should be the highest version that the client DEFAULT_OS_COMPUTE_API_VERSION = '2.latest'
# actually supports without gaps in between. When a higher incremental version
# is implemented in the client, this version should be updated. Note that this
# value should never be 2.latest since what's latest changes depending on which
# cloud provider you're talking to.
DEFAULT_OS_COMPUTE_API_VERSION = '2.5'
DEFAULT_NOVA_ENDPOINT_TYPE = 'publicURL' DEFAULT_NOVA_ENDPOINT_TYPE = 'publicURL'
DEFAULT_NOVA_SERVICE_TYPE = "compute" DEFAULT_NOVA_SERVICE_TYPE = "compute"

View File

@ -65,6 +65,12 @@ FAKE_ENV5 = {'OS_USERNAME': 'username',
'OS_COMPUTE_API_VERSION': '2', 'OS_COMPUTE_API_VERSION': '2',
'OS_AUTH_SYSTEM': 'rackspace'} 'OS_AUTH_SYSTEM': 'rackspace'}
FAKE_ENV6 = {'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where/v2.0',
'OS_AUTH_SYSTEM': 'rackspace'}
def _create_ver_list(versions): def _create_ver_list(versions):
return {'versions': {'values': versions}} return {'versions': {'values': versions}}
@ -424,6 +430,25 @@ class ShellTest(utils.TestCase):
keyring_saver = mock_client_instance.client.keyring_saver keyring_saver = mock_client_instance.client.keyring_saver
self.assertIsInstance(keyring_saver, novaclient.shell.SecretsHelper) self.assertIsInstance(keyring_saver, novaclient.shell.SecretsHelper)
@mock.patch('novaclient.client.Client')
def test_microversion_with_default_behaviour(self, mock_client):
self.make_env(fake_env=FAKE_ENV6)
self.mock_server_version_range.return_value = (
api_versions.APIVersion("2.1"), api_versions.APIVersion("2.3"))
self.shell('list')
client_args = mock_client.call_args_list[1][0]
self.assertEqual(api_versions.APIVersion("2.3"), client_args[0])
@mock.patch('novaclient.client.Client')
def test_microversion_with_default_behaviour_with_legacy_server(
self, mock_client):
self.make_env(fake_env=FAKE_ENV6)
self.mock_server_version_range.return_value = (
api_versions.APIVersion(), api_versions.APIVersion())
self.shell('list')
client_args = mock_client.call_args_list[1][0]
self.assertEqual(api_versions.APIVersion("2.0"), client_args[0])
@mock.patch('novaclient.client.Client') @mock.patch('novaclient.client.Client')
def test_microversion_with_latest(self, mock_client): def test_microversion_with_latest(self, mock_client):
self.make_env() self.make_env()
@ -516,14 +541,6 @@ class ShellTest(utils.TestCase):
err = sys.stderr.getvalue() err = sys.stderr.getvalue()
self.assertEqual(err, 'ERROR (MyException): message\n') self.assertEqual(err, 'ERROR (MyException): message\n')
def test_default_os_compute_api_version(self):
default_version = api_versions.APIVersion(
novaclient.shell.DEFAULT_OS_COMPUTE_API_VERSION)
# The default should never be the latest.
self.assertFalse(default_version.is_latest())
# The default should be less than or equal to API_MAX_VERSION.
self.assertLessEqual(default_version, novaclient.API_MAX_VERSION)
class TestLoadVersionedActions(utils.TestCase): class TestLoadVersionedActions(utils.TestCase):