def test_remote_ssh_wake_action_no_keys(self, write_local_file_mock, temp_dir_mock): self.expectCommands( gpo.Expect('ssh', 'remote_host', 'remotebin', 'arg1').exit(1), gpo.Expect('ssh', 'remote_host', 'remotebin', 'arg1').exit(0), ) manager = FakeManager() action = RemoteSshWakeAction('remote_host', ['remotebin', 'arg1']) self.assertFalse((yield action.perform(manager))) self.assertTrue((yield action.perform(manager))) self.assertAllCommandsRan() self.assertEqual(temp_dir_mock.dirs, []) write_local_file_mock.assert_not_called()
def test_remote_ssh_wake_action_with_keys(self, write_local_file_mock, temp_dir_mock): temp_dir_path = os.path.join('path-to-master', 'ssh-@@@') ssh_key_path = os.path.join(temp_dir_path, 'ssh-key') ssh_known_hosts_path = os.path.join(temp_dir_path, 'ssh-known-hosts') self.expectCommands( gpo.Expect('ssh', '-o', 'BatchMode=yes', '-i', ssh_key_path, '-o', 'UserKnownHostsFile={0}'.format(ssh_known_hosts_path), 'remote_host', 'remotebin', 'arg1').exit(0), ) manager = FakeManager('path-to-master') action = RemoteSshWakeAction('remote_host', ['remotebin', 'arg1'], sshKey='ssh_key', sshHostKey='ssh_host_key') self.assertTrue((yield action.perform(manager))) self.assertAllCommandsRan() self.assertEqual(temp_dir_mock.dirs, [(temp_dir_path, 0o700)]) self.assertSequenceEqual(write_local_file_mock.call_args_list, [ mock.call(ssh_key_path, 'ssh_key', mode=0o400), mock.call(ssh_known_hosts_path, '* ssh_host_key'), ])
def test_remote_ssh_wake_action_no_keys(self, write_local_file_mock, temp_dir_mock): self.expect_commands( ExpectMasterShell(['ssh', '-o', 'BatchMode=yes', 'remote_host', 'remotebin', 'arg1']) .exit(1), ExpectMasterShell(['ssh', '-o', 'BatchMode=yes', 'remote_host', 'remotebin', 'arg1']) .exit(0), ) manager = FakeManager(self.reactor) action = RemoteSshWakeAction('remote_host', ['remotebin', 'arg1']) self.assertFalse((yield action.perform(manager))) self.assertTrue((yield action.perform(manager))) self.assert_all_commands_ran() self.assertEqual(temp_dir_mock.dirs, []) write_local_file_mock.assert_not_called()