Exemplo n.º 1
0
def turnIndexToUniq(tname, idxname):
    if uSysDB.DBType != uSysDB.PgSQL:
        return
    con = uSysDB.connect()
    tab = uDBSchema.getTable(tname, con)
    idx = tab.getIndex(idxname)
    if idx is None:
        uLogging.debug("%s: no such index, it's ok", idxname)
        return
    cur = con.cursor()
    cur.execute("SELECT oid FROM pg_class WHERE relname = %s", tname)
    row = cur.fetchone()
    if not row:
        uLogging.err("Table %s does not exist", tname)
        return

    toid = row[0]
    cur.execute(
        "SELECT relname, conname FROM pg_constraint c JOIN pg_class r ON (r.oid = c.conrelid) WHERE c.confrelid = %s", toid)

    fks = [(uDBSchema.getTable(row[0], con), row[1]) for row in cur.fetchall()]
    fks = [(x[0], x[0].getConstraint(x[1])) for x in fks]

    for t, fk in fks:
        uLogging.debug("Temporarily dropping %s", fk)
        t.dropConstraint(fk.name, con)
    tab.dropIndex(idxname, con)
    tab.addConstraint(uDBSchema.UniqueKey(idxname, idx.columns), con)

    for t, fk in fks:
        uLogging.debug("Restoring %s", fk)
        t.addConstraint(fk, con)
Exemplo n.º 2
0
def handle_async_exec_error(exit_code, task_item, check_cmd_args, check_request_result):
    cluster_upgrade_err_pattern = re.compile("ERROR CODE: (.+)")
    cluster_upgrade_error_parsed = cluster_upgrade_err_pattern.search(check_request_result["out"])

    if cluster_upgrade_error_parsed is not None:
        app_code = int(cluster_upgrade_error_parsed.group(1))

        if app_code == 1604:
            uLogging.info("Agent already upgraded on host {host}".format(host=task_item.host))
        elif app_code == 3010:  # node needs to restart
            uLogging.info("Some files were locked during upgrade and a restart of node {host} is required "
                          "to complete the installation. \nWARNING: You can do it later "
                          "but before the next upgrade.".format(host=task_item.host))
        else:
            # try to interpret MSI code
            uLogging.err("Agent update on host {host} failed. MSI error: {error_description} ({error_id})."
                         "\n{manual_upgrade_instruction}".format(
                            host=task_item.host, error_description=msi_errors.get(app_code, '<unknown error>'),
                            error_id=app_code,
                            manual_upgrade_instruction=get_manual_upgrade_inst(exit_code, task_item.host)))
            raise uUtil.ExecFailed(command=" ".join(check_cmd_args), status=check_request_result['exit_code'],
                                   out=check_request_result['out'], err=check_request_result['err'])
    else:
        uLogging.err("Agent update on host {host} failed:\nUnknown Error\n{manual_upgrade_instruction}".format(
            host=task_item.host, manual_upgrade_instruction=get_manual_upgrade_inst(exit_code, task_item.host)))

        raise uUtil.ExecFailed(command=" ".join(check_cmd_args), status=check_request_result['exit_code'],
                               out=check_request_result['out'], err=check_request_result['err'])
Exemplo n.º 3
0
 def loadProgress(self, config):
     try:
         self.progress = uUtil.loadObj(config.cache, "progress.dat",
                                       PreparationProgress)
     except Exception, e:
         uLogging.err("exception while loading progress: %s" % e)
         self.progress = PreparationProgress()
