summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2016-08-24 17:21:31 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-08-24 17:21:31 +0000
commit1895eba89b351b0f74a2280c023bbf799aa94e09 (patch)
treee1c2bcb487511af0e21e452e9cae9c475116ca2e
parent93ca90fd6892b5768c57199e6f2a4115df82e422 (diff)
parent6c2e34e0ecaaa5c57a24811ebb8a422924537417 (diff)
Merge "converiting the deploy settings obj to a dict"
-rw-r--r--build/rpm_specs/opnfv-apex-common.spec2
-rw-r--r--lib/python/apex/__init__.py2
-rw-r--r--lib/python/apex/deploy_settings.py (renamed from lib/python/apex/deploy_env.py)35
-rw-r--r--tests/test_apex_deploy_settings.py (renamed from tests/test_apex_deploy_env.py)17
4 files changed, 38 insertions, 18 deletions
diff --git a/build/rpm_specs/opnfv-apex-common.spec b/build/rpm_specs/opnfv-apex-common.spec
index 39bcd289..b9125b36 100644
--- a/build/rpm_specs/opnfv-apex-common.spec
+++ b/build/rpm_specs/opnfv-apex-common.spec
@@ -65,7 +65,7 @@ install lib/utility-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/
install lib/python/apex_python_utils.py %{buildroot}%{_var}/opt/opnfv/lib/python/
mkdir -p %{buildroot}%{python3_sitelib}/apex/
install lib/python/apex/__init__.py %{buildroot}%{python3_sitelib}/apex/
-install lib/python/apex/deploy_env.py %{buildroot}%{python3_sitelib}/apex/
+install lib/python/apex/deploy_settings.py %{buildroot}%{python3_sitelib}/apex/
install lib/python/apex/ip_utils.py %{buildroot}%{python3_sitelib}/apex/
install lib/python/apex/network_environment.py %{buildroot}%{python3_sitelib}/apex/
install lib/python/apex/network_settings.py %{buildroot}%{python3_sitelib}/apex/
diff --git a/lib/python/apex/__init__.py b/lib/python/apex/__init__.py
index 5b158501..e1b8b547 100644
--- a/lib/python/apex/__init__.py
+++ b/lib/python/apex/__init__.py
@@ -9,5 +9,5 @@
from .network_settings import NetworkSettings
-from .deploy_env import DeploySettings
+from .deploy_settings import DeploySettings
from .network_environment import NetworkEnvironment
diff --git a/lib/python/apex/deploy_env.py b/lib/python/apex/deploy_settings.py
index 816dc114..b70efdac 100644
--- a/lib/python/apex/deploy_env.py
+++ b/lib/python/apex/deploy_settings.py
@@ -28,7 +28,7 @@ VALID_PERF_OPTS = ['kernel', 'nova']
VALID_DATAPLANES = ['ovs', 'ovs_dpdk', 'fdio']
-class DeploySettings:
+class DeploySettings(dict):
"""
This class parses a APEX deploy settings yaml file into an object
@@ -37,9 +37,16 @@ class DeploySettings:
deployment script move to python.
"""
def __init__(self, filename):
- with open(filename, 'r') as settings_file:
- self.deploy_settings = yaml.load(settings_file)
- self._validate_settings()
+ init_dict = {}
+ if type(filename) is str:
+ with open(filename, 'r') as deploy_settings_file:
+ init_dict = yaml.load(deploy_settings_file)
+ else:
+ # assume input is a dict to build from
+ init_dict = filename
+
+ super().__init__(init_dict)
+ self._validate_settings()
def _validate_settings(self):
"""
@@ -48,14 +55,14 @@ class DeploySettings:
DeploySettingsException will be raised if validation fails.
"""
- if 'deploy_options' not in self.deploy_settings:
+ if 'deploy_options' not in self:
raise DeploySettingsException("No deploy options provided in"
" deploy settings file")
- if 'global_params' not in self.deploy_settings:
+ if 'global_params' not in self:
raise DeploySettingsException("No global options provided in"
" deploy settings file")
- deploy_options = self.deploy_settings['deploy_options']
+ deploy_options = self['deploy_options']
if not isinstance(deploy_options, dict):
raise DeploySettingsException("deploy_options should be a list")
@@ -73,9 +80,9 @@ class DeploySettings:
for req_set in REQ_DEPLOY_SETTINGS:
if req_set not in deploy_options:
if req_set == 'dataplane':
- self.deploy_settings['deploy_options'][req_set] = 'ovs'
+ self['deploy_options'][req_set] = 'ovs'
else:
- self.deploy_settings['deploy_options'][req_set] = False
+ self['deploy_options'][req_set] = False
if 'performance' in deploy_options:
if not isinstance(deploy_options['performance'], dict):
@@ -110,7 +117,7 @@ class DeploySettings:
facilitate modification of the correct image.
"""
bash_str = 'performance_options=(\n'
- deploy_options = self.deploy_settings['deploy_options']
+ deploy_options = self['deploy_options']
for role, settings in deploy_options['performance'].items():
for category, options in settings.items():
for key, value in options.items():
@@ -121,7 +128,7 @@ class DeploySettings:
bash_str += ')\n'
bash_str += '\n'
bash_str += 'performance_roles=(\n'
- for role in self.deploy_settings['deploy_options']['performance']:
+ for role in self['deploy_options']['performance']:
bash_str += role + '\n'
bash_str += ')\n'
bash_str += '\n'
@@ -133,7 +140,7 @@ class DeploySettings:
Creates deploy settings array in bash syntax.
"""
bash_str = ''
- for key, value in self.deploy_settings['deploy_options'].items():
+ for key, value in self['deploy_options'].items():
if not isinstance(value, bool):
bash_str += "deploy_options_array[{}]=\"{}\"\n".format(key,
value)
@@ -150,9 +157,9 @@ class DeploySettings:
instead of stdout.
"""
bash_str = ''
- for key, value in self.deploy_settings['global_params'].items():
+ for key, value in self['global_params'].items():
bash_str += "{}={}\n".format(key, value)
- if 'performance' in self.deploy_settings['deploy_options']:
+ if 'performance' in self['deploy_options']:
bash_str += self._dump_performance()
bash_str += self._dump_deploy_options_array()
diff --git a/tests/test_apex_deploy_env.py b/tests/test_apex_deploy_settings.py
index 563bfd8f..1e26b287 100644
--- a/tests/test_apex_deploy_env.py
+++ b/tests/test_apex_deploy_settings.py
@@ -10,11 +10,12 @@
import io
# https://docs.python.org/3/library/io.html
-from apex.deploy_env import DeploySettings
-from apex.deploy_env import DeploySettingsException
+from apex.deploy_settings import DeploySettings
+from apex.deploy_settings import DeploySettingsException
from nose.tools import assert_equal
from nose.tools import assert_raises
+from nose.tools import assert_is_instance
deploy_files = ('deploy_settings.yaml',
'os-nosdn-nofeature-noha.yaml',
@@ -52,6 +53,12 @@ deploy_options:
performance:
Controller:
error: error
+""",
+ """global_params:
+deploy_options:
+ performance:
+ InvalidRole:
+ error: error
""",)
@@ -73,6 +80,7 @@ class TestIpUtils(object):
def test_init(self):
for f in deploy_files:
ds = DeploySettings('../config/deploy/{}'.format(f))
+ ds = DeploySettings(ds)
def test__validate_settings(self):
for c in test_deploy_content:
@@ -88,3 +96,8 @@ class TestIpUtils(object):
ds = DeploySettings('../config/deploy/os-nosdn-performance-ha.yaml')
assert_equal(ds.dump_bash(), None)
assert_equal(ds.dump_bash(path='/dev/null'), None)
+
+ def test_exception(sefl):
+ e = DeploySettingsException("test")
+ print(e)
+ assert_is_instance(e, DeploySettingsException)