aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsetup.py2
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_ping6.py17
-rw-r--r--tests/unit/common/config_sample.yaml2
-rw-r--r--tests/unit/common/test_utils.py27
-rw-r--r--yardstick/benchmark/scenarios/networking/ping6.py18
-rw-r--r--yardstick/benchmark/scenarios/networking/ping6_setup.bash7
-rw-r--r--yardstick/cmd/cli.py35
-rw-r--r--yardstick/cmd/commands/task.py2
-rw-r--r--yardstick/common/constants.py3
-rw-r--r--yardstick/common/utils.py23
10 files changed, 127 insertions, 9 deletions
diff --git a/setup.py b/setup.py
index 4fe2596c8..9bf656bac 100755
--- a/setup.py
+++ b/setup.py
@@ -66,5 +66,5 @@ setup(
scripts=['tools/yardstick-img-modify',
'tools/yardstick-img-lxd-modify',
'tools/yardstick-img-dpdk-modify'
- ]
+ ]
)
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping6.py b/tests/unit/benchmark/scenarios/networking/test_ping6.py
index 995113e28..0b8fba268 100644
--- a/tests/unit/benchmark/scenarios/networking/test_ping6.py
+++ b/tests/unit/benchmark/scenarios/networking/test_ping6.py
@@ -25,12 +25,29 @@ class PingTestCase(unittest.TestCase):
'host1': {
'ip': '172.16.0.137',
'user': 'cirros',
+ 'role': "Controller",
'key_filename': "mykey.key",
'password': "root"
},
+ 'host2': {
+ "ip": "172.16.0.138",
+ "key_filename": "/root/.ssh/id_rsa",
+ "role": "Compute",
+ "name": "node3.IPV6",
+ "user": "root"
+ },
}
}
+ def test_get_controller_node(self):
+ args = {
+ 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'sla': {'max_rtt': 50}
+ }
+ p = ping6.Ping6(args, self.ctx)
+ controller_node = p._get_controller_node(['host1','host2'])
+ self.assertEqual(controller_node, 'host1')
+
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_successful_setup(self, mock_ssh):
args = {
diff --git a/tests/unit/common/config_sample.yaml b/tests/unit/common/config_sample.yaml
new file mode 100644
index 000000000..8caa19ec6
--- /dev/null
+++ b/tests/unit/common/config_sample.yaml
@@ -0,0 +1,2 @@
+releng:
+ dir: /home/opnfv/repos/releng
diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py
index 002d0494c..a64c1f1ab 100644
--- a/tests/unit/common/test_utils.py
+++ b/tests/unit/common/test_utils.py
@@ -83,6 +83,33 @@ class ImportModulesFromPackageTestCase(unittest.TestCase):
mock_importutils.import_module.assert_called_with('bar.baz')
+class GetParaFromYaml(unittest.TestCase):
+
+ def test_get_para_from_yaml_file_not_exist(self):
+ file_path = '/etc/yardstick/hello.yaml'
+ args = 'hello.world'
+ para = utils.get_para_from_yaml(file_path, args)
+ self.assertIsNone(para)
+
+ def test_get_para_from_yaml_para_not_found(self):
+ file_path = 'config_sample.yaml'
+ file_path = self._get_file_abspath(file_path)
+ args = 'releng.file'
+ self.assertIsNone(utils.get_para_from_yaml(file_path, args))
+
+ def test_get_para_from_yaml_para_exists(self):
+ file_path = 'config_sample.yaml'
+ file_path = self._get_file_abspath(file_path)
+ args = 'releng.dir'
+ para = '/home/opnfv/repos/releng'
+ self.assertEqual(para, utils.get_para_from_yaml(file_path, args))
+
+ def _get_file_abspath(self, filename):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ file_path = os.path.join(curr_path, filename)
+ return file_path
+
+
def main():
unittest.main()
diff --git a/yardstick/benchmark/scenarios/networking/ping6.py b/yardstick/benchmark/scenarios/networking/ping6.py
index c6ec33e3e..9aa94c40c 100644
--- a/yardstick/benchmark/scenarios/networking/ping6.py
+++ b/yardstick/benchmark/scenarios/networking/ping6.py
@@ -55,7 +55,6 @@ class Ping6(base.Scenario): # pragma: no cover
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)
@@ -75,6 +74,14 @@ class Ping6(base.Scenario): # pragma: no cover
status, stdout, stderr = self.client.execute(
"sudo bash pre_setup.sh")
+ 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'''
self.setup_script = pkg_resources.resource_filename(
@@ -104,9 +111,12 @@ class Ping6(base.Scenario): # pragma: no cover
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"))
diff --git a/yardstick/benchmark/scenarios/networking/ping6_setup.bash b/yardstick/benchmark/scenarios/networking/ping6_setup.bash
index fb6da4fdb..592ced3df 100644
--- a/yardstick/benchmark/scenarios/networking/ping6_setup.bash
+++ b/yardstick/benchmark/scenarios/networking/ping6_setup.bash
@@ -15,8 +15,13 @@ openrc=$1
external_network=$2
echo "openrc=$openrc"
echo "external_network=$external_network"
+echo "nameserver 8.8.4.4" >> /etc/resolv.conf
source $openrc
-wget https://download.fedoraproject.org/pub/fedora/linux/releases/22/Cloud/x86_64/Images/Fedora-Cloud-Base-22-20150521.x86_64.qcow2 >/dev/null 2>&1
+
+fedora_img="Fedora-Cloud-Base-22-20150521.x86_64.qcow2"
+if [ ! -f "$fedora_img" ]; then
+ wget https://download.fedoraproject.org/pub/fedora/linux/releases/22/Cloud/x86_64/Images/${fedora_img} >/dev/null 2>&1
+fi
glance image-create --name 'Fedora22' --disk-format qcow2 \
--container-format bare --file ./Fedora-Cloud-Base-22-20150521.x86_64.qcow2
diff --git a/yardstick/cmd/cli.py b/yardstick/cmd/cli.py
index dd74836cb..f2406bf08 100644
--- a/yardstick/cmd/cli.py
+++ b/yardstick/cmd/cli.py
@@ -101,8 +101,7 @@ class YardstickCLI():
cmd_subparsers = subparser.add_subparsers(title='subcommands')
self._find_actions(cmd_subparsers, command_object)
- def main(self, argv):
- '''run the command line interface'''
+ def _register_cli_opt(self):
# register subcommands to parse additional command line arguments
def parser(subparsers):
@@ -114,10 +113,14 @@ class YardstickCLI():
handler=parser)
CONF.register_cli_opt(category_opt)
+ def _load_cli_config(self, argv):
+
# load CLI args and config files
CONF(argv, project="yardstick", version=self._version,
default_config_files=find_config_files(CONFIG_SEARCH_PATHS))
+ def _handle_global_opts(self):
+
# handle global opts
logger = logging.getLogger('yardstick')
logger.setLevel(logging.WARNING)
@@ -128,6 +131,34 @@ class YardstickCLI():
if CONF.debug:
logger.setLevel(logging.DEBUG)
+ def _dispath_func_notask(self):
+
# dispatch to category parser
func = CONF.category.func
func(CONF.category)
+
+ def _dispath_func_task(self, task_id, timestamp):
+
+ # dispatch to category parser
+ func = CONF.category.func
+ func(CONF.category, task_id=task_id, timestamp=timestamp)
+
+ def main(self, argv): # pragma: no cover
+ '''run the command line interface'''
+ self._register_cli_opt()
+
+ self._load_cli_config(argv)
+
+ self._handle_global_opts()
+
+ self._dispath_func_notask()
+
+ def api(self, argv, task_id, timestamp): # pragma: no cover
+ '''run the api interface'''
+ self._register_cli_opt()
+
+ self._load_cli_config(argv)
+
+ self._handle_global_opts()
+
+ self._dispath_func_task(task_id, timestamp)
diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py
index b38e084ac..a10a2a8a3 100644
--- a/yardstick/cmd/commands/task.py
+++ b/yardstick/cmd/commands/task.py
@@ -51,7 +51,7 @@ class TaskCommands(object):
output_file_default, default=output_file_default)
@cliargs("--suite", help="process test suite file instead of a task file",
action="store_true")
- def do_start(self, args):
+ def do_start(self, args, **kwargs):
'''Start a benchmark scenario.'''
atexit.register(atexit_handler)
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
new file mode 100644
index 000000000..40b29a717
--- /dev/null
+++ b/yardstick/common/constants.py
@@ -0,0 +1,3 @@
+CONFIG_SAMPLE = '/etc/yardstick/config.yaml'
+
+RELENG_DIR = 'releng.dir'
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index c482b4da4..d639fb66a 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -17,6 +17,7 @@
import os
import sys
+import yaml
from oslo_utils import importutils
import yardstick
@@ -68,3 +69,25 @@ def import_modules_from_package(package):
new_package = ".".join(root.split(os.sep)).split("....")[1]
module_name = "%s.%s" % (new_package, filename[:-3])
try_append_module(module_name, sys.modules)
+
+
+def get_para_from_yaml(file_path, args):
+
+ def func(a, b):
+ if a is None:
+ return None
+ return a.get(b)
+
+ if os.path.exists(file_path):
+ with open(file_path) as f:
+ value = yaml.safe_load(f)
+ value = reduce(func, args.split('.'), value)
+
+ if value is None:
+ print 'parameter not found'
+ return None
+
+ return value
+ else:
+ print 'file not exist'
+ return None