Path: blob/develop/tests/unit/customizations/emr/test_install_applications.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.121314import json1516from awscli.testutils import mock17from tests.unit.customizations.emr import EMRBaseAWSCommandParamsTest as \18BaseAWSCommandParamsTest192021INSTALL_HIVE_STEP = {22'HadoopJarStep': {23'Args': ['s3://us-east-1.elasticmapreduce/libs/hive/hive-script',24'--install-hive', '--base-path',25's3://us-east-1.elasticmapreduce/libs/hive',26'--hive-versions', 'latest'],27'Jar':28('s3://us-east-1.elasticmapreduce/libs/'29'script-runner/script-runner.jar')30},31'Name': 'Install Hive',32'ActionOnFailure': 'TERMINATE_CLUSTER'33}3435INSTALL_HIVE_SITE_STEP = {36'HadoopJarStep': {37'Args': ['s3://us-east-1.elasticmapreduce/libs/hive/hive-script',38'--base-path',39's3://us-east-1.elasticmapreduce/libs/hive',40'--install-hive-site',41'--hive-site=s3://test/hive-conf/hive-site.xml',42'--hive-versions', 'latest'],43'Jar':44('s3://us-east-1.elasticmapreduce/libs/'45'script-runner/script-runner.jar')46},47'Name': 'Install Hive Site Configuration',48'ActionOnFailure': 'CANCEL_AND_WAIT'49}5051INSTALL_PIG_STEP = {52'HadoopJarStep': {53'Args': ['s3://us-east-1.elasticmapreduce/libs/pig/pig-script',54'--install-pig', '--base-path',55's3://us-east-1.elasticmapreduce/libs/pig',56'--pig-versions', 'latest'],57'Jar':58('s3://us-east-1.elasticmapreduce/libs/'59'script-runner/script-runner.jar')60},61'Name': 'Install Pig',62'ActionOnFailure': 'TERMINATE_CLUSTER'63}646566class TestInstallApplications(BaseAWSCommandParamsTest):67prefix = ('emr install-applications --cluster-id '68'j-ABC123456 --applications ')6970def test_install_hive_site(self):71cmdline = (self.prefix + 'Name=Hive,'72'Args=[--hive-site=s3://test/hive-conf/hive-site.xml]')73result = {'JobFlowId': 'j-ABC123456',74'Steps': [INSTALL_HIVE_STEP, INSTALL_HIVE_SITE_STEP]75}76self.assert_params_for_cmd(cmdline, result)77cmdline = (self.prefix + 'Name=Hive,'78'Args=[--hive-site=s3://test/hive-conf/hive-site.xml,k1]')79self.assert_params_for_cmd(cmdline, result)8081def test_install_hive_and_pig(self):82cmdline = self.prefix + 'Name=Hive Name=Pig'83result = {'JobFlowId': 'j-ABC123456', 'Steps': [INSTALL_HIVE_STEP,84INSTALL_PIG_STEP]}85self.assert_params_for_cmd(cmdline, result)8687def test_install_pig_with_profile_region(self):88self.driver.session.set_config_variable('region', 'cn-north-1')89cmdline = self.prefix + 'Name=Pig'90PIG_STEP = json.dumps(INSTALL_PIG_STEP).\91replace('us-east-1', 'cn-north-1')92result = {'JobFlowId': 'j-ABC123456',93'Steps': [json.loads(PIG_STEP)]}94self.assert_params_for_cmd(cmdline, result)9596def test_install_impala_error(self):97cmdline = self.prefix + ' Name=Impala'9899expected_error_msg = "\naws: error: Impala cannot be installed on" +\100" a running cluster. 'Name' should be one of the following:" +\101" HIVE, PIG\n"102result = self.run_cmd(cmdline, 255)103self.assertEqual(result[1], expected_error_msg)104105def test_install_unknown_app_error(self):106cmdline = self.prefix + 'Name=unknown'107108expected_error_msg = "\naws: error: Unknown application: unknown." +\109" 'Name' should be one of the following: HIVE, PIG, HBASE," +\110" GANGLIA, IMPALA, SPARK, MAPR, MAPR_M3, MAPR_M5, MAPR_M7\n"111result = self.run_cmd(cmdline, 255)112self.assertEqual(result[1], expected_error_msg)113114@mock.patch('awscli.customizations.emr.'115'emrutils.get_release_label')116def test_unsupported_command_on_release_based_cluster_error(117self, grl_patch):118grl_patch.return_value = 'emr-4.0'119cmdline = (self.prefix + 'Name=Hive,'120'Args=[--hive-site=s3://test/hive-conf/hive-site.xml]')121122expected_error_msg = ("\naws: error: install-applications"123" is not supported with 'emr-4.0' release.\n")124result = self.run_cmd(cmdline, 255)125self.assertEqual(result[1], expected_error_msg)126127if __name__ == "__main__":128unittest.main()129130131