From 150481286dcf3c3c1fedd8213070cff48e5ad61d Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Wed, 1 Mar 2017 17:28:46 -0800 Subject: standardize ssh auth we need to be following defautl paramiko rules, first use pkey, then key_filenames (autodetecting ~/.ssh/ keys), then password We have too much boilerplate redudant code everywhere, we need to standardize on a factory function that takes a node dict. Using Python3 ChainMap we can layer overrides and defaults. VNF descriptors have to default key_filename, password to Python None. The only way to do this is to omit key values if the variable is not defined, this way the dict will not have the value and it will default to Python None Add python2 chainmap backport Updated unittest mocking to use ssh.SSH.from_node Change-Id: I80b0cb606e593b33e317c9e5e8ed0b74da591514 Signed-off-by: Ross Brattain (cherry picked from commit 99abbb424007da2e01762f3c040a39c0157cbe1f) --- .../benchmark/scenarios/compute/test_cachestat.py | 14 ++++---- .../scenarios/compute/test_computecapacity.py | 6 ++-- .../benchmark/scenarios/compute/test_cpuload.py | 28 ++++++++-------- .../benchmark/scenarios/compute/test_cyclictest.py | 38 +++++++++++----------- .../benchmark/scenarios/compute/test_lmbench.py | 18 +++++----- .../benchmark/scenarios/compute/test_memload.py | 14 ++++---- .../benchmark/scenarios/compute/test_plugintest.py | 6 ++-- .../benchmark/scenarios/compute/test_ramspeed.py | 18 +++++----- .../benchmark/scenarios/compute/test_unixbench.py | 26 +++++++-------- 9 files changed, 84 insertions(+), 84 deletions(-) (limited to 'tests/unit/benchmark/scenarios/compute') diff --git a/tests/unit/benchmark/scenarios/compute/test_cachestat.py b/tests/unit/benchmark/scenarios/compute/test_cachestat.py index 8a06c754b..b0ddfc6b4 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cachestat.py +++ b/tests/unit/benchmark/scenarios/compute/test_cachestat.py @@ -35,7 +35,7 @@ class CACHEstatTestCase(unittest.TestCase): def test_cachestat_successful_setup(self, mock_ssh): c = cachestat.CACHEstat({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.client) @@ -43,20 +43,20 @@ class CACHEstatTestCase(unittest.TestCase): def test_execute_command_success(self, mock_ssh): c = cachestat.CACHEstat({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = c._execute_command("foo") self.assertEqual(result, expected_result) def test_execute_command_failed(self, mock_ssh): c = cachestat.CACHEstat({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'Failed executing \ + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'Failed executing \ command') self.assertRaises(RuntimeError, c._execute_command, "cat /proc/meminfo") @@ -67,11 +67,11 @@ class CACHEstatTestCase(unittest.TestCase): } args = {"options": options} c = cachestat.CACHEstat(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() output = self._read_file("cachestat_sample_output.txt") - mock_ssh.SSH().execute.return_value = (0, output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, output, '') result = c._get_cache_usage() expected_result = {"cachestat": {"cache0": {"HITS": "6462", "DIRTIES": "29", diff --git a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py index 4efa66932..7b9a5ad4a 100644 --- a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py +++ b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py @@ -45,7 +45,7 @@ class ComputeCapacityTestCase(unittest.TestCase): def test_capacity_successful_setup(self, mock_ssh): c = computecapacity.ComputeCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.client) @@ -54,7 +54,7 @@ class ComputeCapacityTestCase(unittest.TestCase): def test_capacity_successful(self, mock_ssh): c = computecapacity.ComputeCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '') + mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '') c.run(self.result) expected_result = jsonutils.loads(SAMPLE_OUTPUT) self.assertEqual(self.result, expected_result) @@ -62,5 +62,5 @@ class ComputeCapacityTestCase(unittest.TestCase): def test_capacity_unsuccessful_script_error(self, mock_ssh): c = computecapacity.ComputeCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_cpuload.py b/tests/unit/benchmark/scenarios/compute/test_cpuload.py index ffa781215..840ac7885 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cpuload.py +++ b/tests/unit/benchmark/scenarios/compute/test_cpuload.py @@ -42,7 +42,7 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() self.assertIsNotNone(l.client) @@ -58,7 +58,7 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (127, '', '') + mock_ssh.SSH.from_node().execute.return_value = (127, '', '') l.setup() self.assertIsNotNone(l.client) @@ -74,11 +74,11 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = l._execute_command("foo") self.assertEqual(result, expected_result) @@ -91,10 +91,10 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'abcdefg') + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'abcdefg') self.assertRaises(RuntimeError, l._execute_command, "cat /proc/loadavg") @@ -107,10 +107,10 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() - mock_ssh.SSH().execute.return_value = \ + mock_ssh.SSH.from_node().execute.return_value = \ (0, '1.50 1.45 1.51 3/813 14322', '') result = l._get_loadavg() expected_result = \ @@ -126,13 +126,13 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() l.interval = 1 l.count = 1 mpstat_output = self._read_file("cpuload_sample_output1.txt") - mock_ssh.SSH().execute.return_value = (0, mpstat_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, mpstat_output, '') result = l._get_cpu_usage_mpstat() expected_result = \ @@ -175,12 +175,12 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() l.interval = 0 output = self._read_file("cpuload_sample_output2.txt") - mock_ssh.SSH().execute.return_value = (0, output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, output, '') result = l._get_cpu_usage() expected_result = \ @@ -219,12 +219,12 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', '') + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') l.setup() l.interval = 0 stat_output = self._read_file("cpuload_sample_output2.txt") - mock_ssh.SSH().execute.side_effect = \ + mock_ssh.SSH.from_node().execute.side_effect = \ [(0, '1.50 1.45 1.51 3/813 14322', ''), (0, stat_output, '')] l.run(self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py index 04ca2abf9..dc52a80c7 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py +++ b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py @@ -69,7 +69,7 @@ class CyclictestTestCase(unittest.TestCase): def test_cyclictest_successful_setup(self, mock_ssh): c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.guest) @@ -80,12 +80,12 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.pop("sla", None) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') c.run(result) expected_result = jsonutils.loads(sample_output) @@ -101,12 +101,12 @@ class CyclictestTestCase(unittest.TestCase): } }) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') c.run(result) expected_result = jsonutils.loads(sample_output) @@ -117,13 +117,13 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_min_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, c.run, result) def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh): @@ -131,13 +131,13 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_avg_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, c.run, result) def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh): @@ -145,13 +145,13 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_max_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, c.run, result) def test_cyclictest_unsuccessful_script_error(self, mock_ssh): @@ -159,12 +159,12 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_max_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, result) diff --git a/tests/unit/benchmark/scenarios/compute/test_lmbench.py b/tests/unit/benchmark/scenarios/compute/test_lmbench.py index 5b72ef75d..08f5da332 100644 --- a/tests/unit/benchmark/scenarios/compute/test_lmbench.py +++ b/tests/unit/benchmark/scenarios/compute/test_lmbench.py @@ -38,7 +38,7 @@ class LmbenchTestCase(unittest.TestCase): def test_successful_setup(self, mock_ssh): l = lmbench.Lmbench({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() self.assertIsNotNone(l.client) @@ -66,7 +66,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '[{"latency": 4.944, "size": 0.00049}]' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads( '{"latencies": ' + sample_output + "}") @@ -84,7 +84,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -103,7 +103,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '[{"latency": 4.944, "size": 0.00049}]' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads( '{"latencies": ' + sample_output + "}") @@ -124,7 +124,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -143,7 +143,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '[{"latency": 37.5, "size": 0.00049}]' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, l.run, self.result) def test_unsuccessful_bandwidth_run_sla(self, mock_ssh): @@ -161,7 +161,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, l.run, self.result) def test_successful_latency_for_cache_run_sla(self, mock_ssh): @@ -178,7 +178,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = "{\"L1cache\": 1.6}" - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -189,5 +189,5 @@ class LmbenchTestCase(unittest.TestCase): args = {"options": options} l = lmbench.Lmbench(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, l.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_memload.py b/tests/unit/benchmark/scenarios/compute/test_memload.py index ede3309c2..ebae9993d 100644 --- a/tests/unit/benchmark/scenarios/compute/test_memload.py +++ b/tests/unit/benchmark/scenarios/compute/test_memload.py @@ -35,7 +35,7 @@ class MEMLoadTestCase(unittest.TestCase): def test_memload_successful_setup(self, mock_ssh): m = memload.MEMLoad({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() self.assertIsNotNone(m.client) @@ -43,20 +43,20 @@ class MEMLoadTestCase(unittest.TestCase): def test_execute_command_success(self, mock_ssh): m = memload.MEMLoad({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = m._execute_command("foo") self.assertEqual(result, expected_result) def test_execute_command_failed(self, mock_ssh): m = memload.MEMLoad({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'Failed executing \ + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'Failed executing \ command') self.assertRaises(RuntimeError, m._execute_command, "cat /proc/meminfo") @@ -68,11 +68,11 @@ class MEMLoadTestCase(unittest.TestCase): } args = {"options": options} m = memload.MEMLoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() output = self._read_file("memload_sample_output.txt") - mock_ssh.SSH().execute.return_value = (0, output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, output, '') result = m._get_mem_usage() expected_result = { "max": { diff --git a/tests/unit/benchmark/scenarios/compute/test_plugintest.py b/tests/unit/benchmark/scenarios/compute/test_plugintest.py index a5331caf7..680f6ad65 100644 --- a/tests/unit/benchmark/scenarios/compute/test_plugintest.py +++ b/tests/unit/benchmark/scenarios/compute/test_plugintest.py @@ -40,7 +40,7 @@ class PluginTestTestCase(unittest.TestCase): def test_sample_successful_setup(self, mock_ssh): s = plugintest.PluginTest({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') s.setup() self.assertIsNotNone(s.client) @@ -50,7 +50,7 @@ class PluginTestTestCase(unittest.TestCase): s = plugintest.PluginTest({}, self.ctx) sample_output = '{"Test Output": "Hello world!"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') s.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -58,5 +58,5 @@ class PluginTestTestCase(unittest.TestCase): def test_sample_unsuccessful_script_error(self, mock_ssh): s = plugintest.PluginTest({}, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, s.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py index 82cc93870..85d49641e 100644 --- a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py +++ b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py @@ -38,7 +38,7 @@ class RamspeedTestCase(unittest.TestCase): def test_ramspeed_successful_setup(self, mock_ssh): r = ramspeed.Ramspeed({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') r.setup() self.assertIsNotNone(r.client) @@ -75,7 +75,7 @@ class RamspeedTestCase(unittest.TestCase): {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\ "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\ "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -111,7 +111,7 @@ class RamspeedTestCase(unittest.TestCase): {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\ "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\ "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -146,7 +146,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\ "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\ "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, r.run, self.result) def test_ramspeed_unsuccessful_script_error(self, mock_ssh): @@ -158,7 +158,7 @@ class RamspeedTestCase(unittest.TestCase): args = {"options": options} r = ramspeed.Ramspeed(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, r.run, self.result) def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh): @@ -177,7 +177,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\ "Bandwidth(MBps)": 9401.58}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -198,7 +198,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\ "Bandwidth(MBps)": 9401.58}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -219,7 +219,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\ "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\ "Bandwidth(MBps)": 2401.58}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, r.run, self.result) def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh): @@ -231,7 +231,7 @@ class RamspeedTestCase(unittest.TestCase): args = {'options': options} r = ramspeed.Ramspeed(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'No such type_id: 30 for \ + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \ Ramspeed scenario') self.assertRaises(RuntimeError, r.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_unixbench.py b/tests/unit/benchmark/scenarios/compute/test_unixbench.py index 747bda1ed..7d071e91c 100644 --- a/tests/unit/benchmark/scenarios/compute/test_unixbench.py +++ b/tests/unit/benchmark/scenarios/compute/test_unixbench.py @@ -38,7 +38,7 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench({}, self.ctx) u.setup() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(u.client) self.assertEqual(u.setup_done, True) @@ -54,10 +54,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"Score":"4425.4"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') u.run(result) expected_result = jsonutils.loads(sample_output) @@ -76,10 +76,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"Score":"4425.4"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') u.run(result) expected_result = jsonutils.loads(sample_output) @@ -102,10 +102,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"signle_score":"2251.7","parallel_score":"4395.9"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') u.run(result) expected_result = jsonutils.loads(sample_output) @@ -120,10 +120,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"single_score":"200.7","parallel_score":"4395.9"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, u.run, result) def test_unixbench_unsuccessful_sla_parallel_score(self, mock_ssh): @@ -135,10 +135,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"signle_score":"2251.7","parallel_score":"3395.9"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, u.run, result) def test_unixbench_unsuccessful_script_error(self, mock_ssh): @@ -158,9 +158,9 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, u.run, result) -- cgit 1.2.3-korg