|
|
|
@ -1341,7 +1341,8 @@ class TestManager(TestCase): |
|
|
|
self.assertIsNone(zone_with_defaults.update_pcent_threshold) |
|
|
|
self.assertIsNone(zone_with_defaults.delete_pcent_threshold) |
|
|
|
|
|
|
|
def test_preprocess_zones(self): |
|
|
|
def test_preprocess_zones_original(self): |
|
|
|
# these will be unused |
|
|
|
environ['YAML_TMP_DIR'] = '/tmp' |
|
|
|
environ['YAML_TMP_DIR2'] = '/tmp' |
|
|
|
manager = Manager(get_config_filename('simple.yaml')) |
|
|
|
@ -1405,27 +1406,158 @@ class TestManager(TestCase): |
|
|
|
) |
|
|
|
mock_source.list_zones.assert_called_once() |
|
|
|
|
|
|
|
# multiple wildcards, this didn't make sense previously as the 2nd one |
|
|
|
# would just win |
|
|
|
mock_source.reset_mock() |
|
|
|
def test_preprocess_zones_multiple_single_source(self): |
|
|
|
# these will be unused |
|
|
|
environ['YAML_TMP_DIR'] = '/tmp' |
|
|
|
environ['YAML_TMP_DIR2'] = '/tmp' |
|
|
|
manager = Manager(get_config_filename('simple.yaml')) |
|
|
|
|
|
|
|
manager._get_sources = MagicMock() |
|
|
|
mock_source = MagicMock() |
|
|
|
mock_source.id = 'mm' |
|
|
|
manager._get_sources = MagicMock() |
|
|
|
manager._get_sources.return_value = [mock_source] |
|
|
|
|
|
|
|
config_a = {'foo': 42} |
|
|
|
config_b = {'bar': 43} |
|
|
|
zones = {r'.*\.a\.com\.$': config_a, r'.*\.b\.com\.$': config_b} |
|
|
|
mock_source.list_zones.return_value = [ |
|
|
|
'one.a.com.', |
|
|
|
'two.a.com.', |
|
|
|
'three.b.com.', |
|
|
|
zones = {'*.a.com.': config_a, '*.b.com.': config_b} |
|
|
|
mock_source.list_zones.side_effect = [ |
|
|
|
['one.a.com.', 'two.a.com.', 'one.b.com.', 'two.b.com.'] |
|
|
|
] |
|
|
|
got = manager._preprocess_zones(zones, sources=[mock_source]) |
|
|
|
got = manager._preprocess_zones(zones, sources=[]) |
|
|
|
# each zone will have it's sources looked up |
|
|
|
self.assertEqual(2, manager._get_sources.call_count) |
|
|
|
# but there's only one source so it's zones will be cached |
|
|
|
self.assertEqual(1, mock_source.list_zones.call_count) |
|
|
|
# everything will have been matched by the first old style wildcard and |
|
|
|
# thus have its config, nothing will have b's |
|
|
|
self.assertEqual( |
|
|
|
{ |
|
|
|
'one.a.com.': config_a, |
|
|
|
'two.a.com.': config_a, |
|
|
|
'one.b.com.': config_a, |
|
|
|
'two.b.com.': config_a, |
|
|
|
}, |
|
|
|
got, |
|
|
|
) |
|
|
|
|
|
|
|
def test_preprocess_zones_multiple_seperate_sources(self): |
|
|
|
# these will be unused |
|
|
|
environ['YAML_TMP_DIR'] = '/tmp' |
|
|
|
environ['YAML_TMP_DIR2'] = '/tmp' |
|
|
|
manager = Manager(get_config_filename('simple.yaml')) |
|
|
|
|
|
|
|
manager._get_sources = MagicMock() |
|
|
|
mock_source_a = MagicMock() |
|
|
|
mock_source_a.id = 'mm_a' |
|
|
|
mock_source_b = MagicMock() |
|
|
|
mock_source_b.id = 'mm_b' |
|
|
|
manager._get_sources = MagicMock() |
|
|
|
manager._get_sources.side_effect = [[mock_source_a], [mock_source_b]] |
|
|
|
|
|
|
|
config_a = {'foo': 42} |
|
|
|
config_b = {'bar': 43} |
|
|
|
zones = {'*.a.com.': config_a, '*.b.com.': config_b} |
|
|
|
mock_source_a.list_zones.side_effect = [['one.a.com.', 'two.a.com.']] |
|
|
|
mock_source_b.list_zones.side_effect = [['one.b.com.', 'two.b.com.']] |
|
|
|
got = manager._preprocess_zones(zones, sources=[]) |
|
|
|
# each zone will have it's sources looked up |
|
|
|
self.assertEqual(2, manager._get_sources.call_count) |
|
|
|
# so each mock will be called once |
|
|
|
self.assertEqual(1, mock_source_a.list_zones.call_count) |
|
|
|
self.assertEqual(1, mock_source_b.list_zones.call_count) |
|
|
|
# the souces from each source will be matched with the coresponding config |
|
|
|
self.assertEqual( |
|
|
|
{ |
|
|
|
'one.a.com.': config_a, |
|
|
|
'two.a.com.': config_a, |
|
|
|
'one.b.com.': config_b, |
|
|
|
'two.b.com.': config_b, |
|
|
|
}, |
|
|
|
got, |
|
|
|
) |
|
|
|
|
|
|
|
def test_preprocess_zones_glob(self): |
|
|
|
# these will be unused |
|
|
|
environ['YAML_TMP_DIR'] = '/tmp' |
|
|
|
environ['YAML_TMP_DIR2'] = '/tmp' |
|
|
|
manager = Manager(get_config_filename('simple.yaml')) |
|
|
|
|
|
|
|
manager._get_sources = MagicMock() |
|
|
|
mock_source = MagicMock() |
|
|
|
mock_source.id = 'mm' |
|
|
|
manager._get_sources = MagicMock() |
|
|
|
manager._get_sources.return_value = [mock_source] |
|
|
|
|
|
|
|
# match things with .a. |
|
|
|
config_a = {'foo': 42, 'glob': r'*.a.com.'} |
|
|
|
# match things with .b. |
|
|
|
config_b = {'bar': 43, 'glob': r'*.b.com.'} |
|
|
|
zones = {'*.a.com.': config_a, '*.b.com.': config_b} |
|
|
|
mock_source.list_zones.side_effect = [ |
|
|
|
[ |
|
|
|
'one.a.com.', |
|
|
|
'two.a.com.', |
|
|
|
'one.b.com.', |
|
|
|
'two.b.com.', |
|
|
|
'ignored.com.', |
|
|
|
] |
|
|
|
] |
|
|
|
got = manager._preprocess_zones(zones, sources=[]) |
|
|
|
self.assertEqual(2, manager._get_sources.call_count) |
|
|
|
self.assertEqual(1, mock_source.list_zones.call_count) |
|
|
|
# a will glob match .a.com., b will .b.com., ignored.com. won't match |
|
|
|
# anything |
|
|
|
self.assertEqual( |
|
|
|
{ |
|
|
|
'one.a.com.': config_a, |
|
|
|
'two.a.com.': config_a, |
|
|
|
'one.b.com.': config_b, |
|
|
|
'two.b.com.': config_b, |
|
|
|
}, |
|
|
|
got, |
|
|
|
) |
|
|
|
|
|
|
|
def test_preprocess_zones_regex(self): |
|
|
|
# these will be unused |
|
|
|
environ['YAML_TMP_DIR'] = '/tmp' |
|
|
|
environ['YAML_TMP_DIR2'] = '/tmp' |
|
|
|
manager = Manager(get_config_filename('simple.yaml')) |
|
|
|
|
|
|
|
manager._get_sources = MagicMock() |
|
|
|
mock_source = MagicMock() |
|
|
|
mock_source.id = 'mm' |
|
|
|
manager._get_sources = MagicMock() |
|
|
|
manager._get_sources.return_value = [mock_source] |
|
|
|
|
|
|
|
# match things with .a. |
|
|
|
config_a = {'foo': 42, 'regex': r'\.a\.'} |
|
|
|
# match things with .b. |
|
|
|
config_b = {'bar': 43, 'regex': r'\.b\.'} |
|
|
|
zones = {'*.a.com.': config_a, '*.b.com.': config_b} |
|
|
|
mock_source.list_zones.side_effect = [ |
|
|
|
[ |
|
|
|
'one.a.com.', |
|
|
|
'two.a.com.', |
|
|
|
'one.b.com.', |
|
|
|
'two.b.com.', |
|
|
|
'ignored.com.', |
|
|
|
] |
|
|
|
] |
|
|
|
got = manager._preprocess_zones(zones, sources=[]) |
|
|
|
self.assertEqual(2, manager._get_sources.call_count) |
|
|
|
self.assertEqual(1, mock_source.list_zones.call_count) |
|
|
|
# a will regex match .a.com., b will .b.com., ignored.com. won't match |
|
|
|
# anything |
|
|
|
self.assertEqual( |
|
|
|
{ |
|
|
|
'one.a.com.': config_a, |
|
|
|
'two.a.com.': config_a, |
|
|
|
'three.b.com.': config_b, |
|
|
|
'one.b.com.': config_b, |
|
|
|
'two.b.com.': config_b, |
|
|
|
}, |
|
|
|
got, |
|
|
|
) |
|
|
|
self.assertEqual(2, mock_source.list_zones.call_count) |
|
|
|
|
|
|
|
|
|
|
|
class TestMainThreadExecutor(TestCase): |
|
|
|
|