Exemple #1
0
 def fn(*args, **kwargs):
     try:
         uLogging.debug("calling mocked retriable function %s" % fun)
         return fun(*args, **kwargs)
     except Exception, e:
         uLogging.err("Retriable raised error in batch mode: %s", e)
         raise
Exemple #2
0
 def __getBaHostId():
     baHost = uBilling.PBAConf
     try:
         return baHost.get_host_id()
     except:
         uLogging.debug('Component "%s" does not exist.' % baHost.name)
         return None
Exemple #3
0
    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")
Exemple #4
0
 def mockUser(self, question=None, default=None):
     # consider 'yes' answer to every question in batch mode
     if default:
         uLogging.debug("Ignoring default value in batch mode. Value = %s" %
                        default)
     uLogging.info(question)
     uLogging.info("Yes")
     return True
Exemple #5
0
 def _writeToFile(self, filename, record):
     filePath = self._getFilePath(filename)
     f = open(filePath, 'w')
     try:
         uLogging.debug('Write to file "%s" record: "%s"' %
                        (filePath, record))
         f.write(record)
     finally:
         f.close()
Exemple #6
0
 def update(localesIds):
     if CspLocales.exists():
         uLogging.info('Updating CSP locales: %s' % localesIds)
         cspPath = CspLocales.getDirectory()
         out = subprocess.check_output(
             'cd %s && (echo "import pba_upgrade_helper"; echo "pba_upgrade_helper.update_csp_locales(%s)") | python'
             % (cspPath, localesIds),
             shell=True)
         uLogging.debug(out)
     else:
         uLogging.debug('CSP locales was not found.')
Exemple #7
0
def tuneJBoss(config):
    uLogging.debug("tuneJBoss started, scale_down: %s" % config.scale_down)
    if not Const.isWindows() and config.scale_down:
        from u import bootstrap
        jbossdir = bootstrap.getJBossDir(config.rootpath)

        uLogging.info("Tuning JBoss connection pool")
        bootstrap.execCLI(
            jbossdir, 'embed-server --server-config=%s,' % bootstrap.serverConfig + '/subsystem=datasources/data-source=pauds:write-attribute(name="max-pool-size", value="80")')
        # jboss restart required, performed after PUI deployment
    else:
        uLogging.debug("nothing done")
Exemple #8
0
    def install(localesIds, batchMode):
        try:
            oaHostId = Locales.__getOaHostId()
            baHostId = Locales.__getBaHostId()

            Locales.checkAvailability(localesIds)
            Locales.checkLimit(localesIds, oaHostId, baHostId)

            if baHostId:
                uLogging.info(
                    'Stores will be synchronized during locales update process.'
                )
                uLogging.info(
                    'Billing services will be restarted during locales update process and may be unavailable for some time.'
                )
                if not batchMode and not uDialog.askYesNo(
                        'Do you wish to continue?'):
                    uLogging.info('Locales update was rejected.')
                    return

            oaLocales = OaLocale.getAvailableLocales(oaHostId)
            baLocales = BaLocale.getAvailableLocales(baHostId)

            baNeedConfigure = False
            for localeId in localesIds:
                if localeId in oaLocales:
                    for hostId in uPEM.getAllUiHosts():
                        uiLocales = OaLocale.getAvailableLocales(hostId)
                        if localeId in uiLocales:
                            uiLocales[localeId].install(hostId)
                        else:
                            uLogging.err(
                                'OA locale "%s" was not found (hostId=%s)' %
                                (localeId, hostId))
                else:
                    uLogging.err('OA locale "%s" was not found (hostId=%s)' %
                                 (localeId, oaHostId))
                    continue
                if not baHostId:
                    continue
                if localeId in baLocales:
                    baLocales[localeId].install(baHostId)
                    baNeedConfigure = True
                else:
                    uLogging.err('BA locale "%s" was not found (hostId=%s)' %
                                 (localeId, baHostId))
                    continue

            if baHostId and baNeedConfigure:
                Locales.__configureBa(localesIds)
        except Exception as e:
            uLogging.debug(e)
