Unit tests for openstack_config and utils modules

Change-Id: I20e7be8e0d440efb1709f28c9b3b08ef79377de6
This commit is contained in:
Ukov Dmitry 2016-09-02 12:20:50 +03:00
parent 7093112ac7
commit 0611949240
11 changed files with 184 additions and 4 deletions

View File

View File

@ -0,0 +1,14 @@
import os
from oslotest import base
from fuel_external_git import settings
class TestCase(base.BaseTestCase):
"""Test case base class for all unit tests."""
def setUp(self):
super(TestCase, self).setUp()
self.config = settings.GitExtensionSettings().config
self.cfg_sample_dir = os.path.join(os.path.dirname(__file__), 'cfgs')

View File

@ -0,0 +1,5 @@
[DEFAULT]
global_param = global_param
global_param_to_override = override_from_role
role_param = role_param
role_param_to_override = role_param_to_override

View File

@ -0,0 +1,3 @@
[DEFAULT]
role_param_to_override = override_from_node
node_param = node_param

View File

@ -0,0 +1,3 @@
[DEFAULT]
global_param = global_param
global_param_to_override = global_param_to_override

View File

@ -0,0 +1,8 @@
nodes:
'1': node_1_configs
'2': node_2_configs
roles:
'cinder': 'cinder_configs'
'compute': 'compute_configs'
'controller': 'controller_configs'
'primary-controller': 'controller_configs'

View File

@ -0,0 +1,25 @@
import os
from fuel_external_git.tests import base
from fuel_external_git.openstack_config import OpenStackConfig
class TestOpenStackConfig(base.TestCase):
def test_config_name(self):
file_name = os.path.join(self.cfg_sample_dir, 'nova.conf')
cfg = OpenStackConfig(file_name, self.config['resource_mapping'])
self.assertEqual(cfg.config_name, 'nova_config')
def test_dict_generation(self):
resource = {
'DEFAULT/global_param': {
'value': 'global_param'
},
'DEFAULT/global_param_to_override': {
'value': 'global_param_to_override'
},
}
file_name = os.path.join(self.cfg_sample_dir, 'nova.conf')
cfg = OpenStackConfig(file_name, self.config['resource_mapping'])
self.assertEqual(cfg.to_config_dict(), resource)

View File

@ -0,0 +1,59 @@
import copy
from fuel_external_git.tests import base
from fuel_external_git import utils
class TestUtils(base.TestCase):
def test_extension_list(self):
mapping = {
'ceilometer_api_paste_ini': {
'alias': 'ceilometer-api-paste.ini',
'path': '/etc/ceilometer/api-paste.ini',
},
'ceilometer': {
'alias': 'ceilometer.conf',
'path': '/etc/ceilometer/ceilometer.conf',
}
}
ext_list = utils.get_file_exts_list(mapping)
self.assertEqual(ext_list, set(['ini', 'conf']))
def test_deep_merge_two_empy(self):
a = {}
b = {}
utils.deep_merge(a, b)
self.assertEqual(a, {})
def test_deep_merge_one_empy(self):
sample_dict = {
'a': {'b': {'c': 'd'}},
'e': {'f': {'g': 'h'}},
}
new_dict = copy.deepcopy(sample_dict)
utils.deep_merge(new_dict, {})
self.assertEqual(new_dict, sample_dict)
new_dict = {}
utils.deep_merge(new_dict, sample_dict)
self.assertEqual(new_dict, sample_dict)
def test_merge_two_discts(self):
a = {
'a': {'b': {'c': 'd'}},
'e': {'f': {'g': 'h'}},
}
b = {
'x': {'b': {'c': 'd'}},
'y': {'f': {'g': 'h'}},
}
result = {
'a': {'b': {'c': 'd'}},
'e': {'f': {'g': 'h'}},
'x': {'b': {'c': 'd'}},
'y': {'f': {'g': 'h'}},
}
utils.deep_merge(a, b)
self.assertEqual(a, result)

View File

@ -2,10 +2,15 @@ import os
from setuptools import setup
from setuptools.command.install import install
try:
from nailgun.db import db
from nailgun.db.sqlalchemy.models import Cluster
from nailgun.db.sqlalchemy.models import Release
from nailgun.db import db
from nailgun.db.sqlalchemy.models import Cluster
from nailgun.db.sqlalchemy.models import Release
no_nailgun = False
except:
no_nailgun = True
def package_files(directory):
@ -53,7 +58,7 @@ setup(
],
packages=['fuel_external_git'],
package_data={'fuel_external_git': extra_files},
cmdclass={'install': ExtInstall},
cmdclass={'install': ExtInstall} if not no_nailgun else {},
entry_points={
'nailgun.extensions': [
'fuel_external_git = fuel_external_git.extension:ExternalGit',

17
test-requirements.txt Normal file
View File

@ -0,0 +1,17 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
hacking<0.11,>=0.10.0
coverage>=3.6
discover
oslo.db[fixtures,mysql,postgresql]
oslotest>=1.10.0 # Apache-2.0
testrepository>=0.0.18
testscenarios>=0.4
testtools>=1.4.0
requests-mock
python-fuelclient
os-testr>=0.4.1 # Apache-2.0
mock>=1.2 # BSD

41
tox.ini Normal file
View File

@ -0,0 +1,41 @@
[tox]
minversion = 1.6
envlist = py27,pep8
skipsdist = True
[base]
NAILGUN_REPO = git+https://github.com/openstack/fuel-web.git
NAILGUN_CONFIG = {toxinidir}/nailgun-test-settings.yaml
NAILGUN_BRANCH={env:ZUUL_BRANCH:stable/mitaka}
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
PYTHONWARNINGS=ignore:Unmanaged access of declarative attribute __tablename__ from non-mapped class ModelMixin
OS_TEST_DBAPI_ADMIN_CONNECTION=mysql+pymysql://openstack_citest:openstack_citest@localhost/;postgresql://openstack_citest:openstack_citest@localhost/postgres;sqlite:///testdb
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
-e{[base]NAILGUN_REPO}@{[base]NAILGUN_BRANCH}#egg=nailgun[test]&subdirectory=nailgun
commands = py.test -v --junit-xml {toxinidir}/extension.xml {posargs}
[testenv:pep8]
commands = flake8
[testenv:venv]
commands = {posargs}
[testenv:cover]
commands = python setup.py test --coverage --testr-args='{posargs}'
[testenv:debug]
commands = oslo_debug_helper {posargs}
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build