Path: blob/develop/tests/unit/customizations/emr/test_sshutils.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 awscli.customizations.emr import sshutils14from awscli.customizations.emr import exceptions15from awscli.testutils import mock, unittest161718class TestSSHUtils(unittest.TestCase):1920@mock.patch('awscli.customizations.emr.sshutils.emrutils')21def test_validate_and_find_master_dns_waits(self, emrutils):22emrutils.get_cluster_state.return_value = 'STARTING'23session = mock.Mock()24client = mock.Mock()25emrutils.get_client.return_value = client2627sshutils.validate_and_find_master_dns(session, None, 'cluster-id')2829# We should have:30# 1. Waiter for the cluster to be running.31client.get_waiter.assert_called_with('cluster_running')32client.get_waiter.return_value.wait.assert_called_with(33ClusterId='cluster-id')3435# 2. Found the master public DNS36self.assertTrue(emrutils.find_master_dns.called)3738@mock.patch('awscli.customizations.emr.sshutils.emrutils')39def test_cluster_in_terminated_states(self, emrutils):40emrutils.get_cluster_state.return_value = 'TERMINATED'41with self.assertRaises(exceptions.ClusterTerminatedError):42sshutils.validate_and_find_master_dns(43mock.Mock(), None, 'cluster-id')4445@mock.patch('awscli.customizations.emr.sshutils.emrutils')46def test_ssh_scp_key_file_format(self, emrutils):47def which_side_effect(program):48if program == 'ssh' or program == 'scp':49return '/some/path'50emrutils.which.side_effect = which_side_effect5152key_file1 = 'key.abc'53sshutils.validate_ssh_with_key_file(key_file1)54sshutils.validate_scp_with_key_file(key_file1)5556key_file2 = 'key'57sshutils.validate_ssh_with_key_file(key_file2)58sshutils.validate_scp_with_key_file(key_file2)596061