Exemplo n.º 4
0
def check_mount_bind_bug():
    """Check that is possible to perform "mount --bind" command. This bug appear on PCS containers
    with outdated systemd. It was fixed (POA-99460).
    """

    # It reproducible only on containers with RHEL/CentOS 7.2, so we need to check this.
    if determinePlatform().osverfull[:2] != ('7', '2') or not os.path.isfile("/proc/user_beancounters"):
        return True

    # Trying to bindmount inner_dir to outer_dir, raising an error if "mount --bind" failed.
    outer_dir = "/root/bind_test_dir_outer"
    inner_dir = "/root/bind_test_dir_inner"

    uUtil.execCommand(["mkdir", outer_dir, inner_dir])
    try:
        uLogging.debug("Testing execution of \"mount --bind\" command started. ")
        uUtil.execCommand(["mount", "--bind", outer_dir, inner_dir])
        # Waiting 2 sec after mounting (as pointed out by Vasily Averin),
        # if inner_dir is absent in mtab, umount will return an error.
        time.sleep(2)
        uUtil.execCommand(["umount", inner_dir])
        uUtil.execCommand(["rmdir", outer_dir, inner_dir])
        uLogging.debug("Testing execution of \"mount --bind\" command successfully passed. ")
        return True
    except:
        uUtil.execCommand(["rmdir", outer_dir, inner_dir])
        uLogging.err('Precheck error: "mount --bind" command executed idly.\n')
        import sys
        sys.tracebacklimit = 0
        raise Exception('\nUnable to complete the installation. '
                        'The precheck error occurred: "mount --bind" command executed idly. '
                        'This functionality is critical for the named daemon. If you use Virtuozzo container, '
                        'then probably the systemd version in your OS repository is outdated. In this case, '
                        'you should update your systemd to the version "systemd-219-19.el7_2.3" or higher '
                        'so the "mount --bind" can be executed correctly.')
Exemplo n.º 5
0
def logLastException():
    """
    logs last exception with stack trace
    """
    import traceback
    uLogging.debug("Error trace:")
    uLogging.debug(traceback.format_exc())
    uLogging.err(str(sys.exc_info()[1]))
Exemplo n.º 6
0
def handle_win_upgrade_unknown_hcl_error(exit_code, task_item, check_cmd_args, check_request_result):
    uLogging.err("AsyncExec error detection failed. Exit code: {exit_code}; output: {raw_output}".format(
        exit_code=check_request_result["exit_code"], raw_output=check_request_result["out"]
    ))
    uLogging.err("Agent update on host {host} failed.\n{manual_upgrade_instruction}".format(
        host=task_item.host, manual_upgrade_instruction=get_manual_upgrade_inst(exit_code, task_item.host)
    ))
    raise uUtil.ExecFailed(command=" ".join(check_cmd_args), status=check_request_result['exit_code'],
                           out=check_request_result['out'], err=check_request_result['err'])
Exemplo n.º 7
0
def getHaMasterAddr(pghaSettings):
    run = lambda cmd: uUtil.runLocalCmd(cmd)
    cmdStatusSql = """PGPASSWORD=%s PGCONNECT_TIMEOUT=10 psql postgres -t -A --username=%s --host=%s --port=%d -c "select pg_is_in_recovery() " """

    # detect status of PG on DB node A
    try:
        aNodeRecoveryState = run(cmdStatusSql % (pghaSettings.monitorAccountPasswd, pghaSettings.monitorAccount, pghaSettings.aDbNode, pghaSettings.haBackendPort)).strip()
    except Exception, ex:
        uLogging.err("Failed to request DB node A with error '%s'" % ex.message)
        raise Exception("PostgreSQL on DB node A did not response. Both DB nodes should be operable")
Exemplo n.º 8
0
 def add_script_from_file(self, script):
     try:
         action_id, action_owner, action_type = parse_action_filename(
             os.path.basename(script))
     except Exception, e:
         uLogging.err(
             ' *** Upgrade action script %s will be skipped owing to malformed script name'
             % script)
         # skip unsupported files in upgrade action directories
         raise
Exemplo n.º 9
0
def waitTasksComplete(where):
    con = uSysDB.connect()
    cur = con.cursor()
    prev_num = 0
    task_status_dict = {
        # According to modules/platform/u/EAR/poakernel-ejb/src/main/clientidl/TaskManagement.idl
        "n": "not queued",
        "u": "unprocessed",
        "b": "being scheduled",
        "f": "failed",
        "s": "rescheduled",
        "e": "running",
        "r": "restarted",
        "c": "canceled"
    }
    while True:
        cur.execute(
            "SELECT t.name, t.task_id, t.status FROM tm_tasks t LEFT JOIN tm_task_references ref "
            "ON (t.task_id = ref.task_id) WHERE " + where +
            " and t.status != 'c' ORDER BY task_id")
        tasks = [(row[0], row[1], row[2]) for row in cur.fetchall()]
        if not tasks:
            return
        tasks_printable = "\n".join([
            "\tName: {0},\tID: {1},\tStatus: {2} ({3})".format(
                row[0], row[1], task_status_dict[row[2]], row[2])
            for row in tasks
        ]).strip("[]")
        uLogging.debug("Current unfinished tasks: \n" + tasks_printable)
        failed = [t for t in tasks if t[2] not in ('s', 'u', 'e', 'b')]

        if failed:
            for t in failed:
                name, tid, status = t
                cur2 = con.cursor()
                cur2.execute(
                    "SELECT action_output FROM tm_logs WHERE task_id = %s ORDER BY finished DESC",
                    tid)
                row = cur2.fetchone()
                if row:
                    output = str(row[0])
                else:
                    output = ' no output'
                uLogging.err("%s(id=%s) failed with %s", name, tid, output)
            raise Exception("There are failed update tasks")
        if prev_num != len(tasks):
            # nm, tid, status = tasks[0]
            running = ', '.join([t[0] for t in tasks if t[2] == 'e'])

            uLogging.info("%s (%s more to go)", running, len(tasks))
        else:
            sys.stdout.write('.')
            sys.stdout.flush()
        prev_num = len(tasks)
        time.sleep(1)
