diff --git a/lib/config.py b/lib/config.py index 669dadafbe440cc179c8c5e8b6d6dfae0bc02a2b..35ed41075674671b0c950e6954d5893d6a212c25 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 51284a7827412628e15b7d1cc69b80425a850e28..4221e92aecc3cd92e85779637ac56d684bbe7d86 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