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