From 1100c66ce03a059ebe7ece9734e799b49b3a5a9e Mon Sep 17 00:00:00 2001 From: WuKong Date: Sat, 23 Dec 2017 21:49:35 +0100 Subject: moonv4 cleanup Change-Id: Icef927f3236d985ac13ff7376f6ce6314b2b39b0 Signed-off-by: WuKong --- moonv4/python_moondb/tests/unit_python/conftest.py | 145 --------------------- .../tests/unit_python/mock_components.py | 27 ---- .../tests/unit_python/mock_keystone.py | 23 ---- .../tests/unit_python/requirements.txt | 5 - .../tests/unit_python/test_policies.py | 77 ----------- .../python_moondb/tests/unit_python/utilities.py | 136 ------------------- 6 files changed, 413 deletions(-) delete mode 100644 moonv4/python_moondb/tests/unit_python/conftest.py delete mode 100644 moonv4/python_moondb/tests/unit_python/mock_components.py delete mode 100644 moonv4/python_moondb/tests/unit_python/mock_keystone.py delete mode 100644 moonv4/python_moondb/tests/unit_python/requirements.txt delete mode 100644 moonv4/python_moondb/tests/unit_python/test_policies.py delete mode 100644 moonv4/python_moondb/tests/unit_python/utilities.py (limited to 'moonv4/python_moondb/tests/unit_python') diff --git a/moonv4/python_moondb/tests/unit_python/conftest.py b/moonv4/python_moondb/tests/unit_python/conftest.py deleted file mode 100644 index c2e5e579..00000000 --- a/moonv4/python_moondb/tests/unit_python/conftest.py +++ /dev/null @@ -1,145 +0,0 @@ -import base64 -import json -import logging -import os -import pytest -import requests_mock -import mock_components -import mock_keystone - -CONF = { - "openstack": { - "keystone": { - "url": "http://keystone:5000/v3", - "user": "admin", - "check_token": False, - "password": "p4ssw0rd", - "domain": "default", - "certificate": False, - "project": "admin" - } - }, - "components": { - "wrapper": { - "bind": "0.0.0.0", - "port": 8080, - "container": "wukongsun/moon_wrapper:v4.3", - "timeout": 5, - "hostname": "wrapper" - }, - "manager": { - "bind": "0.0.0.0", - "port": 8082, - "container": "wukongsun/moon_manager:v4.3", - "hostname": "manager" - }, - "port_start": 31001, - "orchestrator": { - "bind": "0.0.0.0", - "port": 8083, - "container": "wukongsun/moon_orchestrator:v4.3", - "hostname": "interface" - }, - "interface": { - "bind": "0.0.0.0", - "port": 8080, - "container": "wukongsun/moon_interface:v4.3", - "hostname": "interface" - } - }, - "plugins": { - "session": { - "port": 8082, - "container": "asteroide/session:latest" - }, - "authz": { - "port": 8081, - "container": "wukongsun/moon_authz:v4.3" - } - }, - "logging": { - "handlers": { - "file": { - "filename": "/tmp/moon.log", - "class": "logging.handlers.RotatingFileHandler", - "level": "DEBUG", - "formatter": "custom", - "backupCount": 3, - "maxBytes": 1048576 - }, - "console": { - "class": "logging.StreamHandler", - "formatter": "brief", - "level": "INFO", - "stream": "ext://sys.stdout" - } - }, - "formatters": { - "brief": { - "format": "%(levelname)s %(name)s %(message)-30s" - }, - "custom": { - "format": "%(asctime)-15s %(levelname)s %(name)s %(message)s" - } - }, - "root": { - "handlers": [ - "console" - ], - "level": "ERROR" - }, - "version": 1, - "loggers": { - "moon": { - "handlers": [ - "console", - "file" - ], - "propagate": False, - "level": "DEBUG" - } - } - }, - "slave": { - "name": None, - "master": { - "url": None, - "login": None, - "password": None - } - }, - "docker": { - "url": "tcp://172.88.88.1:2376", - "network": "moon" - }, - "database": { - "url": "sqlite:///database.db", - # "url": "mysql+pymysql://moon:p4sswOrd1@db/moon", - "driver": "sql" - }, - "messenger": { - "url": "rabbit://moon:p4sswOrd1@messenger:5672/moon" - } -} - - -@pytest.fixture -def db(): - return CONF['database'] - - -@pytest.fixture(autouse=True) -def set_consul_and_db(monkeypatch): - """ Modify the response from Requests module - """ - with requests_mock.Mocker(real_http=True) as m: - mock_components.register_components(m) - mock_keystone.register_keystone(m) - - from moon_db.db_manager import init_engine, main - engine = init_engine() - main("upgrade", logging.getLogger("db_manager"), engine) - yield m - os.unlink(CONF['database']['url'].replace("sqlite:///", "")) - - diff --git a/moonv4/python_moondb/tests/unit_python/mock_components.py b/moonv4/python_moondb/tests/unit_python/mock_components.py deleted file mode 100644 index a0319e1a..00000000 --- a/moonv4/python_moondb/tests/unit_python/mock_components.py +++ /dev/null @@ -1,27 +0,0 @@ -import utilities - -COMPONENTS = ( - "logging", - "openstack/keystone", - "database", - "slave", - "components/manager", - "components/orchestrator", - "components/interface", -) - - -def register_components(m): - for component in COMPONENTS: - m.register_uri( - 'GET', 'http://consul:8500/v1/kv/{}'.format(component), - json=[{'Key': component, 'Value': utilities.get_b64_conf(component)}] - ) - - m.register_uri( - 'GET', 'http://consul:8500/v1/kv/components?recurse=true', - json=[ - {"Key": key, "Value": utilities.get_b64_conf(key)} for key in COMPONENTS - ], - # json={'Key': "components", 'Value': get_b64_conf("components")} - ) \ No newline at end of file diff --git a/moonv4/python_moondb/tests/unit_python/mock_keystone.py b/moonv4/python_moondb/tests/unit_python/mock_keystone.py deleted file mode 100644 index c0b26b88..00000000 --- a/moonv4/python_moondb/tests/unit_python/mock_keystone.py +++ /dev/null @@ -1,23 +0,0 @@ -def register_keystone(m): - m.register_uri( - 'POST', 'http://keystone:5000/v3/auth/tokens', - headers={'X-Subject-Token': "111111111"} - ) - m.register_uri( - 'DELETE', 'http://keystone:5000/v3/auth/tokens', - headers={'X-Subject-Token': "111111111"} - ) - m.register_uri( - 'POST', 'http://keystone:5000/v3/users?name=testuser&domain_id=default', - json={"users": {}} - ) - m.register_uri( - 'GET', 'http://keystone:5000/v3/users?name=testuser&domain_id=default', - json={"users": {}} - ) - m.register_uri( - 'POST', 'http://keystone:5000/v3/users/', - json={"users": [{ - "id": "1111111111111" - }]} - ) \ No newline at end of file diff --git a/moonv4/python_moondb/tests/unit_python/requirements.txt b/moonv4/python_moondb/tests/unit_python/requirements.txt deleted file mode 100644 index 5f507ff7..00000000 --- a/moonv4/python_moondb/tests/unit_python/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -sqlalchemy -pymysql -pytest -requests_mock -python_moonutilities \ No newline at end of file diff --git a/moonv4/python_moondb/tests/unit_python/test_policies.py b/moonv4/python_moondb/tests/unit_python/test_policies.py deleted file mode 100644 index 3bd1360e..00000000 --- a/moonv4/python_moondb/tests/unit_python/test_policies.py +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors -# This software is distributed under the terms and conditions of the 'Apache-2.0' -# license which can be found in the file 'LICENSE' in this package distribution -# or at 'http://www.apache.org/licenses/LICENSE-2.0'. - - -def get_policies(): - from moon_db.core import PolicyManager - return PolicyManager.get_policies("admin") - - -def add_policies(value=None): - from moon_db.core import PolicyManager - if not value: - value = { - "name": "test_policiy", - "model_id": "", - "genre": "authz", - "description": "test", - } - return PolicyManager.add_policy("admin", value=value) - - -def delete_policies(uuid=None, name=None): - from moon_db.core import PolicyManager - if not uuid: - for policy_id, policy_value in get_policies(): - if name == policy_value['name']: - uuid = policy_id - break - PolicyManager.delete_policy("admin", uuid) - - -def test_get_policies(db): - policies = get_policies() - assert isinstance(policies, dict) - assert not policies - - -def test_add_policies(db): - value = { - "name": "test_policy", - "model_id": "", - "genre": "authz", - "description": "test", - } - policies = add_policies(value) - assert isinstance(policies, dict) - assert policies - assert len(policies.keys()) == 1 - policy_id = list(policies.keys())[0] - for key in ("genre", "name", "model_id", "description"): - assert key in policies[policy_id] - assert policies[policy_id][key] == value[key] - - -def test_delete_policies(db): - value = { - "name": "test_policy1", - "model_id": "", - "genre": "authz", - "description": "test", - } - policies = add_policies(value) - policy_id1 = list(policies.keys())[0] - value = { - "name": "test_policy2", - "model_id": "", - "genre": "authz", - "description": "test", - } - policies = add_policies(value) - policy_id2 = list(policies.keys())[0] - assert policy_id1 != policy_id2 - delete_policies(policy_id1) - policies = get_policies() - assert policy_id1 not in policies diff --git a/moonv4/python_moondb/tests/unit_python/utilities.py b/moonv4/python_moondb/tests/unit_python/utilities.py deleted file mode 100644 index 1d79d890..00000000 --- a/moonv4/python_moondb/tests/unit_python/utilities.py +++ /dev/null @@ -1,136 +0,0 @@ -import base64 -import json - - -CONF = { - "openstack": { - "keystone": { - "url": "http://keystone:5000/v3", - "user": "admin", - "check_token": False, - "password": "p4ssw0rd", - "domain": "default", - "certificate": False, - "project": "admin" - } - }, - "components": { - "wrapper": { - "bind": "0.0.0.0", - "port": 8080, - "container": "wukongsun/moon_wrapper:v4.3", - "timeout": 5, - "hostname": "wrapper" - }, - "manager": { - "bind": "0.0.0.0", - "port": 8082, - "container": "wukongsun/moon_manager:v4.3", - "hostname": "manager" - }, - "port_start": 31001, - "orchestrator": { - "bind": "0.0.0.0", - "port": 8083, - "container": "wukongsun/moon_orchestrator:v4.3", - "hostname": "interface" - }, - "interface": { - "bind": "0.0.0.0", - "port": 8080, - "container": "wukongsun/moon_interface:v4.3", - "hostname": "interface" - } - }, - "plugins": { - "session": { - "port": 8082, - "container": "asteroide/session:latest" - }, - "authz": { - "port": 8081, - "container": "wukongsun/moon_authz:v4.3" - } - }, - "logging": { - "handlers": { - "file": { - "filename": "/tmp/moon.log", - "class": "logging.handlers.RotatingFileHandler", - "level": "DEBUG", - "formatter": "custom", - "backupCount": 3, - "maxBytes": 1048576 - }, - "console": { - "class": "logging.StreamHandler", - "formatter": "brief", - "level": "INFO", - "stream": "ext://sys.stdout" - } - }, - "formatters": { - "brief": { - "format": "%(levelname)s %(name)s %(message)-30s" - }, - "custom": { - "format": "%(asctime)-15s %(levelname)s %(name)s %(message)s" - } - }, - "root": { - "handlers": [ - "console" - ], - "level": "ERROR" - }, - "version": 1, - "loggers": { - "moon": { - "handlers": [ - "console", - "file" - ], - "propagate": False, - "level": "DEBUG" - } - } - }, - "slave": { - "name": None, - "master": { - "url": None, - "login": None, - "password": None - } - }, - "docker": { - "url": "tcp://172.88.88.1:2376", - "network": "moon" - }, - "database": { - "url": "sqlite:///database.db", - # "url": "mysql+pymysql://moon:p4sswOrd1@db/moon", - "driver": "sql" - }, - "messenger": { - "url": "rabbit://moon:p4sswOrd1@messenger:5672/moon" - } -} - - -def get_b64_conf(component=None): - if component == "components": - return base64.b64encode( - json.dumps(CONF["components"]).encode('utf-8')+b"\n").decode('utf-8') - elif component in CONF: - return base64.b64encode( - json.dumps( - CONF[component]).encode('utf-8')+b"\n").decode('utf-8') - elif not component: - return base64.b64encode( - json.dumps(CONF).encode('utf-8')+b"\n").decode('utf-8') - elif "/" in component: - key1, _, key2 = component.partition("/") - return base64.b64encode( - json.dumps( - CONF[key1][key2]).encode('utf-8')+b"\n").decode('utf-8') -- cgit 1.2.3-korg