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