Example #1
0
 def test_get_ssh_options_private_key_flag_not_added_when_ssh_private_file_string_empty(
         self):
     test_host_vars = {'ansible_ssh_private_key_file': ''}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     self.assertNotIn('-i', result_ssh_options)
 def test_get_ssh_options_private_key_flag_added_when_ssh_private_file_string_not_empty(
         self):
     test_host_vars = {'ansible_ssh_private_key_file': 'test/file.pem'}
     test_ssh_connection_command = SSHConnectionCommand(test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     expected_private_key_option = '-i test/file.pem'
     self.assertIn(expected_private_key_option, result_ssh_options)
Example #3
0
 def test_get_ssh_options_port_flag_with_ansible_cfg_remote_port_is_used(
         self):
     test_host_vars = {'remote_port': '2222'}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     self.assertIn('-p 2222', result_ssh_options)
Example #4
0
 def test_get_ssh_options_private_key_flag_added_with_ansible_cfg_private_key_option(
         self):
     test_host_vars = {'private_key_file': 'test/file.pem'}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     expected_private_key_option = '-i test/file.pem'
     self.assertIn(expected_private_key_option, result_ssh_options)
 def test_get_ssh_options_option_for_no_host_key_checking_when_it_is_selected(
         self):
     test_host_vars = {'ansible_host_key_checking': False}
     test_ssh_connection_command = SSHConnectionCommand(test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     self.assertIn(
         '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no',
         result_ssh_options)
Example #6
0
 def test_get_ssh_options_no_options_for_no_host_key_checking_when_it_is_not_selected(
         self):
     test_host_vars = {}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     self.assertNotIn(
         '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no',
         result_ssh_options)
Example #7
0
 def test_ssh_executable_specified_with_ansible_ssh_executable_option_used(
         self):
     test_host_vars = {'ansible_ssh_executable': '/test/exec'}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     expected_executable = '/test/exec'
     self.assertIn(expected_executable, str(test_ssh_connection_command))
Example #8
0
 def test_user_and_ansible_host_is_used_when_ansible_host_is_defined(self):
     test_host_vars = {
         'ansible_host': 'test_host',
         'ansible_user': '******'
     }
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     self.assertIn('test_user@test_host', str(test_ssh_connection_command))
Example #9
0
 def test_user_and_ansible_host_is_used_with_ansible_cfg_remote_user_option(
         self):
     test_host_vars = {
         'ansible_host': 'test_host',
         'remote_user': '******'
     }
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     self.assertIn('test_user@test_host', str(test_ssh_connection_command))
Example #10
0
 def test_str_sshpass_not_used_when_password_option_not_present(self):
     test_host_vars = {}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     self.assertNotIn('sshpass', str(test_ssh_connection_command))
Example #11
0
 def test_str_sshpass_used_when_password_not_none(self):
     test_host_vars = {'ansible_password': '******'}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     self.assertIn('sshpass -p "testpass"',
                   str(test_ssh_connection_command))
Example #12
0
 def test_get_ssh_options_no_port_flag_when_port_variable_is_not_set(self):
     test_host_vars = {}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     self.assertNotIn('-p 2222', result_ssh_options)
Example #13
0
 def test_inventory_host_name_is_used_when_ansible_host_is_not_defined(
         self):
     test_host_vars = {}
     test_ssh_connection_command = SSHConnectionCommand(
         'test_hostname', test_host_vars)
     self.assertIn('test_hostname', str(test_ssh_connection_command))
 def test_get_ssh_options_port_flag_when_port_variable_is_not_none(self):
     test_host_vars = {'ansible_port': '2222'}
     test_ssh_connection_command = SSHConnectionCommand(test_host_vars)
     result_ssh_options = test_ssh_connection_command._get_ssh_options()
     self.assertIn('-p 2222', result_ssh_options)