X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fping6.py;h=9aa94c40cc56e796dad8f2060c75ac8540a62208;hb=911c3a3729da77386848d5e9843c2fe91a965939;hp=817f3e278a19865f06275b5750f3f90f22b5f347;hpb=601c4126e2acd34d0f5ac7d5e159703e525b3f7d;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/ping6.py b/yardstick/benchmark/scenarios/networking/ping6.py index 817f3e278..9aa94c40c 100644 --- a/yardstick/benchmark/scenarios/networking/ping6.py +++ b/yardstick/benchmark/scenarios/networking/ping6.py @@ -37,9 +37,34 @@ class Ping6(base.Scenario): # pragma: no cover def __init__(self, scenario_cfg, context_cfg): self.scenario_cfg = scenario_cfg self.context_cfg = context_cfg + self.nodes = context_cfg['nodes'] + self.options = scenario_cfg['options'] self.setup_done = False self.run_done = False - self.ping_options = '' + self.external_network = self.options.get("external_network", "ext-net") + self.ping_options = "-s %s -c %s" % \ + (self.options.get("packetsize", '56'), + self.options.get("ping_count", '5')) + self.openrc = self.options.get("openrc", "/opt/admin-openrc.sh") + + def _ssh_host(self, node_name): + # ssh host + node = self.nodes.get(node_name, None) + user = node.get('user', 'ubuntu') + ssh_port = node.get("ssh_port", ssh.DEFAULT_PORT) + ip = node.get('ip', None) + pwd = node.get('password', None) + 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.wait(timeout=60) def _pre_setup(self): for node_name in self.host_list: @@ -49,17 +74,13 @@ class Ping6(base.Scenario): # pragma: no cover status, stdout, stderr = self.client.execute( "sudo bash pre_setup.sh") - def _ssh_host(self, node_name): - # ssh host - print node_name - nodes = self.context_cfg['nodes'] - node = nodes.get(node_name, None) - host_user = node.get('user', 'ubuntu') - host_ip = node.get('ip', None) - host_pwd = node.get('password', 'root') - LOG.debug("user:%s, host:%s", host_user, host_ip) - self.client = ssh.SSH(host_user, host_ip, password=host_pwd) - self.client.wait(timeout=600) + def _get_controller_node(self, host_list): + for host_name in host_list: + node = self.nodes.get(host_name, None) + node_role = node.get('role', None) + if node_role == 'Controller': + return host_name + return None def setup(self): '''scenario setup''' @@ -83,37 +104,37 @@ class Ping6(base.Scenario): # pragma: no cover 'yardstick.benchmark.scenarios.networking', Ping6.RADVD_SCRIPT) - options = self.scenario_cfg['options'] - self.ping_options = "-s %s" % \ - options.get("packetsize", '56') + \ - " -c %s" % \ - options.get("ping_count", '5') - host_str = options.get("host", 'host1') + host_str = self.options.get("host", 'host1') self.host_list = host_str.split(',') self.host_list.sort() - pre_setup = options.get("pre_setup", True) + pre_setup = self.options.get("pre_setup", True) if pre_setup: self._pre_setup() - # ssh host1 - self._ssh_host(self.host_list[0]) - + # log in a contronller node to setup + controller_node_name = self._get_controller_node(self.host_list) + LOG.debug("The Controller Node is: %s", controller_node_name) + if controller_node_name is None: + LOG.exception("Can't find controller node in the context!!!") + self._ssh_host(controller_node_name) self.client.run("cat > ~/metadata.txt", stdin=open(self.ping6_metadata_script, "rb")) # run script to setup ipv6 with nosdn or odl - sdn = options.get("sdn", 'nosdn') + sdn = self.options.get("sdn", 'nosdn') if 'odl' in sdn: self.client.run("cat > ~/br-ex.radvd.conf", stdin=open(self.ping6_radvd_script, "rb")) self.client.run("cat > ~/setup_odl.sh", stdin=open(self.setup_odl_script, "rb")) - cmd = "sudo bash setup_odl.sh" + setup_bash_file = "setup_odl.sh" else: self.client.run("cat > ~/setup.sh", stdin=open(self.setup_script, "rb")) - cmd = "sudo bash setup.sh" - + setup_bash_file = "setup.sh" + cmd = "sudo bash %s %s %s" % \ + (setup_bash_file, self.openrc, self.external_network) + LOG.debug("Executing setup command: %s", cmd) status, stdout, stderr = self.client.execute(cmd) self.setup_done = True @@ -128,14 +149,8 @@ class Ping6(base.Scenario): # pragma: no cover self.ping6_find_host_script = pkg_resources.resource_filename( 'yardstick.benchmark.scenarios.networking', Ping6.FIND_HOST_SCRIPT) - if not self.setup_done: - options = self.scenario_cfg['options'] - self.ping_options = "-s %s" % \ - options.get("packetsize", '56') + \ - " -c %s" % \ - options.get("ping_count", '5') - host_str = options.get("host", 'host1') + host_str = self.options.get("host", 'host1') self.host_list = host_str.split(',') self.host_list.sort() self._ssh_host(self.host_list[0]) @@ -143,8 +158,8 @@ class Ping6(base.Scenario): # pragma: no cover # find ipv4-int-network1 to ssh VM self.client.run("cat > ~/find_host.sh", stdin=open(self.ping6_find_host_script, "rb")) - cmd = "sudo bash find_host.sh" - LOG.debug("Executing command: %s", cmd) + cmd = "sudo bash find_host.sh %s" % self.openrc + LOG.debug("Executing find_host command: %s", cmd) status, stdout, stderr = self.client.execute(cmd) host_name = stdout.strip() @@ -158,9 +173,8 @@ class Ping6(base.Scenario): # pragma: no cover # run ping6 benchmark self.client.run("cat > ~/ping6.sh", stdin=open(self.ping6_script, "rb")) - cmd_args = "%s" % (self.ping_options) - cmd = "sudo bash ping6.sh %s" % (cmd_args) - LOG.debug("Executing command: %s", cmd) + cmd = "sudo bash ping6.sh %s %s" % (self.openrc, self.ping_options) + LOG.debug("Executing ping6 command: %s", cmd) status, stdout, stderr = self.client.execute(cmd) if status: @@ -174,7 +188,7 @@ class Ping6(base.Scenario): # pragma: no cover assert result["rtt"] <= sla_max_rtt, \ "rtt %f > sla:max_rtt(%f); " % (result["rtt"], sla_max_rtt) else: - LOG.error("ping6 timeout") + LOG.error("ping6 timeout!!!") self.run_done = True def teardown(self): @@ -184,8 +198,7 @@ class Ping6(base.Scenario): # pragma: no cover 'yardstick.benchmark.scenarios.networking', Ping6.POST_TEARDOWN_SCRIPT) - options = self.scenario_cfg['options'] - host_str = options.get("host", 'node1') + host_str = self.options.get("host", 'node1') self.host_list = host_str.split(',') self.host_list.sort() @@ -197,10 +210,11 @@ class Ping6(base.Scenario): # pragma: no cover Ping6.TEARDOWN_SCRIPT) self.client.run("cat > ~/teardown.sh", stdin=open(self.teardown_script, "rb")) - cmd = "sudo bash teardown.sh" + cmd = "sudo bash teardown.sh %s %s" % \ + (self.openrc, self.external_network) status, stdout, stderr = self.client.execute(cmd) - post_teardown = options.get("post_teardown", True) + post_teardown = self.options.get("post_teardown", True) if post_teardown: self._post_teardown()