From 99abbb424007da2e01762f3c040a39c0157cbe1f 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 --- yardstick/network_services/vnf_generic/vnf/tg_ping.py | 12 ++---------- .../network_services/vnf_generic/vnf/tg_rfc2544_trex.py | 12 ++++-------- yardstick/network_services/vnf_generic/vnf/tg_trex.py | 15 +++++---------- yardstick/network_services/vnf_generic/vnf/vpe_vnf.py | 16 ++++++---------- 4 files changed, 17 insertions(+), 38 deletions(-) (limited to 'yardstick/network_services/vnf_generic/vnf') diff --git a/yardstick/network_services/vnf_generic/vnf/tg_ping.py b/yardstick/network_services/vnf_generic/vnf/tg_ping.py index 2844a5c01..000a91db4 100644 --- a/yardstick/network_services/vnf_generic/vnf/tg_ping.py +++ b/yardstick/network_services/vnf_generic/vnf/tg_ping.py @@ -69,12 +69,7 @@ class PingTrafficGen(GenericTrafficGen): self._traffic_process = None mgmt_interface = vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - LOG.debug("Connecting to %s", mgmt_interface["ip"]) - - self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + self.connection = ssh.SSH.from_node(mgmt_interface) self.connection.wait() def _bind_device_kernel(self, connection): @@ -130,10 +125,7 @@ class PingTrafficGen(GenericTrafficGen): def _traffic_runner(self, traffic_profile, filewrapper): mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + self.connection = ssh.SSH.from_node(mgmt_interface) self.connection.wait() external_interface = self.vnfd["vdu"][0]["external-interface"] virtual_interface = external_interface[0]["virtual-interface"] diff --git a/yardstick/network_services/vnf_generic/vnf/tg_rfc2544_trex.py b/yardstick/network_services/vnf_generic/vnf/tg_rfc2544_trex.py index 37c1a7345..7da4b31e9 100644 --- a/yardstick/network_services/vnf_generic/vnf/tg_rfc2544_trex.py +++ b/yardstick/network_services/vnf_generic/vnf/tg_rfc2544_trex.py @@ -55,10 +55,8 @@ class TrexTrafficGenRFC(GenericTrafficGen): self.my_ports = None mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + + self.connection = ssh.SSH.from_node(mgmt_interface) self.connection.wait() @classmethod @@ -166,10 +164,8 @@ class TrexTrafficGenRFC(GenericTrafficGen): def _start_server(self): mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - _server = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + + _server = ssh.SSH.from_node(mgmt_interface) _server.wait() _server.execute("fuser -n tcp %s %s -k > /dev/null 2>&1" % diff --git a/yardstick/network_services/vnf_generic/vnf/tg_trex.py b/yardstick/network_services/vnf_generic/vnf/tg_trex.py index 1e751bfce..058b715fe 100644 --- a/yardstick/network_services/vnf_generic/vnf/tg_trex.py +++ b/yardstick/network_services/vnf_generic/vnf/tg_trex.py @@ -53,12 +53,9 @@ class TrexTrafficGen(GenericTrafficGen): self.my_ports = None self.client_started = multiprocessing.Value('i', 0) - mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - self.connection = ssh.SSH(mgmt_interface["user"], - mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + mgmt_interface = vnfd["mgmt-interface"] + + self.connection = ssh.SSH.from_node(mgmt_interface) self.connection.wait() @classmethod @@ -199,10 +196,8 @@ class TrexTrafficGen(GenericTrafficGen): def _start_server(self): mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - _server = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + + _server = ssh.SSH.from_node(mgmt_interface) _server.wait() _server.execute("fuser -n tcp %s %s -k > /dev/null 2>&1" % diff --git a/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py b/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py index 8c766f01e..e9e80bdfb 100644 --- a/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py +++ b/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py @@ -120,14 +120,11 @@ class VpeApproxVnf(GenericVNF): def instantiate(self, scenario_cfg, context_cfg): vnf_cfg = scenario_cfg['vnf_options']['vpe']['cfg'] - mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + mgmt_interface = self.vnfd["mgmt-interface"] + self.connection = ssh.SSH.from_node(mgmt_interface) - self.connection.wait() + self.tc_file_name = '{0}.yaml'.format(scenario_cfg['tc']) self.setup_vnf_environment(self.connection) @@ -189,11 +186,10 @@ class VpeApproxVnf(GenericVNF): def _run_vpe(self, filewrapper, vnf_cfg): mgmt_interface = self.vnfd["mgmt-interface"] - ssh_port = mgmt_interface.get("ssh_port", ssh.DEFAULT_PORT) - self.connection = ssh.SSH(mgmt_interface["user"], mgmt_interface["ip"], - password=mgmt_interface["password"], - port=ssh_port) + + self.connection = ssh.SSH.from_node(mgmt_interface) self.connection.wait() + interfaces = self.vnfd["vdu"][0]['external-interface'] port0_ip = ipaddress.ip_interface(six.text_type( "%s/%s" % (interfaces[0]["virtual-interface"]["local_ip"], -- cgit 1.2.3-korg