Merge "Do not set default versions in parsed args"

This commit is contained in:
Jenkins 2015-07-24 19:51:30 +00:00 committed by Gerrit Code Review
commit 55d9eba093
10 changed files with 51 additions and 47 deletions

View File

@ -75,6 +75,21 @@ List of Backwards Incompatible Changes
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/472613
* Commit: https://review.openstack.org/#/c/194654/
6. Plugin interface change for default API versions
Previously, the default version was set in the parsed arguments,
but this makes it impossible to tell what has been passed in at the
command line, set in an environment variable or is just the default.
Now, the module should have a DEFAULT_API_VERSION that contains the
value and it will be set after command line argument, environment
and OCC file processing.
* In favor of: DEFAULT_API_VERSION
* As of: 1.2.1
* Removed in: NA
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1453229
* Commit: https://review.openstack.org/#/c/181514/
For Developers
==============

View File

@ -83,7 +83,7 @@ so the version should not contain the leading 'v' character.
.. code-block:: python
DEFAULT_OSCPLUGIN_API_VERSION = '1'
DEFAULT_API_VERSION = '1'
# Required by the OSC plugin interface
API_NAME = 'oscplugin'
@ -123,10 +123,7 @@ so the version should not contain the leading 'v' character.
parser.add_argument(
'--os-oscplugin-api-version',
metavar='<oscplugin-api-version>',
default=utils.env(
'OS_OSCPLUGIN_API_VERSION',
default=DEFAULT_OSCPLUGIN_API_VERSION),
help='OSC Plugin API version, default=' +
DEFAULT_OSCPLUGIN_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_OSCPLUGIN_API_VERSION)')
return parser

View File

