def __init__(self, config, build_info): # where to import the latest uHA module from self._u_dir = None # the module itself self._ha = None if build_info.jboss_components.distribution: # JBoss will be re-installed, take uHA # module from distributive u_dir = build_info.jboss_components.distribution u_ha = os.path.join(u_dir, "uHA.py") if os.path.isfile(u_ha): self._u_dir = u_dir if not self._u_dir: # no JBoss distributive for upgrade, check if installed # OA has uHA module u_dir = os.path.join(config.rootpath, "u") u_ha = os.path.join(u_dir, "uHA.py") if os.path.isfile(u_ha): self._u_dir = u_dir if self._u_dir: uAction.retriable(self._init_ha_config)(config) else: uLogging.debug("No uHA module found")
def _upgradeHelmPackagesGroup(self, helms_to_update, deployedReleases, group): uLogging.info('Upgrade Helm packages group: %s' % group) pkgs = helms_to_update.get(group) if not pkgs: return for pkg in self._getNewestPackages(pkgs, deployedReleases, group == HelmGroup.OPTIONAL): uAction.retriable(self._upgradeHelmPackageEx)(pkg)
def _upgradeHelmPackages(self, helms_to_update, groups_to_update): if not helms_to_update: return uAction.retriable(self._resolveLatestVersions)(sum( helms_to_update.values(), [])) deployedReleases = uAction.retriable(self._listDeployedReleases)() if deployedReleases is None: return for group in groups_to_update: self._upgradeHelmPackagesGroup(helms_to_update, deployedReleases, group)
def install(self, helms_to_update, repo_version): if not self.isHelmInstalled(): return uAction.retriable(self._setupK8sApi)() uAction.retriable(self._setupRepos)(repo_version) uAction.retriable(self._updateHelmRepo)() groups_to_install = [HelmGroup.FOUNDATION, HelmGroup.REQUIRED] uAction.retriable(self._upgradeHelmPackages)(helms_to_update, groups_to_install) uLogging.info('Helm install completed')
def action(*args, **kwargs): msg = [fn.__name__] + [str(x) for x in args ] + ['%s=%s' % x for x in kwargs.iteritems()] uAction.progress.do(' '.join(msg).replace('%', '%%')) try: return uAction.retriable(fn)(*args, **kwargs) finally: uAction.progress.done()
def upgrade(self, helms_to_update, repo_version): if not self.isHelmInstalled(): return uAction.retriable(self._upgradeHelmRepo)(repo_version) uAction.retriable(self._updateHelmRepo)() groups_to_update = [ HelmGroup.FOUNDATION, HelmGroup.REQUIRED, HelmGroup.OPTIONAL ] uAction.retriable(self._upgradeHelmPackages)(helms_to_update, groups_to_update) uLogging.info('Helm upgrade completed')
def configureSystem(config, progress, PRODUCT): from poaupdater.uAction import retriable selinux_mode = uUtil.readCmd(['getenforce']).strip() uLogging.debug("SELinux is %s" % selinux_mode) progress.set_progress(1, "Adjusting kernel memory settings") all_mem, sh_mem = getMemTotal() adjustMemSettings(PRODUCT, all_mem) gname = config.sysgroup uname = config.sysuser progress.set_progress(2, "Creating group %s" % gname) try: grpinfo = grp.getgrnam(gname) except KeyError: retriable(uUtil.execCommand)(["groupadd", "-f", gname]) grpinfo = grp.getgrnam(gname) config.sysgroupid = grpinfo.gr_gid progress.set_progress(5, "Creating user %s" % uname) try: pwdinfo = pwd.getpwnam(uname) except KeyError: retriable(uUtil.execCommand)(["useradd", "-M", uname, "-g", gname, "-d", "/nonexistent", "-s", "/bin/false"]) pwdinfo = pwd.getpwnam(uname) config.sysuserid = pwdinfo.pw_uid config.sysgroupid = pwdinfo.pw_gid uLogging.debug("dump config after configureSystem: %s" % uUtil.stipPasswords(vars(config))) uLogging.debug("Setting hostname") hostname_line_pattern = re.compile(r"HOSTNAME=.*") def sysconfig_network(inf, outf): for ln in inf.readlines(): if hostname_line_pattern.match(ln): print >> outf, 'HOSTNAME="%(hostname)s"' % vars(config) else: outf.write(ln) uUtil.editFileSafe('/etc/sysconfig/network', sysconfig_network, '/etc/sysconfig/network.pemsave') uUtil.execCommand(["hostname", config.hostname]) #install httpd + modules httpd_rpms = ["httpd", "mod_ssl"] platform = determinePlatform() if platform.osver == "6": httpd_rpms.append("mod_proxy_wstunnel") # previous call resets hostname that triggers restarting Network Manager. /etc/resolv.conf content become not valid # for a moment. Reproduced sometimes on CentOS 7 VM in Azure IAAS uUtil.execCommand(["yum", "-y", "-e", "0", "install"] + httpd_rpms, retries=5) def tweak_httpd(inf, outf): conf_orig = inf.read() conf_1 = re.sub("ServerLimit.*10", "ServerLimit 256", conf_orig) conf_2 = re.sub("MaxClients.*10", "MaxClients 256", conf_1) outf.write(conf_2) prefork_conf = '/etc/httpd/conf/httpd.conf' if os.path.exists('/etc/httpd/conf.d/mpm_prefork.conf'): prefork_conf = '/etc/httpd/conf.d/mpm_prefork.conf' uUtil.editFileSafe(prefork_conf, tweak_httpd, prefork_conf + '.save') # drop the /icons/ alias; =<2.2.*: tweak httpd.conf, >=2.4.*: rename autoindex.conf if os.path.exists('/etc/httpd/conf.d/autoindex.conf'): uUtil.moveFile('/etc/httpd/conf.d/autoindex.conf', '/etc/httpd/conf.d/autoindex.conf.save') else: uUtil.replaceInFile('/etc/httpd/conf/httpd.conf', r'(?m)^\s*Alias\s+\/icons\/\s+', '#Alias /icons/ ', True) service_control('restart', 'httpd') service_autostart('httpd') if platform.osver == "7": def tweak_journald(inf, outf): conf_orig = inf.read() conf_1 = re.sub('#RateLimitInterval.*s', 'RateLimitInterval=0', conf_orig) conf_2 = re.sub('#Storage=auto', 'Storage=none', conf_1) conf_3 = re.sub('#ForwardToSyslog=no', 'ForwardToSyslog=yes', conf_2) outf.write(conf_3) journald_conf = '/etc/systemd/journald.conf' uUtil.editFileSafe(journald_conf, tweak_journald, journald_conf + '.save') def tweak_rsyslog(inf, outf): conf_orig = inf.read() conf_1 = re.sub('\$ModLoad imjournal', '#$ModLoad imjournal', conf_orig) conf_2 = re.sub('\$IMJournalStateFile imjournal.state', '#$IMJournalStateFile imjournal.state', conf_1) conf_3 = re.sub('\$OmitLocalLogging on', '$OmitLocalLogging off', conf_2) outf.write(conf_3) rsyslog_conf = '/etc/rsyslog.conf' uUtil.editFileSafe(rsyslog_conf, tweak_rsyslog, rsyslog_conf + '.save') def tweak_unix_datagram_query_len(inf, outf): """Tweak unix datagram query length for properly forwarding logs from journald to rsyslog""" conf_orig = inf.read() qlen_regex = re.compile('\nnet\.unix\.max_dgram_qlen.*') if qlen_regex.search(conf_orig): conf_modified = qlen_regex.sub('\nnet.unix.max_dgram_qlen=500', conf_orig) else: conf_modified = conf_orig + "\nnet.unix.max_dgram_qlen=500\n" outf.write(conf_modified) sysctl_conf = "/etc/sysctl.conf" uUtil.editFileSafe(sysctl_conf, tweak_unix_datagram_query_len, sysctl_conf + ".save") # Restart all tweaked services service_control('restart', 'systemd-journald') service_control('restart', 'rsyslog') uUtil.execCommand(["sysctl", "-p"], [0, 255])
def __init__(self, k8s_repo_url=uK8s.default_helm_repo_prefix, k8s_docker_repo_host=uK8s.default_k8s_docker_repo_host): self.k8s_repo_url = k8s_repo_url self.k8s_docker_repo_host = k8s_docker_repo_host uAction.retriable(self._init_helm)()
def configure_ui(self): if self._ha: uAction.progress.do("re-configuring OA Core HA (OA UI)") uAction.retriable(self._ha.configure_ui)(start_extra_mn=True) uAction.progress.done()
def configure_mn(self): if self._ha: uAction.progress.do( "re-configuring OA Core HA (OA MN, OA DB, OA additional MN)") uAction.retriable(self._ha.configure_mn)() uAction.progress.done()
def shutdown_extra_mn(self): if self._ha: uAction.progress.do("shutting down extra MN") uAction.retriable(self._ha.shutdown_extra_mn)() uAction.progress.done()
def upgradeAgentAndRepourl(self, binfo, config, hosts_with_agent): uAction.retriable(uSlaveUpdater.upgrade_paagent_and_repourl)( binfo, config, hosts_with_agent)