| OLD | NEW |
| 1 # Copyright (c) 2011 Blue Pines Technologies LLC, Brad Carleton | 1 # Copyright (c) 2011 Blue Pines Technologies LLC, Brad Carleton |
| 2 # www.bluepines.org | 2 # www.bluepines.org |
| 3 # Copyright (c) 2012 42 Lines Inc., Jim Browne | 3 # Copyright (c) 2012 42 Lines Inc., Jim Browne |
| 4 # | 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a | 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the | 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including | 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- | 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit | 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- | 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| 11 # lowing conditions: | 11 # lowing conditions: |
| 12 # | 12 # |
| 13 # The above copyright notice and this permission notice shall be included | 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. | 14 # in all copies or substantial portions of the Software. |
| 15 # | 15 # |
| 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 # IN THE SOFTWARE. | 22 # IN THE SOFTWARE. |
| 23 # | 23 # |
| 24 | 24 |
| 25 import time |
| 25 import unittest | 26 import unittest |
| 27 from nose.plugins.attrib import attr |
| 26 from boto.route53.connection import Route53Connection | 28 from boto.route53.connection import Route53Connection |
| 27 from boto.exception import TooManyRecordsException | 29 from boto.exception import TooManyRecordsException |
| 28 | 30 |
| 29 | 31 |
| 32 @attr(route53=True) |
| 30 class TestRoute53Zone(unittest.TestCase): | 33 class TestRoute53Zone(unittest.TestCase): |
| 31 @classmethod | 34 @classmethod |
| 32 def setUpClass(self): | 35 def setUpClass(self): |
| 33 route53 = Route53Connection() | 36 route53 = Route53Connection() |
| 34 zone = route53.get_zone('example.com') | 37 self.base_domain = 'boto-test-%s.com' % str(int(time.time())) |
| 38 zone = route53.get_zone(self.base_domain) |
| 35 if zone is not None: | 39 if zone is not None: |
| 36 zone.delete() | 40 zone.delete() |
| 37 self.zone = route53.create_zone('example.com') | 41 self.zone = route53.create_zone(self.base_domain) |
| 38 | 42 |
| 39 def test_nameservers(self): | 43 def test_nameservers(self): |
| 40 self.zone.get_nameservers() | 44 self.zone.get_nameservers() |
| 41 | 45 |
| 42 def test_a(self): | 46 def test_a(self): |
| 43 self.zone.add_a('example.com', '102.11.23.1', 80) | 47 self.zone.add_a(self.base_domain, '102.11.23.1', 80) |
| 44 record = self.zone.get_a('example.com') | 48 record = self.zone.get_a(self.base_domain) |
| 45 self.assertEquals(record.name, u'example.com.') | 49 self.assertEquals(record.name, u'%s.' % self.base_domain) |
| 46 self.assertEquals(record.resource_records, [u'102.11.23.1']) | 50 self.assertEquals(record.resource_records, [u'102.11.23.1']) |
| 47 self.assertEquals(record.ttl, u'80') | 51 self.assertEquals(record.ttl, u'80') |
| 48 self.zone.update_a('example.com', '186.143.32.2', '800') | 52 self.zone.update_a(self.base_domain, '186.143.32.2', '800') |
| 49 record = self.zone.get_a('example.com') | 53 record = self.zone.get_a(self.base_domain) |
| 50 self.assertEquals(record.name, u'example.com.') | 54 self.assertEquals(record.name, u'%s.' % self.base_domain) |
| 51 self.assertEquals(record.resource_records, [u'186.143.32.2']) | 55 self.assertEquals(record.resource_records, [u'186.143.32.2']) |
| 52 self.assertEquals(record.ttl, u'800') | 56 self.assertEquals(record.ttl, u'800') |
| 53 | 57 |
| 54 def test_cname(self): | 58 def test_cname(self): |
| 55 self.zone.add_cname('www.example.com', 'webserver.example.com', 200) | 59 self.zone.add_cname( |
| 56 record = self.zone.get_cname('www.example.com') | 60 'www.%s' % self.base_domain, |
| 57 self.assertEquals(record.name, u'www.example.com.') | 61 'webserver.%s' % self.base_domain, |
| 58 self.assertEquals(record.resource_records, [u'webserver.example.com.']) | 62 200 |
| 63 ) |
| 64 record = self.zone.get_cname('www.%s' % self.base_domain) |
| 65 self.assertEquals(record.name, u'www.%s.' % self.base_domain) |
| 66 self.assertEquals(record.resource_records, [ |
| 67 u'webserver.%s.' % self.base_domain |
| 68 ]) |
| 59 self.assertEquals(record.ttl, u'200') | 69 self.assertEquals(record.ttl, u'200') |
| 60 self.zone.update_cname('www.example.com', 'web.example.com', 45) | 70 self.zone.update_cname( |
| 61 record = self.zone.get_cname('www.example.com') | 71 'www.%s' % self.base_domain, |
| 62 self.assertEquals(record.name, u'www.example.com.') | 72 'web.%s' % self.base_domain, |
| 63 self.assertEquals(record.resource_records, [u'web.example.com.']) | 73 45 |
| 74 ) |
| 75 record = self.zone.get_cname('www.%s' % self.base_domain) |
| 76 self.assertEquals(record.name, u'www.%s.' % self.base_domain) |
| 77 self.assertEquals(record.resource_records, [ |
| 78 u'web.%s.' % self.base_domain |
| 79 ]) |
| 64 self.assertEquals(record.ttl, u'45') | 80 self.assertEquals(record.ttl, u'45') |
| 65 | 81 |
| 66 def test_mx(self): | 82 def test_mx(self): |
| 67 self.zone.add_mx('example.com', | 83 self.zone.add_mx( |
| 68 ['10 mx1.example.com', '20 mx2.example.com'], | 84 self.base_domain, |
| 69 1000) | 85 [ |
| 70 record = self.zone.get_mx('example.com') | 86 '10 mx1.%s' % self.base_domain, |
| 87 '20 mx2.%s' % self.base_domain, |
| 88 ], |
| 89 1000 |
| 90 ) |
| 91 record = self.zone.get_mx(self.base_domain) |
| 71 self.assertEquals(set(record.resource_records), | 92 self.assertEquals(set(record.resource_records), |
| 72 set([u'10 mx1.example.com.', | 93 set([u'10 mx1.%s.' % self.base_domain, |
| 73 u'20 mx2.example.com.'])) | 94 u'20 mx2.%s.' % self.base_domain])) |
| 74 self.assertEquals(record.ttl, u'1000') | 95 self.assertEquals(record.ttl, u'1000') |
| 75 self.zone.update_mx('example.com', | 96 self.zone.update_mx( |
| 76 ['10 mail1.example.com', '20 mail2.example.com'], | 97 self.base_domain, |
| 77 50) | 98 [ |
| 78 record = self.zone.get_mx('example.com') | 99 '10 mail1.%s' % self.base_domain, |
| 100 '20 mail2.%s' % self.base_domain, |
| 101 ], |
| 102 50 |
| 103 ) |
| 104 record = self.zone.get_mx(self.base_domain) |
| 79 self.assertEquals(set(record.resource_records), | 105 self.assertEquals(set(record.resource_records), |
| 80 set([u'10 mail1.example.com.', | 106 set([u'10 mail1.%s.' % self.base_domain, |
| 81 '20 mail2.example.com.'])) | 107 '20 mail2.%s.' % self.base_domain])) |
| 82 self.assertEquals(record.ttl, u'50') | 108 self.assertEquals(record.ttl, u'50') |
| 83 | 109 |
| 84 def test_get_records(self): | 110 def test_get_records(self): |
| 85 self.zone.get_records() | 111 self.zone.get_records() |
| 86 | 112 |
| 87 def test_get_nameservers(self): | 113 def test_get_nameservers(self): |
| 88 self.zone.get_nameservers() | 114 self.zone.get_nameservers() |
| 89 | 115 |
| 90 def test_get_zones(self): | 116 def test_get_zones(self): |
| 91 route53 = Route53Connection() | 117 route53 = Route53Connection() |
| 92 route53.get_zones() | 118 route53.get_zones() |
| 93 | 119 |
| 94 def test_identifiers_wrrs(self): | 120 def test_identifiers_wrrs(self): |
| 95 self.zone.add_a('wrr.example.com', '1.2.3.4', | 121 self.zone.add_a('wrr.%s' % self.base_domain, '1.2.3.4', |
| 96 identifier=('foo', '20')) | 122 identifier=('foo', '20')) |
| 97 self.zone.add_a('wrr.example.com', '5.6.7.8', | 123 self.zone.add_a('wrr.%s' % self.base_domain, '5.6.7.8', |
| 98 identifier=('bar', '10')) | 124 identifier=('bar', '10')) |
| 99 wrrs = self.zone.find_records('wrr.example.com', 'A', all=True) | 125 wrrs = self.zone.find_records( |
| 126 'wrr.%s' % self.base_domain, |
| 127 'A', |
| 128 all=True |
| 129 ) |
| 100 self.assertEquals(len(wrrs), 2) | 130 self.assertEquals(len(wrrs), 2) |
| 101 self.zone.delete_a('wrr.example.com', all=True) | 131 self.zone.delete_a('wrr.%s' % self.base_domain, all=True) |
| 102 | 132 |
| 103 def test_identifiers_lbrs(self): | 133 def test_identifiers_lbrs(self): |
| 104 self.zone.add_a('lbr.example.com', '4.3.2.1', | 134 self.zone.add_a('lbr.%s' % self.base_domain, '4.3.2.1', |
| 105 identifier=('baz', 'us-east-1')) | 135 identifier=('baz', 'us-east-1')) |
| 106 self.zone.add_a('lbr.example.com', '8.7.6.5', | 136 self.zone.add_a('lbr.%s' % self.base_domain, '8.7.6.5', |
| 107 identifier=('bam', 'us-west-1')) | 137 identifier=('bam', 'us-west-1')) |
| 108 lbrs = self.zone.find_records('lbr.example.com', 'A', all=True) | 138 lbrs = self.zone.find_records( |
| 139 'lbr.%s' % self.base_domain, |
| 140 'A', |
| 141 all=True |
| 142 ) |
| 109 self.assertEquals(len(lbrs), 2) | 143 self.assertEquals(len(lbrs), 2) |
| 110 self.zone.delete_a('lbr.example.com', | 144 self.zone.delete_a('lbr.%s' % self.base_domain, |
| 111 identifier=('bam', 'us-west-1')) | 145 identifier=('bam', 'us-west-1')) |
| 112 self.zone.delete_a('lbr.example.com', | 146 self.zone.delete_a('lbr.%s' % self.base_domain, |
| 113 identifier=('baz', 'us-east-1')) | 147 identifier=('baz', 'us-east-1')) |
| 114 | 148 |
| 115 def test_toomany_exception(self): | 149 def test_toomany_exception(self): |
| 116 self.zone.add_a('exception.example.com', '4.3.2.1', | 150 self.zone.add_a('exception.%s' % self.base_domain, '4.3.2.1', |
| 117 identifier=('baz', 'us-east-1')) | 151 identifier=('baz', 'us-east-1')) |
| 118 self.zone.add_a('exception.example.com', '8.7.6.5', | 152 self.zone.add_a('exception.%s' % self.base_domain, '8.7.6.5', |
| 119 identifier=('bam', 'us-west-1')) | 153 identifier=('bam', 'us-west-1')) |
| 120 with self.assertRaises(TooManyRecordsException): | 154 with self.assertRaises(TooManyRecordsException): |
| 121 lbrs = self.zone.get_a('exception.example.com') | 155 lbrs = self.zone.get_a('exception.%s' % self.base_domain) |
| 122 self.zone.delete_a('exception.example.com', all=True) | 156 self.zone.delete_a('exception.%s' % self.base_domain, all=True) |
| 123 | 157 |
| 124 @classmethod | 158 @classmethod |
| 125 def tearDownClass(self): | 159 def tearDownClass(self): |
| 126 self.zone.delete_a('example.com') | 160 self.zone.delete_a(self.base_domain) |
| 127 self.zone.delete_cname('www.example.com') | 161 self.zone.delete_cname('www.%s' % self.base_domain) |
| 128 self.zone.delete_mx('example.com') | 162 self.zone.delete_mx(self.base_domain) |
| 129 self.zone.delete() | 163 self.zone.delete() |
| 130 | 164 |
| 131 if __name__ == '__main__': | 165 if __name__ == '__main__': |
| 132 unittest.main(verbosity=3) | 166 unittest.main(verbosity=3) |
| OLD | NEW |