Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/emr/test_install_applications.py
1569 views
1
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
15
import json
16
17
from awscli.testutils import mock
18
from tests.unit.customizations.emr import EMRBaseAWSCommandParamsTest as \
19
BaseAWSCommandParamsTest
20
21
22
INSTALL_HIVE_STEP = {
23
'HadoopJarStep': {
24
'Args': ['s3://us-east-1.elasticmapreduce/libs/hive/hive-script',
25
'--install-hive', '--base-path',
26
's3://us-east-1.elasticmapreduce/libs/hive',
27
'--hive-versions', 'latest'],
28
'Jar':
29
('s3://us-east-1.elasticmapreduce/libs/'
30
'script-runner/script-runner.jar')
31
},
32
'Name': 'Install Hive',
33
'ActionOnFailure': 'TERMINATE_CLUSTER'
34
}
35
36
INSTALL_HIVE_SITE_STEP = {
37
'HadoopJarStep': {
38
'Args': ['s3://us-east-1.elasticmapreduce/libs/hive/hive-script',
39
'--base-path',
40
's3://us-east-1.elasticmapreduce/libs/hive',
41
'--install-hive-site',
42
'--hive-site=s3://test/hive-conf/hive-site.xml',
43
'--hive-versions', 'latest'],
44
'Jar':
45
('s3://us-east-1.elasticmapreduce/libs/'
46
'script-runner/script-runner.jar')
47
},
48
'Name': 'Install Hive Site Configuration',
49
'ActionOnFailure': 'CANCEL_AND_WAIT'
50
}
51
52
INSTALL_PIG_STEP = {
53
'HadoopJarStep': {
54
'Args': ['s3://us-east-1.elasticmapreduce/libs/pig/pig-script',
55
'--install-pig', '--base-path',
56
's3://us-east-1.elasticmapreduce/libs/pig',
57
'--pig-versions', 'latest'],
58
'Jar':
59
('s3://us-east-1.elasticmapreduce/libs/'
60
'script-runner/script-runner.jar')
61
},
62
'Name': 'Install Pig',
63
'ActionOnFailure': 'TERMINATE_CLUSTER'
64
}
65
66
67
class TestInstallApplications(BaseAWSCommandParamsTest):
68
prefix = ('emr install-applications --cluster-id '
69
'j-ABC123456 --applications ')
70
71
def test_install_hive_site(self):
72
cmdline = (self.prefix + 'Name=Hive,'
73
'Args=[--hive-site=s3://test/hive-conf/hive-site.xml]')
74
result = {'JobFlowId': 'j-ABC123456',
75
'Steps': [INSTALL_HIVE_STEP, INSTALL_HIVE_SITE_STEP]
76
}
77
self.assert_params_for_cmd(cmdline, result)
78
cmdline = (self.prefix + 'Name=Hive,'
79
'Args=[--hive-site=s3://test/hive-conf/hive-site.xml,k1]')
80
self.assert_params_for_cmd(cmdline, result)
81
82
def test_install_hive_and_pig(self):
83
cmdline = self.prefix + 'Name=Hive Name=Pig'
84
result = {'JobFlowId': 'j-ABC123456', 'Steps': [INSTALL_HIVE_STEP,
85
INSTALL_PIG_STEP]}
86
self.assert_params_for_cmd(cmdline, result)
87
88
def test_install_pig_with_profile_region(self):
89
self.driver.session.set_config_variable('region', 'cn-north-1')
90
cmdline = self.prefix + 'Name=Pig'
91
PIG_STEP = json.dumps(INSTALL_PIG_STEP).\
92
replace('us-east-1', 'cn-north-1')
93
result = {'JobFlowId': 'j-ABC123456',
94
'Steps': [json.loads(PIG_STEP)]}
95
self.assert_params_for_cmd(cmdline, result)
96
97
def test_install_impala_error(self):
98
cmdline = self.prefix + ' Name=Impala'
99
100
expected_error_msg = "\naws: error: Impala cannot be installed on" +\
101
" a running cluster. 'Name' should be one of the following:" +\
102
" HIVE, PIG\n"
103
result = self.run_cmd(cmdline, 255)
104
self.assertEqual(result[1], expected_error_msg)
105
106
def test_install_unknown_app_error(self):
107
cmdline = self.prefix + 'Name=unknown'
108
109
expected_error_msg = "\naws: error: Unknown application: unknown." +\
110
" 'Name' should be one of the following: HIVE, PIG, HBASE," +\
111
" GANGLIA, IMPALA, SPARK, MAPR, MAPR_M3, MAPR_M5, MAPR_M7\n"
112
result = self.run_cmd(cmdline, 255)
113
self.assertEqual(result[1], expected_error_msg)
114
115
@mock.patch('awscli.customizations.emr.'
116
'emrutils.get_release_label')
117
def test_unsupported_command_on_release_based_cluster_error(
118
self, grl_patch):
119
grl_patch.return_value = 'emr-4.0'
120
cmdline = (self.prefix + 'Name=Hive,'
121
'Args=[--hive-site=s3://test/hive-conf/hive-site.xml]')
122
123
expected_error_msg = ("\naws: error: install-applications"
124
" is not supported with 'emr-4.0' release.\n")
125
result = self.run_cmd(cmdline, 255)
126
self.assertEqual(result[1], expected_error_msg)
127
128
if __name__ == "__main__":
129
unittest.main()
130
131