예제 #1
0
def create_monster_workdir(out_dir):
    """This keyword is to create monster work directory to save monitored data.
    
    | Parameters   | Man. | Description            |
    | out_dir      | Yes  | the directory under var/log |
    
    | Return value | none |
    
    Example
    | create monster workdir |  monster_test |
    
    """
    command = 'mkdir -p /var/log/%s ' % (out_dir)
    out = connections.execute_cli(command)
    command = 'rm -f /var/log/%s/*.*' % (out_dir)
    out = connections.execute_cli(command)
예제 #2
0
def interrogate_log(tmp_file='', param='', unit='', famid='', level=''):
    """This keyword is to interrogate log

    #COMMAND: ILlogdisp

    | Parameters | Man. | Description |
    | tmp_file   | No  | tmp file to store the interrogate result, need be deleted after case execute
    | command param | No | command param, such as: -h or --help
    | unit       | No  | unit type |
    | famid      | No  | family id combination, such as: famid=1 or famid=1 proc=2 or famid=1 proc=2 focus=3 |
    | level      | No  | log level, including: crit, err, test, info |

    | Return value | Successful: True, Failure: False |

    Example
    | ${result} | interrogate_log | unit=OMU famid=1,2 proc=2 focus=3 | level=crit,info |
    | Should Be True | ${result} |

    """
    if tmp_file != '':
        command = "ILlogdisp %s %s %s %s > %s" % (param, unit, famid, level,
                                                  tmp_file)
    else:
        command = "ILlogdisp %s %s %s %s" % (param, unit, famid, level)


#    print command
    out = connections.execute_cli(command)

    return out
예제 #3
0
def check_top_output_for_monster(pid, suser):
    """This keyword is to check the top output for one monster
           
    | Parameters   | Man. | Description              |
    | pid          | Yes  | the monster process id   |
    | suser        | Yes  | the user name            |
    
    | Return value | all the threads nice value |
    
    ['\x1b[m\x0f', '2840', 'root', '20', '0', '28052', '6688', '6396', 'S', '0.0', '0.6', '0:00.01', 'monster', '\x1b[m\x0f']
    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                              
    28497 root      20   0 28052 6680 6400 S  0.0  0.6   0:00.01 monster                                              
    28499 root      20   0 28052 6680 6400 S  0.0  0.6   0:00.00 monster                                              
    28500 root      20   0 28052 6680 6400 S  0.0  0.6   0:00.02 monster 
    """
    command = "top -H -n 1 -p %s" % (pid)
    out = connections.execute_cli(command)
    #return the NICE values
    nice_values = []
    result_list = out.splitlines()
    result_list_len = len(result_list)
    for i in range(result_list_len):
        if result_list[i].count('PID USER      PR  NI') > 0:
            for j in range(3):
                strings = result_list[i + j + 1].split()
                print strings
                strings_len = len(strings)
                for k in range(strings_len):
                    if (strings[k].count(suser) > 0):
                        nice_values.append(strings[k + 2])
    return nice_values
예제 #4
0
def delete_network_address(owner, iface, ip_addr, dedicated='', instance=''):
    command = ' '.join([
        'delete', 'networking',
        'instance %s' % instance if instance else '',
        'address dedicated' if dedicated else 'address', owner, 'ip-address',
        ip_addr + '/32', 'iface', iface
    ])

    scli_command = 'fsclish -c "%s"' % command
    result = connections.execute_cli(scli_command)
    print result
예제 #5
0
def remove_monster_workdir(out_dir):
    """This keyword is to remove monster work directory.
    
    | Parameters   | Man. | Description              |
    | out_dir      | Yes  | the directory under var/log |
    
    | Return value | none |

    Example
    | remove monster workdir |  monster_test |
    
    """
    command = 'rm -f -r /var/log/%s' % (out_dir)
    out = connections.execute_cli(command)
