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