Revision def6577f
b/lib/config.py | ||
---|---|---|
1805 | 1805 |
for node_name in nodes_fn(inst) |
1806 | 1806 |
if self._UnlockedGetNodeInfo(node_name).group == uuid) |
1807 | 1807 |
|
1808 |
def _UnlockedGetHvparamsString(self, hvname): |
|
1809 |
"""Return the string representation of the list of hyervisor parameters of |
|
1810 |
the given hypervisor. |
|
1811 |
|
|
1812 |
@see: C{GetHvparams} |
|
1813 |
|
|
1814 |
""" |
|
1815 |
result = "" |
|
1816 |
hvparams = self._config_data.cluster.hvparams[hvname] |
|
1817 |
for key in hvparams: |
|
1818 |
result += "%s=%s\n" % (key, hvparams[key]) |
|
1819 |
return result |
|
1820 |
|
|
1821 |
@locking.ssynchronized(_config_lock, shared=1) |
|
1822 |
def GetHvparamsString(self, hvname): |
|
1823 |
"""Return the hypervisor parameters of the given hypervisor. |
|
1824 |
|
|
1825 |
@type hvname: string |
|
1826 |
@param hvname: name of a hypervisor |
|
1827 |
@rtype: string |
|
1828 |
@return: string containing key-value-pairs, one pair on each line; |
|
1829 |
format: KEY=VALUE |
|
1830 |
|
|
1831 |
""" |
|
1832 |
return self._UnlockedGetHvparamsString(hvname) |
|
1833 |
|
|
1808 | 1834 |
def _UnlockedGetNodeList(self): |
1809 | 1835 |
"""Return the list of nodes which are in the configuration. |
1810 | 1836 |
|
... | ... | |
2282 | 2308 |
|
2283 | 2309 |
self._last_cluster_serial = self._config_data.cluster.serial_no |
2284 | 2310 |
|
2311 |
def _GetAllHvparamsStrings(self, hypervisors): |
|
2312 |
"""Get the hvparams of all given hypervisors from the config. |
|
2313 |
|
|
2314 |
@type hypervisors: list of string |
|
2315 |
@param hypervisors: list of hypervisor names |
|
2316 |
@rtype: dict of strings |
|
2317 |
@returns: dictionary mapping the hypervisor name to a string representation |
|
2318 |
of the hypervisor's hvparams |
|
2319 |
|
|
2320 |
""" |
|
2321 |
hvparams = {} |
|
2322 |
for hv in hypervisors: |
|
2323 |
hvparams[hv] = self._UnlockedGetHvparamsString(hv) |
|
2324 |
return hvparams |
|
2325 |
|
|
2326 |
@staticmethod |
|
2327 |
def _ExtendByAllHvparamsStrings(ssconf_values, all_hvparams): |
|
2328 |
"""Extends the ssconf_values dictionary by hvparams. |
|
2329 |
|
|
2330 |
@type ssconf_values: dict of strings |
|
2331 |
@param ssconf_values: dictionary mapping ssconf_keys to strings |
|
2332 |
representing the content of ssconf files |
|
2333 |
@type all_hvparams: dict of strings |
|
2334 |
@param all_hvparams: dictionary mapping hypervisor names to a string |
|
2335 |
representation of their hvparams |
|
2336 |
@rtype: same as ssconf_values |
|
2337 |
@returns: the ssconf_values dictionary extended by hvparams |
|
2338 |
|
|
2339 |
""" |
|
2340 |
for hv in all_hvparams: |
|
2341 |
ssconf_key = constants.SS_HVPARAMS_PREF + hv |
|
2342 |
ssconf_values[ssconf_key] = all_hvparams[hv] |
|
2343 |
return ssconf_values |
|
2344 |
|
|
2285 | 2345 |
def _UnlockedGetSsconfValues(self): |
2286 | 2346 |
"""Return the values needed by ssconf. |
2287 | 2347 |
|
... | ... | |
2313 | 2373 |
cluster_tags = fn(cluster.GetTags()) |
2314 | 2374 |
|
2315 | 2375 |
hypervisor_list = fn(cluster.enabled_hypervisors) |
2376 |
all_hvparams = self._GetAllHvparamsStrings(constants.HYPER_TYPES) |
|
2316 | 2377 |
|
2317 | 2378 |
uid_pool = uidpool.FormatUidPool(cluster.uid_pool, separator="\n") |
2318 | 2379 |
|
... | ... | |
2348 | 2409 |
constants.SS_NODEGROUPS: nodegroups_data, |
2349 | 2410 |
constants.SS_NETWORKS: networks_data, |
2350 | 2411 |
} |
2412 |
ssconf_values = self._ExtendByAllHvparamsStrings(ssconf_values, |
|
2413 |
all_hvparams) |
|
2351 | 2414 |
bad_values = [(k, v) for k, v in ssconf_values.items() |
2352 | 2415 |
if not isinstance(v, (str, basestring))] |
2353 | 2416 |
if bad_values: |
b/lib/constants.py | ||
---|---|---|
2007 | 2007 |
SS_NODEGROUPS = "nodegroups" |
2008 | 2008 |
SS_NETWORKS = "networks" |
2009 | 2009 |
|
2010 |
# This is not a complete SSCONF key, but the prefix for the hypervisor keys |
|
2011 |
SS_HVPARAMS_PREF = "hvparams_" |
|
2012 |
|
|
2013 |
# Hvparams keys: |
|
2014 |
SS_HVPARAMS_XEN_PVM = SS_HVPARAMS_PREF + HT_XEN_PVM |
|
2015 |
SS_HVPARAMS_XEN_FAKE = SS_HVPARAMS_PREF + HT_FAKE |
|
2016 |
SS_HVPARAMS_XEN_HVM = SS_HVPARAMS_PREF + HT_XEN_HVM |
|
2017 |
SS_HVPARAMS_XEN_KVM = SS_HVPARAMS_PREF + HT_KVM |
|
2018 |
SS_HVPARAMS_XEN_CHROOT = SS_HVPARAMS_PREF + HT_CHROOT |
|
2019 |
SS_HVPARAMS_XEN_LXC = SS_HVPARAMS_PREF + HT_LXC |
|
2020 |
|
|
2021 |
VALID_SS_HVPARAMS_KEYS = compat.UniqueFrozenset([ |
|
2022 |
SS_HVPARAMS_XEN_PVM, |
|
2023 |
SS_HVPARAMS_XEN_FAKE, |
|
2024 |
SS_HVPARAMS_XEN_HVM, |
|
2025 |
SS_HVPARAMS_XEN_KVM, |
|
2026 |
SS_HVPARAMS_XEN_CHROOT, |
|
2027 |
SS_HVPARAMS_XEN_LXC, |
|
2028 |
]) |
|
2029 |
|
|
2010 | 2030 |
SS_FILE_PERMS = 0444 |
2011 | 2031 |
|
2012 | 2032 |
# cluster wide default parameters |
b/lib/ssconf.py | ||
---|---|---|
65 | 65 |
constants.SS_UID_POOL, |
66 | 66 |
constants.SS_NODEGROUPS, |
67 | 67 |
constants.SS_NETWORKS, |
68 |
constants.SS_HVPARAMS_XEN_PVM, |
|
69 |
constants.SS_HVPARAMS_XEN_FAKE, |
|
70 |
constants.SS_HVPARAMS_XEN_HVM, |
|
71 |
constants.SS_HVPARAMS_XEN_KVM, |
|
72 |
constants.SS_HVPARAMS_XEN_CHROOT, |
|
73 |
constants.SS_HVPARAMS_XEN_LXC, |
|
68 | 74 |
]) |
69 | 75 |
|
70 | 76 |
#: Maximum size for ssconf files |
... | ... | |
315 | 321 |
nl = data.splitlines(False) |
316 | 322 |
return nl |
317 | 323 |
|
324 |
def GetHvparamsForHypervisor(self, hvname): |
|
325 |
"""Return the hypervisor parameters of the given hypervisor. |
|
326 |
|
|
327 |
@type hvname: string |
|
328 |
@param hvname: name of the hypervisor, must be in C{constants.HYPER_TYPES} |
|
329 |
@rtype: dict of strings |
|
330 |
@returns: dictionary with hypervisor parameters |
|
331 |
|
|
332 |
""" |
|
333 |
data = self._ReadFile(constants.SS_HVPARAMS_PREF + hvname) |
|
334 |
lines = data.splitlines(False) |
|
335 |
hvparams = {} |
|
336 |
for line in lines: |
|
337 |
(key, value) = line.split("=") |
|
338 |
hvparams[key] = value |
|
339 |
return hvparams |
|
340 |
|
|
341 |
def GetHvparams(self): |
|
342 |
"""Return the hypervisor parameters of all hypervisors. |
|
343 |
|
|
344 |
@rtype: dict of dict of strings |
|
345 |
@returns: dictionary mapping hypervisor names to hvparams |
|
346 |
|
|
347 |
""" |
|
348 |
all_hvparams = {} |
|
349 |
for hv in constants.HYPER_TYPES: |
|
350 |
all_hvparams[hv] = self.GetHvparamsForHypervisor(hv) |
|
351 |
return all_hvparams |
|
352 |
|
|
318 | 353 |
def GetMaintainNodeHealth(self): |
319 | 354 |
"""Return the value of the maintain_node_health option. |
320 | 355 |
|
b/test/py/ganeti.config_unittest.py | ||
---|---|---|
41 | 41 |
|
42 | 42 |
import testutils |
43 | 43 |
import mocks |
44 |
import mock |
|
44 | 45 |
|
45 | 46 |
|
46 | 47 |
def _StubGetEntResolver(): |
... | ... | |
579 | 580 |
nodegroup.ipolicy = cluster.SimpleFillIPolicy(nodegroup.ipolicy) |
580 | 581 |
self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
581 | 582 |
|
583 |
# Tests for Ssconf helper functions |
|
584 |
def testUnlockedGetHvparamsString(self): |
|
585 |
hvparams = {"a": "A", "b": "B", "c": "C"} |
|
586 |
hvname = "myhv" |
|
587 |
cfg_writer = self._get_object() |
|
588 |
cfg_writer._config_data = mock.Mock() |
|
589 |
cfg_writer._config_data.cluster = mock.Mock() |
|
590 |
cfg_writer._config_data.cluster.hvparams = {hvname: hvparams} |
|
591 |
|
|
592 |
result = cfg_writer._UnlockedGetHvparamsString(hvname) |
|
593 |
|
|
594 |
self.assertTrue("a=A" in result) |
|
595 |
lines = [line for line in result.split('\n') if line != ''] |
|
596 |
self.assertEqual(len(hvparams.keys()), len(lines)) |
|
597 |
|
|
598 |
def testExtendByAllHvparamsStrings(self): |
|
599 |
all_hvparams = {constants.HT_XEN_PVM: "foo"} |
|
600 |
ssconf_values = {} |
|
601 |
cfg_writer = self._get_object() |
|
602 |
|
|
603 |
cfg_writer._ExtendByAllHvparamsStrings(ssconf_values, all_hvparams) |
|
604 |
|
|
605 |
expected_key = constants.SS_HVPARAMS_PREF + constants.HT_XEN_PVM |
|
606 |
self.assertTrue(expected_key in ssconf_values) |
|
607 |
|
|
582 | 608 |
|
583 | 609 |
def _IsErrorInList(err_str, err_list): |
584 | 610 |
return any(map(lambda e: err_str in e, err_list)) |
b/test/py/ganeti.ssconf_unittest.py | ||
---|---|---|
33 | 33 |
from ganeti import ssconf |
34 | 34 |
|
35 | 35 |
import testutils |
36 |
import mock |
|
36 | 37 |
|
37 | 38 |
|
38 | 39 |
class TestReadSsconfFile(unittest.TestCase): |
... | ... | |
220 | 221 |
|
221 | 222 |
self.assertEqual(os.listdir(self.ssdir), []) |
222 | 223 |
|
224 |
def testGetHvparamsForHypervisor(self): |
|
225 |
hvparams = [("a", "A"), ("b", "B"), ("c", "C")] |
|
226 |
ssconf_file_content = '\n'.join("%s=%s" % (key, value) for (key, value) |
|
227 |
in hvparams) |
|
228 |
self.sstore._ReadFile = mock.Mock(return_value=ssconf_file_content) |
|
229 |
result = self.sstore.GetHvparamsForHypervisor("foo") |
|
230 |
for (key, value) in hvparams: |
|
231 |
self.assertTrue(key in result) |
|
232 |
self.assertEqual(value, result[key]) |
|
233 |
|
|
223 | 234 |
|
224 | 235 |
class TestVerifyClusterName(unittest.TestCase): |
225 | 236 |
def setUp(self): |
Also available in: Unified diff