diff options
-rw-r--r-- | api/conf.py | 2 | ||||
-rw-r--r-- | api/database/__init__.py | 4 | ||||
-rw-r--r-- | api/server.py | 2 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | tests/unit/apiserver/__init__.py | 35 | ||||
-rw-r--r-- | tests/unit/apiserver/resources/__init__.py | 0 | ||||
-rw-r--r-- | tests/unit/apiserver/resources/test_env_action.py | 32 | ||||
-rw-r--r-- | tests/unit/apiserver/utils/test_common.py (renamed from tests/unit/api/utils/test_common.py) | 0 | ||||
-rw-r--r-- | tests/unit/apiserver/utils/test_influx.py (renamed from tests/unit/api/utils/test_influx.py) | 0 | ||||
-rw-r--r-- | tests/unit/benchmark/contexts/test_node.py | 4 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/node.py | 56 | ||||
-rw-r--r-- | yardstick/benchmark/core/task.py | 3 | ||||
-rw-r--r-- | yardstick/common/constants.py | 2 |
13 files changed, 113 insertions, 29 deletions
diff --git a/api/conf.py b/api/conf.py index abaf34a1f..a4f332533 100644 --- a/api/conf.py +++ b/api/conf.py @@ -15,8 +15,6 @@ with IPDB() as ip: GATEWAY_IP = ip.routes['default'].gateway PORT = 8086 -TEST_ACTION = ['runTestCase'] - TEST_CASE_PATH = '../tests/opnfv/test_cases/' SAMPLE_PATH = '../samples/' diff --git a/api/database/__init__.py b/api/database/__init__.py index d7cf4f9c4..753b34684 100644 --- a/api/database/__init__.py +++ b/api/database/__init__.py @@ -13,10 +13,12 @@ from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base +from yardstick.common import constants as consts + logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) -engine = create_engine('sqlite:////tmp/yardstick.db', convert_unicode=True) +engine = create_engine(consts.SQLITE, convert_unicode=True) db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) diff --git a/api/server.py b/api/server.py index 5bac1ba47..be7963481 100644 --- a/api/server.py +++ b/api/server.py @@ -52,7 +52,6 @@ def init_db(): Base.metadata.create_all(bind=engine) -init_db() reduce(lambda a, b: a.add_resource(b.resource, b.url, endpoint=b.endpoint) or a, urlpatterns, api) @@ -60,4 +59,5 @@ if __name__ == '__main__': _init_logging() logger.setLevel(logging.DEBUG) logger.info('Starting server') + init_db() app.run(host='0.0.0.0') diff --git a/requirements.txt b/requirements.txt index 8f03c8717..107e8dee4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -53,7 +53,7 @@ pycrypto==2.6.1 pyflakes==1.0.0 pyparsing==2.1.0 pyrsistent==0.11.12 -osc-lib==1.3.0 +osc-lib==1.2.0 python-cinderclient==1.9.0 python-glanceclient==2.5.0 python-heatclient==1.5.0 diff --git a/tests/unit/apiserver/__init__.py b/tests/unit/apiserver/__init__.py new file mode 100644 index 000000000..021415296 --- /dev/null +++ b/tests/unit/apiserver/__init__.py @@ -0,0 +1,35 @@ +from __future__ import absolute_import + +import os +import unittest +import tempfile + +from oslo_serialization import jsonutils + +from yardstick.common import constants as consts + + +class APITestCase(unittest.TestCase): + + def setUp(self): + self.db_fd, self.db_path = tempfile.mkstemp() + consts.SQLITE = 'sqlite:///{}'.format(self.db_path) + from api import server + + server.app.config['TESTING'] = True + self.app = server.app.test_client() + + server.init_db() + + def tearDown(self): + os.close(self.db_fd) + os.unlink(self.db_path) + + def _post(self, url, data): + headers = {'Content-Type': 'application/json'} + resp = self.app.post(url, data=jsonutils.dumps(data), headers=headers) + return jsonutils.loads(resp.data) + + def _get(self, url): + resp = self.app.get(url) + return jsonutils.loads(resp.data) diff --git a/tests/unit/apiserver/resources/__init__.py b/tests/unit/apiserver/resources/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/unit/apiserver/resources/__init__.py diff --git a/tests/unit/apiserver/resources/test_env_action.py b/tests/unit/apiserver/resources/test_env_action.py new file mode 100644 index 000000000..e8f99b706 --- /dev/null +++ b/tests/unit/apiserver/resources/test_env_action.py @@ -0,0 +1,32 @@ +from __future__ import absolute_import + +import time +import unittest + +from tests.unit.apiserver import APITestCase + + +class EnvTestCase(APITestCase): + + def test_create_grafana(self): + url = 'yardstick/env/action' + data = dict(action='createGrafanaContainer') + resp = self._post(url, data) + + time.sleep(1) + + task_id = resp['result']['task_id'] + url = '/yardstick/asynctask?task_id={}'.format(task_id) + resp = self._get(url) + + time.sleep(2) + + self.assertTrue(u'status' in resp) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/api/utils/test_common.py b/tests/unit/apiserver/utils/test_common.py index acf6e41b1..acf6e41b1 100644 --- a/tests/unit/api/utils/test_common.py +++ b/tests/unit/apiserver/utils/test_common.py diff --git a/tests/unit/api/utils/test_influx.py b/tests/unit/apiserver/utils/test_influx.py index aff0cab5c..aff0cab5c 100644 --- a/tests/unit/api/utils/test_influx.py +++ b/tests/unit/apiserver/utils/test_influx.py diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py index de5ba7066..64fe4a566 100644 --- a/tests/unit/benchmark/contexts/test_node.py +++ b/tests/unit/benchmark/contexts/test_node.py @@ -42,7 +42,7 @@ class NodeContextTestCase(unittest.TestCase): 'file': self._get_file_abspath("error_file") } - self.assertRaises(SystemExit, self.test_context.init, attrs) + self.assertRaises(IOError, self.test_context.init, attrs) def test_successful_init(self): @@ -100,7 +100,7 @@ class NodeContextTestCase(unittest.TestCase): attr_name = 'node1.foo' - self.assertRaises(SystemExit, self.test_context._get_server, attr_name) + self.assertRaises(ValueError, self.test_context._get_server, attr_name) def test__get_server_found(self): diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py index e02a71669..9242e2727 100644 --- a/yardstick/benchmark/contexts/node.py +++ b/yardstick/benchmark/contexts/node.py @@ -8,10 +8,11 @@ ############################################################################## from __future__ import absolute_import -import sys +import logging +import errno import os +import collections import yaml -import logging from yardstick.benchmark.contexts.base import Context from yardstick.definitions import YARDSTICK_ROOT_PATH @@ -33,20 +34,28 @@ class NodeContext(Context): self.baremetals = [] super(self.__class__, self).__init__() + def read_config_file(self): + """Read from config file""" + + with open(self.file_path) as stream: + LOG.info("Parsing pod file: %s", self.file_path) + cfg = yaml.load(stream) + return cfg + def init(self, attrs): """initializes itself from the supplied arguments""" self.name = attrs["name"] self.file_path = attrs.get("file", "pod.yaml") - if not os.path.exists(self.file_path): - self.file_path = os.path.join(YARDSTICK_ROOT_PATH, self.file_path) - - LOG.info("Parsing pod file: %s", self.file_path) try: - with open(self.file_path) as stream: - cfg = yaml.load(stream) + cfg = self.read_config_file() except IOError as ioerror: - sys.exit(ioerror) + if ioerror.errno == errno.ENOENT: + self.file_path = \ + os.path.join(YARDSTICK_ROOT_PATH, self.file_path) + cfg = self.read_config_file() + else: + raise self.nodes.extend(cfg["nodes"]) self.controllers.extend([node for node in cfg["nodes"] @@ -72,23 +81,28 @@ class NodeContext(Context): """lookup server info by name from context attr_name: a name for a server listed in nodes config file """ - if type(attr_name) is dict: + if isinstance(attr_name, collections.Mapping): return None if self.name != attr_name.split(".")[1]: return None node_name = attr_name.split(".")[0] - nodes = [n for n in self.nodes - if n["name"] == node_name] - if len(nodes) == 0: + matching_nodes = (n for n in self.nodes if n["name"] == node_name) + + try: + # A clone is created in order to avoid affecting the + # original one. + node = dict(next(matching_nodes)) + except StopIteration: return None - elif len(nodes) > 1: - LOG.error("Duplicate nodes!!!") - LOG.error("Nodes: %r", nodes) - sys.exit(-1) - - # A clone is created in order to avoid affecting the - # original one. - node = dict(nodes[0]) + + try: + duplicate = next(matching_nodes) + except StopIteration: + pass + else: + raise ValueError("Duplicate nodes!!! Nodes: %s %s", + (matching_nodes, duplicate)) + node["name"] = attr_name return node diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index d05117b47..6cfec7b13 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -294,7 +294,8 @@ class TaskParser(object): # pragma: no cover change_server_name(scenario, name_suffix) try: - change_server_name(scenario['nodes'], name_suffix) + for node in scenario['nodes']: + scenario['nodes'][node] += name_suffix except KeyError: pass diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py index d99e216f4..ffca4b3e9 100644 --- a/yardstick/common/constants.py +++ b/yardstick/common/constants.py @@ -55,3 +55,5 @@ OPENSTACK_RC_FILE = join(YARDSTICK_CONFIG_DIR, 'openstack.creds') BASE_URL = 'http://localhost:5000' ENV_ACTION_API = BASE_URL + '/yardstick/env/action' ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask' + +SQLITE = 'sqlite:////tmp/yardstick.db' |