diff options
author | Ross Brattain <ross.b.brattain@intel.com> | 2017-03-01 17:28:46 -0800 |
---|---|---|
committer | Ross Brattain <ross.b.brattain@intel.com> | 2017-04-11 21:58:20 -0700 |
commit | 99abbb424007da2e01762f3c040a39c0157cbe1f (patch) | |
tree | baab901a9e7444c9fd36aa4a19c1e51d03cb8e7f /tests/unit/network_services/vnf_generic/vnf | |
parent | 2240fcc201fa9665e42e92c29e201cb62490acfa (diff) |
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 <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/network_services/vnf_generic/vnf')
4 files changed, 43 insertions, 43 deletions
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py index 4f0855543..88df7788b 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py @@ -141,7 +141,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(ping_traffic_gen._queue, None) @@ -152,7 +152,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock ping_traffic_gen = PingTrafficGen(vnfd) ping_traffic_gen._queue = Queue() ping_traffic_gen._queue.put({}) @@ -165,7 +165,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.instantiate({}, {})) @@ -176,7 +176,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.listen_traffic({})) @@ -191,7 +191,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = PingTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -210,7 +210,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = PingTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -228,7 +228,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] flavor = "" ping_traffic_gen = PingTrafficGen(vnfd) @@ -241,7 +241,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.terminate()) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py index eda5cea84..4ea180851 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py @@ -195,7 +195,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertIsNotNone(trex_traffic_gen._terminated) @@ -206,7 +206,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) restult = trex_traffic_gen.collect_kpi() @@ -218,7 +218,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual(None, trex_traffic_gen.listen_traffic({})) @@ -233,7 +233,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) trex_traffic_gen._start_server = mock.Mock(return_value=0) @@ -251,7 +251,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(1, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) scenario_cfg = {"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B"} @@ -265,7 +265,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual([0.8, 1.0], @@ -282,7 +282,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual(None, trex_traffic_gen._start_server()) @@ -304,7 +304,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGenRFC(vnfd) self.sut.connection = mock.Mock() @@ -327,7 +327,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) result = ['0x00', '0x00', '0x00', '0x00', '0x00', '0x01'] @@ -342,7 +342,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) tg_rfc2544_trex.WAIT_TIME = 1 @@ -358,7 +358,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGenRFC(vnfd) self.sut.connection = mock.Mock() @@ -376,7 +376,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] flavor = "" trex_traffic_gen = TrexTrafficGenRFC(vnfd) @@ -389,7 +389,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual(None, trex_traffic_gen.terminate()) @@ -399,7 +399,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGenRFC(vnfd) client = mock.Mock(autospec=STLClient) client.connect = mock.Mock(return_value=0) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py index a76fbbd2a..ca8421919 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py @@ -176,7 +176,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertIsNotNone(trex_traffic_gen._terminated) @@ -187,7 +187,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) trex_traffic_gen._queue.put({}) @@ -200,7 +200,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen.listen_traffic({})) @@ -215,7 +215,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(0, trex_traffic_gen.instantiate({}, {})) @@ -230,7 +230,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(1, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertRaises(RuntimeError, @@ -243,7 +243,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen._start_server()) @@ -259,7 +259,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -279,7 +279,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen._generate_trex_cfg(vnfd)) @@ -291,7 +291,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) result = ['0x00', '0x00', '0x00', '0x00', '0x00', '0x01'] @@ -309,7 +309,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -326,7 +326,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] flavor = "" trex_traffic_gen = TrexTrafficGen(vnfd) @@ -339,7 +339,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual( None, trex_traffic_gen.setup_vnf_environment(ssh_mock)) @@ -350,7 +350,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen.terminate()) @@ -360,7 +360,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) client = mock.Mock(autospec=STLClient) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index 36b8c2a22..b69e537aa 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -229,7 +229,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) vpe_approx_vnf.resource = mock.Mock(autospec=ResourceProfile) @@ -249,7 +249,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) cmd = "quit" @@ -261,7 +261,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) vpe_approx_vnf.execute_command = \ @@ -277,7 +277,7 @@ class TestVpeApproxVnf(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) curr_path = os.path.dirname(os.path.abspath(__file__)) @@ -294,7 +294,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.scenario_cfg['vnf_options'] = {'vpe': {'cfg': ""}} @@ -311,7 +311,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.scenario_cfg['vnf_options'] = {'vpe': {'cfg': ""}} @@ -332,7 +332,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.assertEqual(None, |