@ -19,7 +19,7 @@ from openstackclient.common import utils
LOG = logging.getLogger(__name__)
DEFAULT_COMPUTE_API_VERSION = '2'
DEFAULT_API_VERSION = '2'
API_VERSION_OPTION = 'os_compute_api_version'
API_NAME = 'compute'
API_VERSIONS = {
@ -68,10 +68,8 @@ def build_option_parser(parser):
parser.add_argument(
'--os-compute-api-version',
metavar='<compute-api-version>',
default=utils.env(
'OS_COMPUTE_API_VERSION',
default=DEFAULT_COMPUTE_API_VERSION),
default=utils.env('OS_COMPUTE_API_VERSION'),
help='Compute API version, default=' +
DEFAULT_COMPUTE_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_COMPUTE_API_VERSION)')
return parser

View File

@ -21,7 +21,7 @@ from openstackclient.common import utils
LOG = logging.getLogger(__name__)
DEFAULT_IDENTITY_API_VERSION = '2'
DEFAULT_API_VERSION = '2'
API_VERSION_OPTION = 'os_identity_api_version'
API_NAME = 'identity'
API_VERSIONS = {
@ -63,11 +63,9 @@ def build_option_parser(parser):
parser.add_argument(
'--os-identity-api-version',
metavar='<identity-api-version>',
default=utils.env(
'OS_IDENTITY_API_VERSION',
default=DEFAULT_IDENTITY_API_VERSION),
default=utils.env('OS_IDENTITY_API_VERSION'),
help='Identity API version, default=' +
DEFAULT_IDENTITY_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_IDENTITY_API_VERSION)')
return auth.build_auth_plugins_option_parser(parser)

View File

@ -20,7 +20,7 @@ from openstackclient.common import utils
LOG = logging.getLogger(__name__)
DEFAULT_IMAGE_API_VERSION = '1'
DEFAULT_API_VERSION = '1'
API_VERSION_OPTION = 'os_image_api_version'
API_NAME = "image"
API_VERSIONS = {
@ -81,10 +81,8 @@ def build_option_parser(parser):
parser.add_argument(
'--os-image-api-version',
metavar='<image-api-version>',
default=utils.env(
'OS_IMAGE_API_VERSION',
default=DEFAULT_IMAGE_API_VERSION),
default=utils.env('OS_IMAGE_API_VERSION'),
help='Image API version, default=' +
DEFAULT_IMAGE_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_IMAGE_API_VERSION)')
return parser

View File

@ -18,7 +18,7 @@ from openstackclient.common import utils
LOG = logging.getLogger(__name__)
DEFAULT_NETWORK_API_VERSION = '2'
DEFAULT_API_VERSION = '2'
API_VERSION_OPTION = 'os_network_api_version'
API_NAME = "network"
API_VERSIONS = {
@ -83,10 +83,8 @@ def build_option_parser(parser):
parser.add_argument(
'--os-network-api-version',
metavar='<network-api-version>',
default=utils.env(
'OS_NETWORK_API_VERSION',
default=DEFAULT_NETWORK_API_VERSION),
default=utils.env('OS_NETWORK_API_VERSION'),
help='Network API version, default=' +
DEFAULT_NETWORK_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_NETWORK_API_VERSION)')
return parser

View File

@ -22,7 +22,7 @@ from openstackclient.common import utils
LOG = logging.getLogger(__name__)
DEFAULT_OBJECT_API_VERSION = '1'
DEFAULT_API_VERSION = '1'
API_VERSION_OPTION = 'os_object_api_version'
API_NAME = 'object_store'
API_VERSIONS = {
@ -52,10 +52,8 @@ def build_option_parser(parser):
parser.add_argument(
'--os-object-api-version',
metavar='<object-api-version>',
default=utils.env(
'OS_OBJECT_API_VERSION',
default=DEFAULT_OBJECT_API_VERSION),
default=utils.env('OS_OBJECT_API_VERSION'),
help='Object API version, default=' +
DEFAULT_OBJECT_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_OBJECT_API_VERSION)')
return parser

View File

@ -298,7 +298,9 @@ class OpenStackShell(app.App):
# Loop through extensions to get API versions
for mod in clientmanager.PLUGIN_MODULES:
version_opt = getattr(self.options, mod.API_VERSION_OPTION, None)
default_version = getattr(mod, 'DEFAULT_API_VERSION', None)
option = mod.API_VERSION_OPTION.replace('os_', '')
version_opt = self.cloud.config.get(option, default_version)
if version_opt:
api = mod.API_NAME
self.api_version[api] = version_opt

View File

@ -41,17 +41,17 @@ DEFAULT_SERVICE_URL = "http://127.0.0.1:8771/v3.0/"
DEFAULT_AUTH_PLUGIN = "v2password"
DEFAULT_INTERFACE = "internal"
DEFAULT_COMPUTE_API_VERSION = "2"
DEFAULT_IDENTITY_API_VERSION = "2"
DEFAULT_IMAGE_API_VERSION = "2"
DEFAULT_VOLUME_API_VERSION = "1"
DEFAULT_NETWORK_API_VERSION = "2"
DEFAULT_COMPUTE_API_VERSION = ""
DEFAULT_IDENTITY_API_VERSION = ""
DEFAULT_IMAGE_API_VERSION = ""
DEFAULT_VOLUME_API_VERSION = ""
DEFAULT_NETWORK_API_VERSION = ""
LIB_COMPUTE_API_VERSION = "2"
LIB_IDENTITY_API_VERSION = "2"
LIB_IMAGE_API_VERSION = "1"
LIB_VOLUME_API_VERSION = "1"
LIB_NETWORK_API_VERSION = "2"
LIB_COMPUTE_API_VERSION = ""
LIB_IDENTITY_API_VERSION = ""
LIB_IMAGE_API_VERSION = ""
LIB_VOLUME_API_VERSION = ""
LIB_NETWORK_API_VERSION = ""
CLOUD_1 = {
'clouds': {
@ -203,7 +203,9 @@ class TestShell(utils.TestCase):
initialize_app().
"""
self.occ_get_one = mock.Mock("Test Shell")
cloud = mock.Mock(name="cloudy")
cloud.config = {}
self.occ_get_one = mock.Mock(return_value=cloud)
with mock.patch(
"os_client_config.config.OpenStackConfig.get_one_cloud",
self.occ_get_one,

View File

@ -19,7 +19,7 @@ from openstackclient.common import utils
LOG = logging.getLogger(__name__)
DEFAULT_VOLUME_API_VERSION = '1'
DEFAULT_API_VERSION = '1'
API_VERSION_OPTION = 'os_volume_api_version'
API_NAME = "volume"
API_VERSIONS = {
@ -72,10 +72,8 @@ def build_option_parser(parser):
parser.add_argument(
'--os-volume-api-version',
metavar='<volume-api-version>',
default=utils.env(
'OS_VOLUME_API_VERSION',
default=DEFAULT_VOLUME_API_VERSION),
default=utils.env('OS_VOLUME_API_VERSION'),
help='Volume API version, default=' +
DEFAULT_VOLUME_API_VERSION +
DEFAULT_API_VERSION +
' (Env: OS_VOLUME_API_VERSION)')
return parser