def checkRequirements2(required_updates, present_updates): con = uSysDB.connect() cur = con.cursor() cur.execute("SELECT build FROM version_history") installed = reduce(lambda s, x: s.update([x[0]]) or s, cur.fetchall(), set()) cur.execute("SELECT name FROM hotfixes") installed = reduce(lambda s, x: s.update([x[0]]) or s, cur.fetchall(), installed) # Crutch for upgrade from OA 6.5 TODO: Remove in OA 7.1 if "oa-6.5-258" in installed: installed.add("poa-6.0-3517") not_installed = required_updates - installed if not_installed == set([None]) or not_installed == set([]): not_installed = False for build_name in present_updates: for inst in installed: if PEMVersion.compareVersions(inst, build_name) > 0: raise uPrecheck.PrecheckFailed( "%s is installed, it is higher version than %s" % (inst, build_name), None) if not_installed: raise uPrecheck.PrecheckFailed("required Operation Automation versions are not installed: %s" % ', '.join( not_installed), "Install missing versions or select another update") cur.close() uSysDB.close(con)
def checkUncompatibleJDK(): uLogging.info("Checking for incompatible JDK rpms (OpenJDK)...") s = uUtil.readCmd(['rpm', '-qa', '*openjdk*', 'jdk']) rpms = s.strip().split('\n') bad_rpms = filter(lambda p: 'openjdk' in p, rpms) if bad_rpms: raise uPrecheck.PrecheckFailed('incompatible java rpms found: %s' % bad_rpms, 'replace with JDK rpm shipped with PA')
def checkNumberOfActiveTasks(): import uTasks task_number = uTasks.getNumberOfActiveTasks() if task_number > 2000: uLogging.warn("Number of active tasks in Task Manager: %s. Too many active tasks.", task_number) raise uPrecheck.PrecheckFailed("There are %s unprocessed, scheduled, running or failed tasks in Task Manager (including periodic).\nUpdate cannot be performed if this number is more than 2000" % task_number, "Cancel failed tasks or wait for them to complete.") else: uLogging.info("Number of active tasks in Task Manager: %s. OK.", task_number)
def _check_java_version(version_str): version_str = version_str.lower() if ('openjdk' not in version_str) or ('64-bit' not in version_str) or ( not re.search('openjdk version \"11\.', version_str)): raise uPrecheck.PrecheckFailed( 'incorrect JDK installed! OpenJDK 11 x64 required.', 'install JDK shipped with Operation Automation and ensure java executable is in PATH (linux) or in JAVA_HOME/bin/ (windows)' ) uLogging.debug('java version is correct')
def __get_java_version(): if os.getenv('JAVA_HOME') == None: java_path = 'java' else: java_path = os.path.join(os.getenv('JAVA_HOME'), 'bin', 'java') todo = 'ensure JDK installed and java executable is in PATH or in JAVA_HOME/bin' try: out, err, ret = uUtil.readCmdExt([java_path, '-version']) except Exception, e: raise uPrecheck.PrecheckFailed( 'can not check java version! exception %s' % e, todo)
def check_cpu_performance(min_cpu_count=4): uLogging.debug("Checking CPU performance via counting CPU cores.") uPrecheck.warn_precheck_for_deprecated_os() # because there is no multiprocessing module in Python 2.4 (RHEL5) import multiprocessing current_cpu_count = multiprocessing.cpu_count() if current_cpu_count < min_cpu_count: raise uPrecheck.PrecheckFailed("Your server doesn't meet hardware requirements, " "at least %i CPU required to install OA, " "but your server has %i CPU." % (min_cpu_count, current_cpu_count)) ok_text = "Your CPU performance is OK (required %i CPU, detected %i CPU)." % (min_cpu_count, current_cpu_count) uLogging.debug(ok_text) return ok_text
def check_unfinished_installation_tasks(): unfinished_tasks_num = uTasks.get_num_of_unfinished_installation_tasks() if not unfinished_tasks_num: uLogging.info("No unfinished installation tasks in Task Manager: OK.") else: msg = "A number of unfinished installation tasks have been fetched out during pre-check, " \ "total: %s. " \ "These issues prevent the update of being started." % unfinished_tasks_num uLogging.warn(msg) raise uPrecheck.PrecheckFailed(msg, "To resolve these issues, log in to Odin Automation, " "go to Operations > Tasks, filter the tasks by the 'Install' " "sample in their name, eliminate blocker factors " "or fix the cause of the tasks failure" "then wait for these tasks until they will finish " "with the Successful status." "Also you can cancel these tasks, but only if you know what you doing.")
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)
def check_unfinished_upgrade_modules(): if not uTasks.isModuleUpdateFinished(): raise uPrecheck.PrecheckFailed('Detected unfinished process of modules upgrading.', 'Wait until the modules update process is complete.')
def check_internal_net_bandwidth(config): """ Here we are checking network bandwidth to be sure that pa-agents will be delivered in time on all slaves during update. """ if config.skip_check_internal_net_bandwidth: uLogging.warn('Checking internal net bandwidth was skipped.') return from poaupdater import uSlaveUpdater # MB (megabytes) per second, we are assuming to utilize ethernet (100BaseT) # with host count calculated by uSlaveUpdater.max_slave_upgrade_threads() min_mbps = 1 # Initializing file for test firstly to get its instance further and undeploy it finally file_for_speedtest = FileForSpeedtest(config.communication_ip) slaves_with_agent = [host for host in get_hosts_with_agent() if int(host.host_id) != 1] uLogging.debug("Found slaves with agent: \n{slaves}".format(slaves=pprint.pformat(slaves_with_agent))) if config.skip_rpms: slaves_with_agent = filter(lambda host: Const.isOsaWinPlatform(host.platform.os), slaves_with_agent) uLogging.debug("Filtered out Linux slaves because was passed option '--skip:rpms', " "now slave list is \n{slaves}".format(slaves=pprint.pformat(slaves_with_agent))) if config.skip_win: slaves_with_agent = filter(lambda host: not Const.isOsaWinPlatform(host.platform.os), slaves_with_agent) uLogging.debug("Filtered out Windows slaves because was passed option '--skip:win', " "now slave list is \n{slaves}".format(slaves=pprint.pformat(slaves_with_agent))) if not slaves_with_agent: uLogging.debug("No slaves found, no need to check internal network bandwidth") return thread_count = uSlaveUpdater.max_slave_upgrade_threads( hosts_to_upgrade_count=len(slaves_with_agent), slave_upgrade_threads=config.slave_upgrade_threads ) uLogging.info("Checking network bandwidth between MN and slaves " "(parallel: {thread_count})".format(thread_count=thread_count)) pool = uThreadPool.ThreadPool(check_net_bandwidth_for_host) map(pool.put, slaves_with_agent) try: pool.start(thread_count) check_results = pool.get_all_non_empty_results() finally: pool.terminate() file_for_speedtest.undeploy_file_for_test() if "__iter__" not in dir(check_results) or len(check_results) < 1: raise Exception("Check for speed test returned nothing, this is unexpected") completely_failed_checks = filter(lambda result: type(result.result) is not HostBandwidthReport, check_results) if completely_failed_checks: raise Exception("Some of check has completely failed, summary report is inconsistent: \n{failed_items}".format( failed_items=pprint.pformat(completely_failed_checks))) # uThreadPool returns namedtuple ["task_item", "result", "duration"], we need only result check_results = [x.result for x in check_results] uLogging.debug("Checking reports for speed sufficiency") map(lambda report: report.calc_is_sufficient(min_mbps), check_results) uLogging.debug("Results: \n" + pprint.pformat(check_results)) failed_checks_report = [str(check_result) for check_result in check_results if not check_result.sufficient] if failed_checks_report: raise uPrecheck.PrecheckFailed( reason="detected network issue, bandwidth between MN and slave is not sufficient", what_to_do="please fix network issue for hosts reported below: \n{bandwidth_reports}".format( bandwidth_reports="\n".join(failed_checks_report) ) ) uLogging.debug("Checking network bandwidth finished successfully - all slaves are ok.")
uUtil.logLastException() problem_hosts += [(host, str(e))] except: uUtil.logLastException() problem_hosts += [(host, 'General error')] if problem_hosts: table = uTextRender.Table() table.setHeader(["host", "url", "issue"]) for issue in problem_hosts: host, error = issue table.addRow([str(host), url, error]) message = "URL %s is expected to be available from all managed hosts with pleskd RPM installed. " \ "Some of them listed bellow have access problems:\n%s" % (url, table) recommendation = "Fix accessibility problems." raise uPrecheck.PrecheckFailed(message, recommendation) def getPleskdProps(): dummy, rootpath = getMNInfo() propfile = open(os.path.join(rootpath, 'etc', 'pleskd.props')) pleskdProps = uUtil.readPropertiesFile(propfile) propfile.close() return pleskdProps def get_major_version(): con = uSysDB.connect() cur = con.cursor() cur.execute("SELECT version FROM version_history ORDER BY install_date DESC") return cur.fetchone()[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), '')
def __get_java_version(): if os.getenv('JAVA_HOME') == None: java_path = 'java' else: java_path = os.path.join(os.getenv('JAVA_HOME'), 'bin', 'java') todo = 'ensure JDK installed and java executable is in PATH or in JAVA_HOME/bin' try: out, err, ret = uUtil.readCmdExt([java_path, '-version']) except Exception, e: raise uPrecheck.PrecheckFailed( 'can not check java version! exception %s' % e, todo) if ret != 0: raise uPrecheck.PrecheckFailed( 'can not check java version! out %s, err %s, ret %s' % (out, err, ret), todo) out = out + err uLogging.debug('got java version: %s' % out) return out def _check_java_version(version_str): version_str = version_str.lower() if ('openjdk' not in version_str) or ('64-bit' not in version_str) or ( not re.search('openjdk version \"11\.', version_str)): raise uPrecheck.PrecheckFailed( 'incorrect JDK installed! OpenJDK 11 x64 required.', 'install JDK shipped with Operation Automation and ensure java executable is in PATH (linux) or in JAVA_HOME/bin/ (windows)' ) uLogging.debug('java version is correct')