Exemplo n.º 10
0
def waitRequestComplete(request_id, operation, doWait):
    waiting = False
    api = OpenAPI()
    default_tried = False
    sys_stderr_written = False
    while True:
        request_status = api.pem.getRequestStatus(request_id=request_id)
        if request_status['request_status'] == 1:
            if not waiting:
                uLogging.info("%s (request %s) is not completed yet.",
                              operation, request_id)
        elif request_status['request_status'] == 2:
            uLogging.err("%s operation failed", operation)
            for e in request_status['status_messages']:
                uLogging.err('%s', e)
            doWait = False
            waiting = False
        else:
            if sys_stderr_written:
                sys.stderr.write('\n')
            uLogging.info("%s finished successfully", operation)
            return True

        if doWait and not waiting:
            uLogging.info("Waiting for %s completion (Interrupt to abort)",
                          operation)
            waiting = True
        if waiting:
            try:
                sys.stderr.write('.')
                sys_stderr_written = True
                time.sleep(3)
            except KeyboardInterrupt, e:
                doWait = False
        if doWait:
            continue

        default_error_action = uAction.get_default_error_action()
        if default_error_action and not default_tried:
            action = default_error_action
            default_tried = True
        else:
            action = uDialog.askVariants(
                'What should I do', '(A)bort',
                ['(A)bort', '(R)echeck', '(I)gnore', '(W)ait'])
        if action in ('(A)bort', 'abort'):
            raise Exception('%s failed' % operation)
        elif action in ('(I)gnore', 'ignore'):
            if sys_stderr_written:
                sys.stderr.write('\n')
            return False
        elif action in ('(W)ait'):
            doWait = True
        elif action in ('(R)echeck', 'retry'):
            waiting = doWait = False
Exemplo n.º 11
0
def dropIdentity(tab, con):
    identity_column = first(tab.columns,
                            lambda x: isinstance(x.type, uDBTypes.SerialType))
    if identity_column is None:
        uLogging.err("There is no identity column on table %s", tab.name)
        return

    cur = con.cursor()
    cur.execute("ALTER TABLE `%s` ALTER `%s` DROP DEFAULT" %
                (tab.name, identity_column.name))
    cur.execute("DROP SEQUENCE `%s`" % seq(tab.name))
Exemplo n.º 12
0
    def ln_cp(src, dst):
        try:
            if os.path.isdir(dst):
                dst = os.path.join(dst, os.path.basename(src))
            if os.path.isfile(dst):
                os.chmod(dst, stat.S_IWRITE)
                os.unlink(dst)

            shutil.copy2(src, dst)
        except Exception, e:
            uLogging.err("%s while copying %s to %s", e.__class__, src, dst)
            raise
Exemplo n.º 13
0
    def process_result(self):
        host = self.pool_result.task_item.host
        upgrade_result = self.pool_result.result
        without_exception = not isinstance(upgrade_result, Exception)
        empty_result = upgrade_result is None

        if without_exception and not empty_result and upgrade_result is True:
            self.successful = True
        elif empty_result:
            uLogging.err("Slave {host} upgrade failed. Check details in log.".format(host=host))
        else:
            uLogging.err("Slave {host} upgrade failed. Details: \n{error_as_text}".format(
                host=host, error_as_text=self.error_as_text))
