Example #1
0
def _reenableCustomCP(config, host_id, cp_name):
    from u import bootstrap

    request = uHCL.Request(host_id, user='******', group='root')
    jbossdir = bootstrap.getJBossDir(config.rootpath) + "/"
    src = jbossdir + "puitconf_d/" + cp_name + ".properties"
    dst = jbossdir + "puitconf/" + cp_name + ".properties"
    request.copy(src, dst)
    request.perform()
Example #2
0
 def syncLocalesFromDB(cls):
     request = uHCL.Request(cls.get_host_id(), user='******', group='root')
     request.command(
         "python /usr/local/bm/tools_py/configureLocale.py syncLocalesFromDB",
         stdout='stdout',
         stderr='stderr',
         valid_exit_codes=[0])
     output = request.perform()
     uLogging.debug('done, output \n%s' % output['stdout'])
Example #3
0
 def syncStores(cls):
     uLogging.info("Synchronization stores")
     request = uHCL.Request(cls.get_host_id(), user='******', group='root')
     request.command("python /usr/local/bm/tools_py/syncstores.py",
                     stdout='stdout',
                     stderr='stderr',
                     valid_exit_codes=[0])
     output = request.perform()
     uLogging.debug('done, output \n%s' % output['stdout'])
     return output
Example #4
0
def update_linux_slave(task_item, config):
    uLogging.debug("Updating Linux slave {host}".format(host=task_item.host))
    # Initializing request object
    request = uHCL.Request(task_item.host.host_id, user='******', group='root')

    # Preparing the instructions if update repourl is necessarily
    if config.need_update_yum_repourl:
        request = prepare_request_for_repourl_updating(request, config)

    # Filling request object with corresponding commands if paagent_dist_url is not a fake
    if task_item.paagent_dist_url:
        request = prepare_request_for_rpm_updating(request, task_item)

    return request.performCompat()
Example #5
0
def check_update_windows_slave(task_item, config):

    uLogging.debug("Checking if agent on Windows host {host} is updated".format(host=task_item.host))
    auth_token = uHCL.getHostAuthToken(task_item.host, config, config.mn_as_cert_issuer)
    remote_temp_dir = get_remote_temp_dir(task_item.host)
    remote_async_exec_path = get_remote_async_exec_path(task_item.host)

    # Asynchronous upgrade. If installation has been failed then PAgent.exe will be run again for product check only.
    # The following cases can be:
    #   1. exit code is 1604, it means installation is OK (manual upgrade is performed).
    #   2. exit code is 0 , it's OK too.
    #   3. exit code is 1603 (returned by bootstrapper when 'CheckWithoutUpgrade' built-in property
    #      is given at the command line. It means that agent not upgraded.

    check_result_request = uHCL.Request(host_id=task_item.host.host_id, auto_export=True)
    check_cmd_args = [remote_async_exec_path,
                      '--status',
                      '--anchor ' + agent_anchor_name,
                      '"{paagent_exe} /c /qn REBOOT=Suppress AUTO_UPGRADE=1 CheckWithoutRunUpgrade=1"'.format(
                          paagent_exe=PAAGENT_EXE_FILENAME
                      ),
                      '--exit-codes 0,1604']
    check_result_request.command(remote_async_exec_path, check_cmd_args, cwd=remote_temp_dir,
                                 stderr="err", stdout="out", retvar="exit_code")
    host_ip = uPEM.getHostCommunicationIP(task_item.host.host_id)
    check_result_http_request = urllib2.Request("https://{host_ip}:8352/process".format(host_ip=host_ip),
                                                headers={"Authorization": auth_token}, data=None)
    check_result_http_request.get_method = lambda: 'POST'
    uLogging.debug("Checking update status of Windows slave {host} via REST HCL request to {host_ip}".format(
        host=task_item.host, host_ip=host_ip))

    try:

        if uLinux.SSL_VERIFICATION_ENFORCED:
            http_respond = urllib2.urlopen(check_result_http_request, context=ssl._create_unverified_context(),
                                           data=check_result_request.toxml())
        else:
            http_respond = urllib2.urlopen(check_result_http_request, data=check_result_request.toxml())

        http_respond_out = http_respond.read()

        try:
            status_code = http_respond.getcode()
        except AttributeError:
            status_code = http_respond.code

    except urllib2.HTTPError, error:
        status_code = error.code
        http_respond_out = error.read()
