root / test / py / cfgupgrade_unittest.py @ fbeb41e6
History | View | Annotate | Download (16.7 kB)
1 | aefbe369 | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | aefbe369 | Michael Hanselmann | #
|
3 | aefbe369 | Michael Hanselmann | |
4 | 1709435e | Bernardo Dal Seno | # Copyright (C) 2010, 2012, 2013 Google Inc.
|
5 | aefbe369 | Michael Hanselmann | #
|
6 | aefbe369 | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | aefbe369 | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | aefbe369 | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | aefbe369 | Michael Hanselmann | # (at your option) any later version.
|
10 | aefbe369 | Michael Hanselmann | #
|
11 | aefbe369 | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | aefbe369 | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | aefbe369 | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | aefbe369 | Michael Hanselmann | # General Public License for more details.
|
15 | aefbe369 | Michael Hanselmann | #
|
16 | aefbe369 | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | aefbe369 | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | aefbe369 | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | aefbe369 | Michael Hanselmann | # 02110-1301, USA.
|
20 | aefbe369 | Michael Hanselmann | |
21 | aefbe369 | Michael Hanselmann | |
22 | aefbe369 | Michael Hanselmann | """Script for testing tools/cfgupgrade"""
|
23 | aefbe369 | Michael Hanselmann | |
24 | aefbe369 | Michael Hanselmann | import os |
25 | aefbe369 | Michael Hanselmann | import sys |
26 | aefbe369 | Michael Hanselmann | import unittest |
27 | aefbe369 | Michael Hanselmann | import shutil |
28 | aefbe369 | Michael Hanselmann | import tempfile |
29 | aefbe369 | Michael Hanselmann | import operator |
30 | aefbe369 | Michael Hanselmann | |
31 | aefbe369 | Michael Hanselmann | from ganeti import constants |
32 | aefbe369 | Michael Hanselmann | from ganeti import utils |
33 | aefbe369 | Michael Hanselmann | from ganeti import serializer |
34 | 011974df | Michael Hanselmann | from ganeti import netutils |
35 | aefbe369 | Michael Hanselmann | |
36 | effc1b86 | Jose A. Lopes | from ganeti.utils import version |
37 | effc1b86 | Jose A. Lopes | |
38 | aefbe369 | Michael Hanselmann | import testutils |
39 | aefbe369 | Michael Hanselmann | |
40 | aefbe369 | Michael Hanselmann | |
41 | b555101c | Thomas Thrainer | def GetMinimalConfig(): |
42 | b555101c | Thomas Thrainer | return {
|
43 | b555101c | Thomas Thrainer | "version": constants.CONFIG_VERSION,
|
44 | b555101c | Thomas Thrainer | "cluster": {
|
45 | ce7b7617 | Michele Tartara | "master_node": "node1-uuid", |
46 | 8cd19bec | Petr Pudlak | "ipolicy": None, |
47 | 8cd19bec | Petr Pudlak | "ndparams": {}
|
48 | b555101c | Thomas Thrainer | }, |
49 | b555101c | Thomas Thrainer | "instances": {},
|
50 | ce7b7617 | Michele Tartara | "networks": {},
|
51 | b555101c | Thomas Thrainer | "nodegroups": {},
|
52 | b555101c | Thomas Thrainer | "nodes": {
|
53 | b555101c | Thomas Thrainer | "node1-uuid": {
|
54 | b555101c | Thomas Thrainer | "name": "node1", |
55 | b555101c | Thomas Thrainer | "uuid": "node1-uuid" |
56 | b555101c | Thomas Thrainer | } |
57 | b555101c | Thomas Thrainer | }, |
58 | b555101c | Thomas Thrainer | } |
59 | b555101c | Thomas Thrainer | |
60 | b555101c | Thomas Thrainer | |
61 | 1709435e | Bernardo Dal Seno | def _RunUpgrade(path, dry_run, no_verify, ignore_hostname=True, |
62 | 1709435e | Bernardo Dal Seno | downgrade=False):
|
63 | aefbe369 | Michael Hanselmann | cmd = [sys.executable, "%s/tools/cfgupgrade" % testutils.GetSourceDir(),
|
64 | 7939f60c | Michael Hanselmann | "--debug", "--force", "--path=%s" % path, "--confdir=%s" % path] |
65 | 011974df | Michael Hanselmann | |
66 | 011974df | Michael Hanselmann | if ignore_hostname:
|
67 | 011974df | Michael Hanselmann | cmd.append("--ignore-hostname")
|
68 | aefbe369 | Michael Hanselmann | if dry_run:
|
69 | aefbe369 | Michael Hanselmann | cmd.append("--dry-run")
|
70 | aefbe369 | Michael Hanselmann | if no_verify:
|
71 | aefbe369 | Michael Hanselmann | cmd.append("--no-verify")
|
72 | 1709435e | Bernardo Dal Seno | if downgrade:
|
73 | 1709435e | Bernardo Dal Seno | cmd.append("--downgrade")
|
74 | aefbe369 | Michael Hanselmann | |
75 | aefbe369 | Michael Hanselmann | result = utils.RunCmd(cmd, cwd=os.getcwd()) |
76 | aefbe369 | Michael Hanselmann | if result.failed:
|
77 | aefbe369 | Michael Hanselmann | raise Exception("cfgupgrade failed: %s, output %r" % |
78 | aefbe369 | Michael Hanselmann | (result.fail_reason, result.output)) |
79 | aefbe369 | Michael Hanselmann | |
80 | aefbe369 | Michael Hanselmann | |
81 | aefbe369 | Michael Hanselmann | class TestCfgupgrade(unittest.TestCase): |
82 | aefbe369 | Michael Hanselmann | def setUp(self): |
83 | aefbe369 | Michael Hanselmann | self.tmpdir = tempfile.mkdtemp()
|
84 | aefbe369 | Michael Hanselmann | |
85 | aefbe369 | Michael Hanselmann | self.config_path = utils.PathJoin(self.tmpdir, "config.data") |
86 | aefbe369 | Michael Hanselmann | self.noded_cert_path = utils.PathJoin(self.tmpdir, "server.pem") |
87 | aefbe369 | Michael Hanselmann | self.rapi_cert_path = utils.PathJoin(self.tmpdir, "rapi.pem") |
88 | fdd9ac5b | Michael Hanselmann | self.rapi_users_path = utils.PathJoin(self.tmpdir, "rapi", "users") |
89 | fdd9ac5b | Michael Hanselmann | self.rapi_users_path_pre24 = utils.PathJoin(self.tmpdir, "rapi_users") |
90 | aefbe369 | Michael Hanselmann | self.known_hosts_path = utils.PathJoin(self.tmpdir, "known_hosts") |
91 | aefbe369 | Michael Hanselmann | self.confd_hmac_path = utils.PathJoin(self.tmpdir, "hmac.key") |
92 | aefbe369 | Michael Hanselmann | self.cds_path = utils.PathJoin(self.tmpdir, "cluster-domain-secret") |
93 | 011974df | Michael Hanselmann | self.ss_master_node_path = utils.PathJoin(self.tmpdir, "ssconf_master_node") |
94 | 7939f60c | Michael Hanselmann | self.file_storage_paths = utils.PathJoin(self.tmpdir, "file-storage-paths") |
95 | aefbe369 | Michael Hanselmann | |
96 | aefbe369 | Michael Hanselmann | def tearDown(self): |
97 | aefbe369 | Michael Hanselmann | shutil.rmtree(self.tmpdir)
|
98 | aefbe369 | Michael Hanselmann | |
99 | aefbe369 | Michael Hanselmann | def _LoadConfig(self): |
100 | aefbe369 | Michael Hanselmann | return serializer.LoadJson(utils.ReadFile(self.config_path)) |
101 | aefbe369 | Michael Hanselmann | |
102 | cd315ad9 | Bernardo Dal Seno | def _LoadTestDataConfig(self, filename): |
103 | cd315ad9 | Bernardo Dal Seno | return serializer.LoadJson(testutils.ReadTestData(filename))
|
104 | cd315ad9 | Bernardo Dal Seno | |
105 | aefbe369 | Michael Hanselmann | def _CreateValidConfigDir(self): |
106 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.noded_cert_path, data="") |
107 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.known_hosts_path, data="") |
108 | 011974df | Michael Hanselmann | utils.WriteFile(self.ss_master_node_path,
|
109 | 011974df | Michael Hanselmann | data="node.has.another.name.example.net")
|
110 | aefbe369 | Michael Hanselmann | |
111 | aefbe369 | Michael Hanselmann | def testNoConfigDir(self): |
112 | aefbe369 | Michael Hanselmann | self.assertFalse(utils.ListVisibleFiles(self.tmpdir)) |
113 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
114 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, True, True) |
115 | aefbe369 | Michael Hanselmann | |
116 | 011974df | Michael Hanselmann | def testWrongHostname(self): |
117 | 011974df | Michael Hanselmann | self._CreateValidConfigDir()
|
118 | 011974df | Michael Hanselmann | |
119 | b555101c | Thomas Thrainer | utils.WriteFile(self.config_path,
|
120 | b555101c | Thomas Thrainer | data=serializer.DumpJson(GetMinimalConfig())) |
121 | 011974df | Michael Hanselmann | |
122 | 011974df | Michael Hanselmann | hostname = netutils.GetHostname().name |
123 | 011974df | Michael Hanselmann | assert hostname != utils.ReadOneLineFile(self.ss_master_node_path) |
124 | 011974df | Michael Hanselmann | |
125 | 011974df | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True, |
126 | 011974df | Michael Hanselmann | ignore_hostname=False)
|
127 | 011974df | Michael Hanselmann | |
128 | 011974df | Michael Hanselmann | def testCorrectHostname(self): |
129 | 011974df | Michael Hanselmann | self._CreateValidConfigDir()
|
130 | 011974df | Michael Hanselmann | |
131 | b555101c | Thomas Thrainer | utils.WriteFile(self.config_path,
|
132 | b555101c | Thomas Thrainer | data=serializer.DumpJson(GetMinimalConfig())) |
133 | 011974df | Michael Hanselmann | |
134 | 011974df | Michael Hanselmann | utils.WriteFile(self.ss_master_node_path,
|
135 | 011974df | Michael Hanselmann | data="%s\n" % netutils.GetHostname().name)
|
136 | 011974df | Michael Hanselmann | |
137 | 011974df | Michael Hanselmann | _RunUpgrade(self.tmpdir, False, True, ignore_hostname=False) |
138 | 011974df | Michael Hanselmann | |
139 | aefbe369 | Michael Hanselmann | def testInconsistentConfig(self): |
140 | aefbe369 | Michael Hanselmann | self._CreateValidConfigDir()
|
141 | aefbe369 | Michael Hanselmann | # There should be no "config_version"
|
142 | b555101c | Thomas Thrainer | cfg = GetMinimalConfig() |
143 | b555101c | Thomas Thrainer | cfg["version"] = 0 |
144 | b555101c | Thomas Thrainer | cfg["cluster"]["config_version"] = 0 |
145 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg))
|
146 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
147 | aefbe369 | Michael Hanselmann | |
148 | aefbe369 | Michael Hanselmann | def testInvalidConfig(self): |
149 | aefbe369 | Michael Hanselmann | self._CreateValidConfigDir()
|
150 | aefbe369 | Michael Hanselmann | # Missing version from config
|
151 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson({}))
|
152 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
153 | aefbe369 | Michael Hanselmann | |
154 | cd315ad9 | Bernardo Dal Seno | def _TestUpgradeFromFile(self, filename, dry_run): |
155 | cd315ad9 | Bernardo Dal Seno | cfg = self._LoadTestDataConfig(filename)
|
156 | cd315ad9 | Bernardo Dal Seno | self._TestUpgradeFromData(cfg, dry_run)
|
157 | cd315ad9 | Bernardo Dal Seno | |
158 | 7939f60c | Michael Hanselmann | def _TestSimpleUpgrade(self, from_version, dry_run, |
159 | 7939f60c | Michael Hanselmann | file_storage_dir=None,
|
160 | 7939f60c | Michael Hanselmann | shared_file_storage_dir=None):
|
161 | b555101c | Thomas Thrainer | cfg = GetMinimalConfig() |
162 | b555101c | Thomas Thrainer | cfg["version"] = from_version
|
163 | b555101c | Thomas Thrainer | cluster = cfg["cluster"]
|
164 | 7939f60c | Michael Hanselmann | |
165 | 7939f60c | Michael Hanselmann | if file_storage_dir:
|
166 | 7939f60c | Michael Hanselmann | cluster["file_storage_dir"] = file_storage_dir
|
167 | 7939f60c | Michael Hanselmann | if shared_file_storage_dir:
|
168 | 7939f60c | Michael Hanselmann | cluster["shared_file_storage_dir"] = shared_file_storage_dir
|
169 | 7939f60c | Michael Hanselmann | |
170 | fa166f67 | Bernardo Dal Seno | self._TestUpgradeFromData(cfg, dry_run)
|
171 | fa166f67 | Bernardo Dal Seno | |
172 | fa166f67 | Bernardo Dal Seno | def _TestUpgradeFromData(self, cfg, dry_run): |
173 | fa166f67 | Bernardo Dal Seno | assert "version" in cfg |
174 | fa166f67 | Bernardo Dal Seno | from_version = cfg["version"]
|
175 | aefbe369 | Michael Hanselmann | self._CreateValidConfigDir()
|
176 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg))
|
177 | aefbe369 | Michael Hanselmann | |
178 | aefbe369 | Michael Hanselmann | self.assertFalse(os.path.isfile(self.rapi_cert_path)) |
179 | aefbe369 | Michael Hanselmann | self.assertFalse(os.path.isfile(self.confd_hmac_path)) |
180 | aefbe369 | Michael Hanselmann | self.assertFalse(os.path.isfile(self.cds_path)) |
181 | aefbe369 | Michael Hanselmann | |
182 | aefbe369 | Michael Hanselmann | _RunUpgrade(self.tmpdir, dry_run, True) |
183 | aefbe369 | Michael Hanselmann | |
184 | aefbe369 | Michael Hanselmann | if dry_run:
|
185 | aefbe369 | Michael Hanselmann | expversion = from_version |
186 | aefbe369 | Michael Hanselmann | checkfn = operator.not_ |
187 | aefbe369 | Michael Hanselmann | else:
|
188 | aefbe369 | Michael Hanselmann | expversion = constants.CONFIG_VERSION |
189 | aefbe369 | Michael Hanselmann | checkfn = operator.truth |
190 | aefbe369 | Michael Hanselmann | |
191 | aefbe369 | Michael Hanselmann | self.assert_(checkfn(os.path.isfile(self.rapi_cert_path))) |
192 | aefbe369 | Michael Hanselmann | self.assert_(checkfn(os.path.isfile(self.confd_hmac_path))) |
193 | aefbe369 | Michael Hanselmann | self.assert_(checkfn(os.path.isfile(self.cds_path))) |
194 | aefbe369 | Michael Hanselmann | |
195 | aefbe369 | Michael Hanselmann | newcfg = self._LoadConfig()
|
196 | aefbe369 | Michael Hanselmann | self.assertEqual(newcfg["version"], expversion) |
197 | aefbe369 | Michael Hanselmann | |
198 | fdd9ac5b | Michael Hanselmann | def testRapiUsers(self): |
199 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
200 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
201 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(os.path.dirname(self.rapi_users_path))) |
202 | fdd9ac5b | Michael Hanselmann | |
203 | fdd9ac5b | Michael Hanselmann | utils.WriteFile(self.rapi_users_path_pre24, data="some user\n") |
204 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 3, 0), False) |
205 | fdd9ac5b | Michael Hanselmann | |
206 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isdir(os.path.dirname(self.rapi_users_path))) |
207 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.islink(self.rapi_users_path_pre24)) |
208 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.isfile(self.rapi_users_path)) |
209 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
210 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
211 | fdd9ac5b | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
212 | fdd9ac5b | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "some user\n") |
213 | fdd9ac5b | Michael Hanselmann | |
214 | fdd9ac5b | Michael Hanselmann | def testRapiUsers24AndAbove(self): |
215 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
216 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
217 | fdd9ac5b | Michael Hanselmann | |
218 | fdd9ac5b | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
219 | fdd9ac5b | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="other user\n") |
220 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 3, 0), False) |
221 | fdd9ac5b | Michael Hanselmann | |
222 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.islink(self.rapi_users_path_pre24)) |
223 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.isfile(self.rapi_users_path)) |
224 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
225 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
226 | fdd9ac5b | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
227 | fdd9ac5b | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "other user\n") |
228 | fdd9ac5b | Michael Hanselmann | |
229 | fdd9ac5b | Michael Hanselmann | def testRapiUsersExistingSymlink(self): |
230 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
231 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
232 | fdd9ac5b | Michael Hanselmann | |
233 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
234 | fdd9ac5b | Michael Hanselmann | os.symlink(self.rapi_users_path, self.rapi_users_path_pre24) |
235 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="hello world\n") |
236 | fdd9ac5b | Michael Hanselmann | |
237 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 2, 0), False) |
238 | fdd9ac5b | Michael Hanselmann | |
239 | 87c80992 | Michael Hanselmann | self.assert_(os.path.isfile(self.rapi_users_path) and |
240 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path)) |
241 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.islink(self.rapi_users_path_pre24)) |
242 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
243 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
244 | 87c80992 | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
245 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "hello world\n") |
246 | 87c80992 | Michael Hanselmann | |
247 | 87c80992 | Michael Hanselmann | def testRapiUsersExistingTarget(self): |
248 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
249 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
250 | 87c80992 | Michael Hanselmann | |
251 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
252 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="other user\n") |
253 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path_pre24, data="hello world\n") |
254 | 87c80992 | Michael Hanselmann | |
255 | 87c80992 | Michael Hanselmann | self.assertRaises(Exception, self._TestSimpleUpgrade, |
256 | effc1b86 | Jose A. Lopes | version.BuildVersion(2, 2, 0), False) |
257 | 87c80992 | Michael Hanselmann | |
258 | 87c80992 | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
259 | 87c80992 | Michael Hanselmann | self.assert_(os.path.isfile(path) and not os.path.islink(path)) |
260 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(self.rapi_users_path), "other user\n") |
261 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(self.rapi_users_path_pre24), |
262 | 87c80992 | Michael Hanselmann | "hello world\n")
|
263 | 87c80992 | Michael Hanselmann | |
264 | 87c80992 | Michael Hanselmann | def testRapiUsersDryRun(self): |
265 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
266 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
267 | 87c80992 | Michael Hanselmann | |
268 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path_pre24, data="some user\n") |
269 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 3, 0), True) |
270 | 87c80992 | Michael Hanselmann | |
271 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.isdir(os.path.dirname(self.rapi_users_path))) |
272 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isfile(self.rapi_users_path_pre24) and |
273 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path_pre24)) |
274 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
275 | 87c80992 | Michael Hanselmann | |
276 | 87c80992 | Michael Hanselmann | def testRapiUsers24AndAboveDryRun(self): |
277 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
278 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
279 | 87c80992 | Michael Hanselmann | |
280 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
281 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="other user\n") |
282 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 3, 0), True) |
283 | 87c80992 | Michael Hanselmann | |
284 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isfile(self.rapi_users_path) and |
285 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path)) |
286 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
287 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(self.rapi_users_path), "other user\n") |
288 | 87c80992 | Michael Hanselmann | |
289 | 87c80992 | Michael Hanselmann | def testRapiUsersExistingSymlinkDryRun(self): |
290 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
291 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
292 | 87c80992 | Michael Hanselmann | |
293 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
294 | 87c80992 | Michael Hanselmann | os.symlink(self.rapi_users_path, self.rapi_users_path_pre24) |
295 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="hello world\n") |
296 | 87c80992 | Michael Hanselmann | |
297 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 2, 0), True) |
298 | 87c80992 | Michael Hanselmann | |
299 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.islink(self.rapi_users_path_pre24)) |
300 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isfile(self.rapi_users_path) and |
301 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path)) |
302 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
303 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
304 | fdd9ac5b | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
305 | fdd9ac5b | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "hello world\n") |
306 | fdd9ac5b | Michael Hanselmann | |
307 | 7939f60c | Michael Hanselmann | def testFileStoragePathsDryRun(self): |
308 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
309 | 7939f60c | Michael Hanselmann | |
310 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 6, 0), True, |
311 | 7939f60c | Michael Hanselmann | file_storage_dir=self.tmpdir,
|
312 | 7939f60c | Michael Hanselmann | shared_file_storage_dir="/tmp")
|
313 | 7939f60c | Michael Hanselmann | |
314 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
315 | 7939f60c | Michael Hanselmann | |
316 | 7939f60c | Michael Hanselmann | def testFileStoragePathsBoth(self): |
317 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
318 | 7939f60c | Michael Hanselmann | |
319 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 6, 0), False, |
320 | 7939f60c | Michael Hanselmann | file_storage_dir=self.tmpdir,
|
321 | 7939f60c | Michael Hanselmann | shared_file_storage_dir="/tmp")
|
322 | 7939f60c | Michael Hanselmann | |
323 | 7939f60c | Michael Hanselmann | lines = utils.ReadFile(self.file_storage_paths).splitlines()
|
324 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# ")) |
325 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# cfgupgrade")) |
326 | 7939f60c | Michael Hanselmann | self.assertEqual(lines.pop(0), self.tmpdir) |
327 | 7939f60c | Michael Hanselmann | self.assertEqual(lines.pop(0), "/tmp") |
328 | 7939f60c | Michael Hanselmann | self.assertFalse(lines)
|
329 | 7939f60c | Michael Hanselmann | self.assertEqual(os.stat(self.file_storage_paths).st_mode & 0777, |
330 | 7939f60c | Michael Hanselmann | 0600, msg="Wrong permissions") |
331 | 7939f60c | Michael Hanselmann | |
332 | 7939f60c | Michael Hanselmann | def testFileStoragePathsSharedOnly(self): |
333 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
334 | 7939f60c | Michael Hanselmann | |
335 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 5, 0), False, |
336 | 7939f60c | Michael Hanselmann | file_storage_dir=None,
|
337 | 7939f60c | Michael Hanselmann | shared_file_storage_dir=self.tmpdir)
|
338 | 7939f60c | Michael Hanselmann | |
339 | 7939f60c | Michael Hanselmann | lines = utils.ReadFile(self.file_storage_paths).splitlines()
|
340 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# ")) |
341 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# cfgupgrade")) |
342 | 7939f60c | Michael Hanselmann | self.assertEqual(lines.pop(0), self.tmpdir) |
343 | 7939f60c | Michael Hanselmann | self.assertFalse(lines)
|
344 | 7939f60c | Michael Hanselmann | |
345 | aefbe369 | Michael Hanselmann | def testUpgradeFrom_2_0(self): |
346 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 0, 0), False) |
347 | aefbe369 | Michael Hanselmann | |
348 | aefbe369 | Michael Hanselmann | def testUpgradeFrom_2_1(self): |
349 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 1, 0), False) |
350 | aefbe369 | Michael Hanselmann | |
351 | fdd9ac5b | Michael Hanselmann | def testUpgradeFrom_2_2(self): |
352 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 2, 0), False) |
353 | fdd9ac5b | Michael Hanselmann | |
354 | fdd9ac5b | Michael Hanselmann | def testUpgradeFrom_2_3(self): |
355 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 3, 0), False) |
356 | fdd9ac5b | Michael Hanselmann | |
357 | a91f69c4 | Michael Hanselmann | def testUpgradeFrom_2_4(self): |
358 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 4, 0), False) |
359 | a91f69c4 | Michael Hanselmann | |
360 | 9f604ab8 | Michael Hanselmann | def testUpgradeFrom_2_5(self): |
361 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 5, 0), False) |
362 | 9f604ab8 | Michael Hanselmann | |
363 | 93fd9bb1 | Iustin Pop | def testUpgradeFrom_2_6(self): |
364 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 6, 0), False) |
365 | 93fd9bb1 | Iustin Pop | |
366 | cd315ad9 | Bernardo Dal Seno | def testUpgradeFrom_2_7(self): |
367 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 7, 0), False) |
368 | cd315ad9 | Bernardo Dal Seno | |
369 | cd315ad9 | Bernardo Dal Seno | def testUpgradeFullConfigFrom_2_7(self): |
370 | cd315ad9 | Bernardo Dal Seno | self._TestUpgradeFromFile("cluster_config_2.7.json", False) |
371 | cd315ad9 | Bernardo Dal Seno | |
372 | c294f84e | Bernardo Dal Seno | def testUpgradeFullConfigFrom_2_8(self): |
373 | c294f84e | Bernardo Dal Seno | self._TestUpgradeFromFile("cluster_config_2.8.json", False) |
374 | c294f84e | Bernardo Dal Seno | |
375 | c7a02959 | Thomas Thrainer | def testUpgradeFullConfigFrom_2_9(self): |
376 | c7a02959 | Thomas Thrainer | self._TestUpgradeFromFile("cluster_config_2.9.json", False) |
377 | c7a02959 | Thomas Thrainer | |
378 | aefbe369 | Michael Hanselmann | def testUpgradeCurrent(self): |
379 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) |
380 | aefbe369 | Michael Hanselmann | |
381 | fa166f67 | Bernardo Dal Seno | def _RunDowngradeUpgrade(self): |
382 | 1709435e | Bernardo Dal Seno | oldconf = self._LoadConfig()
|
383 | 1709435e | Bernardo Dal Seno | _RunUpgrade(self.tmpdir, False, True, downgrade=True) |
384 | 1709435e | Bernardo Dal Seno | _RunUpgrade(self.tmpdir, False, True) |
385 | 1709435e | Bernardo Dal Seno | newconf = self._LoadConfig()
|
386 | 1709435e | Bernardo Dal Seno | self.assertEqual(oldconf, newconf)
|
387 | 1709435e | Bernardo Dal Seno | |
388 | fa166f67 | Bernardo Dal Seno | def testDowngrade(self): |
389 | 1709435e | Bernardo Dal Seno | self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) |
390 | fa166f67 | Bernardo Dal Seno | self._RunDowngradeUpgrade()
|
391 | fa166f67 | Bernardo Dal Seno | |
392 | cd315ad9 | Bernardo Dal Seno | def testDowngradeFullConfig(self): |
393 | cd315ad9 | Bernardo Dal Seno | """Test for upgrade + downgrade combination."""
|
394 | cd315ad9 | Bernardo Dal Seno | # This test can work only with the previous version of a configuration!
|
395 | c7a02959 | Thomas Thrainer | oldconfname = "cluster_config_2.10.json"
|
396 | cd315ad9 | Bernardo Dal Seno | self._TestUpgradeFromFile(oldconfname, False) |
397 | cd315ad9 | Bernardo Dal Seno | _RunUpgrade(self.tmpdir, False, True, downgrade=True) |
398 | cd315ad9 | Bernardo Dal Seno | oldconf = self._LoadTestDataConfig(oldconfname)
|
399 | cd315ad9 | Bernardo Dal Seno | newconf = self._LoadConfig()
|
400 | 5275a77f | Thomas Thrainer | |
401 | cd315ad9 | Bernardo Dal Seno | self.assertEqual(oldconf, newconf)
|
402 | cd315ad9 | Bernardo Dal Seno | |
403 | cd315ad9 | Bernardo Dal Seno | def testDowngradeFullConfigBackwardFrom_2_7(self): |
404 | cd315ad9 | Bernardo Dal Seno | """Test for upgrade + downgrade + upgrade combination."""
|
405 | cd315ad9 | Bernardo Dal Seno | self._TestUpgradeFromFile("cluster_config_2.7.json", False) |
406 | cd315ad9 | Bernardo Dal Seno | self._RunDowngradeUpgrade()
|
407 | cd315ad9 | Bernardo Dal Seno | |
408 | fa166f67 | Bernardo Dal Seno | def _RunDowngradeTwice(self): |
409 | fa166f67 | Bernardo Dal Seno | """Make sure that downgrade is idempotent."""
|
410 | 1709435e | Bernardo Dal Seno | _RunUpgrade(self.tmpdir, False, True, downgrade=True) |
411 | 1709435e | Bernardo Dal Seno | oldconf = self._LoadConfig()
|
412 | 1709435e | Bernardo Dal Seno | _RunUpgrade(self.tmpdir, False, True, downgrade=True) |
413 | 1709435e | Bernardo Dal Seno | newconf = self._LoadConfig()
|
414 | 1709435e | Bernardo Dal Seno | self.assertEqual(oldconf, newconf)
|
415 | 1709435e | Bernardo Dal Seno | |
416 | fa166f67 | Bernardo Dal Seno | def testDowngradeTwice(self): |
417 | fa166f67 | Bernardo Dal Seno | self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) |
418 | fa166f67 | Bernardo Dal Seno | self._RunDowngradeTwice()
|
419 | fa166f67 | Bernardo Dal Seno | |
420 | cd315ad9 | Bernardo Dal Seno | def testDowngradeTwiceFullConfigFrom_2_7(self): |
421 | cd315ad9 | Bernardo Dal Seno | self._TestUpgradeFromFile("cluster_config_2.7.json", False) |
422 | cd315ad9 | Bernardo Dal Seno | self._RunDowngradeTwice()
|
423 | cd315ad9 | Bernardo Dal Seno | |
424 | aefbe369 | Michael Hanselmann | def testUpgradeDryRunFrom_2_0(self): |
425 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 0, 0), True) |
426 | aefbe369 | Michael Hanselmann | |
427 | aefbe369 | Michael Hanselmann | def testUpgradeDryRunFrom_2_1(self): |
428 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 1, 0), True) |
429 | aefbe369 | Michael Hanselmann | |
430 | fdd9ac5b | Michael Hanselmann | def testUpgradeDryRunFrom_2_2(self): |
431 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 2, 0), True) |
432 | fdd9ac5b | Michael Hanselmann | |
433 | fdd9ac5b | Michael Hanselmann | def testUpgradeDryRunFrom_2_3(self): |
434 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 3, 0), True) |
435 | fdd9ac5b | Michael Hanselmann | |
436 | a91f69c4 | Michael Hanselmann | def testUpgradeDryRunFrom_2_4(self): |
437 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 4, 0), True) |
438 | a91f69c4 | Michael Hanselmann | |
439 | 9f604ab8 | Michael Hanselmann | def testUpgradeDryRunFrom_2_5(self): |
440 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 5, 0), True) |
441 | 9f604ab8 | Michael Hanselmann | |
442 | 93fd9bb1 | Iustin Pop | def testUpgradeDryRunFrom_2_6(self): |
443 | effc1b86 | Jose A. Lopes | self._TestSimpleUpgrade(version.BuildVersion(2, 6, 0), True) |
444 | 93fd9bb1 | Iustin Pop | |
445 | aefbe369 | Michael Hanselmann | def testUpgradeCurrentDryRun(self): |
446 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.CONFIG_VERSION, True) |
447 | aefbe369 | Michael Hanselmann | |
448 | 1709435e | Bernardo Dal Seno | def testDowngradeDryRun(self): |
449 | 1709435e | Bernardo Dal Seno | self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) |
450 | 1709435e | Bernardo Dal Seno | oldconf = self._LoadConfig()
|
451 | 1709435e | Bernardo Dal Seno | _RunUpgrade(self.tmpdir, True, True, downgrade=True) |
452 | 1709435e | Bernardo Dal Seno | newconf = self._LoadConfig()
|
453 | 1709435e | Bernardo Dal Seno | self.assertEqual(oldconf["version"], newconf["version"]) |
454 | aefbe369 | Michael Hanselmann | |
455 | aefbe369 | Michael Hanselmann | if __name__ == "__main__": |
456 | aefbe369 | Michael Hanselmann | testutils.GanetiTestProgram() |