Path: blob/develop/tests/unit/customizations/emr/test_schedule_hbase_backup.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.12from awscli.testutils import mock1314from tests.unit.customizations.emr import EMRBaseAWSCommandParamsTest as \15BaseAWSCommandParamsTest16from copy import deepcopy171819class TestScheduleHBaseBackup(BaseAWSCommandParamsTest):20prefix = 'emr schedule-hbase-backup'21default_steps = [{22'HadoopJarStep': {23'Args': [24'emr.hbase.backup.Main',25'--set-scheduled-backup',26'true',27'--backup-dir',28's3://abc/',29'--full-backup-time-interval',30'10',31'--full-backup-time-unit',32'minutes',33'--start-time',34'now'35],36'Jar': '/home/hadoop/lib/hbase.jar'37},38'Name': 'Modify Backup Schedule',39'ActionOnFailure': 'CANCEL_AND_WAIT'40}]4142def test_schedule_hbase_backup_full(self):43args = ' --cluster-id j-ABCD --dir s3://abc/ --type full' +\44' --interval 10 --unit minutes'45cmdline = self.prefix + args46result = {'JobFlowId': 'j-ABCD', 'Steps': self.default_steps}4748self.assert_params_for_cmd(cmdline, result)4950def test_schedule_hbase_backup_full_upper_case(self):51args = ' --cluster-id j-ABCD --dir s3://abc/ --type FULL' +\52' --interval 10 --unit minutes'53cmdline = self.prefix + args54result = {'JobFlowId': 'j-ABCD', 'Steps': self.default_steps}5556self.assert_params_for_cmd(cmdline, result)5758def test_schedule_hbase_backup_incremental_upper_case(self):59args = ' --cluster-id j-ABCD --dir s3://abc/ --type INCREMENTAL' +\60' --interval 10 --unit HOURS'61cmdline = self.prefix + args6263steps = deepcopy(self.default_steps)64args = steps[0]['HadoopJarStep']['Args']65args[5] = '--incremental-backup-time-interval'66args[7] = '--incremental-backup-time-unit'67args[8] = 'hours'68steps[0]['HadoopJarStep']['Args'] = args69result = {'JobFlowId': 'j-ABCD', 'Steps': steps}7071self.assert_params_for_cmd(cmdline, result)7273def test_schedule_hbase_backup_incremental(self):74args = ' --cluster-id j-ABCD --dir s3://abc/ --type incremental' +\75' --interval 10 --unit minutes'76cmdline = self.prefix + args7778steps = deepcopy(self.default_steps)79args = steps[0]['HadoopJarStep']['Args']80args[5] = '--incremental-backup-time-interval'81args[7] = '--incremental-backup-time-unit'82steps[0]['HadoopJarStep']['Args'] = args8384result = {'JobFlowId': 'j-ABCD', 'Steps': steps}8586self.assert_params_for_cmd(cmdline, result)8788def test_schedule_hbase_backup_wrong_type(self):89args = ' --cluster-id j-ABCD --dir s3://abc/ --type wrong_type' +\90' --interval 10 --unit minutes'91cmdline = self.prefix + args92expected_error_msg = '\naws: error: invalid type. type should be' +\93' either full or incremental.\n'94result = self.run_cmd(cmdline, 255)9596self.assertEqual(expected_error_msg, result[1])9798def test_schedule_hbase_backup_wrong_unit(self):99args = ' --cluster-id j-ABCD --dir s3://abc/ --type full' +\100' --interval 10 --unit wrong_unit'101cmdline = self.prefix + args102expected_error_msg = '\naws: error: invalid unit. unit should be' +\103' one of the following values: minutes,' +\104' hours or days.\n'105result = self.run_cmd(cmdline, 255)106107self.assertEqual(expected_error_msg, result[1])108109def test_schedule_hbase_backup_consistent(self):110args = ' --cluster-id j-ABCD --dir s3://abc/ --type full' +\111' --interval 10 --unit minutes --consistent'112cmdline = self.prefix + args113114steps = deepcopy(self.default_steps)115steps[0]['HadoopJarStep']['Args'].insert(5, '--consistent')116117result = {'JobFlowId': 'j-ABCD', 'Steps': steps}118self.assert_params_for_cmd(cmdline, result)119120def test_schedule_hbase_backup_start_time(self):121args = ' --cluster-id j-ABCD --dir s3://abc/ --type full --interval' +\122' 10 --unit minutes --start-time 2014-04-18T10:43:24-07:00'123cmdline = self.prefix + args124125steps = deepcopy(self.default_steps)126steps[0]['HadoopJarStep']['Args'][10] = '2014-04-18T10:43:24-07:00'127128result = {'JobFlowId': 'j-ABCD', 'Steps': steps}129self.assert_params_for_cmd(cmdline, result)130131@mock.patch('awscli.customizations.emr.'132'emrutils.get_release_label')133def test_unsupported_command_on_release_based_cluster_error(134self, grl_patch):135grl_patch.return_value = 'emr-4.0'136args = ' --cluster-id j-ABCD --dir s3://abc/ --type full' +\137' --interval 10 --unit minutes'138cmdline = self.prefix + args139expected_error_msg = ("\naws: error: schedule-hbase-backup"140" is not supported with 'emr-4.0' release.\n")141result = self.run_cmd(cmdline, 255)142143self.assertEqual(result[1], expected_error_msg)144145146if __name__ == "__main__":147unittest.main()148149150