Example #6
0
 def getRPMlist(cls):
     bm_pattern = '^(bm.*)-(\d+\.\d+\..*)$'
     request = uHCL.Request(cls.get_host_id(), user='******', group='root')
     request.command("rpm -qa",
                     stdout='stdout',
                     stderr='stderr',
                     valid_exit_codes=[0])
     output = request.perform()
     prog = re.compile(bm_pattern)
     res = []
     for x in output['stdout'].split():
         m = prog.match(x)
         if m:
             res.append(RPM(m.group(1), m.group(2)))
     return res
Example #7
0
def installPatches(sourcePatchesDir, con, host_id, upgrade_instructions):
    cur = con.cursor()

    cur.execute(
        "SELECT p.name, p.ctype, p.pkg_id, p.version FROM packages p JOIN components c ON (c.pkg_id = p.pkg_id) WHERE c.host_id = %s ORDER BY c.component_id",
        host_id)
    installed_packages = {}
    for row in cur.fetchall():
        installed_packages[(row[0], row[1])] = row[3]

    to_install = {}
    if upgrade_instructions is not None:
        for patch in upgrade_instructions.patches:
            name, ctype = patch
            if patch in installed_packages:
                uLogging.info(
                    'Going to install %s-%s patch because it is installed',
                    name, ctype)
                to_install[patch] = upgrade_instructions.patches[patch]
    platform, rootpath = uPEM.getHostInfo(con, host_id)
    for nameAndCtype in to_install:
        name, ctype = nameAndCtype
        for patch in to_install[nameAndCtype]:
            if os.path.isabs(patch.fromPath):
                raise Exception(
                    "Source patch path '%s' is absolute, but it must be relative to %s directory"
                    % (patch.fromPath,
                       os.path.join(sourcePatchesDir, name + '-' + ctype,
                                    platform.os + '-' + platform.osver)))
            sourcePatchPath = os.path.join(sourcePatchesDir,
                                           name + '-' + ctype,
                                           platform.os + '-' + platform.osver,
                                           patch.fromPath)
            if not os.path.exists(sourcePatchPath):
                raise Exception(
                    "Path '%s' does not exist in source patch directory" %
                    sourcePatchPath)
            if os.path.isabs(patch.toPath):
                targetPatchPath = patch.toPath
            else:
                targetPatchPath = os.path.join(rootpath, patch.toPath)

            r = uHCL.Request(host_id=host_id, user='******', group='root')
            r.transfer('1', sourcePatchPath, targetPatchPath)
            r.perform()
    return to_install
Example #8
0
def schedule_update_windows_slave(task_item):
    # Preparing HCL request for scheduling agent upgrade via asyncExec.exe
    remote_temp_dir = get_remote_temp_dir(task_item.host)
    remote_async_exec_path = get_remote_async_exec_path(task_item.host)

    schedule_request = uHCL.Request(host_id=task_item.host.host_id, auto_export=True)
    schedule_request.mkdir(remote_temp_dir)
    schedule_request.fetch(
        srcfile=posixpath.basename(task_item.paagent_dist_url),
        urls=[posixpath.dirname(task_item.paagent_dist_url)],
        dstvar="archive"
    )
    schedule_request.extract("${archive}", remote_temp_dir)

    schedule_cmd_args = [
        remote_async_exec_path,
        '--delay 10',
        '--cluster',
        '--checkmutex {mutex}'.format(mutex=agent_msi_mutex),
        '--anchor {anchor}'.format(anchor=agent_anchor_name),
        '"{paagent_exe} /c /qn /l {update_log} REBOOT=Suppress AUTO_UPGRADE=1"'.format(
            paagent_exe=PAAGENT_EXE_FILENAME, update_log=WIN_UPGRADE_LOG)
    ]

    # With 'retvar' option we will catch return code and will not fail if it is not eq 0
    schedule_request.command(remote_async_exec_path, schedule_cmd_args, cwd=remote_temp_dir,
                             stderr="err", stdout="out", retvar="exit_code")

    uLogging.debug("Scheduling agent upgrade on Windows host {host}.".format(host=task_item.host))
    uLogging.debug("Executing {async_exec_launch}".format(async_exec_launch=" ".join(schedule_cmd_args)))
    schedule_result = schedule_request.performCompat()
    schedule_return_code = int(schedule_result['exit_code'])

    if schedule_return_code < 100:
        if schedule_return_code == 12:
            uLogging.info(
                "Agent upgrade on host {host} is running already. Skip scheduling.".format(host=task_item.host)
            )
        elif schedule_return_code != 0:
            err_msg = "Scheduling windows update on host {host} failed. AsyncExec exit code: {exit_code}; " \
                      "stdout: {out}; stderr: {err}".format(host=task_item.host, exit_code=schedule_result['exit_code'],
                                                            out=schedule_result['out'], err=schedule_result['err'])
            uLogging.err(err_msg)
            raise uUtil.ExecFailed(command=" ".join(schedule_cmd_args), status=schedule_result['exit_code'],
                                   out=schedule_result['out'], err=schedule_result['err'])