Exemplo n.º 14
0
    def call(self, verb, path, headers=None, data=None, cert=None, rheaders=None):

        if isinstance(data, JsonNode):
            data = repr(data)
        elif (isinstance(data, (dict, list))):
            data = json.dumps(data)

        url = self.url + path
        uLogging.info('%s %s ...' % (verb, url))
        if headers and self.verbose:
            uLogging.debug('Request headers:\n\t%s' % "\t".join(["%s: %s" % (h, headers[h]) for h in headers.keys()]))

        if data and self.verbose:
            uLogging.debug("Request:\n%r" % data)

        if not(headers):
            headers = dict()

        req = urllib2.Request(url, headers=headers, data=data)
        req.get_method = lambda: verb

        resp = None
        try:
            if cert:
                opener = urllib2.build_opener(HTTPSClientAuthHandler(cert, cert))
                resp = opener.open(req)
            else:
                if _PYTHON_2_7_9_COMPAT:
                    context = ssl._create_unverified_context()
                    resp = urllib2.urlopen(req, context=context)
                else:
                    resp = urllib2.urlopen(req)

        except urllib2.HTTPError, error:
            contents = error.read()
            uLogging.err('API Error:')
            uLogging.err(contents)

            # APS Exceptions have the following structure (example):
            # {
            #    "code": 500,
            #    "type": "APS::Hosting::Exception",
            #    "message": "Limit for resource ..."
            # }
            # In order to allow simple processing of this exception like
            # ('something' in error.aps.message) we convert this exception
            # to JSON directly here.
            error.aps = API.APSExcStruct()
            if len(contents):
                error.aps = json.loads(contents, object_hook=lambda x: JsonNode(**x))
            raise error
Exemplo n.º 15
0
def verifyPostgresCertificate(pgsqlOnMaster):
    uLogging.info("Make sure PostgreSQL server.crt satisfies the installation requirements according to the KB '%s'" % PG_CERT_VERIFY_KB_URL)

    serverCrtPath = pgsqlOnMaster.get_data_dir() + "/server.crt"
    runOnMaster = pgsqlOnMaster.get_commander()
    # make sure certificate exists
    try:
        checkExists = runOnMaster("[ -e '%s' ] && echo 'OK'" % serverCrtPath)
        if checkExists.strip() != 'OK':
            raise Exception("Certificate '%s' not found" % serverCrtPath)
    except Exception, ex:
        uLogging.err(ex.message)
        exceptionMsg = "Failed to validate existence of '%s' with error '%s'. Please refer to the KB %s" % (serverCrtPath, ex.message, PG_CERT_VERIFY_KB_URL)
        uLogging.warn("\n%s\n%s\n%s" %( "*" * 150,  exceptionMsg, "*" * 150))
        raise Exception(exceptionMsg)
Exemplo n.º 16
0
def handle_win_upgrade_failure_on_http(task_item, http_respond_out):
    op_error = uHCL.readHCLOperationError(http_respond_out)

    if op_error["code"] < 0:
        uLogging.debug("HCL operation result: \n{op_error}".format(op_error=pformat(op_error)))
        raise Exception(upgrade_in_progress_msg.format(host=task_item.host))
    else:
        uLogging.err("HTTP request failed. "
                     "Error code: {code}; message: {message}, type: {type}, module: {module}".format(
                        code=op_error["code"], message=op_error["message"], type=op_error["type"],
                        module=op_error["module"]))
        uLogging.err("Agent update on host {host} failed.\n{manual_upgrade_instruction}".format(
            host=task_item.host, manual_upgrade_instruction=get_manual_upgrade_inst(0, task_item.host)))
        raise Exception("Agent upgrade on host {host} failed. "
                        "Check error messages above.".format(host=task_item.host))
Exemplo n.º 17
0
 def update_timezone(self):
     if self._has_updater():
         uLogging.debug('Update time zones: begin')
         try:
             workspace_path = self._create_workspace()
             self._update_timezone(workspace_path)
             uLogging.debug('Update time zones: end')
         except:
             uLogging.save_traceback()
             uLogging.err('Update time zones: end (fail)')
         finally:
             self._remove_workspace(workspace_path)
     else:
         uLogging.debug(
             '%s not found, skipping time zone update (%s)' %
             (self._get_updater_filename(), self._get_updater_path()))
Exemplo n.º 18
0
def tryCheckExec(instructions):
    actionBlacklist = [
    ]  # list upgrade action that should not be verified by pyChecker

    os.environ['PYCHECKER'] = '--limit 8196 --maxlines 8196 --maxlocals 8196'
    try:
        global pychecker_import, orig_import
        if pychecker_import is None:
            orig_import = __builtin__.__import__
            import pychecker.checker as checker
            pychecker_import = __builtin__.__import__
        else:
            __builtin__.__import__ = pychecker_import
    except ImportError, e:
        uLogging.err("Pychecker is not installed: not checking python scripts")
        return
