Esempio n. 1
0
def test_install_virt(log, workspace, test_config, test_config_fpath):
    """
    Start to install virt
    """
    skip_virt = utils.config_value(test_config,
                                   cstr.CSTR_SKIP_VIRT)
    if skip_virt is None:
        log.cl_debug("no [%s] is configured, do not skip checking virt")
        skip_virt = False

    if skip_virt:
        log.cl_debug("skip checking virt")
        return 0

    virt_config_fpath = utils.config_value(test_config,
                                           cstr.CSTR_VIRT_CONFIG)
    if virt_config_fpath is None:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_VIRT_CONFIG, test_config_fpath)
        return -1
    ret = lvirt.lvirt(log, workspace, virt_config_fpath)
    if ret:
        log.cl_error("failed to install the virtual machines")
        return -1
    return 0
Esempio n. 2
0
def clownfish_server_do_loop(log, workspace, config, config_fpath):
    """
    Server routine
    """
    server_config = utils.config_value(config, cstr.CSTR_CLOWNFISH_SERVER)
    if server_config is None:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_CLOWNFISH_SERVER, config_fpath)
        return -1

    clownfish_server_port = utils.config_value(server_config, cstr.CSTR_PORT)
    if clownfish_server_port is None:
        log.cl_info("no [%s] is configured in config [%s], using port [%s]",
                    cstr.CSTR_PORT, cstr.CSTR_CLOWNFISH_SERVER,
                    constants.CLOWNFISH_DEFAULT_SERVER_PORT)
        clownfish_server_port = constants.CLOWNFISH_DEFAULT_SERVER_PORT

    clownfish_instance = clownfish.init_instance(log, workspace, config,
                                                 config_fpath)
    if clownfish_instance is None:
        log.cl_error("failed to init Clownfish")
        return -1

    cserver = ClownfishServer(log, clownfish_server_port, clownfish_instance)
    cserver.cs_loop()
    cserver.cs_fini(log)
Esempio n. 3
0
def lcrpd_do_loop(log, workspace, config, config_fpath):
    """
    Daemon routine
    """
    # pylint: disable=unused-argument
    fsname = utils.config_value(config, LCRPD_STR_FSNAME)
    if fsname is None:
        log.cl_error("no [%s] is configured, please correct config file [%s]",
                     LCRPD_STR_FSNAME, config_fpath)
        return -1

    lcrp_dir = utils.config_value(config, LCRPD_STR_LCRP_DIR)
    if lcrp_dir is None:
        log.cl_error("no [%s] is configured, please correct config file [%s]",
                     LCRPD_STR_LCRP_DIR, config_fpath)
        return -1

    changelog_user = utils.config_value(config, LCRPD_STR_CHANGELOG_USER)
    if changelog_user is None:
        log.cl_error("no [%s] is configured, please correct config file [%s]",
                     LCRPD_STR_CHANGELOG_USER, config_fpath)
        return -1

    if not os.path.isdir(lcrp_dir):
        log.cl_error("[%s] is not directory, please correct [%s] of config file [%s]",
                     lcrp_dir, LCRPD_STR_LCRP_DIR, config_fpath)
        return -1

    return lcrp_changelog(log, fsname, lcrp_dir, changelog_user)
