Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -138,6 +138,26 @@ class SimpleStore(object): ...@@ -138,6 +138,26 @@ class SimpleStore(object):
raise errors.ConfigurationError("Can't read ssconf file %s: %s" % raise errors.ConfigurationError("Can't read ssconf file %s: %s" %
(filename, str(err))) (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): def WriteFiles(self, values, dry_run=False):
"""Writes ssconf files used by external scripts. """Writes ssconf files used by external scripts.
......
...@@ -149,6 +149,16 @@ class TestSimpleStore(unittest.TestCase): ...@@ -149,6 +149,16 @@ class TestSimpleStore(unittest.TestCase):
default="something.example.com"), default="something.example.com"),
"cluster.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): def testWriteFiles(self):
values = { values = {
constants.SS_CLUSTER_NAME: "cluster.example.com", constants.SS_CLUSTER_NAME: "cluster.example.com",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment