PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/tests/integration/ec2/elb/test_connection.py

#
Python | 130 lines | 81 code | 19 blank | 30 comment | 11 complexity | 6c4285f3e4943f1ec054cc496469249f MD5 | raw file
  1. # Copyright (c) 2010 Hunter Blanks http://artifex.org/~hblanks/
  2. # All rights reserved.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a
  5. # copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish, dis-
  8. # tribute, sublicense, and/or sell copies of the Software, and to permit
  9. # persons to whom the Software is furnished to do so, subject to the fol-
  10. # lowing conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  17. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  18. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. # IN THE SOFTWARE.
  22. """
  23. Initial, and very limited, unit tests for ELBConnection.
  24. """
  25. import unittest
  26. from boto.ec2.elb import ELBConnection
  27. class ELBConnectionTest(unittest.TestCase):
  28. ec2 = True
  29. def tearDown(self):
  30. """ Deletes all load balancers after every test. """
  31. for lb in ELBConnection().get_all_load_balancers():
  32. lb.delete()
  33. def test_build_list_params(self):
  34. c = ELBConnection()
  35. params = {}
  36. c.build_list_params(
  37. params, ['thing1', 'thing2', 'thing3'], 'ThingName%d')
  38. expected_params = {
  39. 'ThingName1': 'thing1',
  40. 'ThingName2': 'thing2',
  41. 'ThingName3': 'thing3'
  42. }
  43. self.assertEqual(params, expected_params)
  44. # TODO: for these next tests, consider sleeping until our load
  45. # balancer comes up, then testing for connectivity to
  46. # balancer.dns_name, along the lines of the existing EC2 unit tests.
  47. def test_create_load_balancer(self):
  48. c = ELBConnection()
  49. name = 'elb-boto-unit-test'
  50. availability_zones = ['us-east-1a']
  51. listeners = [(80, 8000, 'HTTP')]
  52. balancer = c.create_load_balancer(name, availability_zones, listeners)
  53. self.assertEqual(balancer.name, name)
  54. self.assertEqual(balancer.availability_zones, availability_zones)
  55. self.assertEqual(balancer.listeners, listeners)
  56. balancers = c.get_all_load_balancers()
  57. self.assertEqual([lb.name for lb in balancers], [name])
  58. def test_create_load_balancer_listeners(self):
  59. c = ELBConnection()
  60. name = 'elb-boto-unit-test'
  61. availability_zones = ['us-east-1a']
  62. listeners = [(80, 8000, 'HTTP')]
  63. balancer = c.create_load_balancer(name, availability_zones, listeners)
  64. more_listeners = [(443, 8001, 'HTTP')]
  65. c.create_load_balancer_listeners(name, more_listeners)
  66. balancers = c.get_all_load_balancers()
  67. self.assertEqual([lb.name for lb in balancers], [name])
  68. self.assertEqual(
  69. sorted(l.get_tuple() for l in balancers[0].listeners),
  70. sorted(listeners + more_listeners)
  71. )
  72. def test_delete_load_balancer_listeners(self):
  73. c = ELBConnection()
  74. name = 'elb-boto-unit-test'
  75. availability_zones = ['us-east-1a']
  76. listeners = [(80, 8000, 'HTTP'), (443, 8001, 'HTTP')]
  77. balancer = c.create_load_balancer(name, availability_zones, listeners)
  78. balancers = c.get_all_load_balancers()
  79. self.assertEqual([lb.name for lb in balancers], [name])
  80. self.assertEqual(
  81. sorted([l.get_tuple() for l in balancers[0].listeners]),
  82. sorted(listeners))
  83. c.delete_load_balancer_listeners(name, [443])
  84. balancers = c.get_all_load_balancers()
  85. self.assertEqual([lb.name for lb in balancers], [name])
  86. self.assertEqual([l.get_tuple() for l in balancers[0].listeners],
  87. listeners[:1])
  88. def test_create_load_balancer_listeners_with_policies(self):
  89. c = ELBConnection()
  90. name = 'elb-boto-unit-test-policy'
  91. availability_zones = ['us-east-1a']
  92. listeners = [(80, 8000, 'HTTP')]
  93. balancer = c.create_load_balancer(name, availability_zones, listeners)
  94. more_listeners = [(443, 8001, 'HTTP')]
  95. c.create_load_balancer_listeners(name, more_listeners)
  96. lb_policy_name = 'lb-policy'
  97. c.create_lb_cookie_stickiness_policy(1000, name, lb_policy_name)
  98. c.set_lb_policies_of_listener(name, listeners[0][0], lb_policy_name)
  99. app_policy_name = 'app-policy'
  100. c.create_app_cookie_stickiness_policy('appcookie', name, app_policy_name)
  101. c.set_lb_policies_of_listener(name, more_listeners[0][0], app_policy_name)
  102. balancers = c.get_all_load_balancers()
  103. self.assertEqual([lb.name for lb in balancers], [name])
  104. self.assertEqual(
  105. sorted(l.get_tuple() for l in balancers[0].listeners),
  106. sorted(listeners + more_listeners)
  107. )
  108. # Policy names should be checked here once they are supported
  109. # in the Listener object.
  110. if __name__ == '__main__':
  111. unittest.main()