Esempio n. 4
0
def _clownfish_local_main_start_stop(log,
                                     workspace,
                                     config,
                                     config_fpath,
                                     service_names,
                                     start=True):
    """
    Start or stop the service
    """
    # pylint: disable=unused-argument,too-many-locals,too-many-arguments
    server_config = utils.config_value(config, cstr.CSTR_CLOWNFISH_SERVER)
    if server_config is None:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_CLOWNFISH_SERVER, config_fpath)
        return -1

    virtual_ip = utils.config_value(server_config, cstr.CSTR_VIRTUAL_IP)
    if not virtual_ip:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_VIRTUAL_IP, config_fpath)
        return -1

    port = utils.config_value(server_config, cstr.CSTR_PORT)
    if not port:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_PORT, config_fpath)
        return -1

    local_hostname = socket.gethostname()

    server_url = "tcp://%s:%s" % (virtual_ip, port)
    console_client = clownfish_console.ClownfishClient(log, workspace,
                                                       server_url)
    ret = console_client.cc_init()
    if ret:
        log.cl_error("failed to connect to Clownfish server [%s]", server_url)
        return -1

    result = log.cl_result
    for service_name in service_names:
        if start:
            command = (
                "%s %s %s %s" %
                (clownfish_subsystem_service.SUBSYSTEM_SERVICE_NAME,
                 clownfish_subsystem_service.SUBSYSTEM_SERVICE_COMMNAD_MOVE,
                 service_name, local_hostname))
        else:
            command = (
                "%s %s %s" %
                (clownfish_subsystem_service.SUBSYSTEM_SERVICE_NAME,
                 clownfish_subsystem_service.SUBSYSTEM_SERVICE_COMMNAD_UMOUNT,
                 service_name))
        console_client.cc_command(log, command)
        if result.cr_exit_status:
            log.cl_error("failed to run command [%s]", command)
            ret = result.cr_exit_status
            break
    console_client.cc_fini()
    return ret
Esempio n. 5
0
def clownfish_install_parse_config(log, workspace, config, config_fpath,
                                   mnt_path, iso_path):
    """
    Parse the config and init Clownfish HA cluster
    """
    # pylint: disable=too-many-locals,too-many-branches,too-many-arguments
    server_config = utils.config_value(config, cstr.CSTR_CLOWNFISH_SERVER)
    if server_config is None:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_CLOWNFISH_SERVER, config_fpath)
        return -1

    virtual_ip = utils.config_value(server_config, cstr.CSTR_VIRTUAL_IP)
    if not virtual_ip:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_VIRTUAL_IP, config_fpath)
        return None

    ip_regular = (r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}"
                  "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
    pattern = re.match(ip_regular, virtual_ip, re.IGNORECASE)
    if not pattern:
        log.cl_error("wrong format of virtual IP [%s], please correct file "
                     "[%s]", virtual_ip, config_fpath)
        return None

    bindnetaddr = utils.config_value(server_config, cstr.CSTR_BINDNETADDR)
    if not bindnetaddr:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_BINDNETADDR, config_fpath)
        return None
    pattern = re.match(ip_regular, bindnetaddr, re.IGNORECASE)
    if not pattern:
        log.cl_error("wrong format of bindnetaddr [%s], please correct file "
                     "[%s]", bindnetaddr, config_fpath)
        return None

    clownfish_hosts = clownfish_parse_server_hosts(log, config, config_fpath)
    if clownfish_hosts is None:
        log.cl_error("failed to parse Clownfish server hosts, please correct "
                     "file [%s]", config_fpath)
        return None

    return ClownfishCluster(workspace, clownfish_hosts, virtual_ip, bindnetaddr,
                            mnt_path, iso_path, config_fpath)
Esempio n. 6
0
def copytoold_do_loop(log, workspace, config, config_fpath):
    """
    Server routine
    """
    # pylint: disable=unused-argument
    if config is not None:
        server_port = utils.config_value(config, COPYTOOLD_PORT_STR)
        if server_port is None:
            log.cl_info("no [%s] is configured, using port [%s]",
                        COPYTOOLD_PORT_STR, COPYTOOLD_DEFAULT_PORT)
            server_port = COPYTOOLD_DEFAULT_PORT
    else:
        log.cl_info("starting copytoold service using port [%s]",
                    COPYTOOLD_DEFAULT_PORT)
        server_port = COPYTOOLD_DEFAULT_PORT

    copytool_daemon = CopytoolDaemon(log, workspace, server_port)
    copytool_daemon.cd_loop()
    copytool_daemon.cd_fini()
    return 0
