Commit 9b4329e9 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add ssconf function to read all files



Configuring a node daemon on a newly added node will need all ssconf
values.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent e1874aa7
......@@ -138,6 +138,26 @@ class SimpleStore(object):
raise errors.ConfigurationError("Can't read ssconf file %s: %s" %
(filename, str(err)))
def ReadAll(self):
"""Reads all keys and returns their values.
@rtype: dict
@return: Dictionary, ssconf key as key, value as value
"""
result = []
for key in _VALID_KEYS:
try:
value = self._ReadFile(key)
except errors.ConfigurationError:
# Ignore non-existing files
pass
else:
result.append((key, value))
return dict(result)
def WriteFiles(self, values, dry_run=False):
"""Writes ssconf files used by external scripts.
......
......@@ -149,6 +149,16 @@ class TestSimpleStore(unittest.TestCase):
default="something.example.com"),
"cluster.example.com")
def testReadAllNoFiles(self):
self.assertEqual(self.sstore.ReadAll(), {})
def testReadAllSingleFile(self):
utils.WriteFile(self.sstore.KeyToFilename(constants.SS_CLUSTER_NAME),
data="cluster.example.com")
self.assertEqual(self.sstore.ReadAll(), {
constants.SS_CLUSTER_NAME: "cluster.example.com",
})
def testWriteFiles(self):
values = {
constants.SS_CLUSTER_NAME: "cluster.example.com",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment