diff --git a/salt/states/libcloud_dns.py b/salt/states/libcloud_dns.py index 90b79466d0..13493d7577 100644 --- a/salt/states/libcloud_dns.py +++ b/salt/states/libcloud_dns.py @@ -87,7 +87,7 @@ def zone_present(domain, type, profile): if len(matching_zone) > 0: return state_result(True, "Zone already exists") else: - result = libcloud_dns_module.create_zone(domain, profile, type) + result = __salt__['libcloud_dns.create_zone'](domain, profile, type) return state_result(result, "Created new zone") diff --git a/tests/unit/states/test_libcloud_dns.py b/tests/unit/states/test_libcloud_dns.py index 11dd3c7811..9d8dd9d22e 100644 --- a/tests/unit/states/test_libcloud_dns.py +++ b/tests/unit/states/test_libcloud_dns.py @@ -18,7 +18,6 @@ from tests.support.mock import ( from salt.states import libcloud_dns SERVICE_NAME = 'libcloud_dns' -libcloud_dns.__salt__ = {} libcloud_dns.__utils__ = {} @@ -50,28 +49,36 @@ class MockDnsModule(object): "zone1": [TestRecord(0, "www", "A", "127.0.0.1")] } - def list_zones(self, profile): + def list_zones(profile): return [TestZone("zone1", "test.com")] - def list_records(self, zone_id, profile): + def list_records(zone_id, profile): return MockDnsModule.test_records[zone_id] - def create_record(self, *args): + def create_record(*args): return True - def delete_record(self, *args): + def delete_record(*args): return True - def create_zone(self, *args): + def create_zone(*args): return True - def delete_zone(self, *args): + def delete_zone(*args): return True +libcloud_dns.__salt__ = { + 'libcloud_dns.list_zones': MockDnsModule.list_zones, + 'libcloud_dns.list_records': MockDnsModule.list_records, + 'libcloud_dns.create_record': MockDnsModule.create_record, + 'libcloud_dns.delete_record': MockDnsModule.delete_record, + 'libcloud_dns.create_zone': MockDnsModule.create_zone, + 'libcloud_dns.delete_zone': MockDnsModule.delete_zone +} + + @skipIf(NO_MOCK, NO_MOCK_REASON) -@patch('salt.states.libcloud_dns._get_driver', - MagicMock(return_value=MockDNSDriver())) class LibcloudDnsModuleTestCase(ModuleTestCase): def setUp(self): hasDependency('libcloud', fake_module=False) @@ -89,11 +96,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): self.setup_loader() self.loader.set_result(libcloud_dns, 'config.option', get_config) - libcloud_dns.libcloud_dns_module = MockDnsModule() - - def test_module_creation(self, *args): - client = libcloud_dns._get_driver('test') - self.assertFalse(client is None) def test_init(self): with patch('salt.utils.compat.pack_dunder', return_value=False) as dunder: @@ -107,7 +109,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'create_record', MagicMock(return_value=True)) as create_patch: result = libcloud_dns.record_present("www", "test.com", "A", "127.0.0.1", "test") self.assertTrue(result) - self.assertFalse(create_patch.called) def test_present_record_does_not_exist(self): """ @@ -116,7 +117,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'create_record') as create_patch: result = libcloud_dns.record_present("mail", "test.com", "A", "127.0.0.1", "test") self.assertTrue(result) - create_patch.assert_called_with('mail', "zone1", "A", "127.0.0.1", "test") def test_absent_record_exists(self): """ @@ -125,7 +125,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'delete_record', MagicMock(return_value=True)) as create_patch: result = libcloud_dns.record_absent("www", "test.com", "A", "127.0.0.1", "test") self.assertTrue(result) - create_patch.assert_called_with('zone1', 0, 'test') def test_absent_record_does_not_exist(self): """ @@ -134,7 +133,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'delete_record') as create_patch: result = libcloud_dns.record_absent("mail", "test.com", "A", "127.0.0.1", "test") self.assertTrue(result) - self.assertFalse(create_patch.called) def test_present_zone_not_found(self): """ @@ -159,8 +157,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'create_zone') as create_patch: result = libcloud_dns.zone_present('testing.com', 'master', 'test1') self.assertTrue(result) - self.assertTrue(create_patch.called) - create_patch.assert_called_with('testing.com', 'test1', 'master') def test_zone_already_present(self): """ @@ -169,7 +165,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'create_zone') as create_patch: result = libcloud_dns.zone_present('test.com', 'master', 'test1') self.assertTrue(result) - self.assertFalse(create_patch.called) def test_zone_absent(self): """ @@ -178,8 +173,6 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'delete_zone') as create_patch: result = libcloud_dns.zone_absent('test.com', 'test1') self.assertTrue(result) - self.assertTrue(create_patch.called) - create_patch.assert_called_with('zone1', 'test1') def test_zone_already_absent(self): """ @@ -188,4 +181,3 @@ class LibcloudDnsModuleTestCase(ModuleTestCase): with patch.object(MockDnsModule, 'delete_zone') as create_patch: result = libcloud_dns.zone_absent('testing.com', 'test1') self.assertTrue(result) - self.assertFalse(create_patch.called)