Example #9
0
def check_net_bandwidth_for_host(host):
    uLogging.info("Checking bandwidth between MN and host {host}".format(host=host))
    bandwidth_report = HostBandwidthReport(host)

    try:
        file_for_test = FileForSpeedtest()
        test_request = uHCL.Request(host_id=host.host_id)
        test_request.fetch(srcfile=file_for_test.file_name, urls=[file_for_test.site_url],
                           dstvar="dummy_speedtest_file")
        test_request.rm(path="${dummy_speedtest_file}")
        execution_time = measure_hcl_execution_time(request=test_request)
        bandwidth_report.measuring_finished = True
        bandwidth_report.calc_mbps(execution_time=execution_time, file_size_bytes=file_for_test.size_bytes)
        uLogging.debug(bandwidth_report)
    except Exception as e:
        uLogging.save_traceback()
        bandwidth_report.failure_reason = e
        uLogging.warn(str(bandwidth_report))
    finally:
        return bandwidth_report
Example #10
0
 def _start_stop(cls, command):
     if not command:
         uLogging.info('...requested operation is not defined for %s' %
                       cls.name)
         return
     request = uHCL.Request(cls.get_host_id(), user='******', group='root')
     request.command(command,
                     stdout='stdout',
                     stderr='stderr',
                     retvar='retvar')
     output = request.perform()
     if output['retvar'] != '0':
         if not (command == cls.stopCmd and output['retvar'] == '1'
                 and 'STOPPED' in output['stdout']):
             raise Exception(
                 "Command '%s' failed. Return code: %s, \n stdout: %s \n stderr: %s"
                 % (command, output['retvar'], output['stdout'],
                    output['stderr']))
     uLogging.debug('done, output \n%s' % output['stdout'])
     return output
Example #11
0
 def configure(cls):
     uLogging.info('Running billing configure')
     request = uHCL.Request(cls.get_host_id(), user='******', group='root')
     request.command(cls.configureScript,
                     stdout='stdout',
                     stderr='stderr',
                     retvar='retvar')
     output = request.perform()
     # w/a for POA-114760 (null error message if script outrput is too long). Need to check retvar explicitly,
     if output['retvar'] != '0':
         uLogging.err(
             "Command '%s' failed. Return code: %s, \n stdout: %s \n stderr: %s"
             % (cls.configureScript, output['retvar'], output['stdout'],
                output['stderr']))
         raise Exception(
             "Command '%s' failed. Return code: %s, \n stdout: %s \n stderr: %s"
             % (cls.configureScript, output['retvar'],
                output['stdout'][-4048:], output['stderr'][-4048:]))
     uLogging.debug('done, output \n%s' % output['stdout'])
     return output
Example #12
0
def checkURLAccessFromServiceNodes(hosts_to_check, url, in_precheck=False, proxy=""):
    problem_hosts = []

    for host in hosts_to_check:
        try:
            proxy_arg = ""
            if proxy:
                proxy_arg = "--proxy %s" % proxy
            request = uHCL.Request(host.host_id, user='******', group='root')
            # HTTP 301 redirect for requesting folders w/o trailing slash
            request.command(
                "curl -o /dev/null --silent --head -L --write-out '%%{http_code}' %s %s" % (url, proxy_arg), stdout='stdout', stderr='stderr', valid_exit_codes=range(0, 100))
            output = request.performCompat()
            if output['stdout'] != "200":
                uLogging.err('URL "%s" is not accessible from host "%s": HTTP response code is "%s"' % (
                    url, host, output['stdout']))
                problem_hosts += [(host, 'HTTP response code for %s is %s' % (url, output['stdout']))]
        except Exception, e:
            uUtil.logLastException()
            problem_hosts += [(host, str(e))]
        except:
Example #13
0
    return rv