def _iso_mount_and_install(log, workspace, config, config_fpath,
                           install_funct):
    """
    Mount the ISO and install the system
    """
    # pylint: disable=bare-except
    local_host = ssh_host.SSHHost("localhost", local=True)
    fname = utils.config_value(config, cstr.CSTR_ISO_PATH)
    if fname is None:
        fname = "clownfish-*.iso"
        iso_path = install_common.find_iso_path_in_cwd(log, local_host, fname)
        if iso_path is None:
            log.cl_error(
                "failed to find Clownfish ISO [%s] under currect "
                "directory", fname)
            return -1
        log.cl_info(
            "no [%s] is configured, use [%s] under current "
            "directory", cstr.CSTR_ISO_PATH, iso_path)
    else:
        # ISO could have wild card, find that
        iso_path = install_common.find_iso_path_in_cwd(log, local_host, fname)
        if iso_path is None:
            log.cl_error(
                "failed to find Clownfish ISO [%s] under currect "
                "directory", fname)
            return -1

    mnt_path = "/mnt/" + utils.random_word(8)

    command = ("mkdir -p %s && mount -o loop %s %s" %
               (mnt_path, iso_path, mnt_path))
    retval = local_host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        return -1

    try:
        ret = install_funct(log, workspace, config, config_fpath, mnt_path,
                            iso_path, local_host)
    except:
        ret = -1
        log.cl_error("exception: %s", traceback.format_exc())

    command = ("umount %s" % (mnt_path))
    retval = local_host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        ret = -1

    command = ("rmdir %s" % (mnt_path))
    retval = local_host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        return -1
    return ret
Esempio n. 8
0
def clownfish_parse_server_hosts(log, config, config_fpath):
    """
    Return the server hosts of clownfish
    """
    ssh_host_configs = utils.config_value(config, cstr.CSTR_SSH_HOSTS)
    if ssh_host_configs is None:
        log.cl_error("can NOT find [%s] in the config file, "
                     "please correct file [%s]",
                     cstr.CSTR_SSH_HOSTS, config_fpath)
        return None

    server_config = utils.config_value(config, cstr.CSTR_CLOWNFISH_SERVER)
    if server_config is None:
        log.cl_error("no [%s] is configured, please correct file [%s]",
                     cstr.CSTR_CLOWNFISH_SERVER, config_fpath)
        return None

    hosts = {}
    for host_config in ssh_host_configs:
        host_id = host_config[cstr.CSTR_HOST_ID]
        if host_id is None:
            log.cl_error("can NOT find [%s] in the config of a "
                         "SSH host, please correct file [%s]",
                         cstr.CSTR_HOST_ID, config_fpath)
            return None

        hostname = utils.config_value(host_config, cstr.CSTR_HOSTNAME)
        if hostname is None:
            log.cl_error("can NOT find [%s] in the config of SSH host "
                         "with ID [%s], please correct file [%s]",
                         cstr.CSTR_HOSTNAME, host_id, config_fpath)
            return None

        ssh_identity_file = utils.config_value(host_config, cstr.CSTR_SSH_IDENTITY_FILE)

        if host_id in hosts:
            log.cl_error("multiple SSH hosts with the same ID [%s], please "
                         "correct file [%s]", host_id, config_fpath)
            return None
        host = ssh_host.SSHHost(hostname,
                                identity_file=ssh_identity_file,
                                host_id=host_id)
        hosts[host_id] = host

    server_hosts = utils.config_value(server_config, cstr.CSTR_SERVER_HOSTS)
    if server_hosts is None:
        log.cl_error("can NOT find [%s] in the config file, "
                     "please correct file [%s]",
                     cstr.CSTR_SERVER_HOSTS, config_fpath)
        return None

    clownfish_hosts = []
    for host_config in server_hosts:
        host_id = host_config[cstr.CSTR_HOST_ID]
        if host_id is None:
            log.cl_error("can NOT find [%s/%s] in the config of a "
                         "SSH host, please correct file [%s]",
                         cstr.CSTR_HOST_ID, cstr.CSTR_SERVER_HOSTS,
                         config_fpath)
            return None

        if host_id not in hosts:
            log.cl_error("host with host id is not configured,"
                         "please correct file [%s]", config_fpath)
            return None

        clownfish_hosts.append(hosts[host_id])
    return clownfish_hosts