def test_ssh_modify_command(self, connect_mock):
     set_module_args({
         'clustername': 'clustername',
         'username': '******',
         'password': '******',
         'command': 'svcinfo lsuser',
     })
     conn = IBMSVCsshClient()
     new_command = conn.modify_command("svcinfo lsuser user1")
     self.assertEqual(new_command, "svcinfo lsuser -json user1")
 def test_ssh_disconnect(self, connect_mock, disconnect_mock):
     set_module_args({
         'clustername': 'clustername',
         'username': '******',
         'password': '******',
         'command': 'svcinfo lsuser',
     })
     conn = IBMSVCsshClient()
     conn.is_client_connected = True
     conn.ssh_client._svc_disconnect()
     self.assertTrue(conn.ssh_client.is_client_connected)
    def test_ssh_connect_with_password(self, connect_mock):
        set_module_args({
            'clustername': 'clustername',
            'username': '******',
            'password': '******',
            'command': 'svcinfo cli_command',
        })
        if paramiko is None:
            print("paramiko is not installed")

        patch.object(paramiko.SSHClient, 'exec_command')
        conn = IBMSVCsshClient()
        with pytest.raises(Exception) as exc:
            conn.send_svcinfo_command()
        print('Info: %s' % exc.value.args[0])
        self.assertTrue(conn.ssh_client.is_client_connected)
 def test_ssh_connect_with_missing_password(self):
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({
             'clustername': 'clustername',
             'username': '******',
             'command': 'svcinfo lsuser',
         })
         IBMSVCsshClient()
         print('Info: %s' % exc.value.args[0]['msg'])
         self.assertFalse(exc.value.args[0]['changed'])