diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-01-18 22:06:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-01-18 22:06:19 +0000 |
| commit | 0ed09a3f4e34f8039e471242517dca14b278bcdb (patch) | |
| tree | 7785c91e6401a2e2af244ae17478bee61a9027d7 | |
| parent | ec244a1d940d0dbe56527b290f4b5052fba96739 (diff) | |
| parent | 53abee197dfc5dd7a77b746141d8321c20722092 (diff) | |
| download | nova-0ed09a3f4e34f8039e471242517dca14b278bcdb.tar.gz nova-0ed09a3f4e34f8039e471242517dca14b278bcdb.tar.xz nova-0ed09a3f4e34f8039e471242517dca14b278bcdb.zip | |
Merge "Automatically clean up DNS when a floating IP is deallocated."
| -rw-r--r-- | nova/network/manager.py | 13 | ||||
| -rw-r--r-- | nova/tests/test_network.py | 44 |
2 files changed, 57 insertions, 0 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py index 9d6009e0d..fbd8e5075 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -355,6 +355,10 @@ class FloatingIP(object): floating_address = floating_ip['address'] raise exception.FloatingIpAssociated(address=floating_address) + # clean up any associated DNS entries + self._delete_all_entries_for_ip(context, + floating_ip['address']) + self.db.floating_ip_deallocate(context, address) @wrap_check_policy @@ -550,6 +554,15 @@ class FloatingIP(object): def delete_dns_entry(self, context, dns_name, dns_zone): self.floating_dns_manager.delete_entry(dns_name, dns_zone) + def _delete_all_entries_for_ip(self, context, address): + domain_list = self.get_dns_zones(context) + for domain in domain_list: + names = self.get_dns_entries_by_address(context, + address, + domain['domain']) + for name in names: + self.delete_dns_entry(context, name, domain['domain']) + @wrap_check_policy def get_dns_entries_by_address(self, context, address, dns_zone): return self.floating_dns_manager.get_entries_by_address(address, diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 7b8bd3aa3..351876a41 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -1365,6 +1365,50 @@ class FloatingIPTestCase(test.TestCase): entryname, domain1) self.assertFalse(entries) + def test_delete_all_by_ip(self): + domain1 = "example.org" + domain2 = "example.com" + address = "10.10.10.10" + name1 = "foo" + name2 = "bar" + + def fake_domains(context): + return [{'domain': 'example.org', 'scope': 'public'}, + {'domain': 'example.com', 'scope': 'public'}, + {'domain': 'test.example.org', 'scope': 'public'}] + + self.stubs.Set(self.network, 'get_dns_zones', fake_domains) + + context_admin = context.RequestContext('testuser', 'testproject', + is_admin=True) + + self.network.create_public_dns_domain(context_admin, domain1, + 'testproject') + self.network.create_public_dns_domain(context_admin, domain2, + 'fakeproject') + + domains = self.network.get_dns_zones(self.context) + for domain in domains: + self.network.add_dns_entry(self.context, address, + name1, "A", domain['domain']) + self.network.add_dns_entry(self.context, address, + name2, "A", domain['domain']) + entries = self.network.get_dns_entries_by_address(self.context, + address, + domain['domain']) + self.assertEquals(len(entries), 2) + + self.network._delete_all_entries_for_ip(self.context, address) + + for domain in domains: + entries = self.network.get_dns_entries_by_address(self.context, + address, + domain['domain']) + self.assertFalse(entries) + + self.network.delete_dns_domain(context_admin, domain1) + self.network.delete_dns_domain(context_admin, domain2) + class NetworkPolicyTestCase(test.TestCase): def setUp(self): |