예제 #6
0
def copy_file(file1, file2):
    """This keyword is to copy file1 to file2 us cp command

    #COMMAND: cp

    | Parameters | Man. | Description |
    | file1   | Yes | source file name
    | file2   | Yes | destination name

    | Return value | Successful: True, Failure: False |

    Example
    | ${result} | copy_file | test.txt | test.bak |
    | Should Be True | ${result} |

    """
    #just copying file/folder but not symbol links
    command = "cp -rfL %s %s" % (file1, file2)
    out = connections.execute_mml_without_check(command, 'y')
    if out.count("Read-only file system") != 0:
        connections.execute_mml("mount -o rw,remount /mnt/sysimg")
        connections.execute_cli(command, 'y')

    return True
예제 #7
0
def start_monster_at_background(computer_id,family_id,out_file):
    """This keyword is to start monster monitoring at background.
    
    | Parameters   | Man. | Description            |
    | computer_id  | Yes  | the computer address   |
    | family_id    | Yes  | the target family to monitor and send message  |

    | Return value | the process id |

    Example
    | result | start monster at background |  0x700 | 0x1B58 | /root/bottom.bin |
    """   
    command = 'monster -u %s -f %s -c "SR:NUM=6034,9901" -b %s >/dev/null&' % (computer_id,family_id,out_file)
    out = connections.execute_cli(command)
    result_list = out.split()
    return result_list[1].strip()
예제 #8
0
def start_libdmxmsg_process(prb_name, inst_num):
    """This keyword is to start libdmxms process and return the process id.
    
    | Parameters  | Man. | Description                                  |
    | prb_name    | Yes  | the libdmxmsg prb name, such as msgmonstub   |
    | inst_num    | Yes  | the startup instance num for this prb        |

    | Return value | the process id |

    Example
    | result | start_libdmxmsg_process |  msgmonstub | 2 |
    """   
    command = "%s -s %s &" % (prb_name, inst_num)
    out = connections.execute_cli(command)
    result_list = out.split()
    return result_list[1].strip()
예제 #9
0
def monster_should_start_ok_for_defined_nice_value(nice_value, suser, file_id):
    if (nice_value == 'default'):
        command = 'monster'
    else:
        command = 'monster' + ' -P ' + nice_value
    if (suser == 'root'):
        command = command + ' -o monster_' + str(file_id) + '.bin &'
    else:
        command = command + ' &'
    out = connections.execute_cli(command)
    #return the monster process id
    result_list = out.split()
    result_list_len = len(result_list)
    for i in range(result_list_len):
        if result_list[i].count('[') > 0 and result_list[i].count(']') > 0:
            return result_list[i + 1].strip()
    return result_list[1].strip()
예제 #10
0
def test_libdmxmsg_family_register_limit(prb_name, inst_num):
    """This keyword is to start libdmxms process and return the process id.
    
    | Parameters  | Man. | Description                                  |
    | prb_name    | Yes  | the libdmxmsg prb name, such as msgmonstub   |
    | inst_num    | Yes  | the startup instance num for this prb        |

    | Return value | 'success' or 'failure' |

    Example
    | result | Test Libdmxmsg Family Register Limit |  msgmonstub | 555 |
    """   
    command = "%s -s %s" % (prb_name, inst_num)
    out = connections.execute_cli(command)
    if out.count('Registering pid fail. (ret 0x11e)') == 1:
        return 'success'
    else:
        return 'failure'
예제 #11
0
def send_msg_to_not_exist_process(computer_id,family_id):
    """This keyword is to send msg to not exist process
    
    | Parameters   | Man. | Description            |
    | computer_id  | Yes  | the computer address   |
    | family_id    | Yes  | the target family to monitor and send message  |

    | Return value | failure, for the process does not exist so the result will be failure |

    Example
    | result | send msg to not exist |  0x700 | 0x1B58 |
    """   
    command = 'ILDMXTestCli -f 0xfffe -- -r %s %s 0 -a' % (computer_id,family_id)
    out = connections.execute_cli(command)

    if out.count('failure')==1:
        return 'failure'
    else:
        return 'the result is wrong'
