From b1eb58006197c7a41aa5f1e2c2db465bb2f0dbc3 Mon Sep 17 00:00:00 2001 From: QiLiang Date: Sun, 25 Oct 2015 14:47:37 +0000 Subject: Support NodeContext type Initial NodeContext implementation to support BareMetal, Controller, Compute scenarios. Usage: 0) install yardstick 1) mkdir -p /etc/yardstick/nodes 2) cp /etc/yardstick/nodes/pod.yaml.sample \ /etc/yardstick/nodes/pod.yaml 3) edit /etc/yardstick/nodes/pod.yaml (make show ip, username, ssh key are configured correctly) 4) yardstick -d task start \ /samples/ping-node-context.yaml 5) cat /tmp/yardstick.out Design etherpad link: https://etherpad.opnfv.org/p/yardstick_framework JIRA: YARDSTICK-169 Change-Id: I3f6ade8243e68d88326f23ed213edb32c638ed32 Signed-off-by: QiLiang --- .../benchmark/contexts/nodes_duplicate_sample.yaml | 13 +++ tests/unit/benchmark/contexts/nodes_sample.yaml | 25 +++++ tests/unit/benchmark/contexts/test_node.py | 123 +++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml create mode 100644 tests/unit/benchmark/contexts/nodes_sample.yaml create mode 100644 tests/unit/benchmark/contexts/test_node.py (limited to 'tests/unit') diff --git a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml new file mode 100644 index 000000000..cdb5138c2 --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml @@ -0,0 +1,13 @@ +nodes: +- + name: node1 + role: Controller + ip: 10.229.47.137 + user: root + key_filename: /root/.yardstick_key +- + name: node1 + role: Controller + ip: 10.229.47.138 + user: root + key_filename: /root/.yardstick_key diff --git a/tests/unit/benchmark/contexts/nodes_sample.yaml b/tests/unit/benchmark/contexts/nodes_sample.yaml new file mode 100644 index 000000000..59b5bb9fe --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_sample.yaml @@ -0,0 +1,25 @@ +nodes: +- + name: node1 + role: Controller + ip: 10.229.47.137 + user: root + key_filename: /root/.yardstick_key +- + name: node2 + role: Controller + ip: 10.229.47.138 + user: root + key_filename: /root/.yardstick_key +- + name: node3 + role: Compute + ip: 10.229.47.139 + user: root + key_filename: /root/.yardstick_key +- + name: node4 + role: Baremetal + ip: 10.229.47.140 + user: root + key_filename: /root/.yardstick_key diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py new file mode 100644 index 000000000..6939b8551 --- /dev/null +++ b/tests/unit/benchmark/contexts/test_node.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2015 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.contexts.node + +import os +import unittest + +from yardstick.benchmark.contexts import node + + +class NodeContextTestCase(unittest.TestCase): + + NODES_SAMPLE = "nodes_sample.yaml" + NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml" + def setUp(self): + self.test_context = node.NodeContext() + + def test_construct(self): + + self.assertIsNone(self.test_context.name) + self.assertIsNone(self.test_context.file_path) + self.assertEqual(self.test_context.nodes, []) + self.assertEqual(self.test_context.controllers, []) + self.assertEqual(self.test_context.computes, []) + self.assertEqual(self.test_context.baremetals, []) + + def test_unsuccessful_init(self): + + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath("error_file") + } + + self.assertRaises(SystemExit, self.test_context.init, attrs) + + def test_successful_init(self): + + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + + self.test_context.init(attrs) + + self.assertEqual(self.test_context.name, "foo") + self.assertEqual(len(self.test_context.nodes), 4) + self.assertEqual(len(self.test_context.controllers), 2) + self.assertEqual(len(self.test_context.computes), 1) + self.assertEqual(self.test_context.computes[0]["name"], "node3") + self.assertEqual(len(self.test_context.baremetals), 1) + self.assertEqual(self.test_context.baremetals[0]["name"], "node4") + + def test__get_server_with_dic_attr_name(self): + + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + + self.test_context.init(attrs) + + attr_name = {'name': 'foo.bar'} + result = self.test_context._get_server(attr_name) + + self.assertEqual(result, None) + + def test__get_server_not_found(self): + + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + + self.test_context.init(attrs) + + attr_name = 'bar.foo' + result = self.test_context._get_server(attr_name) + + self.assertEqual(result, None) + + def test__get_server_duplicate(self): + + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE) + } + + self.test_context.init(attrs) + + attr_name = 'node1.foo' + + self.assertRaises(SystemExit, self.test_context._get_server, attr_name) + + def test__get_server_found(self): + + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + + self.test_context.init(attrs) + + attr_name = 'node1.foo' + result = self.test_context._get_server(attr_name) + + self.assertEqual(result['ip'], '10.229.47.137') + self.assertEqual(result['name'], 'node1.foo') + self.assertEqual(result['user'], 'root') + self.assertEqual(result['key_filename'], '/root/.yardstick_key') + + 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 -- cgit 1.2.3-korg