from yardstick import ssh
from yardstick.benchmark.contexts.base import Context
-from yardstick.common.constants import YARDSTICK_ROOT_PATH
+from yardstick.common import constants as consts
LOG = logging.getLogger(__name__)
self.name = None
self.file_path = None
self.nodes = []
+ self.networks = {}
self.controllers = []
self.computes = []
self.baremetals = []
except IOError as ioerror:
if ioerror.errno == errno.ENOENT:
self.file_path = \
- os.path.join(YARDSTICK_ROOT_PATH, self.file_path)
+ os.path.join(consts.YARDSTICK_ROOT_PATH, self.file_path)
cfg = self.read_config_file()
else:
raise
self.env = attrs.get('env', {})
LOG.debug("Env: %r", self.env)
+ # add optional static network definition
+ self.networks.update(cfg.get("networks", {}))
+
def deploy(self):
config_type = self.env.get('type', '')
if config_type == 'ansible':
def _do_ansible_job(self, path):
cmd = 'ansible-playbook -i inventory.ini %s' % path
- base = '/home/opnfv/repos/yardstick/ansible'
- p = subprocess.Popen(cmd, shell=True, cwd=base)
+ p = subprocess.Popen(cmd, shell=True, cwd=consts.ANSIBLE_DIR)
p.communicate()
def _get_server(self, attr_name):
node["name"] = attr_name
return node
+ def _get_network(self, attr_name):
+ if not isinstance(attr_name, collections.Mapping):
+ network = self.networks.get(attr_name)
+
+ else:
+ # Don't generalize too much Just support vld_id
+ vld_id = attr_name.get('vld_id')
+ if vld_id is None:
+ return None
+
+ network = next((n for n in self.networks.values() if
+ n.get("vld_id") == vld_id), None)
+
+ if network is None:
+ return None
+
+ result = {
+ # name is required
+ "name": network["name"],
+ "vld_id": network.get("vld_id"),
+ "segmentation_id": network.get("segmentation_id"),
+ "network_type": network.get("network_type"),
+ "physical_network": network.get("physical_network"),
+ }
+ return result
+
def _execute_script(self, node_name, info):
if node_name == 'local':
self._execute_local_script(info)
def _execute_local_script(self, info):
script, options = self._get_script(info)
- script = os.path.join(YARDSTICK_ROOT_PATH, script)
+ script = os.path.join(consts.YARDSTICK_ROOT_PATH, script)
cmd = ['bash', script, options]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
if node is None:
raise SystemExit('No such node')
- user = node.get('user', 'ubuntu')
- ssh_port = node.get("ssh_port", ssh.DEFAULT_PORT)
- ip = node.get('ip')
- pwd = node.get('password')
- key_fname = node.get('key_filename', '/root/.ssh/id_rsa')
-
- if pwd is not None:
- LOG.debug("Log in via pw, user:%s, host:%s, password:%s",
- user, ip, pwd)
- self.client = ssh.SSH(user, ip, password=pwd, port=ssh_port)
- else:
- LOG.debug("Log in via key, user:%s, host:%s, key_filename:%s",
- user, ip, key_fname)
- self.client = ssh.SSH(user, ip, key_filename=key_fname,
- port=ssh_port)
+ self.client = ssh.SSH.from_node(node, defaults={'user': 'ubuntu'})
self.client.wait(timeout=600)