summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-09-10 14:18:58 -0400
committerScott Moser <smoser@ubuntu.com>2013-09-10 14:18:58 -0400
commit7dff14c285d6562b9cd0b47876628607feac4a18 (patch)
tree50daaed5a66f6404f9511e92df0027e00ec3f826 /tests/unittests/test_datasource
parent8ed952a461ed81af4011e02f3df47add1066cd0f (diff)
downloadvyos-cloud-init-7dff14c285d6562b9cd0b47876628607feac4a18.tar.gz
vyos-cloud-init-7dff14c285d6562b9cd0b47876628607feac4a18.zip
some cleanups and changes
* use util.subp from inside parse_shell_config, and adjust exception handling accordingly. * add 'switch_user_cmd' as a callback function to pass to parse_shell_config, which allows us to mock this to avoid 'sudo' when running test cases. Basically the test cases just return '[]' here. * fix some pylint * handle empty 'content' in parse_shell_config and remove the protection that was present.
Diffstat (limited to 'tests/unittests/test_datasource')
-rw-r--r--tests/unittests/test_datasource/test_opennebula.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/unittests/test_datasource/test_opennebula.py b/tests/unittests/test_datasource/test_opennebula.py
index f2457657..9c7a644a 100644
--- a/tests/unittests/test_datasource/test_opennebula.py
+++ b/tests/unittests/test_datasource/test_opennebula.py
@@ -37,6 +37,7 @@ CMD_IP_OUT = '''\
class TestOpenNebulaDataSource(MockerTestCase):
+ parsed_user = None
def setUp(self):
super(TestOpenNebulaDataSource, self).setUp()
@@ -48,6 +49,18 @@ class TestOpenNebulaDataSource(MockerTestCase):
self.seed_dir = os.path.join(self.paths.seed_dir, "opennebula")
self.sys_cfg = {'datasource': {'OpenNebula': {'dsmode': 'local'}}}
+ # we don't want 'sudo' called in tests. so we patch switch_user_cmd
+ def my_switch_user_cmd(user):
+ self.parsed_user = user
+ return []
+
+ self.switch_user_cmd_real = ds.switch_user_cmd
+ ds.switch_user_cmd = my_switch_user_cmd
+
+ def tearDown(self):
+ ds.switch_user_cmd = self.switch_user_cmd_real
+ super(TestOpenNebulaDataSource, self).tearDown()
+
def test_get_data_non_contextdisk(self):
try:
# dont' try to lookup for CDs
@@ -96,9 +109,9 @@ class TestOpenNebulaDataSource(MockerTestCase):
util.find_devs_with = orig_find_devs_with
def test_get_data(self):
+ orig_find_devs_with = util.find_devs_with
try:
# dont' try to lookup for CDs
- orig_find_devs_with = util.find_devs_with
util.find_devs_with = lambda n: []
populate_context_dir(self.seed_dir, {'KEY1': 'val1'})
dsrc = self.ds(sys_cfg=self.sys_cfg, distro=None, paths=self.paths)