| OLD | NEW |
| 1 # Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved | 1 # Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 2 # | 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 9 # lowing conditions: |
| 10 # | 10 # |
| 11 # The above copyright notice and this permission notice shall be included | 11 # The above copyright notice and this permission notice shall be included |
| 12 # in all copies or substantial portions of the Software. | 12 # in all copies or substantial portions of the Software. |
| 13 # | 13 # |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 # IN THE SOFTWARE. | 20 # IN THE SOFTWARE. |
| 21 # | 21 # |
| 22 | 22 |
| 23 import time |
| 23 import unittest | 24 import unittest |
| 25 from tests.integration.route53 import Route53TestCase |
| 26 |
| 24 from boto.route53.connection import Route53Connection | 27 from boto.route53.connection import Route53Connection |
| 25 from boto.route53.record import ResourceRecordSets | 28 from boto.route53.record import ResourceRecordSets |
| 26 | 29 |
| 27 | 30 class TestRoute53ResourceRecordSets(Route53TestCase): |
| 28 class TestRoute53ResourceRecordSets(unittest.TestCase): | |
| 29 def setUp(self): | |
| 30 super(TestRoute53ResourceRecordSets, self).setUp() | |
| 31 self.conn = Route53Connection() | |
| 32 self.zone = self.conn.create_zone('example.com') | |
| 33 | |
| 34 def tearDown(self): | |
| 35 self.zone.delete() | |
| 36 super(TestRoute53ResourceRecordSets, self).tearDown() | |
| 37 | |
| 38 def test_add_change(self): | 31 def test_add_change(self): |
| 39 rrs = ResourceRecordSets(self.conn, self.zone.id) | 32 rrs = ResourceRecordSets(self.conn, self.zone.id) |
| 40 | 33 |
| 41 created = rrs.add_change("CREATE", "vpn.example.com.", "A") | 34 created = rrs.add_change("CREATE", "vpn.%s." % self.base_domain, "A") |
| 42 created.add_value('192.168.0.25') | 35 created.add_value('192.168.0.25') |
| 43 rrs.commit() | 36 rrs.commit() |
| 44 | 37 |
| 45 rrs = ResourceRecordSets(self.conn, self.zone.id) | 38 rrs = ResourceRecordSets(self.conn, self.zone.id) |
| 46 deleted = rrs.add_change('DELETE', "vpn.example.com.", "A") | 39 deleted = rrs.add_change('DELETE', "vpn.%s." % self.base_domain, "A") |
| 47 deleted.add_value('192.168.0.25') | 40 deleted.add_value('192.168.0.25') |
| 48 rrs.commit() | 41 rrs.commit() |
| 49 | 42 |
| 50 def test_record_count(self): | 43 def test_record_count(self): |
| 51 rrs = ResourceRecordSets(self.conn, self.zone.id) | 44 rrs = ResourceRecordSets(self.conn, self.zone.id) |
| 52 hosts = 101 | 45 hosts = 101 |
| 53 | 46 |
| 54 for hostid in range(hosts): | 47 for hostid in range(hosts): |
| 55 rec = "test" + str(hostid) + ".example.com" | 48 rec = "test" + str(hostid) + ".%s" % self.base_domain |
| 56 created = rrs.add_change("CREATE", rec, "A") | 49 created = rrs.add_change("CREATE", rec, "A") |
| 57 ip = '192.168.0.' + str(hostid) | 50 ip = '192.168.0.' + str(hostid) |
| 58 created.add_value(ip) | 51 created.add_value(ip) |
| 59 | 52 |
| 60 # Max 100 changes per commit | 53 # Max 100 changes per commit |
| 61 if (hostid + 1) % 100 == 0: | 54 if (hostid + 1) % 100 == 0: |
| 62 rrs.commit() | 55 rrs.commit() |
| 63 rrs = ResourceRecordSets(self.conn, self.zone.id) | 56 rrs = ResourceRecordSets(self.conn, self.zone.id) |
| 64 | 57 |
| 65 rrs.commit() | 58 rrs.commit() |
| 66 | 59 |
| 67 all_records = self.conn.get_all_rrsets(self.zone.id) | 60 all_records = self.conn.get_all_rrsets(self.zone.id) |
| 68 | 61 |
| 69 # First time around was always fine | 62 # First time around was always fine |
| 70 i = 0 | 63 i = 0 |
| 71 for rset in all_records: | 64 for rset in all_records: |
| 72 i += 1 | 65 i += 1 |
| 73 | 66 |
| 74 # Second time was a failure | 67 # Second time was a failure |
| 75 i = 0 | 68 i = 0 |
| 76 for rset in all_records: | 69 for rset in all_records: |
| 77 i += 1 | 70 i += 1 |
| 78 | 71 |
| 79 # Cleanup indivual records | 72 # Cleanup indivual records |
| 80 rrs = ResourceRecordSets(self.conn, self.zone.id) | 73 rrs = ResourceRecordSets(self.conn, self.zone.id) |
| 81 for hostid in range(hosts): | 74 for hostid in range(hosts): |
| 82 rec = "test" + str(hostid) + ".example.com" | 75 rec = "test" + str(hostid) + ".%s" % self.base_domain |
| 83 deleted = rrs.add_change("DELETE", rec, "A") | 76 deleted = rrs.add_change("DELETE", rec, "A") |
| 84 ip = '192.168.0.' + str(hostid) | 77 ip = '192.168.0.' + str(hostid) |
| 85 deleted.add_value(ip) | 78 deleted.add_value(ip) |
| 86 | 79 |
| 87 # Max 100 changes per commit | 80 # Max 100 changes per commit |
| 88 if (hostid + 1) % 100 == 0: | 81 if (hostid + 1) % 100 == 0: |
| 89 rrs.commit() | 82 rrs.commit() |
| 90 rrs = ResourceRecordSets(self.conn, self.zone.id) | 83 rrs = ResourceRecordSets(self.conn, self.zone.id) |
| 91 | 84 |
| 92 rrs.commit() | 85 rrs.commit() |
| 93 | 86 |
| 94 # 2nd count should match the number of hosts plus NS/SOA records | 87 # 2nd count should match the number of hosts plus NS/SOA records |
| 95 records = hosts + 2 | 88 records = hosts + 2 |
| 96 self.assertEqual(i, records) | 89 self.assertEqual(i, records) |
| 97 | 90 |
| 98 if __name__ == '__main__': | 91 if __name__ == '__main__': |
| 99 unittest.main() | 92 unittest.main() |
| OLD | NEW |