aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/core
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-03-01 17:28:46 -0800
committerRoss Brattain <ross.b.brattain@intel.com>2017-04-11 21:58:20 -0700
commit99abbb424007da2e01762f3c040a39c0157cbe1f (patch)
treebaab901a9e7444c9fd36aa4a19c1e51d03cb8e7f /yardstick/benchmark/core
parent2240fcc201fa9665e42e92c29e201cb62490acfa (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 'yardstick/benchmark/core')
-rw-r--r--yardstick/benchmark/core/plugin.py72
1 files changed, 14 insertions, 58 deletions
diff --git a/yardstick/benchmark/core/plugin.py b/yardstick/benchmark/core/plugin.py
index 3080f5dd9..7f67a04b3 100644
--- a/yardstick/benchmark/core/plugin.py
+++ b/yardstick/benchmark/core/plugin.py
@@ -80,33 +80,17 @@ class Plugin(object):
self.script = pkg_resources.resource_filename(
'yardstick.resources', 'scripts/install/' + target_script)
- deployment_user = deployment.get("user")
- deployment_ssh_port = deployment.get("ssh_port", ssh.DEFAULT_PORT)
deployment_ip = deployment.get("ip", None)
- deployment_password = deployment.get("password", None)
- deployment_key_filename = deployment.get("key_filename",
- "/root/.ssh/id_rsa")
if deployment_ip == "local":
- installer_ip = os.environ.get("INSTALLER_IP", None)
-
- if deployment_password is not None:
- self._login_via_password(deployment_user, installer_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, installer_ip,
- deployment_key_filename,
- deployment_ssh_port)
+ self.client = ssh.SSH.from_node(deployment, overrides={
+ # host can't be None, fail if no INSTALLER_IP
+ 'ip': os.environ["INSTALLER_IP"],
+ })
else:
- if deployment_password is not None:
- self._login_via_password(deployment_user, deployment_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, deployment_ip,
- deployment_key_filename,
- deployment_ssh_port)
+ self.client = ssh.SSH.from_node(deployment)
+ self.client.wait(timeout=600)
+
# copy script to host
remotepath = '~/%s.sh' % plugin_name
@@ -119,33 +103,16 @@ class Plugin(object):
self.script = pkg_resources.resource_filename(
'yardstick.resources', 'scripts/remove/' + target_script)
- deployment_user = deployment.get("user")
- deployment_ssh_port = deployment.get("ssh_port", ssh.DEFAULT_PORT)
deployment_ip = deployment.get("ip", None)
- deployment_password = deployment.get("password", None)
- deployment_key_filename = deployment.get("key_filename",
- "/root/.ssh/id_rsa")
if deployment_ip == "local":
- installer_ip = os.environ.get("INSTALLER_IP", None)
-
- if deployment_password is not None:
- self._login_via_password(deployment_user, installer_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, installer_ip,
- deployment_key_filename,
- deployment_ssh_port)
+ self.client = ssh.SSH.from_node(deployment, overrides={
+ # host can't be None, fail if no INSTALLER_IP
+ 'ip': os.environ["INSTALLER_IP"],
+ })
else:
- if deployment_password is not None:
- self._login_via_password(deployment_user, deployment_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, deployment_ip,
- deployment_key_filename,
- deployment_ssh_port)
+ self.client = ssh.SSH.from_node(deployment)
+ self.client.wait(timeout=600)
# copy script to host
remotepath = '~/%s.sh' % plugin_name
@@ -153,23 +120,12 @@ class Plugin(object):
LOG.info("copying script to host: %s", remotepath)
self.client._put_file_shell(self.script, remotepath)
- def _login_via_password(self, user, ip, password, ssh_port):
- LOG.info("Log in via pw, user:%s, host:%s", user, ip)
- self.client = ssh.SSH(user, ip, password=password, port=ssh_port)
- self.client.wait(timeout=600)
-
- def _login_via_key(self, user, ip, key_filename, ssh_port):
- LOG.info("Log in via key, user:%s, host:%s", user, ip)
- self.client = ssh.SSH(user, ip, key_filename=key_filename,
- port=ssh_port)
- self.client.wait(timeout=600)
-
def _run(self, plugin_name):
"""Run installation script """
cmd = "sudo bash %s" % plugin_name + ".sh"
LOG.info("Executing command: %s", cmd)
- status, stdout, stderr = self.client.execute(cmd)
+ self.client.execute(cmd)
class PluginParser(object):