blob: 9e26ed188adcfee34b27275ce6a7279c92ac7010 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6import unittest
7from unittest import mock
8
9from google.protobuf import any_pb2
10from google.protobuf.json_format import MessageToJson
11from configuration import mconfig_managers
12from configuration.exceptions import LoadConfigError
13from orc8r.protos.mconfig import mconfigs_pb2
14
15
16class MconfigManagerImplTest(unittest.TestCase):
17 @mock.patch('magma.configuration.service_configs.load_service_config')
18 def test_load_mconfig(self, get_service_config_value_mock):
19 # Fixture mconfig has 1 unrecognized service, 1 unregistered type
20 magmad_fixture = mconfigs_pb2.MagmaD(
21 checkin_interval=10,
22 checkin_timeout=5,
23 autoupgrade_enabled=True,
24 autoupgrade_poll_interval=300,
25 package_version='1.0.0-0',
26 images=[],
27 tier_id='default',
28 feature_flags={'flag1': False},
29 )
30 magmad_fixture_any = any_pb2.Any()
31 magmad_fixture_any.Pack(magmad_fixture)
32 magmad_fixture_serialized = MessageToJson(magmad_fixture_any)
33 fixture = '''
34 {
35 "configs_by_key": {
36 "magmad": %s,
37 "foo": {
38 "@type": "type.googleapis.com/magma.mconfig.NotAType",
39 "value": "test1"
40 },
41 "not_a_service": {
42 "@type": "type.googleapis.com/magma.mconfig.MagmaD",
43 "value": "test2"
44 }
45 }
46 }
47 ''' % magmad_fixture_serialized
48 get_service_config_value_mock.return_value = {
49 'magma_services': ['foo'],
50 }
51
52 with mock.patch('builtins.open', mock.mock_open(read_data=fixture)):
53 manager = mconfig_managers.MconfigManagerImpl()
54 with self.assertRaises(LoadConfigError):
55 manager.load_mconfig()