blob: 4be0adc49dfcf209f741b55ea2aacdd30ea708d3 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14import unittest
15from unittest import mock
16
17from google.protobuf import any_pb2
18from google.protobuf.json_format import MessageToJson
19from configuration import mconfig_managers
20from configuration.exceptions import LoadConfigError
21from orc8r.protos.mconfig import mconfigs_pb2
22
23
24class MconfigManagerImplTest(unittest.TestCase):
25 @mock.patch('magma.configuration.service_configs.load_service_config')
26 def test_load_mconfig(self, get_service_config_value_mock):
27 # Fixture mconfig has 1 unrecognized service, 1 unregistered type
28 magmad_fixture = mconfigs_pb2.MagmaD(
29 checkin_interval=10,
30 checkin_timeout=5,
31 autoupgrade_enabled=True,
32 autoupgrade_poll_interval=300,
33 package_version='1.0.0-0',
34 images=[],
35 tier_id='default',
36 feature_flags={'flag1': False},
37 )
38 magmad_fixture_any = any_pb2.Any()
39 magmad_fixture_any.Pack(magmad_fixture)
40 magmad_fixture_serialized = MessageToJson(magmad_fixture_any)
41 fixture = '''
42 {
43 "configs_by_key": {
44 "magmad": %s,
45 "foo": {
46 "@type": "type.googleapis.com/magma.mconfig.NotAType",
47 "value": "test1"
48 },
49 "not_a_service": {
50 "@type": "type.googleapis.com/magma.mconfig.MagmaD",
51 "value": "test2"
52 }
53 }
54 }
55 ''' % magmad_fixture_serialized
56 get_service_config_value_mock.return_value = {
57 'magma_services': ['foo'],
58 }
59
60 with mock.patch('builtins.open', mock.mock_open(read_data=fixture)):
61 manager = mconfig_managers.MconfigManagerImpl()
62 with self.assertRaises(LoadConfigError):
63 manager.load_mconfig()