예제 #12
0
def empty_file(file):
    """This keyword is to copy file1 to file2 us cp command

    #COMMAND: :>

    | Parameters | Man. | Description |
    | file   | Yes | file name that will be cleared

    | Return value | Successful: True, Failure: False |

    Example
    | ${result} | clear_file | test.txt |
    | Should Be True | ${result} |

    """

    command = ":> %s " % (file)
    out = connections.execute_cli(command)

    return True
예제 #13
0
def _file_should_exist(dir_name, file_name):
    """This keyword is to check if the file exists
           
    | Parameters   | Man. | Description              |
    | dir_name     | Yes  | the directory name       |
    | file_name    | Yes  | the file name            |
    
    | Return value | file_length |
    
    """
    file_length = 0
    command = "ll /var/log/%s/%s" % (dir_name, file_name)
    out = connections.execute_cli(command)
    if (out.count('No such file or directory') > 0):
        exceptions.raise_ILError("ILCommandExecuteError",
                                 "The compressed file is not saved.")
    else:
        file_length = out.split()[4]
    print file_length
    return file_length
예제 #14
0
def remove_file(file):
    """*DEPRECATED* Please use 'delete_file' to instead of.
    This keyword is to remove file1 to file2 us cp command

    #COMMAND: rm -rf

    | Parameters | Man. | Description |
    | file   | Yes | file name that will be removed

    | Return value | Successful: True, Failure: False |

    Example
    | ${result} | clear_file | test.txt |
    | Should Be True | ${result} |

    """

    command = "rm -rf %s " % (file)
    out = connections.execute_cli(command)

    return True
예제 #15
0
def start_monster_at_background_with_compress_mode(computer_id,
                                                   family_id,
                                                   out_dir,
                                                   out_file,
                                                   message_number,
                                                   compress_mode,
                                                   ssize='0',
                                                   ssequence='0',
                                                   snicevalue=''):
    """This keyword is to start monster monitoring at background with data compress mode.
    
    | Parameters   | Man. | Description            |
    | computer_id  | Yes  | the computer address   |
    | family_id    | Yes  | the target family to monitor and send message  |
    | out_dir      | Yes  | the directory under var/log |
    | out_file     | Yes  | the output file name   |
    | message_number| Yes | the monitored message nubmer |
    | compress_mode    | Yes  | file output format -b, -o, -g -e |
    | ssize        | No   | split file size limit(unit:Mbytes)|
    | ssequence    | No   | split file up limit sequence |
    | snice value  | No   | nice value |
    
    | Return value | the process id |

    Example
    | result | start monster at background |  0x700 | 0x1B58 | /var/log/test.mgi | 8000 | -e |

    -b <file>
       Stores messages in DX binary format to given file.
    -o <file>
       Stores monitoring data in Linux LIBGEN format to given file.
    -g <file>
      Stores monitoring data in Linux LIBGEN format with compression to
      given file. The file should be uncompressed with gunzip. 
    -e <file>
      Stores monitoring data to given file which follows GIVAXI interface
      The file externtion is .mgi and can be read by Emil. 
    """
    command = 'rm -f /var/log/%s/%s*.*' % (out_dir, out_file)
    out = connections.execute_cli(command)
    if (ssize == '0'):
        command = '-u %s -f %s -c "SR:NUM=%s" %s /var/log/%s/%s&' % (
            computer_id, family_id, message_number, compress_mode, out_dir,
            out_file)
    else:
        ssize_parameter = '-S %s -N %s -F' % (ssize, ssequence)
        command = '-u %s -f %s -c "SR:NUM=%s" %s /var/log/%s/%s %s&' % (
            computer_id, family_id, message_number, compress_mode, out_dir,
            out_file, ssize_parameter)
    if (snicevalue <> ''):
        command = 'monster' + ' -P ' + str(snicevalue) + ' ' + command
    else:
        command = 'monster ' + command

    out = connections.execute_cli(command)
    #return the monster process id
    result_list = out.split()
    result_list_len = len(result_list)
    for i in range(result_list_len):
        if result_list[i].count('[') > 0 and result_list[i].count(']') > 0:
            return result_list[i + 1].strip()
    #sleep 0.5 to make sure monitoring session connected
    time.sleep(0.5)
    return result_list[1].strip()