root / test / py / cfgupgrade_unittest.py @ ea2bcb82
History | View | Annotate | Download (13.9 kB)
1 | aefbe369 | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | aefbe369 | Michael Hanselmann | #
|
3 | aefbe369 | Michael Hanselmann | |
4 | 93fd9bb1 | Iustin Pop | # Copyright (C) 2010, 2012 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 | 011974df | Michael Hanselmann | def _RunUpgrade(path, dry_run, no_verify, ignore_hostname=True): |
41 | aefbe369 | Michael Hanselmann | cmd = [sys.executable, "%s/tools/cfgupgrade" % testutils.GetSourceDir(),
|
42 | 7939f60c | Michael Hanselmann | "--debug", "--force", "--path=%s" % path, "--confdir=%s" % path] |
43 | 011974df | Michael Hanselmann | |
44 | 011974df | Michael Hanselmann | if ignore_hostname:
|
45 | 011974df | Michael Hanselmann | cmd.append("--ignore-hostname")
|
46 | aefbe369 | Michael Hanselmann | if dry_run:
|
47 | aefbe369 | Michael Hanselmann | cmd.append("--dry-run")
|
48 | aefbe369 | Michael Hanselmann | if no_verify:
|
49 | aefbe369 | Michael Hanselmann | cmd.append("--no-verify")
|
50 | aefbe369 | Michael Hanselmann | |
51 | aefbe369 | Michael Hanselmann | result = utils.RunCmd(cmd, cwd=os.getcwd()) |
52 | aefbe369 | Michael Hanselmann | if result.failed:
|
53 | aefbe369 | Michael Hanselmann | raise Exception("cfgupgrade failed: %s, output %r" % |
54 | aefbe369 | Michael Hanselmann | (result.fail_reason, result.output)) |
55 | aefbe369 | Michael Hanselmann | |
56 | aefbe369 | Michael Hanselmann | |
57 | aefbe369 | Michael Hanselmann | class TestCfgupgrade(unittest.TestCase): |
58 | aefbe369 | Michael Hanselmann | def setUp(self): |
59 | aefbe369 | Michael Hanselmann | self.tmpdir = tempfile.mkdtemp()
|
60 | aefbe369 | Michael Hanselmann | |
61 | aefbe369 | Michael Hanselmann | self.config_path = utils.PathJoin(self.tmpdir, "config.data") |
62 | aefbe369 | Michael Hanselmann | self.noded_cert_path = utils.PathJoin(self.tmpdir, "server.pem") |
63 | aefbe369 | Michael Hanselmann | self.rapi_cert_path = utils.PathJoin(self.tmpdir, "rapi.pem") |
64 | fdd9ac5b | Michael Hanselmann | self.rapi_users_path = utils.PathJoin(self.tmpdir, "rapi", "users") |
65 | fdd9ac5b | Michael Hanselmann | self.rapi_users_path_pre24 = utils.PathJoin(self.tmpdir, "rapi_users") |
66 | aefbe369 | Michael Hanselmann | self.known_hosts_path = utils.PathJoin(self.tmpdir, "known_hosts") |
67 | aefbe369 | Michael Hanselmann | self.confd_hmac_path = utils.PathJoin(self.tmpdir, "hmac.key") |
68 | aefbe369 | Michael Hanselmann | self.cds_path = utils.PathJoin(self.tmpdir, "cluster-domain-secret") |
69 | 011974df | Michael Hanselmann | self.ss_master_node_path = utils.PathJoin(self.tmpdir, "ssconf_master_node") |
70 | 7939f60c | Michael Hanselmann | self.file_storage_paths = utils.PathJoin(self.tmpdir, "file-storage-paths") |
71 | aefbe369 | Michael Hanselmann | |
72 | aefbe369 | Michael Hanselmann | def tearDown(self): |
73 | aefbe369 | Michael Hanselmann | shutil.rmtree(self.tmpdir)
|
74 | aefbe369 | Michael Hanselmann | |
75 | aefbe369 | Michael Hanselmann | def _LoadConfig(self): |
76 | aefbe369 | Michael Hanselmann | return serializer.LoadJson(utils.ReadFile(self.config_path)) |
77 | aefbe369 | Michael Hanselmann | |
78 | aefbe369 | Michael Hanselmann | def _CreateValidConfigDir(self): |
79 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.noded_cert_path, data="") |
80 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.known_hosts_path, data="") |
81 | 011974df | Michael Hanselmann | utils.WriteFile(self.ss_master_node_path,
|
82 | 011974df | Michael Hanselmann | data="node.has.another.name.example.net")
|
83 | aefbe369 | Michael Hanselmann | |
84 | aefbe369 | Michael Hanselmann | def testNoConfigDir(self): |
85 | aefbe369 | Michael Hanselmann | self.assertFalse(utils.ListVisibleFiles(self.tmpdir)) |
86 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
87 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, True, True) |
88 | aefbe369 | Michael Hanselmann | |
89 | 011974df | Michael Hanselmann | def testWrongHostname(self): |
90 | 011974df | Michael Hanselmann | self._CreateValidConfigDir()
|
91 | 011974df | Michael Hanselmann | |
92 | 011974df | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson({
|
93 | 011974df | Michael Hanselmann | "version": constants.CONFIG_VERSION,
|
94 | 011974df | Michael Hanselmann | "cluster": {},
|
95 | a19d8cd5 | Iustin Pop | "instances": {},
|
96 | 6e8091f9 | Dimitris Aragiorgis | "nodegroups": {},
|
97 | 011974df | Michael Hanselmann | })) |
98 | 011974df | Michael Hanselmann | |
99 | 011974df | Michael Hanselmann | hostname = netutils.GetHostname().name |
100 | 011974df | Michael Hanselmann | assert hostname != utils.ReadOneLineFile(self.ss_master_node_path) |
101 | 011974df | Michael Hanselmann | |
102 | 011974df | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True, |
103 | 011974df | Michael Hanselmann | ignore_hostname=False)
|
104 | 011974df | Michael Hanselmann | |
105 | 011974df | Michael Hanselmann | def testCorrectHostname(self): |
106 | 011974df | Michael Hanselmann | self._CreateValidConfigDir()
|
107 | 011974df | Michael Hanselmann | |
108 | 011974df | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson({
|
109 | 011974df | Michael Hanselmann | "version": constants.CONFIG_VERSION,
|
110 | 011974df | Michael Hanselmann | "cluster": {},
|
111 | a19d8cd5 | Iustin Pop | "instances": {},
|
112 | 6e8091f9 | Dimitris Aragiorgis | "nodegroups": {},
|
113 | 011974df | Michael Hanselmann | })) |
114 | 011974df | Michael Hanselmann | |
115 | 011974df | Michael Hanselmann | utils.WriteFile(self.ss_master_node_path,
|
116 | 011974df | Michael Hanselmann | data="%s\n" % netutils.GetHostname().name)
|
117 | 011974df | Michael Hanselmann | |
118 | 011974df | Michael Hanselmann | _RunUpgrade(self.tmpdir, False, True, ignore_hostname=False) |
119 | 011974df | Michael Hanselmann | |
120 | aefbe369 | Michael Hanselmann | def testInconsistentConfig(self): |
121 | aefbe369 | Michael Hanselmann | self._CreateValidConfigDir()
|
122 | aefbe369 | Michael Hanselmann | # There should be no "config_version"
|
123 | aefbe369 | Michael Hanselmann | cfg = { |
124 | aefbe369 | Michael Hanselmann | "version": 0, |
125 | aefbe369 | Michael Hanselmann | "cluster": {
|
126 | aefbe369 | Michael Hanselmann | "config_version": 0, |
127 | aefbe369 | Michael Hanselmann | }, |
128 | a19d8cd5 | Iustin Pop | "instances": {},
|
129 | 6e8091f9 | Dimitris Aragiorgis | "nodegroups": {},
|
130 | aefbe369 | Michael Hanselmann | } |
131 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg))
|
132 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
133 | aefbe369 | Michael Hanselmann | |
134 | aefbe369 | Michael Hanselmann | def testInvalidConfig(self): |
135 | aefbe369 | Michael Hanselmann | self._CreateValidConfigDir()
|
136 | aefbe369 | Michael Hanselmann | # Missing version from config
|
137 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson({}))
|
138 | aefbe369 | Michael Hanselmann | self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
139 | aefbe369 | Michael Hanselmann | |
140 | 7939f60c | Michael Hanselmann | def _TestSimpleUpgrade(self, from_version, dry_run, |
141 | 7939f60c | Michael Hanselmann | file_storage_dir=None,
|
142 | 7939f60c | Michael Hanselmann | shared_file_storage_dir=None):
|
143 | 7939f60c | Michael Hanselmann | cluster = {} |
144 | 7939f60c | Michael Hanselmann | |
145 | 7939f60c | Michael Hanselmann | if file_storage_dir:
|
146 | 7939f60c | Michael Hanselmann | cluster["file_storage_dir"] = file_storage_dir
|
147 | 7939f60c | Michael Hanselmann | if shared_file_storage_dir:
|
148 | 7939f60c | Michael Hanselmann | cluster["shared_file_storage_dir"] = shared_file_storage_dir
|
149 | 7939f60c | Michael Hanselmann | |
150 | aefbe369 | Michael Hanselmann | cfg = { |
151 | aefbe369 | Michael Hanselmann | "version": from_version,
|
152 | 7939f60c | Michael Hanselmann | "cluster": cluster,
|
153 | a19d8cd5 | Iustin Pop | "instances": {},
|
154 | 6e8091f9 | Dimitris Aragiorgis | "nodegroups": {},
|
155 | aefbe369 | Michael Hanselmann | } |
156 | aefbe369 | Michael Hanselmann | self._CreateValidConfigDir()
|
157 | aefbe369 | Michael Hanselmann | utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg))
|
158 | aefbe369 | Michael Hanselmann | |
159 | aefbe369 | Michael Hanselmann | self.assertFalse(os.path.isfile(self.rapi_cert_path)) |
160 | aefbe369 | Michael Hanselmann | self.assertFalse(os.path.isfile(self.confd_hmac_path)) |
161 | aefbe369 | Michael Hanselmann | self.assertFalse(os.path.isfile(self.cds_path)) |
162 | aefbe369 | Michael Hanselmann | |
163 | aefbe369 | Michael Hanselmann | _RunUpgrade(self.tmpdir, dry_run, True) |
164 | aefbe369 | Michael Hanselmann | |
165 | aefbe369 | Michael Hanselmann | if dry_run:
|
166 | aefbe369 | Michael Hanselmann | expversion = from_version |
167 | aefbe369 | Michael Hanselmann | checkfn = operator.not_ |
168 | aefbe369 | Michael Hanselmann | else:
|
169 | aefbe369 | Michael Hanselmann | expversion = constants.CONFIG_VERSION |
170 | aefbe369 | Michael Hanselmann | checkfn = operator.truth |
171 | aefbe369 | Michael Hanselmann | |
172 | aefbe369 | Michael Hanselmann | self.assert_(checkfn(os.path.isfile(self.rapi_cert_path))) |
173 | aefbe369 | Michael Hanselmann | self.assert_(checkfn(os.path.isfile(self.confd_hmac_path))) |
174 | aefbe369 | Michael Hanselmann | self.assert_(checkfn(os.path.isfile(self.cds_path))) |
175 | aefbe369 | Michael Hanselmann | |
176 | aefbe369 | Michael Hanselmann | newcfg = self._LoadConfig()
|
177 | aefbe369 | Michael Hanselmann | self.assertEqual(newcfg["version"], expversion) |
178 | aefbe369 | Michael Hanselmann | |
179 | fdd9ac5b | Michael Hanselmann | def testRapiUsers(self): |
180 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
181 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
182 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(os.path.dirname(self.rapi_users_path))) |
183 | fdd9ac5b | Michael Hanselmann | |
184 | fdd9ac5b | Michael Hanselmann | utils.WriteFile(self.rapi_users_path_pre24, data="some user\n") |
185 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 3, 0), False) |
186 | fdd9ac5b | Michael Hanselmann | |
187 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isdir(os.path.dirname(self.rapi_users_path))) |
188 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.islink(self.rapi_users_path_pre24)) |
189 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.isfile(self.rapi_users_path)) |
190 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
191 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
192 | fdd9ac5b | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
193 | fdd9ac5b | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "some user\n") |
194 | fdd9ac5b | Michael Hanselmann | |
195 | fdd9ac5b | Michael Hanselmann | def testRapiUsers24AndAbove(self): |
196 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
197 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
198 | fdd9ac5b | Michael Hanselmann | |
199 | fdd9ac5b | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
200 | fdd9ac5b | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="other user\n") |
201 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 3, 0), False) |
202 | fdd9ac5b | Michael Hanselmann | |
203 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.islink(self.rapi_users_path_pre24)) |
204 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.isfile(self.rapi_users_path)) |
205 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
206 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
207 | fdd9ac5b | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
208 | fdd9ac5b | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "other user\n") |
209 | fdd9ac5b | Michael Hanselmann | |
210 | fdd9ac5b | Michael Hanselmann | def testRapiUsersExistingSymlink(self): |
211 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
212 | fdd9ac5b | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
213 | fdd9ac5b | Michael Hanselmann | |
214 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
215 | fdd9ac5b | Michael Hanselmann | os.symlink(self.rapi_users_path, self.rapi_users_path_pre24) |
216 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="hello world\n") |
217 | fdd9ac5b | Michael Hanselmann | |
218 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 2, 0), False) |
219 | fdd9ac5b | Michael Hanselmann | |
220 | 87c80992 | Michael Hanselmann | self.assert_(os.path.isfile(self.rapi_users_path) and |
221 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path)) |
222 | fdd9ac5b | Michael Hanselmann | self.assert_(os.path.islink(self.rapi_users_path_pre24)) |
223 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
224 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
225 | 87c80992 | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
226 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "hello world\n") |
227 | 87c80992 | Michael Hanselmann | |
228 | 87c80992 | Michael Hanselmann | def testRapiUsersExistingTarget(self): |
229 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
230 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
231 | 87c80992 | Michael Hanselmann | |
232 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
233 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="other user\n") |
234 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path_pre24, data="hello world\n") |
235 | 87c80992 | Michael Hanselmann | |
236 | 87c80992 | Michael Hanselmann | self.assertRaises(Exception, self._TestSimpleUpgrade, |
237 | 87c80992 | Michael Hanselmann | constants.BuildVersion(2, 2, 0), False) |
238 | 87c80992 | Michael Hanselmann | |
239 | 87c80992 | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
240 | 87c80992 | Michael Hanselmann | self.assert_(os.path.isfile(path) and not os.path.islink(path)) |
241 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(self.rapi_users_path), "other user\n") |
242 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(self.rapi_users_path_pre24), |
243 | 87c80992 | Michael Hanselmann | "hello world\n")
|
244 | 87c80992 | Michael Hanselmann | |
245 | 87c80992 | Michael Hanselmann | def testRapiUsersDryRun(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 | utils.WriteFile(self.rapi_users_path_pre24, data="some user\n") |
250 | 87c80992 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 3, 0), True) |
251 | 87c80992 | Michael Hanselmann | |
252 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.isdir(os.path.dirname(self.rapi_users_path))) |
253 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isfile(self.rapi_users_path_pre24) and |
254 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path_pre24)) |
255 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
256 | 87c80992 | Michael Hanselmann | |
257 | 87c80992 | Michael Hanselmann | def testRapiUsers24AndAboveDryRun(self): |
258 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
259 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
260 | 87c80992 | Michael Hanselmann | |
261 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
262 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="other user\n") |
263 | 87c80992 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 3, 0), True) |
264 | 87c80992 | Michael Hanselmann | |
265 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isfile(self.rapi_users_path) and |
266 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path)) |
267 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
268 | 87c80992 | Michael Hanselmann | self.assertEqual(utils.ReadFile(self.rapi_users_path), "other user\n") |
269 | 87c80992 | Michael Hanselmann | |
270 | 87c80992 | Michael Hanselmann | def testRapiUsersExistingSymlinkDryRun(self): |
271 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path)) |
272 | 87c80992 | Michael Hanselmann | self.assertFalse(os.path.exists(self.rapi_users_path_pre24)) |
273 | 87c80992 | Michael Hanselmann | |
274 | 87c80992 | Michael Hanselmann | os.mkdir(os.path.dirname(self.rapi_users_path))
|
275 | 87c80992 | Michael Hanselmann | os.symlink(self.rapi_users_path, self.rapi_users_path_pre24) |
276 | 87c80992 | Michael Hanselmann | utils.WriteFile(self.rapi_users_path, data="hello world\n") |
277 | 87c80992 | Michael Hanselmann | |
278 | 87c80992 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 2, 0), True) |
279 | 87c80992 | Michael Hanselmann | |
280 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.islink(self.rapi_users_path_pre24)) |
281 | 87c80992 | Michael Hanselmann | self.assertTrue(os.path.isfile(self.rapi_users_path) and |
282 | 87c80992 | Michael Hanselmann | not os.path.islink(self.rapi_users_path)) |
283 | 87c80992 | Michael Hanselmann | self.assertEqual(os.readlink(self.rapi_users_path_pre24), |
284 | 87c80992 | Michael Hanselmann | self.rapi_users_path)
|
285 | fdd9ac5b | Michael Hanselmann | for path in [self.rapi_users_path, self.rapi_users_path_pre24]: |
286 | fdd9ac5b | Michael Hanselmann | self.assertEqual(utils.ReadFile(path), "hello world\n") |
287 | fdd9ac5b | Michael Hanselmann | |
288 | 7939f60c | Michael Hanselmann | def testFileStoragePathsDryRun(self): |
289 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
290 | 7939f60c | Michael Hanselmann | |
291 | 7939f60c | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 6, 0), True, |
292 | 7939f60c | Michael Hanselmann | file_storage_dir=self.tmpdir,
|
293 | 7939f60c | Michael Hanselmann | shared_file_storage_dir="/tmp")
|
294 | 7939f60c | Michael Hanselmann | |
295 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
296 | 7939f60c | Michael Hanselmann | |
297 | 7939f60c | Michael Hanselmann | def testFileStoragePathsBoth(self): |
298 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
299 | 7939f60c | Michael Hanselmann | |
300 | 7939f60c | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 6, 0), False, |
301 | 7939f60c | Michael Hanselmann | file_storage_dir=self.tmpdir,
|
302 | 7939f60c | Michael Hanselmann | shared_file_storage_dir="/tmp")
|
303 | 7939f60c | Michael Hanselmann | |
304 | 7939f60c | Michael Hanselmann | lines = utils.ReadFile(self.file_storage_paths).splitlines()
|
305 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# ")) |
306 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# cfgupgrade")) |
307 | 7939f60c | Michael Hanselmann | self.assertEqual(lines.pop(0), self.tmpdir) |
308 | 7939f60c | Michael Hanselmann | self.assertEqual(lines.pop(0), "/tmp") |
309 | 7939f60c | Michael Hanselmann | self.assertFalse(lines)
|
310 | 7939f60c | Michael Hanselmann | self.assertEqual(os.stat(self.file_storage_paths).st_mode & 0777, |
311 | 7939f60c | Michael Hanselmann | 0600, msg="Wrong permissions") |
312 | 7939f60c | Michael Hanselmann | |
313 | 7939f60c | Michael Hanselmann | def testFileStoragePathsSharedOnly(self): |
314 | 7939f60c | Michael Hanselmann | self.assertFalse(os.path.exists(self.file_storage_paths)) |
315 | 7939f60c | Michael Hanselmann | |
316 | 7939f60c | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 5, 0), False, |
317 | 7939f60c | Michael Hanselmann | file_storage_dir=None,
|
318 | 7939f60c | Michael Hanselmann | shared_file_storage_dir=self.tmpdir)
|
319 | 7939f60c | Michael Hanselmann | |
320 | 7939f60c | Michael Hanselmann | lines = utils.ReadFile(self.file_storage_paths).splitlines()
|
321 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# ")) |
322 | 7939f60c | Michael Hanselmann | self.assertTrue(lines.pop(0).startswith("# cfgupgrade")) |
323 | 7939f60c | Michael Hanselmann | self.assertEqual(lines.pop(0), self.tmpdir) |
324 | 7939f60c | Michael Hanselmann | self.assertFalse(lines)
|
325 | 7939f60c | Michael Hanselmann | |
326 | aefbe369 | Michael Hanselmann | def testUpgradeFrom_2_0(self): |
327 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 0, 0), False) |
328 | aefbe369 | Michael Hanselmann | |
329 | aefbe369 | Michael Hanselmann | def testUpgradeFrom_2_1(self): |
330 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 1, 0), False) |
331 | aefbe369 | Michael Hanselmann | |
332 | fdd9ac5b | Michael Hanselmann | def testUpgradeFrom_2_2(self): |
333 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 2, 0), False) |
334 | fdd9ac5b | Michael Hanselmann | |
335 | fdd9ac5b | Michael Hanselmann | def testUpgradeFrom_2_3(self): |
336 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 3, 0), False) |
337 | fdd9ac5b | Michael Hanselmann | |
338 | a91f69c4 | Michael Hanselmann | def testUpgradeFrom_2_4(self): |
339 | a91f69c4 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 4, 0), False) |
340 | a91f69c4 | Michael Hanselmann | |
341 | 9f604ab8 | Michael Hanselmann | def testUpgradeFrom_2_5(self): |
342 | 9f604ab8 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 5, 0), False) |
343 | 9f604ab8 | Michael Hanselmann | |
344 | 93fd9bb1 | Iustin Pop | def testUpgradeFrom_2_6(self): |
345 | 93fd9bb1 | Iustin Pop | self._TestSimpleUpgrade(constants.BuildVersion(2, 6, 0), False) |
346 | 93fd9bb1 | Iustin Pop | |
347 | aefbe369 | Michael Hanselmann | def testUpgradeCurrent(self): |
348 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) |
349 | aefbe369 | Michael Hanselmann | |
350 | aefbe369 | Michael Hanselmann | def testUpgradeDryRunFrom_2_0(self): |
351 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 0, 0), True) |
352 | aefbe369 | Michael Hanselmann | |
353 | aefbe369 | Michael Hanselmann | def testUpgradeDryRunFrom_2_1(self): |
354 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 1, 0), True) |
355 | aefbe369 | Michael Hanselmann | |
356 | fdd9ac5b | Michael Hanselmann | def testUpgradeDryRunFrom_2_2(self): |
357 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 2, 0), True) |
358 | fdd9ac5b | Michael Hanselmann | |
359 | fdd9ac5b | Michael Hanselmann | def testUpgradeDryRunFrom_2_3(self): |
360 | fdd9ac5b | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 3, 0), True) |
361 | fdd9ac5b | Michael Hanselmann | |
362 | a91f69c4 | Michael Hanselmann | def testUpgradeDryRunFrom_2_4(self): |
363 | a91f69c4 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 4, 0), True) |
364 | a91f69c4 | Michael Hanselmann | |
365 | 9f604ab8 | Michael Hanselmann | def testUpgradeDryRunFrom_2_5(self): |
366 | 9f604ab8 | Michael Hanselmann | self._TestSimpleUpgrade(constants.BuildVersion(2, 5, 0), True) |
367 | 9f604ab8 | Michael Hanselmann | |
368 | 93fd9bb1 | Iustin Pop | def testUpgradeDryRunFrom_2_6(self): |
369 | 93fd9bb1 | Iustin Pop | self._TestSimpleUpgrade(constants.BuildVersion(2, 6, 0), True) |
370 | 93fd9bb1 | Iustin Pop | |
371 | aefbe369 | Michael Hanselmann | def testUpgradeCurrentDryRun(self): |
372 | aefbe369 | Michael Hanselmann | self._TestSimpleUpgrade(constants.CONFIG_VERSION, True) |
373 | aefbe369 | Michael Hanselmann | |
374 | aefbe369 | Michael Hanselmann | |
375 | aefbe369 | Michael Hanselmann | if __name__ == "__main__": |
376 | aefbe369 | Michael Hanselmann | testutils.GanetiTestProgram() |