Revision b555101c
b/test/py/cfgupgrade_unittest.py | ||
---|---|---|
37 | 37 |
import testutils |
38 | 38 |
|
39 | 39 |
|
40 |
def GetMinimalConfig(): |
|
41 |
return { |
|
42 |
"version": constants.CONFIG_VERSION, |
|
43 |
"cluster": { |
|
44 |
"master_node": "node1-uuid" |
|
45 |
}, |
|
46 |
"instances": {}, |
|
47 |
"nodegroups": {}, |
|
48 |
"nodes": { |
|
49 |
"node1-uuid": { |
|
50 |
"name": "node1", |
|
51 |
"uuid": "node1-uuid" |
|
52 |
} |
|
53 |
}, |
|
54 |
} |
|
55 |
|
|
56 |
|
|
40 | 57 |
def _RunUpgrade(path, dry_run, no_verify, ignore_hostname=True, |
41 | 58 |
downgrade=False): |
42 | 59 |
cmd = [sys.executable, "%s/tools/cfgupgrade" % testutils.GetSourceDir(), |
... | ... | |
95 | 112 |
def testWrongHostname(self): |
96 | 113 |
self._CreateValidConfigDir() |
97 | 114 |
|
98 |
utils.WriteFile(self.config_path, data=serializer.DumpJson({ |
|
99 |
"version": constants.CONFIG_VERSION, |
|
100 |
"cluster": {}, |
|
101 |
"instances": {}, |
|
102 |
"nodegroups": {}, |
|
103 |
})) |
|
115 |
utils.WriteFile(self.config_path, |
|
116 |
data=serializer.DumpJson(GetMinimalConfig())) |
|
104 | 117 |
|
105 | 118 |
hostname = netutils.GetHostname().name |
106 | 119 |
assert hostname != utils.ReadOneLineFile(self.ss_master_node_path) |
... | ... | |
111 | 124 |
def testCorrectHostname(self): |
112 | 125 |
self._CreateValidConfigDir() |
113 | 126 |
|
114 |
utils.WriteFile(self.config_path, data=serializer.DumpJson({ |
|
115 |
"version": constants.CONFIG_VERSION, |
|
116 |
"cluster": {}, |
|
117 |
"instances": {}, |
|
118 |
"nodegroups": {}, |
|
119 |
})) |
|
127 |
utils.WriteFile(self.config_path, |
|
128 |
data=serializer.DumpJson(GetMinimalConfig())) |
|
120 | 129 |
|
121 | 130 |
utils.WriteFile(self.ss_master_node_path, |
122 | 131 |
data="%s\n" % netutils.GetHostname().name) |
... | ... | |
126 | 135 |
def testInconsistentConfig(self): |
127 | 136 |
self._CreateValidConfigDir() |
128 | 137 |
# There should be no "config_version" |
129 |
cfg = { |
|
130 |
"version": 0, |
|
131 |
"cluster": { |
|
132 |
"config_version": 0, |
|
133 |
}, |
|
134 |
"instances": {}, |
|
135 |
"nodegroups": {}, |
|
136 |
} |
|
138 |
cfg = GetMinimalConfig() |
|
139 |
cfg["version"] = 0 |
|
140 |
cfg["cluster"]["config_version"] = 0 |
|
137 | 141 |
utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg)) |
138 | 142 |
self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True) |
139 | 143 |
|
... | ... | |
150 | 154 |
def _TestSimpleUpgrade(self, from_version, dry_run, |
151 | 155 |
file_storage_dir=None, |
152 | 156 |
shared_file_storage_dir=None): |
153 |
cluster = {} |
|
157 |
cfg = GetMinimalConfig() |
|
158 |
cfg["version"] = from_version |
|
159 |
cluster = cfg["cluster"] |
|
154 | 160 |
|
155 | 161 |
if file_storage_dir: |
156 | 162 |
cluster["file_storage_dir"] = file_storage_dir |
157 | 163 |
if shared_file_storage_dir: |
158 | 164 |
cluster["shared_file_storage_dir"] = shared_file_storage_dir |
159 | 165 |
|
160 |
cfg = { |
|
161 |
"version": from_version, |
|
162 |
"cluster": cluster, |
|
163 |
"instances": {}, |
|
164 |
"nodegroups": {}, |
|
165 |
} |
|
166 | 166 |
self._TestUpgradeFromData(cfg, dry_run) |
167 | 167 |
|
168 | 168 |
def _TestUpgradeFromData(self, cfg, dry_run): |
b/tools/cfgupgrade | ||
---|---|---|
278 | 278 |
backup=True) |
279 | 279 |
|
280 | 280 |
|
281 |
def GetNewNodeIndex(nodes_by_old_key, old_key, new_key_field): |
|
282 |
if old_key not in nodes_by_old_key: |
|
283 |
logging.warning("Can't find node '%s' in configuration, assuming that it's" |
|
284 |
" already up-to-date", old_key) |
|
285 |
return old_key |
|
286 |
return nodes_by_old_key[old_key][new_key_field] |
|
287 |
|
|
288 |
|
|
289 |
def ChangeNodeIndices(config_data, old_key_field, new_key_field): |
|
290 |
def ChangeDiskNodeIndices(disk): |
|
291 |
if disk["dev_type"] in constants.LDS_DRBD: |
|
292 |
for i in range(0, 2): |
|
293 |
disk["logical_id"][i] = GetNewNodeIndex(nodes_by_old_key, |
|
294 |
disk["logical_id"][i], |
|
295 |
new_key_field) |
|
296 |
if "children" in disk: |
|
297 |
for child in disk["children"]: |
|
298 |
ChangeDiskNodeIndices(child) |
|
299 |
|
|
300 |
nodes_by_old_key = {} |
|
301 |
nodes_by_new_key = {} |
|
302 |
for (_, node) in config_data["nodes"].items(): |
|
303 |
nodes_by_old_key[node[old_key_field]] = node |
|
304 |
nodes_by_new_key[node[new_key_field]] = node |
|
305 |
|
|
306 |
config_data["nodes"] = nodes_by_new_key |
|
307 |
|
|
308 |
cluster = config_data["cluster"] |
|
309 |
cluster["master_node"] = GetNewNodeIndex(nodes_by_old_key, |
|
310 |
cluster["master_node"], |
|
311 |
new_key_field) |
|
312 |
|
|
313 |
for inst in config_data["instances"].values(): |
|
314 |
inst["primary_node"] = GetNewNodeIndex(nodes_by_old_key, |
|
315 |
inst["primary_node"], |
|
316 |
new_key_field) |
|
317 |
for disk in inst["disks"]: |
|
318 |
ChangeDiskNodeIndices(disk) |
|
319 |
|
|
320 |
|
|
321 |
def UpgradeNodeIndices(config_data): |
|
322 |
ChangeNodeIndices(config_data, "name", "uuid") |
|
323 |
|
|
324 |
|
|
281 | 325 |
def UpgradeAll(config_data): |
282 | 326 |
config_data["version"] = constants.BuildVersion(TARGET_MAJOR, |
283 | 327 |
TARGET_MINOR, 0) |
... | ... | |
288 | 332 |
UpgradeCluster(config_data) |
289 | 333 |
UpgradeGroups(config_data) |
290 | 334 |
UpgradeInstances(config_data) |
335 |
UpgradeNodeIndices(config_data) |
|
291 | 336 |
|
292 | 337 |
|
293 | 338 |
def DowngradeDisks(disks, owner): |
... | ... | |
309 | 354 |
DowngradeDisks(iobj["disks"], iname) |
310 | 355 |
|
311 | 356 |
|
357 |
def DowngradeNodeIndices(config_data): |
|
358 |
ChangeNodeIndices(config_data, "uuid", "name") |
|
359 |
|
|
360 |
|
|
312 | 361 |
def DowngradeAll(config_data): |
313 | 362 |
# Any code specific to a particular version should be labeled that way, so |
314 | 363 |
# it can be removed when updating to the next version. |
315 | 364 |
DowngradeInstances(config_data) |
365 |
DowngradeNodeIndices(config_data) |
|
316 | 366 |
|
317 | 367 |
|
318 | 368 |
def main(): |
Also available in: Unified diff