summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJingLu5 <lvjing5@huawei.com>2017-10-11 05:54:25 +0000
committerJing Lu <lvjing5@huawei.com>2017-10-19 03:47:15 +0000
commit0389453486af8b58f77a65a6455068fe95346e47 (patch)
treee16b4ec41a00956d654d4001411ca53966612efb
parent1addec17ea56fa077b01c307e64343f69207bfe5 (diff)
add CheckConnectivity scenario
Change-Id: I9d246828790467c2a57ba410826ee9751fff89c5 Signed-off-by: JingLu5 <lvjing5@huawei.com> (cherry picked from commit 4712d72a570dc9e2799227d489ee41768881a06d)
-rw-r--r--samples/check_connectivity.yaml31
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_check_connectivity.py84
-rw-r--r--yardstick/benchmark/scenarios/lib/check_connectivity.py99
3 files changed, 214 insertions, 0 deletions
diff --git a/samples/check_connectivity.yaml b/samples/check_connectivity.yaml
new file mode 100644
index 000000000..47f7d2c81
--- /dev/null
+++ b/samples/check_connectivity.yaml
@@ -0,0 +1,31 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+---
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+ type: CheckConnectivity
+ options:
+ src_ip_addr: '192.168.23.2'
+ dest_ip_addr: '192.168.23.10'
+ ssh_user: 'root'
+ ssh_passwd: 'root'
+ # ssh_key:
+ ssh_port: 22
+ ssh_timeout: 600
+ ping_parameter: "-s 2048"
+
+ runner:
+ type: Iteration
+ iterations: 1
+
+ sla:
+ status: True
+ action: assert
diff --git a/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py b/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py
new file mode 100644
index 000000000..1fb2f89ca
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py
@@ -0,0 +1,84 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.lib.check_connectivity.CheckConnectivity
+
+from __future__ import absolute_import
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.lib import check_connectivity
+
+
+class CheckConnectivityTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'root',
+ 'key_filename': 'mykey.key',
+ 'ssh_port': '22'
+ },
+ 'target': {
+ 'ipaddr': '172.16.0.138'
+ }
+ }
+
+ @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh')
+ def test_check_connectivity(self, mock_ssh):
+
+ args = {
+ 'options': {'src_ip_addr': '192.168.23.2',
+ 'dest_ip_addr': '192.168.23.10',
+ 'ssh_user': 'root',
+ 'ssh_passwd': 'root',
+ 'ssh_port': '22',
+ 'ssh_timeout': 600,
+ 'ping_parameter': "-s 2048"
+ },
+ 'sla': {'status': 'True',
+ 'action': 'assert'}
+ }
+
+ result = {}
+
+ obj = check_connectivity.CheckConnectivity(args, {})
+ obj.setup()
+ mock_ssh.SSH.execute.return_value = (0, '100', '')
+
+
+ @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh')
+ def test_check_connectivity_key(self, mock_ssh):
+
+ args = {
+ 'options': {'ssh_user': 'root',
+ 'ssh_key': '/root/.ssh/id_rsa',
+ 'ssh_port': '22',
+ 'ssh_timeout': 600,
+ 'ping_parameter': "-s 2048"
+ },
+ 'sla': {'status': 'True',
+ 'action': 'assert'}
+ }
+
+ result = {}
+
+ obj = check_connectivity.CheckConnectivity(args, self.ctx)
+ obj.setup()
+
+ mock_ssh.SSH.execute.return_value = (0, '100', '')
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/yardstick/benchmark/scenarios/lib/check_connectivity.py b/yardstick/benchmark/scenarios/lib/check_connectivity.py
new file mode 100644
index 000000000..bdf52d4c8
--- /dev/null
+++ b/yardstick/benchmark/scenarios/lib/check_connectivity.py
@@ -0,0 +1,99 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from __future__ import print_function
+from __future__ import absolute_import
+
+import logging
+import yardstick.ssh as ssh
+
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class CheckConnectivity(base.Scenario):
+ """Check connectivity between two VMs"""
+
+ __scenario_type__ = "CheckConnectivity"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.options = self.scenario_cfg['options']
+
+ try:
+ self.source_ip_addr = self.options['src_ip_addr']
+ self.dest_ip_addr = self.options['dest_ip_addr']
+ except KeyError:
+ host = self.context_cfg['host']
+ target = self.context_cfg['target']
+ self.ssh_user = host.get('user', 'ubuntu')
+ self.ssh_port = host.get("ssh_port", 22)
+ self.source_ip_addr = host.get('ip', None)
+ self.dest_ip_addr = target.get('ipaddr', None)
+ self.ssh_key = host.get('key_filename', '/root/.ssh/id_rsa')
+ self.ssh_passwd = host.get('password', None)
+ self.ssh_timeout = 600
+ else:
+ self.ssh_user = self.options.get("ssh_user", 'ubuntu')
+ self.ssh_port = self.options.get("ssh_port", 22)
+ self.ssh_key = self.options.get("ssh_key", '/root/.ssh/id_rsa')
+ self.ssh_passwd = self.options.get("ssh_passwd", None)
+ self.ssh_timeout = self.options.get("ssh_timeout", 600)
+
+ self.connection = None
+ self.setup_done = False
+
+ def setup(self):
+ """scenario setup"""
+
+ if self.ssh_passwd is not None:
+ LOG.info("Log in via pw, user:%s, host:%s, pw:%s",
+ self.ssh_user, self.source_ip_addr, self.ssh_passwd)
+ self.connection = ssh.SSH(self.ssh_user,
+ self.source_ip_addr,
+ password=self.ssh_passwd,
+ port=self.ssh_port)
+ else:
+ LOG.info("Log in via key, user:%s, host:%s, key_filename:%s",
+ self.ssh_user, self.source_ip_addr, self.ssh_key)
+ self.connection = ssh.SSH(self.ssh_user,
+ self.source_ip_addr,
+ key_filename=self.ssh_key,
+ port=self.ssh_port)
+
+ self.connection.wait(timeout=self.ssh_timeout)
+ self.setup_done = True
+
+ def run(self, result): # pragma: no cover
+ """execute the test"""
+
+ if not self.setup_done:
+ self.setup()
+
+ cmd = 'ping -c 4 ' + self.dest_ip_addr
+ parameter = self.options.get('ping_parameter', None)
+ if parameter:
+ cmd += (" %s" % parameter)
+
+ LOG.info("Executing command: %s", cmd)
+ LOG.info("ping %s ==> %s", self.source_ip_addr, self.dest_ip_addr)
+ status, stdout, stderr = self.connection.execute(cmd)
+
+ conn_status = self.scenario_cfg['sla']['status']
+
+ if bool(status) != bool(conn_status):
+ LOG.info("%s ===> %s connectivity check passed!" % (self.source_ip_addr,
+ self.dest_ip_addr))
+ result['Check_Connectivity'] = 'PASS'
+ else:
+ LOG.info("%s ===> %s connectivity check failed!" % (self.source_ip_addr,
+ self.dest_ip_addr))
+ result['Check_Connectivity'] = 'FAIL'