PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/telemetry/third_party/gsutilz/third_party/boto/tests/integration/route53/test_zone.py

https://gitlab.com/jonnialva90/iridium-browser
Python | 196 lines | 153 code | 19 blank | 24 comment | 4 complexity | 220ffc33417025626ddba7bccaa06eba MD5 | raw file
  1. # Copyright (c) 2011 Blue Pines Technologies LLC, Brad Carleton
  2. # www.bluepines.org
  3. # Copyright (c) 2012 42 Lines Inc., Jim Browne
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the
  7. # "Software"), to deal in the Software without restriction, including
  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
  10. # persons to whom the Software is furnished to do so, subject to the fol-
  11. # lowing conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included
  14. # in all copies or substantial portions of the Software.
  15. #
  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-
  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,
  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
  22. # IN THE SOFTWARE.
  23. #
  24. import time
  25. from tests.compat import unittest
  26. from nose.plugins.attrib import attr
  27. from boto.route53.connection import Route53Connection
  28. from boto.exception import TooManyRecordsException
  29. from boto.vpc import VPCConnection
  30. @attr(route53=True)
  31. class TestRoute53Zone(unittest.TestCase):
  32. @classmethod
  33. def setUpClass(self):
  34. route53 = Route53Connection()
  35. self.base_domain = 'boto-test-%s.com' % str(int(time.time()))
  36. zone = route53.get_zone(self.base_domain)
  37. if zone is not None:
  38. zone.delete()
  39. self.zone = route53.create_zone(self.base_domain)
  40. def test_nameservers(self):
  41. self.zone.get_nameservers()
  42. def test_a(self):
  43. self.zone.add_a(self.base_domain, '102.11.23.1', 80)
  44. record = self.zone.get_a(self.base_domain)
  45. self.assertEquals(record.name, u'%s.' % self.base_domain)
  46. self.assertEquals(record.resource_records, [u'102.11.23.1'])
  47. self.assertEquals(record.ttl, u'80')
  48. self.zone.update_a(self.base_domain, '186.143.32.2', '800')
  49. record = self.zone.get_a(self.base_domain)
  50. self.assertEquals(record.name, u'%s.' % self.base_domain)
  51. self.assertEquals(record.resource_records, [u'186.143.32.2'])
  52. self.assertEquals(record.ttl, u'800')
  53. def test_cname(self):
  54. self.zone.add_cname(
  55. 'www.%s' % self.base_domain,
  56. 'webserver.%s' % self.base_domain,
  57. 200
  58. )
  59. record = self.zone.get_cname('www.%s' % self.base_domain)
  60. self.assertEquals(record.name, u'www.%s.' % self.base_domain)
  61. self.assertEquals(record.resource_records, [
  62. u'webserver.%s.' % self.base_domain
  63. ])
  64. self.assertEquals(record.ttl, u'200')
  65. self.zone.update_cname(
  66. 'www.%s' % self.base_domain,
  67. 'web.%s' % self.base_domain,
  68. 45
  69. )
  70. record = self.zone.get_cname('www.%s' % self.base_domain)
  71. self.assertEquals(record.name, u'www.%s.' % self.base_domain)
  72. self.assertEquals(record.resource_records, [
  73. u'web.%s.' % self.base_domain
  74. ])
  75. self.assertEquals(record.ttl, u'45')
  76. def test_mx(self):
  77. self.zone.add_mx(
  78. self.base_domain,
  79. [
  80. '10 mx1.%s' % self.base_domain,
  81. '20 mx2.%s' % self.base_domain,
  82. ],
  83. 1000
  84. )
  85. record = self.zone.get_mx(self.base_domain)
  86. self.assertEquals(set(record.resource_records),
  87. set([u'10 mx1.%s.' % self.base_domain,
  88. u'20 mx2.%s.' % self.base_domain]))
  89. self.assertEquals(record.ttl, u'1000')
  90. self.zone.update_mx(
  91. self.base_domain,
  92. [
  93. '10 mail1.%s' % self.base_domain,
  94. '20 mail2.%s' % self.base_domain,
  95. ],
  96. 50
  97. )
  98. record = self.zone.get_mx(self.base_domain)
  99. self.assertEquals(set(record.resource_records),
  100. set([u'10 mail1.%s.' % self.base_domain,
  101. '20 mail2.%s.' % self.base_domain]))
  102. self.assertEquals(record.ttl, u'50')
  103. def test_get_records(self):
  104. self.zone.get_records()
  105. def test_get_nameservers(self):
  106. self.zone.get_nameservers()
  107. def test_get_zones(self):
  108. route53 = Route53Connection()
  109. route53.get_zones()
  110. def test_identifiers_wrrs(self):
  111. self.zone.add_a('wrr.%s' % self.base_domain, '1.2.3.4',
  112. identifier=('foo', '20'))
  113. self.zone.add_a('wrr.%s' % self.base_domain, '5.6.7.8',
  114. identifier=('bar', '10'))
  115. wrrs = self.zone.find_records(
  116. 'wrr.%s' % self.base_domain,
  117. 'A',
  118. all=True
  119. )
  120. self.assertEquals(len(wrrs), 2)
  121. self.zone.delete_a('wrr.%s' % self.base_domain, all=True)
  122. def test_identifiers_lbrs(self):
  123. self.zone.add_a('lbr.%s' % self.base_domain, '4.3.2.1',
  124. identifier=('baz', 'us-east-1'))
  125. self.zone.add_a('lbr.%s' % self.base_domain, '8.7.6.5',
  126. identifier=('bam', 'us-west-1'))
  127. lbrs = self.zone.find_records(
  128. 'lbr.%s' % self.base_domain,
  129. 'A',
  130. all=True
  131. )
  132. self.assertEquals(len(lbrs), 2)
  133. self.zone.delete_a('lbr.%s' % self.base_domain,
  134. identifier=('bam', 'us-west-1'))
  135. self.zone.delete_a('lbr.%s' % self.base_domain,
  136. identifier=('baz', 'us-east-1'))
  137. def test_toomany_exception(self):
  138. self.zone.add_a('exception.%s' % self.base_domain, '4.3.2.1',
  139. identifier=('baz', 'us-east-1'))
  140. self.zone.add_a('exception.%s' % self.base_domain, '8.7.6.5',
  141. identifier=('bam', 'us-west-1'))
  142. self.assertRaises(TooManyRecordsException,
  143. lambda: self.zone.get_a('exception.%s' %
  144. self.base_domain))
  145. self.zone.delete_a('exception.%s' % self.base_domain, all=True)
  146. @classmethod
  147. def tearDownClass(self):
  148. self.zone.delete_a(self.base_domain)
  149. self.zone.delete_cname('www.%s' % self.base_domain)
  150. self.zone.delete_mx(self.base_domain)
  151. self.zone.delete()
  152. @attr(route53=True)
  153. class TestRoute53PrivateZone(unittest.TestCase):
  154. @classmethod
  155. def setUpClass(self):
  156. time_str = str(int(time.time()))
  157. self.route53 = Route53Connection()
  158. self.base_domain = 'boto-private-zone-test-%s.com' % time_str
  159. self.vpc = VPCConnection()
  160. self.test_vpc = self.vpc.create_vpc(cidr_block='10.11.0.0/16')
  161. # tag the vpc to make it easily identifiable if things go spang
  162. self.test_vpc.add_tag("Name", self.base_domain)
  163. self.zone = self.route53.get_zone(self.base_domain)
  164. if self.zone is not None:
  165. self.zone.delete()
  166. def test_create_private_zone(self):
  167. self.zone = self.route53.create_hosted_zone(self.base_domain,
  168. private_zone=True,
  169. vpc_id=self.test_vpc.id,
  170. vpc_region='us-east-1')
  171. @classmethod
  172. def tearDownClass(self):
  173. if self.zone is not None:
  174. self.zone.delete()
  175. self.test_vpc.delete()
  176. if __name__ == '__main__':
  177. unittest.main(verbosity=3)