def ping(host_id):
    ip = getHostCommunicationIP(host_id)
    port = 8352
    try:
        if ip:
            uURLChecker.try_connect((ip, port), 2)
    except socket.error, e:
        raise Exception('Connection to host %s failed (%s). Please ensure host is online and pa-agent service is running on it.' % (ip, e))

    # node is reachable by http. remove from unreachable_hosts just in case (POA-113200)
    cleanUnreachableState(host_id)

    hcl = uHCL.Request(host_id=host_id)
    host = getHost(host_id)
    if Const.isOsaWinPlatform(host.platform.os):
        hcl.command("echo 0")
    else:
        hcl.set_creds(user='******')
        hcl.command("/bin/echo 0")
    try:
        hcl.performCompat()
        return
    except uUtil.ExecFailed:
        pass
    execCtl('pleskd_ctl', ['ping', str(host_id)])

def _execCtl(ctlname, fun, *args):
    platform, root = getMNInfo()
Example #14
0
    def precheck(cls, lpath_to_precheck_tar=None):

        host_id = cls.get_host_id()
        request = uHCL.Request(host_id, user='******', group='root')

        rpath_tmp = '/usr/local/bm/tmp'
        rpath_to_precheck = os.path.join(rpath_tmp, 'precheck')

        if lpath_to_precheck_tar:  #else prechecks is assumed already at billing host
            rpath_to_precheck_tar = os.path.join(
                rpath_tmp, os.path.basename(lpath_to_precheck_tar))

            lpath_to_poaupdater = os.path.dirname(__file__)
            rpath_to_poaupdater = os.path.join(rpath_to_precheck, 'poaupdater')

            uLogging.debug(
                'Transfer %s to %s at host %s' %
                (lpath_to_precheck_tar, rpath_to_precheck_tar, host_id))
            request.transfer('1', lpath_to_precheck_tar, rpath_tmp)

            uLogging.debug('Remove %s at host %s' %
                           (rpath_to_precheck, host_id))
            request.rm(rpath_to_precheck)

            uLogging.debug('Extract %s to %s at host %s' %
                           (rpath_to_precheck_tar, rpath_to_precheck, host_id))

            request.mkdir(rpath_to_precheck)
            extract_cmd = ('tar -xf %s -C %s' %
                           (rpath_to_precheck_tar, rpath_to_precheck))
            request.command(extract_cmd,
                            stdout='stdout',
                            stderr='stderr',
                            valid_exit_codes=[0])

            uLogging.debug('Transfer %s to %s at host %s' %
                           (lpath_to_poaupdater, rpath_to_precheck, host_id))
            request.mkdir(rpath_to_poaupdater)
            request.transfer('1', lpath_to_poaupdater, rpath_to_poaupdater)

        packages = [
            x for x in uPackaging.listInstalledPackagesOnHost(host_id)
            if is_billing_package(x.name)
        ]
        tmp = ' '.join([
            '-p %s:%s:%s:%s' % (p.name, p.version, '0', 'x86_64')
            for p in packages
        ])
        rcmd = 'python %s %s %s' % (os.path.join(
            rpath_to_precheck, 'prechecker.py'), cls.role, tmp)
        uLogging.debug('Launch %s at host %s' % (rcmd, host_id))
        request.command(rcmd,
                        stdout='stdout',
                        stderr='stderr',
                        valid_exit_codes=[0, 1, 2])

        try:
            output = request.perform()

            if output['stdout']:
                raise BillingPrecheckFailed(output['stdout'])

            if output['stderr']:
                uLogging.debug(output['stderr'])
                if 'No such file or directory' in output['stderr']:
                    uLogging.warn(
                        'It looks like prechecks were skipped during MN upgrade. Billing prechecks will be skipped too'
                    )
                else:
                    raise uPrecheck.PrecheckFailed(
                        'Several Billing prechecks were failed at %s (host id #%s).'
                        % (cls.name, host_id), '')

        except uUtil.ExecFailed, e:
            err = str(e)
            uLogging.debug(err)
            if "attribute 'src_host_id' is not declared for element 'TRANSFER'" in err:
                raise uPrecheck.PrecheckFailed(
                    'Pleskd agent at %s (host id #%s) has version lower then pleskd on MN. This may be the caused by hosts skip during previous updates.'
                    % (cls.name, host_id), "Update pleskd to 6.0.7 or higher")
            raise uPrecheck.PrecheckFailed(
                'Several Billing prechecks were failed at %s (host id #%s).' %
                (cls.name, host_id), '')