Exemplo n.º 19
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'])
Exemplo n.º 20
0
def readPropertiesFile(f, fail_on_errors=True, to_array=False):
    rv = []
    line_no = 1
    for line in f:
        if line.strip().startswith('#') or not line.strip():
            continue
        pmatch = __prop_line_pattern.match(line)
        if pmatch is None:
            errmsg = "%d: '%s' bad property line" % (line_no, line)
            if fail_on_errors:
                raise Exception(errmsg)
            else:
                uLogging.err("%s", errmsg)
        else:
            rv.append((pmatch.group(1), pmatch.group(2)))
        line_no += 1

    return rv if to_array else dict(rv)
Exemplo n.º 21
0
def __assignPkgIds(output, pkglist):
    i = 0
    line = output.readline()
    while line:
        if i < len(pkglist):
            pkg = pkglist[i]
            outp = mass_import_out_pattern.match(line)
            if not outp:
                uLogging.err("Cannot understand ppm_ctl output: '%s'", line)
            oldnew, pkg_id = outp.group(1), outp.group(2)
            pkg.pkg_id = int(pkg_id)
            if oldnew == 'n':
                pkg.old = False
            elif oldnew == 'o':
                pkg.old = True
            else:
                pkg.old = None
        i += 1
        line = output.readline()
Exemplo n.º 22
0
def update_binary(pkg, rootpath):
    def do_unpack(pkg, rootpath):
        uLogging.info("Updating %s (%s)", pkg.package, pkg.tarball_location)
        arc = tarfile.open(pkg.tarball_location, 'r')
        for tarinfo in arc:
            arc.extract(tarinfo, path=rootpath)
        arc.close()

    if pkg.tarball_location is not None:
        try:
            do_unpack(pkg, rootpath)
        except IOError, e:
            if Const.isWindows() and e.errno == errno.EACCES:
                uLogging.err(
                    "Cannot unpack, file is probably locked. retrying")
                time.sleep(1)
                do_unpack(pkg, rootpath)
            else:
                raise
Exemplo n.º 23
0
def dropIdentity(tab, con):
    identity_column = first(tab.columns, lambda x: isinstance(x.type, uDBTypes.SerialType))
    if not identity_column:
        uLogging.err("There is no identity column on table %s", tab.name)
        return
    icname = identity_column.name
    cur = con.cursor()
    oid = _getTableOid(tab.name, cur)
    cur.execute(
        "SELECT ft.name, fk.name FROM sys.foreign_keys fk JOIN sys.objects ft ON (ft.object_id = fk.parent_object_id) WHERE fk.referenced_object_id = %s", oid)

    fks = [(getTable(row[0], con), row[1]) for row in cur.fetchall()]
    fks = [(x[0], x[0].getConstraint(x[1])) for x in fks]

    for ft, fk in fks:
        ft.dropConstraint(fk.name, con)

    constraints = [x for x in tab.constraints if x.refers(icname)]
    for c in constraints:
        tab.dropConstraint(c.name, con)

    was_nullable = identity_column.nullable
    new_column = Column(icname, uDBTypes.IntType(), True)
    indices = [x for x in tab.indexes if x.refers(icname)]
    for i in indices:
        tab.dropIndex(i.name, con)
    tab.renameColumn(icname, icname + '_old', con)
    tab.addColumn(new_column, con)
    cur.execute("UPDATE %s SET %s = %s" % (tab.name, icname, icname + '_old'))
    tab.dropColumn(icname + '_old', con)

    if not was_nullable:
        tab.dropNullable(icname, con)

    for c in constraints:
        tab.addConstraint(c, con)

    for i in indices:
        tab.addIndex(i, con)

    for ft, fk in fks:
        ft.addConstraint(fk, con)
Exemplo n.º 24
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
Exemplo n.º 25
0
    def fn(*args, **kwargs):
        for i in range(1, n + 1):
            uLogging.info(
                'N-times retried action "{action_name}", try {i} of {n}...'.
                format(action_name=fun.__name__, i=i, n=n))
            try:
                return fun(*args, **kwargs)
            except Exception, e:

                if i >= n:
                    uLogging.err(
                        'Failed n-times retried action "{action_name}"')
                    raise e

                uLogging.debug(
                    'Got exception in action "{action_name}", retrying after timeout {timeout} sec. '
                    'Exception message: \n{e}'.format(action_name=fun.__name__,
                                                      timeout=timeout,
                                                      e=e))
                time.sleep(timeout)
