Init commit for standalone enodebd

Change-Id: I88eeef5135dd7ba8551ddd9fb6a0695f5325337b
diff --git a/configuration/tests/__init__.py b/configuration/tests/__init__.py
new file mode 100644
index 0000000..5c6cb64
--- /dev/null
+++ b/configuration/tests/__init__.py
@@ -0,0 +1,12 @@
+"""
+Copyright 2020 The Magma Authors.
+
+This source code is licensed under the BSD-style license found in the
+LICENSE file in the root directory of this source tree.
+
+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.
+"""
diff --git a/configuration/tests/mconfig_manager_impl_tests.py b/configuration/tests/mconfig_manager_impl_tests.py
new file mode 100644
index 0000000..4be0adc
--- /dev/null
+++ b/configuration/tests/mconfig_manager_impl_tests.py
@@ -0,0 +1,63 @@
+"""
+Copyright 2020 The Magma Authors.
+
+This source code is licensed under the BSD-style license found in the
+LICENSE file in the root directory of this source tree.
+
+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.
+"""
+
+import unittest
+from unittest import mock
+
+from google.protobuf import any_pb2
+from google.protobuf.json_format import MessageToJson
+from configuration import mconfig_managers
+from configuration.exceptions import LoadConfigError
+from orc8r.protos.mconfig import mconfigs_pb2
+
+
+class MconfigManagerImplTest(unittest.TestCase):
+    @mock.patch('magma.configuration.service_configs.load_service_config')
+    def test_load_mconfig(self, get_service_config_value_mock):
+        # Fixture mconfig has 1 unrecognized service, 1 unregistered type
+        magmad_fixture = mconfigs_pb2.MagmaD(
+            checkin_interval=10,
+            checkin_timeout=5,
+            autoupgrade_enabled=True,
+            autoupgrade_poll_interval=300,
+            package_version='1.0.0-0',
+            images=[],
+            tier_id='default',
+            feature_flags={'flag1': False},
+        )
+        magmad_fixture_any = any_pb2.Any()
+        magmad_fixture_any.Pack(magmad_fixture)
+        magmad_fixture_serialized = MessageToJson(magmad_fixture_any)
+        fixture = '''
+        {
+            "configs_by_key": {
+                "magmad": %s,
+                "foo": {
+                    "@type": "type.googleapis.com/magma.mconfig.NotAType",
+                    "value": "test1"
+                },
+                "not_a_service": {
+                    "@type": "type.googleapis.com/magma.mconfig.MagmaD",
+                    "value": "test2"
+                }
+            }
+        }
+        ''' % magmad_fixture_serialized
+        get_service_config_value_mock.return_value = {
+            'magma_services': ['foo'],
+        }
+
+        with mock.patch('builtins.open', mock.mock_open(read_data=fixture)):
+            manager = mconfig_managers.MconfigManagerImpl()
+            with self.assertRaises(LoadConfigError):
+                manager.load_mconfig()
diff --git a/configuration/tests/mconfigs_tests.py b/configuration/tests/mconfigs_tests.py
new file mode 100644
index 0000000..be8ae0f
--- /dev/null
+++ b/configuration/tests/mconfigs_tests.py
@@ -0,0 +1,103 @@
+"""
+Copyright 2020 The Magma Authors.
+
+This source code is licensed under the BSD-style license found in the
+LICENSE file in the root directory of this source tree.
+
+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.
+"""
+
+import unittest
+from unittest import mock
+
+from google.protobuf.any_pb2 import Any
+from configuration import mconfigs
+from orc8r.protos.mconfig import mconfigs_pb2
+
+
+class MconfigsTest(unittest.TestCase):
+
+    @mock.patch('magma.configuration.service_configs.load_service_config')
+    def test_filter_configs_by_key(self, load_service_config_mock):
+        # All services present, but 1 type not
+        configs_by_key = {
+            'magmad': {
+                '@type': 'type.googleapis.com/magma.mconfig.MagmaD',
+                'value': 'world'.encode(),
+            },
+            'directoryd': {
+                '@type': 'type.googleapis.com/magma.mconfig.DirectoryD',
+                'value': 'hello'.encode(),
+            },
+            'foo': {
+                '@type': 'type.googleapis.com/magma.mconfig.Foo',
+                'value': 'test'.encode(),
+            },
+        }
+
+        # Directoryd not present
+        load_service_config_mock.return_value = {
+            'magma_services': ['mme', 'foo'],
+        }
+        actual = mconfigs.filter_configs_by_key(configs_by_key)
+        expected = {
+            'magmad': configs_by_key['magmad'],
+            'foo': configs_by_key['foo'],
+        }
+        self.assertEqual(expected, actual)
+
+        # No services present
+        load_service_config_mock.return_value = {
+            'magma_services': [],
+        }
+        actual = mconfigs.filter_configs_by_key(configs_by_key)
+        expected = {'magmad': configs_by_key['magmad']}
+        self.assertEqual(expected, actual)
+
+        # Directoryd service present as a dynamic service
+        load_service_config_mock.return_value = {
+            'magma_services': [],
+            'registered_dynamic_services': ['directoryd'],
+        }
+        actual = mconfigs.filter_configs_by_key(configs_by_key)
+        expected = {
+            'magmad': configs_by_key['magmad'],
+            'directoryd': configs_by_key['directoryd'],
+        }
+        self.assertEqual(expected, actual)
+
+    def test_unpack_mconfig_any(self):
+        magmad_mconfig = mconfigs_pb2.MagmaD(
+            checkin_interval=10,
+            checkin_timeout=5,
+            autoupgrade_enabled=True,
+            autoupgrade_poll_interval=300,
+            package_version='1.0.0-0',
+            images=[],
+            tier_id='default',
+            feature_flags={'flag1': False},
+        )
+        magmad_any = Any(
+            type_url='type.googleapis.com/magma.mconfig.MagmaD',
+            value=magmad_mconfig.SerializeToString(),
+        )
+        actual = mconfigs.unpack_mconfig_any(magmad_any, mconfigs_pb2.MagmaD())
+        self.assertEqual(magmad_mconfig, actual)
+
+    def test_unpack_mconfig_directoryd(self):
+        directoryd_mconfig = mconfigs_pb2.DirectoryD(
+            log_level=5,
+        )
+        magmad_any = Any(
+            type_url='type.googleapis.com/magma.mconfig.DirectoryD',
+            value=directoryd_mconfig.SerializeToString(),
+        )
+
+        actual = mconfigs.unpack_mconfig_any(
+            magmad_any, mconfigs_pb2.DirectoryD(),
+        )
+        self.assertEqual(directoryd_mconfig, actual)