Browse Source

Merge "Add test for data migration version"

tags/18.0.0.0rc1
Zuul 7 months ago
parent
commit
034a4837c4
1 changed files with 59 additions and 0 deletions
  1. 59
    0
      glance/tests/unit/test_data_migration_version.py

+ 59
- 0
glance/tests/unit/test_data_migration_version.py View File

@@ -0,0 +1,59 @@
1
+# Copyright 2019 Red Hat, Inc.
2
+# All Rights Reserved.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+
16
+import six
17
+import testtools
18
+
19
+from glance.db.migration import CURRENT_RELEASE
20
+from glance.version import version_info
21
+
22
+
23
+class TestDataMigrationVersion(testtools.TestCase):
24
+
25
+    def test_migration_version(self):
26
+        """Make sure the data migration version info has been updated."""
27
+
28
+        release_number = int(version_info.version_string().split('.', 1)[0])
29
+
30
+        # by rule, release names must be composed of the 26 letters of the
31
+        # ISO Latin alphabet (ord('A')==65, ord('Z')==90)
32
+        release_letter = six.text_type(CURRENT_RELEASE[:1].upper()).encode(
33
+            'ascii')
34
+
35
+        # Convert release letter into an int in [1:26].  The first
36
+        # glance release was 'Bexar'.
37
+        converted_release_letter = (ord(release_letter) -
38
+                                    ord(u'B'.encode('ascii')) + 1)
39
+
40
+        # Project the release number into [1:26]
41
+        converted_release_number = release_number % 26
42
+
43
+        # Prepare for the worst with a super-informative message
44
+        msg = ('\n\n'
45
+               'EMERGENCY!\n'
46
+               'glance.db.migration.CURRENT_RELEASE is out of sync '
47
+               'with the glance version.\n'
48
+               '  CURRENT_RELEASE: %s\n'
49
+               '  glance version: %s\n'
50
+               'glance.db.migration.CURRENT_RELEASE needs to be '
51
+               'updated IMMEDIATELY.\n'
52
+               'The gate will be wedged until the update is made.\n'
53
+               'EMERGENCY!\n'
54
+               '\n') % (CURRENT_RELEASE,
55
+                        version_info.version_string())
56
+
57
+        self.assertEqual(converted_release_letter,
58
+                         converted_release_number,
59
+                         msg)

Loading…
Cancel
Save