summaryrefslogtreecommitdiff
path: root/ironic/api
diff options
context:
space:
mode:
authorRuby Loo <ruby.loo@intel.com>2017-11-07 17:47:40 -0500
committerRuby Loo <ruby.loo@intel.com>2017-12-04 10:17:30 -0500
commitfeac8cfb786f7490743b3f270aa569054795ef4f (patch)
tree22d4571c01351e412ae92d6d0cb4e6fd99e8d8ae /ironic/api
parent638943dbf8e4adbcbe81a2af0f8a1d5ffd9771f6 (diff)
downloadironic-feac8cfb786f7490743b3f270aa569054795ef4f.tar.gz
Pin API version during rolling upgrade
During a rolling upgrade, when the new services are pinned to the old release, the API version will also be pinned to the old release. This will prevent users from accessing new features that may not quite work. The .sample was updated to reflect the change to the help string for the [DEFAULT]/pin_release_version configuration option. The update also pulled in changes for other options, from other (non-ironic) libraries. Change-Id: I38a0f106b589945fb62071f3dfe5bff43c6fee93 Partial-Bug: #1708549
Diffstat (limited to 'ironic/api')
-rw-r--r--ironic/api/controllers/root.py4
-rw-r--r--ironic/api/controllers/v1/__init__.py35
-rw-r--r--ironic/api/controllers/v1/versions.py38
3 files changed, 55 insertions, 22 deletions
diff --git a/ironic/api/controllers/root.py b/ironic/api/controllers/root.py
index 1a359b505..5fc14a530 100644
--- a/ironic/api/controllers/root.py
+++ b/ironic/api/controllers/root.py
@@ -85,8 +85,8 @@ class Root(base.APIBase):
root.description = ("Ironic is an OpenStack project which aims to "
"provision baremetal machines.")
root.default_version = Version(ID_VERSION1,
- versions.MIN_VERSION_STRING,
- versions.MAX_VERSION_STRING)
+ versions.min_version_string(),
+ versions.max_version_string())
root.versions = [root.default_version]
return root
diff --git a/ironic/api/controllers/v1/__init__.py b/ironic/api/controllers/v1/__init__.py
index e2ac631a3..a94a14ac9 100644
--- a/ironic/api/controllers/v1/__init__.py
+++ b/ironic/api/controllers/v1/__init__.py
@@ -39,12 +39,17 @@ from ironic.common.i18n import _
BASE_VERSION = versions.BASE_VERSION
-MIN_VER = base.Version(
- {base.Version.string: versions.MIN_VERSION_STRING},
- versions.MIN_VERSION_STRING, versions.MAX_VERSION_STRING)
-MAX_VER = base.Version(
- {base.Version.string: versions.MAX_VERSION_STRING},
- versions.MIN_VERSION_STRING, versions.MAX_VERSION_STRING)
+
+def min_version():
+ return base.Version(
+ {base.Version.string: versions.min_version_string()},
+ versions.min_version_string(), versions.max_version_string())
+
+
+def max_version():
+ return base.Version(
+ {base.Version.string: versions.max_version_string()},
+ versions.min_version_string(), versions.max_version_string())
class MediaType(base.APIBase):
@@ -200,29 +205,29 @@ class Controller(rest.RestController):
"Mutually exclusive versions requested. Version %(ver)s "
"requested but not supported by this service. The supported "
"version range is: [%(min)s, %(max)s].") %
- {'ver': version, 'min': versions.MIN_VERSION_STRING,
- 'max': versions.MAX_VERSION_STRING},
+ {'ver': version, 'min': versions.min_version_string(),
+ 'max': versions.max_version_string()},
headers=headers)
# ensure the minor version is within the supported range
- if version < MIN_VER or version > MAX_VER:
+ if version < min_version() or version > max_version():
raise exc.HTTPNotAcceptable(_(
"Version %(ver)s was requested but the minor version is not "
"supported by this service. The supported version range is: "
"[%(min)s, %(max)s].") %
- {'ver': version, 'min': versions.MIN_VERSION_STRING,
- 'max': versions.MAX_VERSION_STRING},
+ {'ver': version, 'min': versions.min_version_string(),
+ 'max': versions.max_version_string()},
headers=headers)
@pecan.expose()
def _route(self, args, request=None):
- v = base.Version(pecan.request.headers, versions.MIN_VERSION_STRING,
- versions.MAX_VERSION_STRING)
+ v = base.Version(pecan.request.headers, versions.min_version_string(),
+ versions.max_version_string())
# Always set the min and max headers
pecan.response.headers[base.Version.min_string] = (
- versions.MIN_VERSION_STRING)
+ versions.min_version_string())
pecan.response.headers[base.Version.max_string] = (
- versions.MAX_VERSION_STRING)
+ versions.max_version_string())
# assert that requested version is supported
self._check_version(v, pecan.response.headers)
diff --git a/ironic/api/controllers/v1/versions.py b/ironic/api/controllers/v1/versions.py
index 9e2340f08..c49638928 100644
--- a/ironic/api/controllers/v1/versions.py
+++ b/ironic/api/controllers/v1/versions.py
@@ -13,6 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
+from oslo_config import cfg
+
+from ironic.common import release_mappings
+
+CONF = cfg.CONF
+
# This is the version 1 API
BASE_VERSION = 1
@@ -104,11 +110,33 @@ MINOR_33_STORAGE_INTERFACE = 33
MINOR_34_PORT_PHYSICAL_NETWORK = 34
MINOR_35_REBUILD_CONFIG_DRIVE = 35
-# When adding another version, update MINOR_MAX_VERSION and also update
-# doc/source/dev/webapi-version-history.rst with a detailed explanation of
-# what the version has changed.
+# When adding another version, update:
+# - MINOR_MAX_VERSION
+# - doc/source/dev/webapi-version-history.rst with a detailed explanation of
+# what changed in the new version
+# - common/release_mappings.py, RELEASE_MAPPING['master']['api']
+
MINOR_MAX_VERSION = MINOR_35_REBUILD_CONFIG_DRIVE
# String representations of the minor and maximum versions
-MIN_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_1_INITIAL_VERSION)
-MAX_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_MAX_VERSION)
+_MIN_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_1_INITIAL_VERSION)
+_MAX_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_MAX_VERSION)
+
+
+def min_version_string():
+ """Returns the minimum supported API version (as a string)"""
+ return _MIN_VERSION_STRING
+
+
+def max_version_string():
+ """Returns the maximum supported API version (as a string).
+
+ If the service is pinned, the maximum API version is the pinned
+ version. Otherwise, it is the maximum supported API version.
+ """
+ release_ver = release_mappings.RELEASE_MAPPING.get(
+ CONF.pin_release_version)
+ if release_ver:
+ return release_ver['api']
+ else:
+ return _MAX_VERSION_STRING