Exemple #1
0
def importPackages(newestPackages, plesk_root, pkg_counter=None):
    # import pleskds - it registers platforms in system.
    uLogging.info("Importing new packages")
    new_pleskds = []

    total_packages = 0
    for pform_ctypes in newestPackages.values():
        for ctype_packages in pform_ctypes.values():
            total_packages += len(ctype_packages)

    if not pkg_counter:
        pkg_counter = uUtil.CounterCallback()

    pkg_counter.set_total(total_packages)

    for pform in newestPackages:
        if newestPackages[pform].has_key(
                'other') and newestPackages[pform]['other'].has_key('pleskd'):
            new_pleskds.append(newestPackages[pform]['other']['pleskd'])

    if new_pleskds:
        uLogging.debug("importing new agent packages")
        uAction.retriable(doMassImport)(plesk_root, new_pleskds, pkg_counter)
        to_update = [x for x in new_pleskds if x.old]
        if to_update:
            updateManifestSources(plesk_root, to_update, pkg_counter)

    for pform in newestPackages:
        uLogging.debug("importing new packages for %s", pform)
        for ctype in newestPackages[pform]:
            if newestPackages[pform][ctype]:
                uAction.retriable(doMassImport)(
                    plesk_root, newestPackages[pform][ctype].values(),
                    pkg_counter)
Exemple #2
0
def performFakeUpgrade(scs, rootpath):
    if not scs:
        return
    con = uSysDB.connect()
    cur = con.cursor()
    for sc, sc_rootpath in scs.values():
        if not sc_rootpath:
            sc_rootpath = rootpath
        new_location = '%s:%s' % (sc.package.name,
                                  os.path.join(sc_rootpath, sc.content.bin))

        cur.execute(
            "UPDATE sc_instances SET location_id = %s WHERE sc_id IN (SELECT sc_id FROM service_classes WHERE name= %s)",
            (new_location, sc.package.name))

    con.commit()

    uAction.progress.do("fake upgrading service controllers")

    cur.execute(
        "SELECT component_id, name FROM service_classes sc JOIN sc_instances si ON (si.sc_id = sc.sc_id) ORDER BY component_id"
    )

    changed_scs_component_ids = [(x[0], x[1]) for x in cur.fetchall()
                                 if x[1] in scs]
    cur.close()
    con.commit()
    for sc in changed_scs_component_ids:
        uLogging.info('%s', sc)
        cid, name = sc
        cid = int(cid)
        uLogging.info("Upgrading %s(%s)", name, cid)
        uAction.retriable(uFakePackaging.upgradeSC)(cid)

    uAction.progress.done()
Exemple #3
0
def updateManifestSources(plesk_root, pkglist, pkg_counter):
    uAction.progress.do("updating agent manifests")
    con = uSysDB.connect()
    # Update old package set its version to zero (zero is less than anything else :)
    # After it, import new package, update components and properties to point to new version, and delete old one.
    for pkg in pkglist:
        uAction.progress.do("updating %s", pkg)
        old_pkg_id = pkg.pkg_id
        cur = con.cursor()
        cur.execute(
            "UPDATE packages SET version = '0', filename = NULL WHERE pkg_id = %s",
            old_pkg_id)
        con.commit()

        uAction.retriable(doMassImport)(plesk_root, [pkg], pkg_counter)
        cur.execute("UPDATE components SET pkg_id = %s WHERE pkg_id = %s",
                    pkg.pkg_id, old_pkg_id)

        cur.execute(
            """
		   SELECT p.prop_id, p.name, p2.prop_id AS new_prop_id,
		   cp.component_id FROM component_properties cp
		   JOIN properties p ON (cp.prop_id = p.prop_id)
		   LEFT JOIN properties p2 ON (p.name = p2.name)
		   WHERE p.pkg_id = %s
		   AND p2.pkg_id = %s """, (old_pkg_id, pkg.pkg_id))

        rows = cur.fetchall()

        for row in rows:
            old_prop_id, prop_name, new_prop_id, component_id = row[0], row[
                1], row[2], row[3]
            if new_prop_id is None:
                uLogging.debug("Deleting property %s (old prop_id %s)",
                               prop_name, old_prop_id)
                cur.execute(
                    """DELETE FROM component_properties
		                    WHERE component_id = %s AND prop_id = %s """,
                    (component_id, old_prop_id))
            else:
                uLogging.debug(
                    'Copying property %s (old prop_id %s, new prop_id %s)',
                    prop_name, old_prop_id, new_prop_id)
                cur.execute(
                    """UPDATE component_properties
				    SET prop_id = %s
		                    WHERE component_id = %s
		                    AND prop_id = %s """,
                    (new_prop_id, component_id, old_prop_id))
        cur.execute("DELETE FROM packages WHERE pkg_id = %s", old_pkg_id)
        con.commit()
        uAction.progress.done()
        pkg_counter.new_item(pkg)
    uAction.progress.done()
Exemple #4
0
def update_packages_on_host(host_id, packages):
    # at first upgrade pleskd, config and Privileges packages, their dependencies cannot be resolved by ppm properly

    packages_first = filter(lambda x: re.match("pleskd|config|Privileges|libsso", x.package.name), packages)
    for pkg in packages_first:
        uAction.progress.do("installing %s (%s)", pkg.package, pkg.pkg_id)
        uAction.retriable(uPackaging.installPackageToHostAPI, allow_console=True)(
            host_id, print_name=str(pkg), pkg_id=pkg.pkg_id)
        uAction.progress.done()

    # update others using meta-package
    packages_ids = [pkg.pkg_id for pkg in packages]
    uAction.retriable(uFakePackaging.installMetaPackage, allow_console=True)(host_id, pkg_id_list=packages_ids)
