예제 #1
0
def ForceMaster(node, is_testver):
    """ Force a node to become GSA master

  Arguments:
    node: 'ent2'
    is_testver: 0
  """
    gsaport = core_utils.GSAMasterPort(is_testver)
    # ignore the result of forcemaster
    port_talker.TCPTalk(node, gsaport, 30, command='GET /forcemaster\n')
예제 #2
0
def Check_SMTP(name, my_ip):
    """check on our SMTP server"""

    if nslookup(name)[0] != 0:
        add_info(name, SMTP_SERVER, "cannot resolve SMTP server")
        return 1
    if ping_machine(name) != 0:
        add_info(name, SMTP_SERVER, "cannot ping SMTP server")
        return 2

    status, err = tryconnect(name, SMTP_PORT)
    if status == 1 or status == 2:
        add_info(name, SMTP_SERVER, err)
    if status == 1:
        # if we time'd out, things can still be OK (say reverse DNS problems)
        # so return only an error if no timeout
        return 3

    stat, out = port_talker.TCPTalk(
        name,
        SMTP_PORT,
        60,  # timeout (>30sec for messed up servers)
        "HELO " + my_ip + "\r\nQUIT\r\n",
        None,  # terminator
        1024,  # max len
        1)  # use external resolver

    # expected answer:
    #220 'mail.forobozz.com' ESMTP
    #250 mail.frobozz.com Hello grue.frobozz.com [192.168.0.21], pleased to meet ya
    #221 mail.frobozz.com closing connection

    # Each line can be repeated several times, so we check that all codes appear
    # and that no other codes appear
    codes = map(lambda x: x[:4], string.split(out, '\n'))
    valid_codes = ('220 ', '250 ', '221 ', '')
    try:
        for code in codes:
            assert (code in valid_codes)
        for valid in valid_codes:
            assert (valid in codes)
    except:
        # If we wanted, we could check whether reverse DNS lookup is not working.
        # This would be the most likely explanation
        add_info(name, SMTP_SERVER, "cannot HELO SMTP server")
        return 4
    add_info(name, SMTP_SERVER, "OK")
    return 0
예제 #3
0
def verify_url(u, host, port, command):
    errcode = 400
    try:
        _, output = port_talker.TCPTalk(host, port, 30, command, None, 1000, 1)
    except:
        add_info(u, TEST_URL, "Timed out")
        return 1
    try:
        errcode = int(string.split(output, None, 2)[1])
    except:
        add_info(u, TEST_URL, "Invalid response from the server")
        return 1

    if errcode == 200:
        add_info(u, TEST_URL, "OK")
        return 0
    else:
        add_info(u, TEST_URL, "returncode %d, should be 200" % errcode)
    return 1
예제 #4
0
def IsAdminRunnerAlive(max_tries, sleep_time):
    """Check whehter AdminRunner is alive on the localhost."""

    try_count = 0
    is_alive = 0
    while try_count < max_tries:
        # This just tries to establish a connection to verify whether it is alive
        status, response = port_talker.TCPTalk('localhost', 2100, sleep_time)
        if status == 0:
            is_alive = 1
            break
        else:
            try_count += 1
            logging.info(
                'Could not connect to adminrunner on localhost, '
                'sleeping for %d seconds...', sleep_time)
            time.sleep(sleep_time)

    return is_alive
예제 #5
0
def FindMachinesAlive(port, machines, cmd):
    '''
  Finds the machines that answer on a port to a command.
  '''

    master = []

    # Looking for a master.

    for machine in machines:
        response = port_talker.TCPTalk(machine,
                                       port,
                                       40,
                                       cmd,
                                       max_len=sys.maxint)
        if 0 == response[0]:
            master.append(machine)

    return master
def execute(flag_config_file, flag_machine, flag_port, flag_cmd,
            flag_expected_answer, flag_no_extra_req):
    """
  Provides the actual execution. Receives the flag values.
  All returns are OK, errors are on sys.exit

  """
    #
    # If the request does not specify the machine or port we create
    # a number of subsequent send server command requests for each machine:port
    # in the server map that matches the server type
    #
    if not (flag_machine and flag_port):
        sys.exit("Invalid parameters: port and machine must be specified")

    #
    # We have machine & port -> issue the command
    #
    status, ret = port_talker.TCPTalk(flag_machine, flag_port, 15, flag_cmd)
    if status or string.find(ret, flag_expected_answer) == -1:
        sys.exit("Error sending command %s to server %s:%s" %
                 (flag_cmd, flag_machine, flag_port))
    return 0
예제 #7
0
 def is_admin_console_alive(self, sleep_time):
     """Check whehter AdminConsole is alive on the localhost."""
     # This just tries to establish a connection to verify whether it is alive
     status, response = port_talker.TCPTalk('localhost', 8000, sleep_time)
     return not status
예제 #8
0
def tryconnect(name, port):
    """Can we connect to machine (giving optional command)"""
    return port_talker.TCPTalk(name, port, 2, '', None, 0,
                               1)  # use ext. resolver