Exemplo n.º 26
0
    def __init__(self, con, dep_id, dep_type):
        self.same_host = dep_type == 'H'
        self.dep_id = dep_id
        cur = con.cursor()
        cur.execute("SELECT name, ctype, version FROM dep_packages WHERE dep_id = %s", self.dep_id)
        row = cur.fetchone()
        if row:
            self.package = (row[0], row[1], row[2])
        else:
            self.package = None

        cur.execute(
            "SELECT i.interface_id, i.service_type FROM dep_interfaces di JOIN interfaces i ON (i.interface_id = di.interface_id) WHERE di.dep_id = %s", self.dep_id)
        row = cur.fetchone()
        if row:
            self.interface = (row[0], row[1])
        else:
            self.interface = None
        if self.package is None and self.interface is None:
            uLogging.err("%d: could not determine dependency kind", dep_id)
Exemplo n.º 27
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:
Exemplo n.º 28
0
def __yum_local_deploy_package(rpms, command, **kwargs):
    file_names = []
    for rkey in rpms.keys():
        if rkey == tuple([rpms[rkey]["info"].name, "RHEL", determinePlatform().osverfull[0]]):
            rpm_file = rpms[rkey]['path']
            if not rpm_file:
                if 'strict' in kwargs and kwargs['strict'] is False:
                    continue
                else:
                    raise Exception('Unable to find rpm %s in distribution at %s' % (rpms[rkey]["info"].name, rpm_file))
            file_names.append(rpm_file)

    if file_names:
        command = ["yum", "-y", "--nogpgcheck", command] + file_names
        try:
            uUtil.execCommand(command)
        except uUtil.ExecFailed as e:
            uLogging.err("""Failed to install [%s]:\n
            Command '%s' failed\n
            Check if YUM is properly installed and configured, note that you can use option --repo-base-url to
            customize Central PA YUM URL.""" % (' '.join(file_names),  " ".join(command)))
            raise e
Exemplo n.º 29
0
def tryCheckSQL(instructions):
    actions = [
        x for x in instructions.preparation.actions
        if isinstance(x, SQLScript)
    ]
    actions += [
        x for x in instructions.pre.actions if isinstance(x, SQLScript)
    ]
    actions += [
        x for x in instructions.prepkg.actions if isinstance(x, SQLScript)
    ]
    actions += [x for x in instructions.actions if isinstance(x, SQLScript)]
    actions += [
        x for x in instructions.post.actions if isinstance(x, SQLScript)
    ]
    actions += [
        x for x in instructions.cleanup.actions if isinstance(x, SQLScript)
    ]

    # need set some value for ConcatOperator when it is not initialized naturally (when one have database connected)
    import uSysDB
    if not uSysDB.ConcatOperator:
        uSysDB.ConcatOperator = '||'

    errors = False
    for action in actions:
        for stmt in action.parsed_code():
            kind, text = stmt
            if kind in ('CREATE', 'ALTER', 'DROP'):
                uLogging.err("Action:%s, not portable statement '%s'",
                             action.id, stmt)
                errors = True
            elif kind in ('BEGIN', 'COMMIT', 'ROLLBACK'):
                uLogging.warn(
                    '%s statements are ignored, <SQL> action always implicitly begins and commits transaction',
                    kind)

    if errors:
        raise Exception('Non portable SQL in some actions')
Exemplo n.º 30
0
    def done(self, success=True):
        now = time.time()
        if not self.whats:
            uLogging.err("Internal error / unmatched do/done")
            return
        st, what, args = self.whats[-1]

        del self.whats[-1]
        wargs = what % args
        totals = now - st
        time_str = pretty_timing(totals)

        if success:
            uLogging.debug(
                "%s<%s finished %s [%s]",
                self.phase is not None and ('[' + self.phase + '] ') or '',
                '-' * (len(self.whats) + 1), wargs, time_str)
        else:
            uLogging.debug(
                "%s<%s %s failed [%s]",
                self.phase is not None and ('[' + self.phase + '] ') or '',
                '-' * (len(self.whats) + 1), wargs, time_str)