Path: blob/develop/tests/unit/customizations/emr/test_modify_cluster_attributes.py
1569 views
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.1213from tests.unit.customizations.emr import EMRBaseAWSCommandParamsTest as \14BaseAWSCommandParamsTest151617class TestModifyClusterAttributes(BaseAWSCommandParamsTest):18prefix = 'emr modify-cluster-attributes'1920def test_visible_to_all(self):21args = ' --cluster-id j-ABC123456 --visible-to-all-users'22cmdline = self.prefix + args23result = {'JobFlowIds': ['j-ABC123456'], 'VisibleToAllUsers': True}24self.assert_params_for_cmd(cmdline, result)2526def test_no_visible_to_all(self):27args = ' --cluster-id j-ABC123456 --no-visible-to-all-users'28cmdline = self.prefix + args29result = {'JobFlowIds': ['j-ABC123456'], 'VisibleToAllUsers': False}30self.assert_params_for_cmd(cmdline, result)3132def test_termination_protected(self):33args = ' --cluster-id j-ABC123456 --termination-protected'34cmdline = self.prefix + args35result = {'JobFlowIds': ['j-ABC123456'], 'TerminationProtected': True}36self.assert_params_for_cmd(cmdline, result)3738def test_no_termination_protected(self):39args = ' --cluster-id j-ABC123456 --no-termination-protected'40cmdline = self.prefix + args41result = {'JobFlowIds': ['j-ABC123456'], 'TerminationProtected': False}42self.assert_params_for_cmd(cmdline, result)4344def test_no_auto_terminate(self):45args = ' --cluster-id j-ABC123456 --no-auto-terminate'46cmdline = self.prefix + args47result = {'JobFlowIds': ['j-ABC123456'], 'KeepJobFlowAliveWhenNoSteps': True}48self.assert_params_for_cmd(cmdline, result)4950def test_auto_terminate(self):51args = ' --cluster-id j-ABC123456 --auto-terminate'52cmdline = self.prefix + args53result = {'JobFlowIds': ['j-ABC123456'], 'KeepJobFlowAliveWhenNoSteps': False}5455def test_unhealthy_node_replacement(self):56args = ' --cluster-id j-ABC123456 --unhealthy-node-replacement'57cmdline = self.prefix + args58result = {'JobFlowIds': ['j-ABC123456'], 'UnhealthyNodeReplacement': True}59self.assert_params_for_cmd(cmdline, result)6061def test_no_unhealthy_node_replacement(self):62args = ' --cluster-id j-ABC123456 --no-unhealthy-node-replacement'63cmdline = self.prefix + args64result = {'JobFlowIds': ['j-ABC123456'], 'UnhealthyNodeReplacement': False}65self.assert_params_for_cmd(cmdline, result)6667def test_visible_to_all_and_no_visible_to_all(self):68args = ' --cluster-id j-ABC123456 --no-visible-to-all-users'\69' --visible-to-all-users'70cmdline = self.prefix + args71expected_error_msg = (72'\naws: error: You cannot specify both --visible-to-all-users '73'and --no-visible-to-all-users options together.\n')74result = self.run_cmd(cmdline, 255)75self.assertEqual(expected_error_msg, result[1])7677def test_temination_protected_and_no_termination_protected(self):78args = ' --cluster-id j-ABC123456 --no-termination-protected'\79' --termination-protected'80cmdline = self.prefix + args81expected_error_msg = (82'\naws: error: You cannot specify both --termination-protected '83'and --no-termination-protected options together.\n')84result = self.run_cmd(cmdline, 255)85self.assertEqual(expected_error_msg, result[1])8687def test_auto_terminate_and_no_auto_terminate(self):88args = ' --cluster-id j-ABC123456 --auto-terminate'\89' --no-auto-terminate'90cmdline = self.prefix + args91expected_error_msg = (92'\naws: error: You cannot specify both --auto-terminate '93'and --no-auto-terminate options together.\n')94result = self.run_cmd(cmdline, 255)95self.assertEqual(expected_error_msg, result[1])9697def test_can_set_multiple_attributes(self):98args = ' --cluster-id j-ABC123456 --termination-protected'\99' --visible-to-all-users --unhealthy-node-replacement'100cmdline = self.prefix + args101result_set_termination_protection = {102'JobFlowIds': ['j-ABC123456'], 'TerminationProtected': True}103result_set_visible_to_all_users = {104'JobFlowIds': ['j-ABC123456'], 'VisibleToAllUsers': True}105result_set_unhealty_node_replacement = {106'JobFlowIds': ['j-ABC123456'], 'UnhealthyNodeReplacement': True}107self.run_cmd(cmdline)108self.assertDictEqual(109self.operations_called[0][1], result_set_visible_to_all_users)110self.assertDictEqual(111self.operations_called[1][1], result_set_termination_protection)112self.assertDictEqual(113self.operations_called[2][1], result_set_unhealty_node_replacement)114115def test_can_set_multiple_attributes_with_no(self):116args = ' --cluster-id j-ABC123456 --termination-protected'\117' --no-visible-to-all-users --unhealthy-node-replacement'118cmdline = self.prefix + args119result_set_termination_protection = {120'JobFlowIds': ['j-ABC123456'], 'TerminationProtected': True}121result_set_visible_to_all_users = {122'JobFlowIds': ['j-ABC123456'], 'VisibleToAllUsers': False}123result_set_unhealty_node_replacement = {124'JobFlowIds': ['j-ABC123456'], 'UnhealthyNodeReplacement': True}125self.run_cmd(cmdline)126self.assertDictEqual(127self.operations_called[0][1], result_set_visible_to_all_users)128self.assertDictEqual(129self.operations_called[1][1], result_set_termination_protection)130self.assertDictEqual(131self.operations_called[2][1], result_set_unhealty_node_replacement)132133def test_at_least_one_option(self):134args = ' --cluster-id j-ABC123456'135cmdline = self.prefix + args136expected_error_msg = (137'\naws: error: Must specify one of the following boolean options: '138'--visible-to-all-users|--no-visible-to-all-users, '139'--termination-protected|--no-termination-protected, '140'--auto-terminate|--no-auto-terminate, '141'--unhealthy-node-replacement|--no-unhealthy-node-replacement.\n')142result = self.run_cmd(cmdline, 255)143self.assertEqual(expected_error_msg, result[1])144145if __name__ == "__main__":146unittest.main()147148149