Exemple #1
0
    def do_command(self):
        number = self.app.pargs.number
        env_name = self.get_env_name()
        instance = self.app.pargs.instance
        cmd = self.app.pargs.command
        custom_ssh = self.app.pargs.custom
        keep_open = self.app.pargs.keep_open
        force = self.app.pargs.force
        setup = self.app.pargs.setup
        timeout = self.app.pargs.timeout

        if timeout and not setup:
            raise InvalidOptionsError(strings['ssh.timeout_without_setup'])

        sshops.prepare_for_ssh(
                env_name=env_name,
                instance=instance,
                keep_open=keep_open,
                force=force,
                setup=setup,
                number=number,
                custom_ssh=custom_ssh,
                command=cmd,
                timeout=timeout
        )
 def test_prepare_for_ssh__instance_and_number(self):
     with self.assertRaises(sshops.InvalidOptionsError) as context_manager:
         sshops.prepare_for_ssh('my-environment', 'instance', False, False,
                                False, 1)
     self.assertEqual(
         'You cannot use the "--instance" and "--number" options together.',
         str(context_manager.exception))
    def test_prepare_for_ssh__choose_instance_to_ssh_into(
            self, ssh_into_instance_mock, prompt_for_item_in_list_mock,
            get_instance_ids_mock):
        get_instance_ids_mock.return_value = [
            'i-123123123123',
        ]
        prompt_for_item_in_list_mock.return_value = 'i-353454535434'

        sshops.prepare_for_ssh('my-environment', None, False, False, False,
                               None)

        ssh_into_instance_mock.assert_called_once_with('i-123123123123',
                                                       command=None,
                                                       custom_ssh=None,
                                                       force_open=False,
                                                       keep_open=False)
    def test_prepare_for_ssh__ssh_into_instance_fails(
            self, log_error_mock, ssh_into_instance_mock,
            prompt_for_item_in_list_mock, get_instance_ids_mock):
        get_instance_ids_mock.return_value = [
            'i-123123123123',
            'i-234234234424',
            'i-353454535434',
        ]
        prompt_for_item_in_list_mock.return_value = 'i-353454535434'
        ssh_into_instance_mock.side_effect = sshops.NoKeypairError

        sshops.prepare_for_ssh('my-environment', None, False, False, False, 2)

        ssh_into_instance_mock.assert_called_once_with('i-234234234424',
                                                       command=None,
                                                       custom_ssh=None,
                                                       force_open=False,
                                                       keep_open=False)
        log_error_mock.assert_called_once_with(
            'This environment is not set up for SSH. Use "eb ssh --setup" to set up SSH for the environment.'
        )
 def test_prepare_for_ssh(self, setup_ssh_mock):
     sshops.prepare_for_ssh('my-environment', 'instance', False, False,
                            True, None)
     setup_ssh_mock.assert_called_once_with('my-environment',
                                            None,
                                            timeout=None)