diff --git a/doc/source/backwards-incompatible.rst b/doc/source/backwards-incompatible.rst index c511852f39..e89cc3a680 100644 --- a/doc/source/backwards-incompatible.rst +++ b/doc/source/backwards-incompatible.rst @@ -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 ============== diff --git a/doc/source/plugins.rst b/doc/source/plugins.rst index d603e10217..17a508fed7 100644 --- a/doc/source/plugins.rst +++ b/doc/source/plugins.rst @@ -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='', - 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 diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py index 6ae87b7982..9dda32d660 100644 --- a/openstackclient/compute/client.py +++ b/openstackclient/compute/client.py @@ -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='', - 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 diff --git a/openstackclient/identity/client.py b/openstackclient/identity/client.py index d7b663ddaf..b8bb33f43f 100644 --- a/openstackclient/identity/client.py +++ b/openstackclient/identity/client.py @@ -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='', - 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) diff --git a/openstackclient/image/client.py b/openstackclient/image/client.py index 8fbf8c0f25..8dd146e9f2 100644 --- a/openstackclient/image/client.py +++ b/openstackclient/image/client.py @@ -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='', - 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 diff --git a/openstackclient/network/client.py b/openstackclient/network/client.py index 0ef6885287..5f72782bb1 100644 --- a/openstackclient/network/client.py +++ b/openstackclient/network/client.py @@ -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='', - 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 diff --git a/openstackclient/object/client.py b/openstackclient/object/client.py index 0359940d82..e75878026f 100644 --- a/openstackclient/object/client.py +++ b/openstackclient/object/client.py @@ -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='', - 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 diff --git a/openstackclient/shell.py b/openstackclient/shell.py index edeffdfb54..55b93b7a46 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -297,7 +297,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 diff --git a/openstackclient/tests/test_shell.py b/openstackclient/tests/test_shell.py index e2f0580b2c..0e0cc50b54 100644 --- a/openstackclient/tests/test_shell.py +++ b/openstackclient/tests/test_shell.py @@ -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, diff --git a/openstackclient/volume/client.py b/openstackclient/volume/client.py index 093178e305..d4800b8d5c 100644 --- a/openstackclient/volume/client.py +++ b/openstackclient/volume/client.py @@ -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='', - 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