Fixes including default SDN env file in deploy cmd 31/50431/1
authorTim Rozet <trozet@redhat.com>
Thu, 11 Jan 2018 15:41:29 +0000 (10:41 -0500)
committerTim Rozet <trozet@redhat.com>
Thu, 11 Jan 2018 15:41:29 +0000 (10:41 -0500)
The latest method to deploy opendaylight features upstream is to include
the default SDN file and then add-on the feature env file which should
override any default settings in the previous SDN env file.  For
example for bgpvpn:

openstack overcloud deploy -e <tht_dir>/neutron-opendaylight.yaml -e \
<tht_dir>/neutron-bgpvpn-opendaylight.yaml

This change documents the recursive function used to find the SDN env
files and includes the default for the SDN controller.

JIRA: APEX-555

Change-Id: I4270932ca4fbc21ea54e965d9d6491424f4463e2
Signed-off-by: Tim Rozet <trozet@redhat.com>
apex/overcloud/deploy.py
apex/tests/test_apex_overcloud_deploy.py

index 809afc1..5c95796 100644 (file)
@@ -71,14 +71,37 @@ ODL_NETVIRT_VPP_RPM = "/root/opendaylight-7.0.0-0.1.20170531snap665.el7" \
 
 
 def build_sdn_env_list(ds, sdn_map, env_list=None):
+    """
+    Builds a list of SDN environment files to be used in the deploy cmd.
+
+    This function recursively searches an sdn_map.  First the sdn controller is
+    matched and then the function looks for enabled features for that
+    controller to determine which environment files should be used.  By
+    default the feature will be checked if set to true in deploy settings to be
+    added to the list.  If a feature does not have a boolean value, then the
+    key and value pair to compare with are checked as a tuple (k,v).
+
+    :param ds: deploy settings
+    :param sdn_map: SDN map to recursively search
+    :param env_list: recursive var to hold previously found env_list
+    :return: A list of env files
+    """
     if env_list is None:
         env_list = list()
     for k, v in sdn_map.items():
         if ds['sdn_controller'] == k or (k in ds and ds[k] is True):
             if isinstance(v, dict):
+                # Append default SDN env file first
+                # The assumption is that feature-enabled SDN env files
+                # override and do not conflict with previously set default
+                # settings
+                if ds['sdn_controller'] == k and 'default' in v:
+                    env_list.append(os.path.join(con.THT_ENV_DIR,
+                                                 v['default']))
                 env_list.extend(build_sdn_env_list(ds, v))
             else:
                 env_list.append(os.path.join(con.THT_ENV_DIR, v))
+        # check if the value is not a boolean
         elif isinstance(v, tuple):
                 if ds[k] == v[0]:
                     env_list.append(os.path.join(con.THT_ENV_DIR, v[1]))
index 59e9048..8ff98a8 100644 (file)
@@ -7,6 +7,7 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
+import os
 import sys
 import unittest
 
@@ -26,6 +27,7 @@ from apex.overcloud.deploy import generate_ceph_key
 from apex.overcloud.deploy import prep_storage_env
 from apex.overcloud.deploy import external_network_cmds
 from apex.overcloud.deploy import create_congress_cmds
+from apex.overcloud.deploy import SDN_FILE_MAP
 
 from nose.tools import (
     assert_regexp_matches,
@@ -70,6 +72,14 @@ class TestOvercloudDeploy(unittest.TestCase):
         res = '/usr/share/openstack-tripleo-heat-templates/environments/test'
         assert_equal(build_sdn_env_list(ds, sdn_map), [res])
 
+    def test_build_sdn_env_list_with_default(self):
+        ds = {'sdn_controller': 'opendaylight',
+              'vpn': True}
+        prefix = '/usr/share/openstack-tripleo-heat-templates/environments'
+        res = [os.path.join(prefix, 'neutron-opendaylight.yaml'),
+               os.path.join(prefix, 'neutron-bgpvpn-opendaylight.yaml')]
+        assert_equal(build_sdn_env_list(ds, SDN_FILE_MAP), res)
+
     @patch('apex.overcloud.deploy.prep_storage_env')
     @patch('apex.overcloud.deploy.build_sdn_env_list')
     @patch('builtins.open', mock_open())