示例#1
0
 def itoolkit_run_rtv_command(self, command, args_dict):
     '''IBM i XMLSERVICE call *CMD with REXX'''
     itool = iToolKit(iparm=0, iret=0, ids=1, irow=0)
     itransport = DatabaseTransport(self.conn)
     args = ' '
     for (k, v) in args_dict.items():
         parm = '(?) '
         if v == 'number':
             parm = '(?N) '
         args = args + k + parm
     itool.add(iCmd('rtv_command', command + args))
     itool.call(itransport)
     rtv_command = itool.dict_out('rtv_command')
     ibmi_util.log_debug("rtv_command " + str(rtv_command), sys._getframe().f_code.co_name)
     if 'error' in rtv_command:
         rc = ibmi_util.IBMi_COMMAND_RC_ERROR
         out_dict = dict()
         error = str(rtv_command)
     else:
         # remove the key 'success' and its value, just left the result
         del rtv_command['success']
         rc = ibmi_util.IBMi_COMMAND_RC_SUCCESS
         out_dict = rtv_command
         error = ''
     return rc, out_dict, error
示例#2
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
示例#3
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('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
示例#4
0
def itoolkit_rum_command(conn, command):
    try:
        itransport = DatabaseTransport(conn)
        itool = iToolKit()
        itool.add(iCmd('command', command, {'error': 'on'}))
        itool.call(itransport)
        rc = ''
        out = ''
        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
            else:
                # should not be here, must xmlservice has internal error
                rc = IBMi_COMMAND_RC_ITOOLKIT_NO_KEY_JOBLOG
        else:
            # should not be here, must xmlservice has internal error
            rc = IBMi_COMMAND_RC_ITOOLKIT_NO_KEY_ERROR
    except Exception as e_disconnect:
        raise Exception(e_disconnect)
    return rc, interpret_return_code(rc), out
def test_cmd_error(transport):
    """Test calling a CL command with an invalid parameter returns an error"""

    transport.set_out(
        """<?xml version="1.0" ?><xmlservice><cmd error="fast" exec="cmd" var="cmderror"><error>*** error CHGLIBL LIBL(FROGLEGLONG)</error>
<error>202</error>
<version>XML Toolkit 1.9.9</version>
<error>
<status>202</status>
<errnoxml>1100012</errnoxml>
<xmlerrmsg>XML run cmd failed</xmlerrmsg>
<xmlhint>CHGLIBL LIBL(FROGLEGLONG)</xmlhint>
</error>
<error>
<status>202</status>
<errnoxml>1100012</errnoxml>
<xmlerrmsg>XML run cmd failed</xmlerrmsg>
<xmlhint>CHGLIBL LIBL(FROGLEGLONG)</xmlhint>
</error>
<jobinfo>
<jobipc>*na</jobipc>
<jobipcskey>FFFFFFFF</jobipcskey>
<jobname>QSQSRVR</jobname>
<jobuser>QUSER</jobuser>
<jobnbr>774740</jobnbr>
<jobsts>*ACTIVE</jobsts>
<curuser>KADLER</curuser>
<ccsid>37</ccsid>
<dftccsid>37</dftccsid>
<paseccsid>0</paseccsid>
<langid>ENU</langid>
<cntryid>US</cntryid>
<sbsname>QSYSWRK</sbsname>
<sbslib>QSYS</sbslib>
<curlib/>
<syslibl>QSYS QSYS2 QHLPSYS QUSRSYS</syslibl>
<usrlibl>QGPL QTEMP QDEVELOP QBLDSYS QBLDSYSR</usrlibl>
<jobcpffind>see log scan, not error list</jobcpffind>
</jobinfo>
</cmd>
</xmlservice>""")  # noqa E501

    tk = iToolKit()

    tk.add(iCmd('cmderror', 'CHGLIBL LIBL(FROGLEGLONG)'))

    tk.call(transport)

    cmderror = tk.dict_out('cmderror')

    for k, v in cmderror.items():
        if not k.startswith('error'):
            continue

        item = cmderror[k]
        if 'errnoxml' not in item:
            continue

        assert (item['errnoxml'] == '1100012')
示例#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
示例#7
0
def test_cmd_rexx_no_row(transport):
    """Test calling command with output parms and irow=0 returns data in dict"""
    transport.set_out(_xml)

    tk = iToolKit(irow=0)
    tk.add(iCmd('rtvjoba', 'RTVJOBA USRLIBL(?) SYSLIBL(?) CCSID(?N) OUTQ(?)'))

    tk.call(transport)
    rtvjoba = tk.dict_out('rtvjoba')

    assert ('success' in rtvjoba)
    assert ('USRLIBL' in rtvjoba)
    assert ('SYSLIBL' in rtvjoba)
    assert ('CCSID' in rtvjoba)
    assert ('OUTQ' in rtvjoba)
示例#8
0
def test_exec():
    cmd = 'DSPSYSSTS'
    key = 'kjwlenrn'

    element = ET.fromstring(iCmd(key, cmd).xml_in())
    assert (element.tag == 'cmd')

    assert ('exec' in element.attrib)
    assert (element.attrib['exec'] == 'cmd')

    assert ('error' in element.attrib)
    assert (element.attrib['error'] == 'fast')

    assert ('var' in element.attrib)
    assert (element.attrib['var'] == key)

    assert (element.text == cmd)
示例#9
0
def test_rexx():
    cmd = 'RTVJOBA USRLIBL(?) SYSLIBL(?)'
    key = 'rtvjoba'

    element = ET.fromstring(iCmd(key, cmd).xml_in())
    assert (element.tag == 'cmd')

    assert ('exec' in element.attrib)
    assert (element.attrib['exec'] == 'rexx')

    assert ('error' in element.attrib)
    assert (element.attrib['error'] == 'fast')

    assert ('var' in element.attrib)
    assert (element.attrib['var'] == key)

    assert (element.text == cmd)
示例#10
0
    def itoolkit_run_command(self, command):
        '''IBM i XMLSERVICE call *CMD not returning *OUTPUT'''
        itool = iToolKit()
        itransport = DatabaseTransport(self.conn)
        itool.add(iCmd('command', command))
        itool.call(itransport)
        command_output = itool.dict_out('command')

        out = ''
        err = ''

        if 'success' in command_output:
            rc = ibmi_util.IBMi_COMMAND_RC_SUCCESS
            out = str(command_output)
        else:
            rc = ibmi_util.IBMi_COMMAND_RC_ERROR
            err = str(command_output)
        return rc, out, err
示例#11
0
def test_exec_on():
    cmd = 'DSPSYSSTS'
    key = 'pndsfnwer'
    error = 'on'

    element = ET.fromstring(iCmd(key, cmd, {'error': error}).xml_in())
    assert (element.tag == 'cmd')

    assert ('exec' in element.attrib)
    assert (element.attrib['exec'] == 'cmd')

    assert ('error' in element.attrib)
    assert (element.attrib['error'] == error)

    assert ('var' in element.attrib)
    assert (element.attrib['var'] == key)

    assert (element.text == cmd)
示例#12
0
def test_rexx_error_off():
    cmd = 'RTVJOBA USRLIBL(?) SYSLIBL(?)'
    key = 'lkjwernm'
    error = 'off'

    element = ET.fromstring(iCmd(key, cmd, {'error': error}).xml_in())
    assert (element.tag == 'cmd')

    assert ('exec' in element.attrib)
    assert (element.attrib['exec'] == 'rexx')

    assert ('error' in element.attrib)
    assert (element.attrib['error'] == error)

    assert ('var' in element.attrib)
    assert (element.attrib['var'] == key)

    assert (element.text == cmd)
示例#13
0
def test_cmd_rexx_row(transport):
    """Test calling command with output parameters returns data in rows"""
    transport.set_out(_xml)

    tk = iToolKit(irow=1)
    tk.add(iCmd('rtvjoba', 'RTVJOBA USRLIBL(?) SYSLIBL(?) CCSID(?N) OUTQ(?)'))

    tk.call(transport)
    rtvjoba = tk.dict_out('rtvjoba')

    assert ('success' in rtvjoba)
    assert ('row' in rtvjoba)
    row = rtvjoba['row']

    assert (len(row) == 4)
    assert ('USRLIBL' in row[0])
    assert ('SYSLIBL' in row[1])
    assert ('CCSID' in row[2])
    assert ('OUTQ' in row[3])