Path: blob/develop/tests/functional/elb/test_register_instances_with_load_balancer.py
2630 views
#!/usr/bin/env python1# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from awscli.testutils import BaseAWSCommandParamsTest, TestEventHandler14import os151617TWO_INSTANCE_EXPECTED = {18'LoadBalancerName': 'my-lb',19'Instances': [{'InstanceId': 'i-12345678'},20{'InstanceId': 'i-87654321'}]21}222324class TestRegisterInstancesWithLoadBalancer(BaseAWSCommandParamsTest):2526prefix = 'elb register-instances-with-load-balancer'2728def test_one_instance(self):29cmdline = self.prefix30cmdline += ' --load-balancer-name my-lb'31cmdline += ' --instances {"InstanceId":"i-12345678"}'32result = {'LoadBalancerName': 'my-lb',33'Instances': [{'InstanceId': 'i-12345678'}]}34self.assert_params_for_cmd(cmdline, result)3536def test_shorthand(self):37cmdline = self.prefix38cmdline += ' --load-balancer-name my-lb'39cmdline += ' --instances i-12345678'40result = {'LoadBalancerName': 'my-lb',41'Instances': [{'InstanceId': 'i-12345678'}]}42self.assert_params_for_cmd(cmdline, result)4344def test_two_instance(self):45cmdline = self.prefix46cmdline += ' --load-balancer-name my-lb'47cmdline += ' --instances {"InstanceId":"i-12345678"}'48cmdline += ' {"InstanceId":"i-87654321"}'49self.assert_params_for_cmd(cmdline, TWO_INSTANCE_EXPECTED)5051def test_two_instance_as_json(self):52cmdline = self.prefix53cmdline += ' --load-balancer-name my-lb'54cmdline += ' --instances [{"InstanceId":"i-12345678"},'55cmdline += '{"InstanceId":"i-87654321"}]'56self.assert_params_for_cmd(cmdline, TWO_INSTANCE_EXPECTED)5758def test_two_instance_from_file(self):59data_path = os.path.join(os.path.dirname(__file__),60'test.json')61cmdline = self.prefix62cmdline += ' --load-balancer-name my-lb'63cmdline += ' --instances file://%s' % data_path64self.assert_params_for_cmd(cmdline, TWO_INSTANCE_EXPECTED)6566def test_json_file_with_spaces(self):67data_path = os.path.join(os.path.dirname(__file__),68'test_with_spaces.json')69cmdline = self.prefix70cmdline += ' --load-balancer-name my-lb'71cmdline += ' --instances file://%s' % data_path72self.assert_params_for_cmd(cmdline, TWO_INSTANCE_EXPECTED)7374def test_two_instance_shorthand(self):75cmdline = self.prefix76cmdline += ' --load-balancer-name my-lb'77cmdline += ' --instances i-12345678 i-87654321'78self.assert_params_for_cmd(cmdline, TWO_INSTANCE_EXPECTED)7980def test_unpack_event_uses_service_name(self):81cmdline = self.prefix82cmdline += ' --load-balancer-name my-lb'83cmdline += ' --instances {"InstanceId":"i-12345678"}'84handler = TestEventHandler()85event = 'process-cli-arg.elb.register-instances-with-load-balancer'86self.driver.session.register(event, handler.handler)87self.run_cmd(cmdline)88self.assertTrue(handler.called, "Expected event not called.")899091