| OLD | NEW |
| 1 # Copyright (c) 2010 Hunter Blanks http://artifex.org/~hblanks/ | 1 # Copyright (c) 2010 Hunter Blanks http://artifex.org/~hblanks/ |
| 2 # All rights reserved. | 2 # All rights reserved. |
| 3 # | 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 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 | 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- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: | 10 # lowing conditions: |
| 11 # | 11 # |
| 12 # The above copyright notice and this permission notice shall be included | 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. | 13 # in all copies or substantial portions of the Software. |
| 14 # | 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 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- | 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 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, | 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, | 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 | 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. | 21 # IN THE SOFTWARE. |
| 22 | 22 |
| 23 """ | 23 """ |
| 24 Initial, and very limited, unit tests for ELBConnection. | 24 Initial, and very limited, unit tests for ELBConnection. |
| 25 """ | 25 """ |
| 26 | 26 |
| 27 import boto |
| 28 import time |
| 27 import unittest | 29 import unittest |
| 28 from boto.ec2.elb import ELBConnection | 30 from boto.ec2.elb import ELBConnection |
| 29 | 31 |
| 30 class ELBConnectionTest(unittest.TestCase): | 32 class ELBConnectionTest(unittest.TestCase): |
| 31 ec2 = True | 33 ec2 = True |
| 32 | 34 |
| 33 def setUp(self): | 35 def setUp(self): |
| 34 """Creates a named load balancer that can be safely | 36 """Creates a named load balancer that can be safely |
| 35 deleted at the end of each test""" | 37 deleted at the end of each test""" |
| 36 self.conn = ELBConnection() | 38 self.conn = ELBConnection() |
| 37 self.name = 'elb-boto-unit-test' | 39 self.name = 'elb-boto-unit-test' |
| 38 self.availability_zones = ['us-east-1a'] | 40 self.availability_zones = ['us-east-1a'] |
| 39 self.listeners = [(80, 8000, 'HTTP')] | 41 self.listeners = [(80, 8000, 'HTTP')] |
| 40 self.balancer = self.conn.create_load_balancer(self.name, self.availabil
ity_zones, self.listeners) | 42 self.balancer = self.conn.create_load_balancer(self.name, self.availabil
ity_zones, self.listeners) |
| 41 | 43 |
| 44 # S3 bucket for log tests |
| 45 self.s3 = boto.connect_s3() |
| 46 self.timestamp = str(int(time.time())) |
| 47 self.bucket_name = 'boto-elb-%s' % self.timestamp |
| 48 self.bucket = self.s3.create_bucket(self.bucket_name) |
| 49 self.bucket.set_canned_acl('public-read-write') |
| 50 self.addCleanup(self.cleanup_bucket, self.bucket) |
| 51 |
| 52 def cleanup_bucket(self, bucket): |
| 53 for key in bucket.get_all_keys(): |
| 54 key.delete() |
| 55 bucket.delete() |
| 56 |
| 42 def tearDown(self): | 57 def tearDown(self): |
| 43 """ Deletes the test load balancer after every test. | 58 """ Deletes the test load balancer after every test. |
| 44 It does not delete EVERY load balancer in your account""" | 59 It does not delete EVERY load balancer in your account""" |
| 45 self.balancer.delete() | 60 self.balancer.delete() |
| 46 | 61 |
| 47 def test_build_list_params(self): | 62 def test_build_list_params(self): |
| 48 params = {} | 63 params = {} |
| 49 self.conn.build_list_params( | 64 self.conn.build_list_params( |
| 50 params, ['thing1', 'thing2', 'thing3'], 'ThingName%d') | 65 params, ['thing1', 'thing2', 'thing3'], 'ThingName%d') |
| 51 expected_params = { | 66 expected_params = { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 balancers = self.conn.get_all_load_balancers( | 169 balancers = self.conn.get_all_load_balancers( |
| 155 load_balancer_names=[self.name] | 170 load_balancer_names=[self.name] |
| 156 ) | 171 ) |
| 157 self.assertEqual([lb.name for lb in balancers], [self.name]) | 172 self.assertEqual([lb.name for lb in balancers], [self.name]) |
| 158 self.assertEqual( | 173 self.assertEqual( |
| 159 sorted(l.get_complex_tuple() for l in balancers[0].listeners), | 174 sorted(l.get_complex_tuple() for l in balancers[0].listeners), |
| 160 # We need an extra 'HTTP' here over what ``self.listeners`` uses. | 175 # We need an extra 'HTTP' here over what ``self.listeners`` uses. |
| 161 sorted([(80, 8000, 'HTTP', 'HTTP')] + complex_listeners) | 176 sorted([(80, 8000, 'HTTP', 'HTTP')] + complex_listeners) |
| 162 ) | 177 ) |
| 163 | 178 |
| 179 def test_load_balancer_access_log(self): |
| 180 attributes = self.balancer.get_attributes() |
| 181 |
| 182 self.assertEqual(False, attributes.access_log.enabled) |
| 183 |
| 184 attributes.access_log.enabled = True |
| 185 attributes.access_log.s3_bucket_name = self.bucket_name |
| 186 attributes.access_log.s3_bucket_prefix = 'access-logs' |
| 187 attributes.access_log.emit_interval = 5 |
| 188 |
| 189 self.conn.modify_lb_attribute(self.balancer.name, 'accessLog', |
| 190 attributes.access_log) |
| 191 |
| 192 new_attributes = self.balancer.get_attributes() |
| 193 |
| 194 self.assertEqual(True, new_attributes.access_log.enabled) |
| 195 self.assertEqual(self.bucket_name, |
| 196 new_attributes.access_log.s3_bucket_name) |
| 197 self.assertEqual('access-logs', |
| 198 new_attributes.access_log.s3_bucket_prefix) |
| 199 self.assertEqual(5, new_attributes.access_log.emit_interval) |
| 200 |
| 201 def test_load_balancer_get_attributes(self): |
| 202 attributes = self.balancer.get_attributes() |
| 203 connection_draining = self.conn.get_lb_attribute(self.balancer.name, |
| 204 'ConnectionDraining') |
| 205 self.assertEqual(connection_draining.enabled, |
| 206 attributes.connection_draining.enabled) |
| 207 self.assertEqual(connection_draining.timeout, |
| 208 attributes.connection_draining.timeout) |
| 209 |
| 210 access_log = self.conn.get_lb_attribute(self.balancer.name, |
| 211 'AccessLog') |
| 212 self.assertEqual(access_log.enabled, attributes.access_log.enabled) |
| 213 self.assertEqual(access_log.s3_bucket_name, attributes.access_log.s3_buc
ket_name) |
| 214 self.assertEqual(access_log.s3_bucket_prefix, attributes.access_log.s3_b
ucket_prefix) |
| 215 self.assertEqual(access_log.emit_interval, attributes.access_log.emit_in
terval) |
| 216 |
| 217 cross_zone_load_balancing = self.conn.get_lb_attribute(self.balancer.nam
e, |
| 218 'CrossZoneLoadBalancing') |
| 219 self.assertEqual(cross_zone_load_balancing, |
| 220 attributes.cross_zone_load_balancing.enabled) |
| 221 |
| 222 def change_and_verify_load_balancer_connection_draining(self, enabled, timeo
ut = None): |
| 223 attributes = self.balancer.get_attributes() |
| 224 |
| 225 attributes.connection_draining.enabled = enabled |
| 226 if timeout != None: |
| 227 attributes.connection_draining.timeout = timeout |
| 228 |
| 229 self.conn.modify_lb_attribute(self.balancer.name, |
| 230 'ConnectionDraining', attributes.connectio
n_draining) |
| 231 |
| 232 attributes = self.balancer.get_attributes() |
| 233 self.assertEqual(enabled, attributes.connection_draining.enabled) |
| 234 if timeout != None: |
| 235 self.assertEqual(timeout, attributes.connection_draining.timeout) |
| 236 |
| 237 def test_load_balancer_connection_draining_config(self): |
| 238 self.change_and_verify_load_balancer_connection_draining(True, 128) |
| 239 self.change_and_verify_load_balancer_connection_draining(True, 256) |
| 240 self.change_and_verify_load_balancer_connection_draining(False) |
| 241 self.change_and_verify_load_balancer_connection_draining(True, 64) |
| 242 |
| 243 def test_set_load_balancer_policies_of_listeners(self): |
| 244 more_listeners = [(443, 8001, 'HTTP')] |
| 245 self.conn.create_load_balancer_listeners(self.name, more_listeners) |
| 246 |
| 247 lb_policy_name = 'lb-policy' |
| 248 self.conn.create_lb_cookie_stickiness_policy( |
| 249 1000, |
| 250 self.name, |
| 251 lb_policy_name |
| 252 ) |
| 253 self.conn.set_lb_policies_of_listener( |
| 254 self.name, |
| 255 self.listeners[0][0], |
| 256 lb_policy_name |
| 257 ) |
| 258 |
| 259 # Try to remove the policy by passing empty list. |
| 260 # http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/AP
I_SetLoadBalancerPoliciesOfListener.html |
| 261 # documents this as the way to remove policies. |
| 262 self.conn.set_lb_policies_of_listener( |
| 263 self.name, |
| 264 self.listeners[0][0], |
| 265 [] |
| 266 ) |
| 267 |
| 268 |
| 164 if __name__ == '__main__': | 269 if __name__ == '__main__': |
| 165 unittest.main() | 270 unittest.main() |
| OLD | NEW |