Exemple #5
0
def checkHostsAvailability(in_precheck=False):
    uLogging.info("Checking slave hosts availability...")
    # skip hosts without pleskd (they are not managed by POA)
    hosts = filter(lambda h: h.pleskd_id and int(h.host_id) != 1, getAllHosts())
    results = []
    for host in hosts:
        if in_precheck:
            res = checkOneHostAvailability(host, True)
            results.append((res, host))
        else:
            uAction.retriable(checkOneHostAvailability)(host)

    # need to make aggregated exception in precheck
    if in_precheck:
        not_reachable_hosts = filter(lambda x: x[0], results)
        if not_reachable_hosts:
            message = ""
            for msg, host in not_reachable_hosts:
                message += "\n * %s (%s)	 error message: %s" % (host.name, host.host_id, msg)
            raise uPrecheck.PrecheckFailed(
                "Some Operation Automation slave hosts are not available", "check the following hosts, probably unreacheable by network or have pleskd agent down:%s" % message)
Exemple #6
0
def upgrade_paagent_and_repourl(binfo, config, slave_hosts):
    config.need_update_paagent = is_need_to_update_paagent(binfo)
    
    if not config.need_update_paagent and not config.need_update_yum_repourl:
        uLogging.info("No new agent RPMs in build, updating YUM repo URL is not needed also, skipping agent update.")
        return

    uLogging.debug(
        "Need update YUM repo URL: {need_update_yum_repourl}; "
        "there are new agents in build: {need_update_paagent}".format(
            need_update_yum_repourl=config.need_update_yum_repourl, need_update_paagent=config.need_update_paagent))

    uAction.progress.do("Updating agents on slave nodes")
    config.mn_as_cert_issuer = uHCL.getHostCertificateDigest(uPEM.getHost(1))

    # Filtering out non-upgradable slaves
    slaves = [host for host in slave_hosts if host.host_id != 1]
    uLogging.debug("Found slaves with agent: \n{slaves}".format(slaves=pformat(slaves)))
    slaves = filter(lambda slave: is_slave_upgradable(slave, binfo, config), slaves)
    uLogging.debug("All non-upgradable slaves are filtered out, actual slave-to-upgrade list now: "
                   "\n{slaves}".format(slaves=pformat(slaves)))

    if not slaves:
        uLogging.info("There is no slaves marked for update.")
        uAction.progress.done()
        return

    # Preparing task pool for updating.
    pool = preparePool(config)
    slave_upgrade_monitoring = SlaveUpgradeMonitoring(pool, binfo, slaves)

    # Filling task pool for slaves
    for host in slaves:
        try:
            # Defining paagent url. If this will be eq None, package will not be updated
            paagent_url = prepare_paagent_url(host.platform, binfo, config)
            uLogging.debug("Slave '{host}' upgrade scheduled. Pa-agent URL is: '{agent_url}'"
                           .format(host=host, agent_url=paagent_url))
            pool.put(TaskItem(host, paagent_url))
        except uAction.ActionIgnored:
            continue

    thread_count = max_slave_upgrade_threads(hosts_to_upgrade_count=len(slaves),
                                             slave_upgrade_threads=config.slave_upgrade_threads)

    try:
        pool.start(thread_count)
        slave_upgrade_monitoring.start()
        uLogging.info("Upgrade for agents on slaves started (parallel: {thread_count})".format(
            thread_count=thread_count))
        uAction.retriable(process_pool_results)(pool, binfo, config)
        uLogging.info("All results of upgrading agents on slaves processed. ")
        report_skipped_hosts(binfo)
    except (Exception, KeyboardInterrupt) as e:
        # to remember and raise what is happened under try statement if finally statement has failures too
        uLogging.save_traceback()
        pool.terminateLocked()
        raise e
    finally:
        pool.terminate()
        slave_upgrade_monitoring.terminate()
        uAction.progress.done()
Exemple #7
0
def canProceedWithHost(host):
    # will return "" (host available), None (error ignored), or raise exception (host unavailable & abort selected)
    msg = uAction.retriable(checkOneHostAvailability)(host)
    return msg == ""
Exemple #8
0
def waitForPuiWarRedeploy():
    uAction.progress.do("Waiting for 'pui-war.war' re-deployment...")
    uAction.retriable(waitTasksComplete)("t.name like 'Reloading PUI %'")
    uAction.progress.done()
Exemple #9
0
def waitForAPS20ApplicationUpgradeTasks(message):
    uAction.progress.do(message)
    uAction.retriable(waitTasksComplete)("t.method = 'taskUpgradeApp2x'")
    uAction.retriable(waitTasksComplete)("t.method = 'APSUpgradeApplication'")
    uAction.progress.done()
Exemple #10
0
def waitInstallationTasksComplete(message):
    uAction.progress.do(message)
    uAction.retriable(waitTasksComplete)("t.name like 'Install %'")
    uAction.progress.done()
Exemple #11
0
def waitUpdateModuleComplete():
    uLogging.info('Waiting for completion of modules upgrade')
    uAction.retriable(waitTaskGroupComplete)(upgraderModuleGroupPattern)
    uLogging.info('Modules upgrade finished successfully')
Exemple #12
0
def update_binaries(packages, rootpath):
    for pkg, sc_rootpath in packages.values():
        if not sc_rootpath:
            sc_rootpath = rootpath
        uAction.retriable(update_binary)(pkg, sc_rootpath)