Exemple #9
0
    def _init_ha_config(self, config):
        uLogging.debug("Attempting to import uHA module from %s...",
                       self._u_dir)

        sys.path.insert(0, self._u_dir)
        try:
            import uHA
            uAction.progress.do("reading OA Core HA configuration")
            uHA.init(config)
            uAction.progress.done()
            self._ha = uHA
        finally:
            sys.path.remove(self._u_dir)
Exemple #10
0
 def _readFromFile(self, filename):
     filePath = self._getFilePath(filename)
     if os.path.exists(filePath):
         f = open(filePath, 'r')
         try:
             record = f.read()
             uLogging.debug('Read from file "%s" record: "%s"' %
                            (filePath, record))
             return record
         finally:
             f.close()
     else:
         errorMessage = 'File not found: %s' % filePath
         uLogging.err(errorMessage)
         raise Exception(errorMessage)
Exemple #11
0
 def exists():
     foundCsp = len([
         pkg for pkg in uPackaging.listInstalledPackagesOnHost(1)
         if pkg.name == CspLocales.getPackage()
     ]) > 0
     if not foundCsp:
         uLogging.debug('CSP package "%s" was not found.' %
                        CspLocales.getPackage())
         return False
     if not os.path.isdir(CspLocales.getDirectory()):
         uLogging.err('CSP directory "%s" was not found.' %
                      CspLocales.getDirectory())
         return False
     if not os.path.isfile(CspLocales.getConfigurationScript()):
         uLogging.err('CSP configuration script "%s" was not found.' %
                      CspLocales.getConfigurationScript())
         return False
     return True
Exemple #12
0
def tuneDatabase(config):
    uLogging.debug("tuneDatabase started, scale_down: %s" % config.scale_down)
    if not Const.isWindows() and config.scale_down:
        uLogging.debug("tuning PgSQL")
        p = uPgSQL.PostgreSQLConfig()

        pg_conf = p.get_postgresql_conf()
        env = os.environ.copy()
        # 2147483648 bytes = 2 GB
        # 2 GB limit is set because 'shared_buffers' should be equal to 512 mb
        uUtil.readCmdExt(["odin-pg-tune", "-f", "--input-config=" + pg_conf, "--min-connections=128", "--output-config=" + pg_conf, "--memory=2147483648"], env = env)

        uLogging.debug("restarting PgSQL...")
        p.restart()
    else:
        uLogging.debug("nothing done")
Exemple #13
0
def _log_stdout(msg):
    uLogging.debug(msg)
Exemple #14
0
def _log_stderr(msg):
    uLogging.debug(msg)
Exemple #15
0
 def clear(self):
     for udlFile in self.getUdlFiles():
         uLogging.debug('Remove UDL file: "%s"' % udlFile)
         os.remove(udlFile)
     self._removeFile(self._getOaUpdaterCommandFileName())
