示例#1
0
    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'),
        ])
示例#2
0
    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()
示例#3
0
    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()
示例#4
0
 def test_remote_ssh_wake_action_command_not_list(self):
     with self.assertRaisesConfigError(
             'remoteCommand parameter must be a list'):
         RemoteSshWakeAction('host', 'cmd')
示例#5
0
 def test_remote_ssh_wake_action_host_not_str(self):
     with self.assertRaisesConfigError('host parameter must be a string'):
         RemoteSshWakeAction(123, ['cmd'])
示例#6
0
 def test_remote_ssh_wake_action_sshBin_not_str(self):
     with self.assertRaisesConfigError('sshBin parameter must be a string'):
         RemoteSshWakeAction('host', ['cmd'], sshBin=123)