def test_direct_transport_call_raises_when_closed(mocker):
    mock = mock_direct(mocker)

    transport = DirectTransport()
    transport.close()

    with pytest.raises(TransportClosedException):
        tk = iToolKit()
        out = transport.call(tk)
def test_direct_transport(mocker):
    mock = mock_direct(mocker)

    transport = DirectTransport()
    tk = iToolKit()
    out = transport.call(tk)

    assert_xmlservice_params_correct(mock)
    assert isinstance(out, (bytes, str))
def test_direct_transport_unsupported(mocker):
    "Test that we get an error running on an unsupported platform"

    mock_direct = mocker.patch('itoolkit.transport.direct._direct',
                               create=True)
    mock_direct.xmlservice = mocker.Mock(side_effect=NameError)

    transport = DirectTransport()
    tk = iToolKit()
    with pytest.raises(RuntimeError):
        transport.call(tk)
예제 #4
0
def itoolkit_run_command(command):
    conn = dbi.connect()
    itransport = DirectTransport()
    itool = iToolKit()
    itool.add(iCmd('command', command, {'error': 'on'}))
    itool.call(itransport)

    rc = IBMi_COMMAND_RC_UNEXPECTED
    out = ''
    err = ''

    command_output = itool.dict_out('command')
    if 'success' in command_output:
        rc = IBMi_COMMAND_RC_SUCCESS
        out = command_output['success']

    elif 'error' in command_output:
        command_error = command_output['error']
        if 'joblog' in command_error:
            rc = IBMi_COMMAND_RC_ERROR
            err = command_error['joblog']
        else:
            # should not be here, must xmlservice has internal error
            rc = IBMi_COMMAND_RC_ITOOLKIT_NO_KEY_JOBLOG
            err = "iToolKit result dict does not have key 'joblog', the output \
                  is %s" % command_output
    else:
        # should not be here, must xmlservice has internal error
        rc = IBMi_COMMAND_RC_ITOOLKIT_NO_KEY_ERROR
        err = "iToolKit result dict does not have key 'error', the output is \
              %s" % command_output

    return rc, out, err
예제 #5
0
def run_cl_command(job_number, job_user, job_name):
    itool = iToolKit()
    itool.add(iCmd('test', 'CRTLIB wytest'))
    # itransport = DatabaseTransport(conn)
    itransport = DirectTransport()
    itool.call(itransport)

    # output
    rtvjoba = itool.dict_out('rtvjoba')
    print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    print(rtvjoba)
    if 'error' in rtvjoba:
        print(rtvjoba['error'])
        exit()
    elif 'row' in rtvjoba:
        rtvjoba_vals = rtvjoba['row']

        for item_dict in rtvjoba_vals:
            for key in item_dict:
                print(item_dict[key])

        print('hahahahahahhahahahahhaah')

        # print('value:' + rtvjoba)
        # print('USRLIBL = ' + rtvjoba_vals['USRLIBL'])
        # print('SYSLIBL = ' + rtvjoba_vals['SYSLIBL'])
        # print('CCSID   = ' + rtvjoba_vals['CCSID'])
        # print('OUTQ    = ' + rtvjoba_vals['OUTQ'])
    else:
        print('ERRORRRRRRRRRRRRRRRRRRR')
    print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
예제 #6
0
def itoolkit_run_command(command, asp_group):
    conn = dbi.connect()
    itransport = DatabaseTransport(conn)
    itool = iToolKit()
    if asp_group != '':
        itransport = DirectTransport()
        itool.add(
            iCmd(
                'command', "SETASPGRP ASPGRP({asp_group_pattern})".format(
                    asp_group_pattern=asp_group), {'error': 'on'}))
    itool.add(iCmd('command', command, {'error': 'on'}))
    itool.call(itransport)

    out = ''
    err = ''

    if asp_group != '' and isinstance(
            itool.dict_out('command'),
            list) and len(itool.dict_out('command')) > 1:
        command_output = itool.dict_out('command')[1]
    else:
        command_output = itool.dict_out('command')

    command_output = itool.dict_out('command')
    if 'success' in command_output:
        rc = IBMi_COMMAND_RC_SUCCESS
        out = command_output['success']

    elif 'error' in command_output:
        command_error = command_output['error']
        if 'joblog' in command_error:
            rc = IBMi_COMMAND_RC_ERROR
            err = command_error['joblog']
        else:
            # should not be here, must xmlservice has internal error
            rc = IBMi_COMMAND_RC_ITOOLKIT_NO_KEY_JOBLOG
            err = "iToolKit result dict does not have key 'joblog', the output \
                  is %s" % command_output
    else:
        # should not be here, must xmlservice has internal error
        rc = IBMi_COMMAND_RC_ITOOLKIT_NO_KEY_ERROR
        err = "iToolKit result dict does not have key 'error', the output is \
              %s" % command_output

    return rc, out, err
print("********************")
print("Hey user,")
print("Using '*debug' transport parameter allows debug halt before run.")
print("\n  itransport = DirectTransport('*here *debug')\n")
print("Expect qsysopr inquire message, you must answer to continue script.")
print("You may attach a debugger before you answer the inquiry.")
print("\n  dspmsg qsysopr\n")
print("  Reply inquiry message any character.")
print("    From  . . . :   ADC            06/25/15   14:08:07")
print("    Debug client 362262/QSECOFR/QP0ZSPWP")
print("      Reply . . :   c\n")
print("Script continues to run after answer (call PGM, etc.)")
print("********************")
print("********************")

itransport = DirectTransport(
    "*here *debug")  # i will stop, inquiry message qsysopr
itool = iToolKit()
itool.add(iCmd('chglibl', 'CHGLIBL LIBL(XMLSERVICE)'))
itool.add(
    iPgm('zzcall', 'ZZCALL').addParm(iData('INCHARA', '1a', 'a')).addParm(
        iData('INCHARB', '1a', 'b')).addParm(iData(
            'INDEC1', '7p4',
            '32.1234')).addParm(iData('INDEC2', '12p2', '33.33')).addParm(
                iDS('INDS1').addData(iData('DSCHARA', '1a', 'a')).addData(
                    iData('DSCHARB', '1a', 'b')).addData(
                        iData('DSDEC1', '7p4', '32.1234')).addData(
                            iData('DSDEC2', '12p2', '33.33'))))

# xmlservice
itool.call(itransport)