Exemple #16
0
def _init(options):
    uLogging.init2(log_file='/var/log/pa/k8s.install.log',
                   log_file_rotation=False,
                   verbose=False)

    class PrintLogger(object):
        def __init__(self):
            self.terminal = sys.stdout

        def write(self, message):
            self.terminal.write(message)
            uLogging.debug(message)

        def flush(self):
            self.terminal.flush()

    sys.stdout = PrintLogger()

    uLogging.debug("Platform version is {0}".format(uPEM.get_major_version()))
    uLogging.debug("Command line %s " % (sys.argv))

    global _log_cmd, _log_stdout, _log_stderr

    def _log_cmd(msg):
        uLogging.info('\x1b[32m%s\x1b[0m' % msg)

    def _log_stdout(msg):
        uLogging.info(msg)

    def _log_stderr(msg):
        uLogging.info('\x1b[1m%s\x1b[0m', msg)

    global config
    config = uConfig.Config()
    openapi.initFromEnv(config)

    def use_option(key, attr, default=None, empty=True):
        if key in options:
            value = options[key]
            if value == "":
                value = empty
            setattr(config, attr, value)
        else:
            setattr(config, attr, default)

    use_option('--check', 'check')
    use_option('--install', 'install')
    use_option('--proxy', 'proxy', empty='')
    use_option('--dry-run', 'dry_run', False)
    use_option('--repo', 'prefix', default_helm_repo_prefix, empty='')
    use_option('--username', 'username', default_helm_repo_username, empty='')
    use_option('--password', 'password', default_helm_repo_password, empty='')
    use_option('--pod-network-cidr', 'pod_network_cidr',
               default_pod_networ_cidr)
    use_option('--service-cidr', 'service_cidr', default_service_cidr)

    uLogging.debug('Recognized config: \n' +
                   pprint.pformat(uUtil.stipPasswords(vars(config))))

    uSysDB.init(config)

    k8s_host = K8sHost(host_id=K8sHost.detectNodeInDB(uSysDB.connect()),
                       proxy=config.proxy,
                       dry_run=config.dry_run)
    k8s_host.set_network(pod_network_cidr=config.pod_network_cidr,
                         service_cidr=config.service_cidr)

    repo = Repo(prefix=config.prefix,
                username=config.username,
                password=config.password)

    return (k8s_host, repo)
Exemple #17
0
def _log_cmd(msg):
    uLogging.debug(msg)
Exemple #18
0
 def write(self, message):
     self.terminal.write(message)
     uLogging.debug(message)
Exemple #19
0
 def precheck(self):
     if self._ha:
         self._ha.check_configuration()
     else:
         uLogging.debug("OA Core HA is not configured")
Exemple #20
0
def _save_traceback():
    import traceback
    uLogging.debug(str(sys.exc_info()))
    uLogging.debug(traceback.format_exc())
