From 5768e6a6ba95511ab9bcd2e5bf2a5db53455675a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Mon, 22 Nov 2010 14:15:41 +0100 Subject: [PATCH] Adding convenience getter for ndparams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/config.py | 27 +++++++++++++++++++++++++-- test/ganeti.config_unittest.py | 17 +++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/config.py b/lib/config.py index 669dadafb..35ed41075 100644 --- a/lib/config.py +++ b/lib/config.py @@ -178,6 +178,18 @@ class ConfigWriter: mac = "%s:%02x:%02x:%02x" % (prefix, byte1, byte2, byte3) return mac + @locking.ssynchronized(_config_lock, shared=1) + def GetNdParams(self, node): + """Get the node params populated with cluster defaults. + + @type node: L{object.Node} + @param node: The node we want to know the params for + @return: A dict with the filled in node params + + """ + nodegroup = self._UnlockedGetNodeGroup(node.group) + return self._config_data.cluster.FillND(node, nodegroup) + @locking.ssynchronized(_config_lock, shared=1) def GenerateMAC(self, ec_id): """Generate a MAC for an instance. @@ -876,8 +888,7 @@ class ConfigWriter: return nodegroup.uuid raise errors.OpPrereqError("Nodegroup '%s' not found", target) - @locking.ssynchronized(_config_lock, shared=1) - def GetNodeGroup(self, uuid): + def _UnlockedGetNodeGroup(self, uuid): """Lookup a node group. @type uuid: string @@ -891,6 +902,18 @@ class ConfigWriter: return self._config_data.nodegroups[uuid] + @locking.ssynchronized(_config_lock, shared=1) + def GetNodeGroup(self, uuid): + """Lookup a node group. + + @type uuid: string + @param uuid: group UUID + @rtype: L{objects.NodeGroup} or None + @return: nodegroup object, or None if not found + + """ + return self._UnlockedGetNodeGroup(uuid) + @locking.ssynchronized(_config_lock, shared=1) def GetAllNodeGroupsInfo(self): """Get the configuration of all node groups. diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py index 51284a782..4221e92ae 100755 --- a/test/ganeti.config_unittest.py +++ b/test/ganeti.config_unittest.py @@ -79,6 +79,7 @@ class TestConfigRunner(unittest.TestCase): volume_group_name="xenvg", drbd_usermode_helper="/bin/true", nicparams={constants.PP_DEFAULT: constants.NICC_DEFAULTS}, + ndparams=constants.NDC_DEFAULTS, tcpudp_port_pool=set(), enabled_hypervisors=[constants.HT_FAKE], master_node=me.name, @@ -187,6 +188,22 @@ class TestConfigRunner(unittest.TestCase): self.assertRaises(errors.ConfigurationError, CheckSyntax, {mode: m_bridged, link: ''}) + def testGetNdParamsDefault(self): + cfg = self._get_object() + node = cfg.GetNodeInfo(cfg.GetNodeList()[0]) + self.assertEqual(cfg.GetNdParams(node), constants.NDC_DEFAULTS) + + def testGetNdParamsModifiedNode(self): + my_ndparams = { + constants.ND_OOB_PROGRAM: "/bin/node-oob", + } + + cfg = self._get_object() + node = cfg.GetNodeInfo(cfg.GetNodeList()[0]) + node.ndparams = my_ndparams + cfg.Update(node, None) + self.assertEqual(cfg.GetNdParams(node), my_ndparams) + class TestTRM(unittest.TestCase): EC_ID = 1 -- GitLab