DataSourceOpenNebula:parse_shell_config skip 'SECONDS' var if seen

SECONDS is a special variable in bash, it gets set to the time the
shell has been alive.  This would cause us to fail randomly (if the
process happened to take more than 1 second, then SECONDS would
be defined).
This commit is contained in:
Scott Moser 2014-01-16 20:11:27 -05:00
parent 1f0eab4c8c
commit 0062fccd97
2 changed files with 9 additions and 1 deletions

View File

@ -323,7 +323,7 @@ def parse_shell_config(content, keylist=None, bash=None, asuser=None,
(output, _error) = util.subp(cmd, data=bcmd)
# exclude vars in bash that change on their own or that we used
excluded = ("RANDOM", "LINENO", "_", "__v")
excluded = ("RANDOM", "LINENO", "SECONDS", "_", "__v")
preset = {}
ret = {}
target = None

View File

@ -258,6 +258,14 @@ iface eth0 inet static
''')
class TestParseShellConfig(MockerTestCase):
def test_no_seconds(self):
cfg = '\n'.join(["foo=bar", "SECONDS=2", "xx=foo"])
# we could test 'sleep 2', but that would make the test run slower.
ret = ds.parse_shell_config(cfg);
self.assertEqual(ret, {"foo": "bar", "xx": "foo"})
def populate_context_dir(path, variables):
data = "# Context variables generated by OpenNebula\n"
for (k, v) in variables.iteritems():