OLD | NEW |
(Empty) | |
| 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 """ |
| 24 Initial, and very limited, unit tests for ELBConnection. |
| 25 """ |
| 26 |
| 27 import unittest |
| 28 from boto.ec2.elb import ELBConnection |
| 29 |
| 30 class ELBConnectionTest(unittest.TestCase): |
| 31 ec2 = True |
| 32 |
| 33 def tearDown(self): |
| 34 """ Deletes all load balancers after every test. """ |
| 35 for lb in ELBConnection().get_all_load_balancers(): |
| 36 lb.delete() |
| 37 |
| 38 def test_build_list_params(self): |
| 39 c = ELBConnection() |
| 40 params = {} |
| 41 c.build_list_params( |
| 42 params, ['thing1', 'thing2', 'thing3'], 'ThingName%d') |
| 43 expected_params = { |
| 44 'ThingName1': 'thing1', |
| 45 'ThingName2': 'thing2', |
| 46 'ThingName3': 'thing3' |
| 47 } |
| 48 self.assertEqual(params, expected_params) |
| 49 |
| 50 # TODO: for these next tests, consider sleeping until our load |
| 51 # balancer comes up, then testing for connectivity to |
| 52 # balancer.dns_name, along the lines of the existing EC2 unit tests. |
| 53 |
| 54 def test_create_load_balancer(self): |
| 55 c = ELBConnection() |
| 56 name = 'elb-boto-unit-test' |
| 57 availability_zones = ['us-east-1a'] |
| 58 listeners = [(80, 8000, 'HTTP')] |
| 59 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 60 self.assertEqual(balancer.name, name) |
| 61 self.assertEqual(balancer.availability_zones, availability_zones) |
| 62 self.assertEqual(balancer.listeners, listeners) |
| 63 |
| 64 balancers = c.get_all_load_balancers() |
| 65 self.assertEqual([lb.name for lb in balancers], [name]) |
| 66 |
| 67 def test_create_load_balancer_listeners(self): |
| 68 c = ELBConnection() |
| 69 name = 'elb-boto-unit-test' |
| 70 availability_zones = ['us-east-1a'] |
| 71 listeners = [(80, 8000, 'HTTP')] |
| 72 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 73 |
| 74 more_listeners = [(443, 8001, 'HTTP')] |
| 75 c.create_load_balancer_listeners(name, more_listeners) |
| 76 balancers = c.get_all_load_balancers() |
| 77 self.assertEqual([lb.name for lb in balancers], [name]) |
| 78 self.assertEqual( |
| 79 sorted(l.get_tuple() for l in balancers[0].listeners), |
| 80 sorted(listeners + more_listeners) |
| 81 ) |
| 82 |
| 83 def test_delete_load_balancer_listeners(self): |
| 84 c = ELBConnection() |
| 85 name = 'elb-boto-unit-test' |
| 86 availability_zones = ['us-east-1a'] |
| 87 listeners = [(80, 8000, 'HTTP'), (443, 8001, 'HTTP')] |
| 88 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 89 |
| 90 balancers = c.get_all_load_balancers() |
| 91 self.assertEqual([lb.name for lb in balancers], [name]) |
| 92 self.assertEqual( |
| 93 sorted([l.get_tuple() for l in balancers[0].listeners]), |
| 94 sorted(listeners)) |
| 95 |
| 96 c.delete_load_balancer_listeners(name, [443]) |
| 97 balancers = c.get_all_load_balancers() |
| 98 self.assertEqual([lb.name for lb in balancers], [name]) |
| 99 self.assertEqual([l.get_tuple() for l in balancers[0].listeners], |
| 100 listeners[:1]) |
| 101 |
| 102 def test_create_load_balancer_listeners_with_policies(self): |
| 103 c = ELBConnection() |
| 104 name = 'elb-boto-unit-test-policy' |
| 105 availability_zones = ['us-east-1a'] |
| 106 listeners = [(80, 8000, 'HTTP')] |
| 107 balancer = c.create_load_balancer(name, availability_zones, listeners) |
| 108 |
| 109 more_listeners = [(443, 8001, 'HTTP')] |
| 110 c.create_load_balancer_listeners(name, more_listeners) |
| 111 |
| 112 lb_policy_name = 'lb-policy' |
| 113 c.create_lb_cookie_stickiness_policy(1000, name, lb_policy_name) |
| 114 c.set_lb_policies_of_listener(name, listeners[0][0], lb_policy_name) |
| 115 |
| 116 app_policy_name = 'app-policy' |
| 117 c.create_app_cookie_stickiness_policy('appcookie', name, app_policy_name
) |
| 118 c.set_lb_policies_of_listener(name, more_listeners[0][0], app_policy_nam
e) |
| 119 |
| 120 balancers = c.get_all_load_balancers() |
| 121 self.assertEqual([lb.name for lb in balancers], [name]) |
| 122 self.assertEqual( |
| 123 sorted(l.get_tuple() for l in balancers[0].listeners), |
| 124 sorted(listeners + more_listeners) |
| 125 ) |
| 126 # Policy names should be checked here once they are supported |
| 127 # in the Listener object. |
| 128 |
| 129 if __name__ == '__main__': |
| 130 unittest.main() |
OLD | NEW |