Exemple #21
0
def make_aps_certificates(installation):
    uLogging.debug('Making APS certificates')
    KEYTOOL = "keytool"
    CRED_PATH = os.path.join(installation.rootpath, "credentials")
    APS_CRED_PATH = os.path.join(installation.rootpath, "APS", "certificates")
    PSWD = "password"
    UUID = "5c3d720e-2307-4573-9183-5ce5837e5bd5"
    OPENSSL = uCrypt._get_openssl_binary()
    CA = os.path.join(APS_CRED_PATH, 'ca.pem')
    CTRL = os.path.join(APS_CRED_PATH, 'controller.pem')
    TMPDIR = tempfile.mkdtemp()
    SSLCNF = os.path.join(TMPDIR, 'openssl.cnf')
    CAK = os.path.join(TMPDIR, 'server.key')
    CACK = os.path.join(TMPDIR, 'server_clean.key')
    CACSR = os.path.join(TMPDIR, 'server.csr')
    CACER = os.path.join(TMPDIR, 'server.pem')
    CTRLK = os.path.join(TMPDIR, 'server2.key')
    CTRLCK = os.path.join(TMPDIR, 'server_clean2.key')
    CTRLCSR = os.path.join(TMPDIR, 'server2.csr')
    CTRLCER = os.path.join(TMPDIR, 'server2.pem')

    if not os.path.isfile(CA):
        cnf = open(SSLCNF, 'w')
        cnf.write("""
		distinguished_name  = req_distinguished_name
		[req_distinguished_name]
		[v3_req]
		[v3_ca]
		""")
        cnf.close()

        server_key = """%(OPENSSL)s genrsa -des3 -out %(CAK)s
			-passout pass:%(PSWD)s 2048""" % locals()
        csr = """%(OPENSSL)s req -new -key %(CAK)s -out %(CACSR)s
			-subj "/C=RU/O=Parallels/CN=APS CA Certificate"
			-config %(SSLCNF)s
			-passin pass:%(PSWD)s""" % locals()

        del_passphrase = """%(OPENSSL)s rsa -in %(CAK)s -out %(CACK)s
		-passin pass:%(PSWD)s""" % locals()

        cacert = """%(OPENSSL)s x509 -req -days 5475 -in %(CACSR)s -signkey %(CACK)s -out %(CACER)s
		-passin pass:%(PSWD)s""" % locals()

        server_key2 = """%(OPENSSL)s genrsa -des3 -out %(CTRLK)s
			-passout pass:%(PSWD)s 2048""" % locals()
        csr2 = """%(OPENSSL)s req -new -key %(CTRLK)s -out %(CTRLCSR)s
			-subj "/C=RU/O=Parallels/OU=Controller/CN=%(UUID)s"
			-config %(SSLCNF)s
			-passin pass:%(PSWD)s""" % locals()
        del_passphrase2 = """%(OPENSSL)s rsa -in %(CTRLK)s -out %(CTRLCK)s
		-passin pass:%(PSWD)s""" % locals()

        cntcert = """%(OPENSSL)s x509 -req -days 5475 -in %(CTRLCSR)s -signkey %(CTRLCK)s -out %(CTRLCER)s
		-passin pass:%(PSWD)s""" % locals()

        cmds = [
            server_key, csr, del_passphrase, cacert, server_key2, csr2,
            del_passphrase2, cntcert
        ]

        for i in cmds:
            run(i)

        if not os.path.exists(APS_CRED_PATH):
            os.makedirs(APS_CRED_PATH)

        merge = open(CACER).read() + open(CACK).read()
        outf = open(CA, 'w')
        outf.write(merge)
        outf.close()

        merge = open(CTRLCER).read() + open(CTRLCK).read()
        outf = open(CTRL, 'w')
        outf.write(merge)
        outf.close()

        shutil.rmtree(TMPDIR)

    if not os.path.exists(CRED_PATH):
        os.makedirs(CRED_PATH)

    uLogging.debug("APS certificates completed")
Exemple #22
0
 def _removeFile(self, filename):
     filePath = self._getFilePath(filename)
     if os.path.exists(filePath):
         uLogging.debug('Remove file: "%s"' % filePath)
         os.remove(filePath)
Exemple #23
0
def run(c, valid_codes=[0]):
    uLogging.debug(c)
    c = c.replace("\n", " ")
    c = c.replace("\t", " ")
    return uUtil.execCommand(c, valid_codes)
Exemple #24
0
 def addUdlFile(self, udlFilePath, buildName):
     udlFileNewPath = self._getUdlFileNewPath(udlFilePath, buildName)
     uLogging.debug('Copy UDL file from: "%s" to: "%s"' %
                    (udlFilePath, udlFileNewPath))
     shutil.copy2(udlFilePath, udlFileNewPath)
Exemple #25
0
    sys.setdefaultencoding('utf-8')

    import getopt
    try:
        opts, args = getopt.getopt(sys.argv[1:], '',
                                   dict(_long_options).keys())
        opts = dict(opts)
    except getopt.GetoptError, err:
        print str(err)
        _print_usage()
        sys.exit(2)
    if opts and '--help' in opts:
        _print_usage()
        sys.exit(0)

    try:
        k8s_node, repo = _init(opts)
        _main(k8s_node, repo)
    except KeyboardInterrupt:
        _save_traceback()
        uLogging.debug("Keybord interrupted")
        sys.exit(3)
    except Exception, e:
        uLogging.err("%s", e)
        _save_traceback()

        if uLogging.logfile:
            uLogging.info("See additional info at %s" % uLogging.logfile.name)

        exit(1)
Exemple #26
0
 def _createDirectory(self):
     uLogging.debug('Create directory: "%s"' % self.getDirectory())
     os.makedirs(self.getDirectory())