Skip to content

Commit

Permalink
Fix mconfig tests (magma#899)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: magma#899

- Fix tests after change to mconfig filtering

Reviewed By: themarwhal

Differential Revision: D18588239

fbshipit-source-id: 5e9980c5fef3fc5ef246e1c97e9e04f5897fb359
  • Loading branch information
xjtian authored and gjalves committed Nov 19, 2019
1 parent 136a5a5 commit 42d6d70
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
7 changes: 7 additions & 0 deletions orc8r/gateway/python/magma/configuration/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Copyright (c) Facebook, Inc. and its affiliates.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
from google.protobuf import any_pb2
from google.protobuf.json_format import MessageToJson
from magma.configuration import mconfig_managers
from orc8r.protos import mconfig_pb2
from orc8r.protos.mconfig import mconfigs_pb2
from magma.configuration.exceptions import LoadConfigError
from orc8r.protos.mconfig import mconfigs_pb2


class MconfigManagerImplTest(unittest.TestCase):
@mock.patch('magma.configuration.service_configs.get_service_config_value')
@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(
Expand Down Expand Up @@ -50,7 +49,9 @@ def test_load_mconfig(self, get_service_config_value_mock):
}
}
''' % magmad_fixture_serialized
get_service_config_value_mock.return_value = ['foo']
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()
Expand Down
27 changes: 22 additions & 5 deletions orc8r/gateway/python/magma/configuration/tests/mconfigs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

class MconfigsTest(unittest.TestCase):

@mock.patch('magma.configuration.service_configs.get_service_config_value')
def test_filter_configs_by_key(self, get_service_config_value_mock):
@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': {
Expand All @@ -35,20 +35,37 @@ def test_filter_configs_by_key(self, get_service_config_value_mock):
},
}

get_service_config_value_mock.return_value = ['mme', 'foo']
# 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)

# Directoryd service not present
get_service_config_value_mock.return_value = []
# 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,
Expand Down
11 changes: 6 additions & 5 deletions orc8r/gateway/python/magma/magmad/tests/config_manager_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@

from google.protobuf.any_pb2 import Any
from google.protobuf.json_format import MessageToJson
from orc8r.protos.mconfig.mconfigs_pb2 import MagmaD, MetricsD
from orc8r.protos.mconfig_pb2 import GatewayConfigs

from magma.configuration.mconfig_managers import MconfigManagerImpl
from magma.magmad.config_manager import CONFIG_STREAM_NAME, ConfigManager
from orc8r.protos.mconfig.mconfigs_pb2 import MagmaD, MetricsD
from orc8r.protos.mconfig_pb2 import GatewayConfigs


class ConfigManagerTest(TestCase):
"""
Tests for the config manager class
"""
@patch('magma.configuration.service_configs.get_service_config_value')
@patch('magma.configuration.service_configs.load_service_config')
def test_update(self, config_mock):
"""
Test that mconfig updates are handled correctly
Expand All @@ -50,7 +49,9 @@ def test_update(self, config_mock):
updated_mconfig.configs_by_key['metricsd'].CopyFrom(some_any)

# Set up mock dependencies
config_mock.return_value = ['magmad', 'metricsd']
config_mock.return_value = {
'magma_services': ['magmad', 'metricsd'],
}

@asyncio.coroutine
def _mock_restart_services(): return "blah"
Expand Down

0 comments on commit 42d6d70

Please sign in to comment.