summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2020-09-06 15:39:27 +0200
committerDmitry Tantsur <dtantsur@protonmail.com>2020-09-11 17:45:37 +0200
commit6a8056414ef0e353555df396417989aa054114ea (patch)
tree302b78c18d94c12c7bde92513680ba92718d866d /ironic_python_agent
parent67f053d94cbde91f9fd9de9e32be32b3436daea7 (diff)
downloadironic-python-agent-6a8056414ef0e353555df396417989aa054114ea.tar.gz
Refactor API version negotiation code
Makes sure heartbeats can send versions higher than one required for tokens while also making sure we never send a version we don't know. Also makes code easier to understand. Change-Id: Ice1e7d45ea90c9fd8220c4b94e691b6015e23074
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/ironic_api_client.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/ironic_python_agent/ironic_api_client.py b/ironic_python_agent/ironic_api_client.py
index 4738f22d..a8923060 100644
--- a/ironic_python_agent/ironic_api_client.py
+++ b/ironic_python_agent/ironic_api_client.py
@@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
-from distutils.version import StrictVersion
-
from oslo_config import cfg
from oslo_log import log
from oslo_serialization import jsonutils
@@ -35,6 +32,9 @@ LOG = log.getLogger(__name__)
MIN_IRONIC_VERSION = (1, 31)
AGENT_VERSION_IRONIC_VERSION = (1, 36)
AGENT_TOKEN_IRONIC_VERSION = (1, 62)
+# NOTE(dtantsur): change this constant every time you add support for more
+# versions to ensure that we send the highest version we know about.
+MAX_KNOWN_VERSION = AGENT_TOKEN_IRONIC_VERSION
class APIClient(object):
@@ -80,17 +80,11 @@ class APIClient(object):
cert=cert,
**kwargs)
- def _get_ironic_api_version_header(self):
- # TODO(TheJulia): It would be great to improve version handling
- # logic, but we need to ship a newer version if we can.
- ironic_version = "%d.%d" % self._get_ironic_api_version()
- agent_token_version = "%d.%d" % AGENT_TOKEN_IRONIC_VERSION
- if (StrictVersion(ironic_version)
- >= StrictVersion(agent_token_version)):
- version = agent_token_version
- else:
- version = ironic_version
- return {'X-OpenStack-Ironic-API-Version': version}
+ def _get_ironic_api_version_header(self, version=None):
+ if version is None:
+ ironic_version = self._get_ironic_api_version()
+ version = min(ironic_version, AGENT_TOKEN_IRONIC_VERSION)
+ return {'X-OpenStack-Ironic-API-Version': '%d.%d' % version}
def _get_ironic_api_version(self):
if not self._ironic_api_version:
@@ -121,7 +115,8 @@ class APIClient(object):
if api_ver >= AGENT_VERSION_IRONIC_VERSION:
data['agent_version'] = version.version_info.release_string()
- headers = self._get_ironic_api_version_header()
+ api_ver = min(MAX_KNOWN_VERSION, api_ver)
+ headers = self._get_ironic_api_version_header(api_ver)
try:
response = self._request('POST', path, data=data, headers=headers)