[CORD-3022] Adding an option to provide an extra configuration

Change-Id: Iaef5d7bc6041b76f2896f9fcf91a0072e78ad0c2
diff --git a/lib/xos-config/tests/confs/extend_conf.yaml b/lib/xos-config/tests/confs/extend_conf.yaml
new file mode 100644
index 0000000..dd888e3
--- /dev/null
+++ b/lib/xos-config/tests/confs/extend_conf.yaml
@@ -0,0 +1,17 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+xos_dir: /opt/xos
\ No newline at end of file
diff --git a/lib/xos-config/tests/confs/override_conf.yaml b/lib/xos-config/tests/confs/override_conf.yaml
new file mode 100644
index 0000000..683b8da
--- /dev/null
+++ b/lib/xos-config/tests/confs/override_conf.yaml
@@ -0,0 +1,21 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+database:
+  # as per xos-config-schema.yaml these are all required
+  name: xos
+  username: test
+  password: overridden_password
\ No newline at end of file
diff --git a/lib/xos-config/tests/confs/sample_conf.yaml b/lib/xos-config/tests/confs/sample_conf.yaml
index 3e08f03..e177fbb 100644
--- a/lib/xos-config/tests/confs/sample_conf.yaml
+++ b/lib/xos-config/tests/confs/sample_conf.yaml
@@ -23,5 +23,4 @@
   level: info
   channels:
     - file
-    - console
-xos_dir: /opt/xos
\ No newline at end of file
+    - console
\ No newline at end of file
diff --git a/lib/xos-config/tests/test_config.py b/lib/xos-config/tests/test_config.py
index 1684472..ee80b52 100644
--- a/lib/xos-config/tests/test_config.py
+++ b/lib/xos-config/tests/test_config.py
@@ -24,6 +24,8 @@
 yaml_not_valid = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/yaml_not_valid.yaml")
 invalid_format = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/invalid_format.yaml")
 sample_conf = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/sample_conf.yaml")
+override_conf = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/override_conf.yaml")
+extend_conf = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/confs/extend_conf.yaml")
 
 small_schema = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/schemas/small_schema.yaml")
 
@@ -158,7 +160,7 @@
 
     def test_get_missing_param(self):
         """
-        [XOS-Config] Should raise reading a missing param
+        [XOS-Config] Should return None reading a missing param
         """
         Config.init(sample_conf)
         res = Config.get("foo")
@@ -178,13 +180,33 @@
             "password": "safe"
         })
 
-    def _test_get_child_level(self):
+    def test_get_child_level(self):
         """
         [XOS-Config] Should return a child level param
         """
         Config.init(sample_conf)
-        res = Config.get("nested.parameter.for")
-        self.assertEqual(res, "testing")
+        res = Config.get("database.name")
+        self.assertEqual(res, "xos")
+
+    def test_config_override(self):
+        """
+        [XOS-Config] If an override is provided for the config, it should return the overridden value
+        """
+        Config.init(sample_conf, 'xos-config-schema.yaml', override_conf)
+        res = Config.get("logging.level")
+        self.assertEqual(res, "info")
+        res = Config.get("database.password")
+        self.assertEqual(res, "overridden_password")
+
+    def test_config_extend(self):
+        """
+        [XOS-Config] If an override is provided for the config, it should return the overridden value (also if not defined in the base one)
+        """
+        Config.init(sample_conf, 'xos-config-schema.yaml', extend_conf)
+        res = Config.get("xos_dir")
+        self.assertEqual(res, "/opt/xos")
+        res = Config.get("database.password")
+        self.assertEqual(res, "safe")
 
 if __name__ == '__main__':
     unittest.main()