Improve the checks of Dynamic UI format versions

Current implementation of DynamicUI checks the "Version" field of UI
definition files to exactly match a single constant value (currently 2).
This contradicts to our desired versioning strategy.

Instead, it should check that the major component of the Version field
in the UI definition being processed  matches tha major component of the
current latest version of the format (i.e. we assume that the versions
are compatible if their major version are the same). At the same time
the version of the definition being processed is not greater than the
latest supported version.

The implementation is done using the semantic_version library which has
all the needed functionality, including the coercing method (parsing of
string-based content into the proper version) and partial versions.

Targets Blueprint murano-versioning

Change-Id: I96cbbddc4389804fafe9a1d6f48f63ac4ee5620a
This commit is contained in:
Alexander Tivelkov 2015-07-14 14:41:41 +03:00
parent 633bcb4571
commit cdb94feb2f
3 changed files with 66 additions and 4 deletions

View File

@ -12,10 +12,22 @@
# License for the specific language governing permissions and limitations
# under the License.
VERSION = 2
import semantic_version
LATEST_FORMAT_VERSION = 2.0
def check_version(version):
msg = 'Unsupported Dynamic UI version: required {0}, got {1}'
if version != VERSION:
raise ValueError(msg.format(VERSION, version))
latest = semantic_version.Version.coerce(str(LATEST_FORMAT_VERSION))
supported = semantic_version.Version(str(latest.major), partial=True)
requested = semantic_version.Version.coerce(str(version))
if supported != requested:
msg = 'Unsupported Dynamic UI format version: ' \
'requested format version {0} is not compatible with the ' \
'supported family {1}'
raise ValueError(msg.format(requested, supported))
if requested > latest:
msg = 'Unsupported Dynamic UI format version: ' \
'requested format version {0} is newer than ' \
'latest supported {1}'
raise ValueError(msg.format(requested, latest))

View File

@ -0,0 +1,49 @@
# Copyright (c) 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from muranodashboard.dynamic_ui import version
class TestVersions(testtools.TestCase):
def setUp(self):
super(TestVersions, self).setUp()
self.original = version.LATEST_FORMAT_VERSION
version.LATEST_FORMAT_VERSION = 2.4
def tearDown(self):
version.LATEST_FORMAT_VERSION = self.original
super(TestVersions, self).tearDown()
def test_exact_match(self):
version.check_version(2.4)
def test_string_match(self):
version.check_version('2.4')
def test_older_in_family(self):
version.check_version(2.1)
def test_oldest_in_family(self):
version.check_version(2)
def test_newer(self):
self.assertRaises(ValueError, version.check_version, 2.5)
def test_uncompatible_old(self):
self.assertRaises(ValueError, version.check_version, 1.6)
def test_uncompatible_new(self):
self.assertRaises(ValueError, version.check_version, 3.0)

View File

@ -9,6 +9,7 @@ six>=1.9.0
PyYAML>=3.1.0
oslo.log>=1.2.0 # Apache-2.0
semantic_version>=2.3.1
# not listed in global requirements
yaql>=0.2.6,<0.3 # Apache 2.0 License