Exemplo n.º 1
0
def get_test_versions(edition, version, specified_version, current_version):
    # Do not upgrade himself
    if specified_version and current_version and \
            compare_versions(current_version, specified_version) <= 0:
        return None
    if edition == "ent":
        archive_url = PGPRO_ARCHIVE_ENTERPRISE
    elif edition in ["std", "1c"]:
        archive_url = PGPRO_ARCHIVE_STANDARD
    else:
        raise Exception("Unsupported postgrespro edition (%s)." % edition)

    # Choose two versions -- newest and oldest supported
    soup = get_soup(archive_url)
    arcversions = []
    startswith = 'pgproee-' if edition == 'ent' else \
        ('pgpro-' if edition == 'std' else 'pg1c-')
    specified_version_found = False
    for link in soup.findAll('a'):
        href = link.get('href')
        if href.startswith(startswith) and href.endswith('/'):
            vere = re.search(r'\w+-([0-9.]+)/', href)
            if vere:
                if vere.group(1).startswith(version):
                    ver = vere.group(1)
                    if not specified_version_found and \
                            ver == specified_version:
                        specified_version_found = True
                    if version == '9.6':
                        # Due to CATALOG_VERSION_NO change
                        # we don't support lower 9.6 versions
                        if compare_versions(ver, '9.6.4.1') < 0:
                            ver = None
                    if ver:
                        arcversions.append(ver)
    arcversions.sort(key=extend_ver)
    if not arcversions:
        return None

    # Choose first and last versions
    if specified_version and not specified_version_found:
        print("Specified first version is not present in archive yet.")
        return None
    n = len(arcversions) - 1
    while n >= 0 and compare_versions(current_version, arcversions[n]) <= 0:
        n = n - 1
    if n < 0:
        return None
    res = [
        specified_version if specified_version else arcversions[0],
        arcversions[n]
    ]
    if res[0] == res[1]:
        return [res[0]]
    else:
        return res
Exemplo n.º 2
0
    def test_cfs(self, request):

        pginst = request.cls.pginst
        if not pginst.edition.startswith('ent'):
            pytest.skip("This test only for enterprise versions.")
        tablespace_path = os.path.join(os.getcwd(), 'tmp', 'cfs')
        os.mkdir(tablespace_path)
        if self.system != 'Windows':
            import pwd
            import grp
            os.chown(tablespace_path,
                     pwd.getpwnam("postgres").pw_uid,
                     grp.getgrnam("postgres").gr_gid)
        else:
            subprocess.check_call(
                'icacls "%s" /grant *S-1-5-32-545:(OI)(CI)F /T' %
                tablespace_path,
                shell=True)
            subprocess.check_call('icacls "%s" /grant *S-1-5-20:(OI)(CI)F /T' %
                                  tablespace_path,
                                  shell=True)
        algorithm = 'true'
        expected_algorithm = 'zlib' \
            if self.system == 'Windows' and pginst.version != '9.6' \
            else 'zstd'
        if compare_versions(pginst.version, '12') >= 0:
            algorithm = 'zstd'
            expected_algorithm = 'zstd'
        if compare_versions(pginst.version, '13') >= 0 and \
                pginst.os_name + ' ' + pginst.os_version != \
                'Astra Linux (Smolensk) 1.5':
            algorithm = 'lz4'
            expected_algorithm = 'lz4'
        pginst.exec_psql('CREATE TABLESPACE compressed LOCATION \'%s\''
                         ' WITH (compression=\'%s\');' %
                         (tablespace_path, algorithm))
        pginst.exec_psql("CREATE TABLE tbl TABLESPACE compressed"
                         " AS SELECT i, repeat('a', 30)"
                         " FROM generate_series(0,100000) AS i;")
        cfm_present = False
        real_algorithm = ''
        for root, directories, files in os.walk(tablespace_path):
            for filename in files:
                fn, ext = os.path.splitext(filename)
                if ext == '.cfm':
                    cfm_present = True
                if fn == 'pg_compression':
                    with open(root + os.sep + fn, 'r') as f:
                        real_algorithm = f.read().strip()
                if cfm_present and real_algorithm:
                    break
            if cfm_present and real_algorithm:
                break
        assert cfm_present
        assert real_algorithm == expected_algorithm
Exemplo n.º 3
0
def get_last_version(edition, version):

    if edition == "ent":
        archive_url = PGPRO_ARCHIVE_ENTERPRISE
    elif edition in ["std", "1c"]:
        archive_url = PGPRO_ARCHIVE_STANDARD
    else:
        raise Exception("Unsupported postgrespro edition (%s)." % edition)

    # Choose two versions -- newest and oldest supported
    soup = get_soup(archive_url)
    arcversions = []
    startswith = 'pgproee-' if edition == 'ent' else \
        ('pgpro-' if edition == 'std' else 'pg1c-')
    for link in soup.findAll('a'):
        href = link.get('href')
        if href.startswith(startswith) and href.endswith('/'):
            vere = re.search(r'\w+-([0-9.]+)/', href)
            if vere:
                if vere.group(1).startswith(version):
                    ver = vere.group(1)
                    if version == '9.6':
                        # Due to CATALOG_VERSION_NO change
                        # we don't support lower 9.6 versions
                        if compare_versions(ver, '9.6.4.1') < 0:
                            ver = None
                    if ver:
                        arcversions.append(ver)
    arcversions.sort(key=extend_ver)
    return arcversions[-1]
Exemplo n.º 4
0
 def test_pgprobackup_internal(self, request):
     if request.cls.skip:
         print("PgProBackup test is only for postgrespro std and ent.")
         return
     self.pginst = request.cls.pginst
     if sys.version_info > (3, 0) and \
             compare_versions(self.version, '2.4.5') < 0:
         print("Only 2 python temporary supported")
         return
     if self.system == 'Windows':
         print("Only linuxes temporary supported")
         return
     self.version = request.cls.version
     self.bindir = self.pginst.get_bin_path() + os.sep
     os.environ['PATH'] = os.environ['PATH'] + ':' + self.bindir
     tar_file = self.download_source()
     print(tar_file)
     tar = tarfile.open(tar_file, "r:gz")
     tar.extractall()
     tar.close()
     dir = '.'.join(tar_file.split('.')[:-2])
     print(dir)
     # Patch tests for 2.4.2
     if self.version == '2.4.2':
         urlretrieve('https://github.com/postgrespro/pg_probackup/raw/8147'
                     '001/tests/incr_restore.py',
                     os.path.join(dir, 'tests', 'incr_restore.py'))
     self.fix_permissions(dir)
     subprocess.check_call('pip%s install testgres%s' %
                           (sys.version_info[0],
                            '==1.8.2' if sys.version_info[0] == 2 else ''),
                           shell=True)
     # PGPRO-4108 wait ptrack2.0 in 10
     cmd = "%s sh -c 'PG_CONFIG=\"%s/pg_config\"" \
           " LANG=C PG_PROBACKUP_PTRACK=%s " \
           " PG_PROBACKUP_TEST_BASIC=ON python%s -m unittest -v tests'" \
           % (self.pginst.pg_sudo_cmd, self.pginst.get_bin_path(),
              'ON' if compare_versions(self.pginst.version, '10') > 0
              else 'OFF',
              '2.7' if self.pginst.os_name in REDHAT_BASED and
              self.pginst.os_version.startswith('6') else
              sys.version_info[0])
     print(subprocess.check_output(cmd, cwd=dir, shell=True).decode())
     print("OK")
Exemplo n.º 5
0
def generate_db(pg, pgnew, custom_dump=None, on_error_stop=True):
    key = "-".join([pg.product, pg.edition, pg.version])
    dump_file_name = download_dump(pg.product, pg.edition, pg.version, tempdir,
                                   custom_dump)
    with open(os.path.join(tempdir, 'load-%s.log' % key), 'wb') as out:
        pg.exec_psql_file(dump_file_name,
                          '-q%s' %
                          (' -v ON_ERROR_STOP=1' if on_error_stop else ''),
                          stdout=out)
    if compare_versions(pg.version, '12') < 0 and \
            compare_versions(pgnew.version, '12') >= 0:
        pg.do_in_all_dbs(prepare_for_12_plus_sql)
    if compare_versions(pg.version, '13') < 0 and \
            compare_versions(pgnew.version, '13') >= 0:
        pg.do_in_all_dbs(prepare_for_13_plus_sql)
    # wait for 12.5
    if pg.version == '12':
        pg.exec_psql('DROP TABLE IF EXISTS test_like_5c CASCADE',
                     '-d regression')
    if pgnew.edition in ['ent', 'ent-cert'] and \
            pg.edition not in ['ent', 'ent-cert']:
        pg.do_in_all_dbs(remove_xid_type_columns_sql)
    expected_file_name = os.path.join(tempdir, "%s-expected.sql" % key)
    dumpall(pgnew, expected_file_name)
Exemplo n.º 6
0
    def test_hotstandby_compat(self, request):
        """
        Scenario:
        1. Install current version
        2. Check that setup successfull (select version)

        :return:
        """
        global windows_os
        if self.system == 'Linux':
            dist = " ".join(get_distro()[0:2])
        elif self.system == 'Windows':
            dist = 'Windows'
            windows_os = True
        else:
            raise Exception("OS %s is not supported." % self.system)
        version = request.config.getoption('--product_version')
        name = request.config.getoption('--product_name')
        edition = request.config.getoption('--product_edition')
        milestone = request.config.getoption('--product_milestone')
        target = request.config.getoption('--target')
        product_info = " ".join([dist, name, edition, version])
        tag_mark = allure.label(LabelType.TAG, product_info)
        request.node.add_marker(tag_mark)
        branch = request.config.getoption('--branch')

        if name != 'postgrespro':
            print("Hot Standby compatibility test is only for postgrespro.")
            return
        if edition == "ent":
            archive_url = PGPRO_ARCHIVE_ENTERPRISE
        elif edition == "std":
            archive_url = PGPRO_ARCHIVE_STANDARD
        else:
            raise Exception("Unsupported postgrespro edition (%s)." % edition)
        print("Running on %s." % target)

        # Choose two versions -- newest and oldest supported
        soup = get_soup(archive_url)
        arcversions = []
        startswith = 'pgproee-' if edition == 'ent' else \
            ('pgpro-' if edition == 'std' else 'pg1c-')
        for link in soup.findAll('a'):
            href = link.get('href')
            if href.startswith(startswith) and href.endswith('/'):
                vere = re.search(r'\w+-([0-9.]+)/', href)
                if vere:
                    if vere.group(1).startswith(version):
                        arcvers = vere.group(1)
                        if version == '9.6':
                            # Due to CATALOG_VERSION_NO change
                            # we don't support lower 9.6 versions
                            if compare_versions(arcvers, '9.6.4.1') < 0:
                                arcvers = None
                        # PGPRO-3227, PGPRO-3834
                        if windows_os and version == '10':
                            if compare_versions(arcvers, '10.11.1'):
                                arcvers = None
                        if windows_os and version == '11':
                            if compare_versions(arcvers, '11.6.1') < 0:
                                arcvers = None
                        if arcvers:
                            arcversions.append(arcvers)
        arcversions.sort(key=extend_ver)
        if not arcversions:
            print("No previous minor versions found. Test skipped.")
            return
        # Choose first and last versions
        testversions = [arcversions[0], arcversions[-1]]
        if testversions[0] == testversions[1]:
            testversions = [testversions[0]]
        # Workaround for unsupported libpq options
        fix_extra_libpq_options = False
        if edition == 'ent' and version == '10':
            if compare_versions(arcversions[0], '10.4.1') < 0:
                fix_extra_libpq_options = True
        pre12version = version in ['9.6', '10', '11']

        if windows_os:
            waldir = r'C:\tmp\pgwal'
            srcdir = r'C:\tmp'
        else:
            waldir = os.path.join(tempfile.gettempdir(), 'pgwal')
            srcdir = '/var/src'

        pgsrcdir = None

        for oldversion in testversions:
            print("Installing", oldversion)
            pgold = PgInstall(product=name, edition=edition,
                              version=oldversion, milestone='archive',
                              branch=None, windows=windows_os)

            pgold.setup_repo()
            if not windows_os:
                pgold.install_base()
                pgold.initdb_start()
            else:
                pgold.install_postgres_win()

            setup_pgpass('replicator', 'replicator')

            server_version = pgold.get_server_version()
            client_version = pgold.get_psql_version()
            print("Old server version:\n%s\nOld client version:\n%s" %
                  (server_version, client_version))
            pgold.exec_psql('ALTER SYSTEM SET port=15432')
            oldpgprefix = pgold.get_pg_prefix()
            olddatadir = pgold.get_datadir()
            if oldpgprefix == '/usr':
                raise Exception("/usr as postgres prefix is not supported.")
            if pgold.get_configdir() != pgold.get_datadir():
                raise Exception("Separate config dir is not supported.")
            pgold.stop_service()
            time.sleep(5)
            if not windows_os:
                subprocess.check_call('cp -a "%s" "%s.old"' %
                                      (oldpgprefix, oldpgprefix), shell=True)
                subprocess.check_call('cp -a "%s" "%s.old"' %
                                      (olddatadir, olddatadir), shell=True)
                oldpgprefix += ".old"
                olddatadir += ".old"
            else:
                print('xcopy /S /E /O /X /I /Q "%s" "%s.old"' %
                      (oldpgprefix, oldpgprefix))
                subprocess.check_call('xcopy /S /E /O /X /I /Q "%s" "%s.old"' %
                                      (oldpgprefix, oldpgprefix), shell=True)
                oldpgprefix += ".old"
                olddatadir = os.path.join(oldpgprefix, 'data')
                if os.path.exists(os.path.join(olddatadir,
                                               'postgresql.conf.old')):
                    os.remove(os.path.join(olddatadir, 'postgresql.conf.old'))

            pgold.remove_full(remove_data=True)

            pgold.pg_prefix = oldpgprefix
            pgold.datadir = olddatadir
            pgold.configdir = olddatadir
            pgold.port = 15432
            if not windows_os:
                pgold.pg_preexec = 'sudo -u postgres ' \
                                   'LD_LIBRARY_PATH=${LD_LIBRARY_PATH} '
                old_env = os.environ.copy()
                old_env["LD_LIBRARY_PATH"] = os.path.join(oldpgprefix, 'lib')
                pgold.env = old_env
            else:
                subprocess.check_call(
                    'sc create postgres-old binpath= '
                    '"\\"%s\\" runservice -N postgres-old -D \\"%s\\" -w"'
                    ' start= demand obj= "NT Authority\\NetworkService" ' %
                    (os.path.join(oldpgprefix, 'bin', 'pg_ctl'), olddatadir),
                    shell=True)
                pgold.service_name = 'postgres-old'

            pgnew = PgInstall(product=name, edition=edition,
                              version=version, milestone=milestone,
                              branch=branch, windows=windows_os)
            pgnew.setup_repo()
            if not windows_os:
                pgnew.install_base()
                pgnew.initdb_start()
            else:
                pgnew.install_postgres_win()
            if not pgsrcdir:
                pgsrcdir = prepare_pg_regress(pgnew, srcdir)
            pgnew.stop_service()
            pgnew.remove_data()

            # Test replication from old to new
            setup_sender(pgold, waldir, pgnew.get_datadir())
            start_receiver(pgnew, waldir, pre12version)

            run_hs_test(pgold, pgnew, pgsrcdir)

            do_server_action(pgnew, "stop")
            do_server_action(pgold, "stop")

            # Test replication from new to old
            pgnew.init_cluster(force_remove=True)
            pgold.remove_data()
            setup_sender(pgnew, waldir, pgold.get_datadir())
            if fix_extra_libpq_options:
                workaround_for_extra_libpq_options(pgold)
            start_receiver(pgold, waldir, pre12version)

            run_hs_test(pgnew, pgold, pgsrcdir)

            do_server_action(pgnew, "stop")
            do_server_action(pgold, "stop")

            pgnew.remove_full(remove_data=True)
            shutil.rmtree(olddatadir)
            shutil.rmtree(oldpgprefix)
            if windows_os:
                subprocess.check_call('sc delete postgres-old', shell=True)
        print("OK")
Exemplo n.º 7
0
    def test_upgrade_minor(self, request):
        """
        Scenario:
        1. Install current version
        2. Check that setup successfull (select version)

        :return:
        """
        global windows_os
        distro = get_distro()
        if distro[2] == 'x86_64' or self.system == 'Windows':
            distro = distro[:-1]
        dist = " ".join(distro)
        if self.system == 'Linux':
            windows_os = False
        elif self.system == 'Windows':
            windows_os = True
        else:
            raise Exception("OS %s is not supported." % self.system)

        version = request.config.getoption('--product_version')
        name = request.config.getoption('--product_name')
        edition = request.config.getoption('--product_edition')
        milestone = request.config.getoption('--product_milestone')
        target = request.config.getoption('--target')
        product_info = " ".join([dist, name, edition, version])
        tag_mark = allure.label(LabelType.TAG, product_info)
        request.node.add_marker(tag_mark)
        branch = request.config.getoption('--branch')
        if edition not in ['std', 'ent', '1c']:
            print("Minor upgrade only for 1c, std and ent")
            return
        if name != 'postgrespro':
            print("Minor upgrade test is only for postgrespro.")
            return

        small_key = "-".join([name, edition, version])
        specified_version = False
        if dist in ARCHIVE_VERSIONS \
                and small_key in ARCHIVE_VERSIONS[dist]:
            specified_version = ARCHIVE_VERSIONS[dist][small_key]

        if specified_version is None:
            return "%s %s %s does not support archived versions on %s." % \
                (name, edition, version, dist)
        print("specified version is %s" % specified_version)
        print("Running on %s." % target)
        pgnew = PgInstall(product=name,
                          edition=edition,
                          version=version,
                          milestone=milestone,
                          branch=branch,
                          windows=windows_os)
        if pgnew.os.is_altlinux() and pgnew.os.os_arch == 'aarch64':
            os.environ['LANG'] = 'en_US.UTF-8'
        pgnew.setup_repo()
        if not windows_os:
            pgnew.install_full()
            subprocess.check_call('cp -a "%s" "%s"' %
                                  (pgnew.get_pg_prefix(), client_dir),
                                  shell=True)
            pgnew.remove_full(False, True)
            pgnew.remove_data(True)
            # PGPRO-3310
            if pgnew.os_name in DEBIAN_BASED:
                remove_alternatives()
        else:
            pgnew.install_postgres_win()
            pgnew.stop_service()
            subprocess.check_call('xcopy /S /E /O /X /I /Q "%s" "%s"' %
                                  (pgnew.get_pg_prefix(), client_dir),
                                  shell=True)
            pgnew.remove_full(True)
        pgconfig = subprocess.check_output(
            '"%s"' % os.path.join(client_dir, 'bin', 'pg_config'),
            shell=True).decode(ConsoleEncoding)
        vere = re.search(r'PGPRO\_VERSION\s=\s([0-9.]+)', pgconfig)
        if (vere):
            current_ver = vere.group(1)
        else:
            vere = re.search(r'VERSION\s=\s\w+\s([0-9.]+)', pgconfig)
            current_ver = vere.group(1)
        print("Current version is %s" % current_ver)
        test_versions = get_test_versions(edition, version, specified_version,
                                          current_ver)

        if test_versions is None:
            print("No archive versions found.")
            return

        print(test_versions)

        dump_file_name = download_dump(name, edition, version + '-old',
                                       tempdir)

        for oldversion in test_versions:
            print("Installing", oldversion)
            key = "-".join([name, edition, oldversion])
            pgold = PgInstall(product=name,
                              edition=edition,
                              version=oldversion,
                              milestone='archive',
                              branch=None,
                              windows=windows_os)
            if pgold.os.is_altlinux() and pgold.os.os_arch == 'aarch64':
                os.environ['LANG'] = 'en_US.UTF-8'

            pgold.setup_repo()
            if not windows_os:
                # PGPRO-3889
                if (pgold.os_name.startswith('CentOS') or
                    pgold.os_name.startswith('Red Hat') or
                    pgold.os_name.startswith('Oracle Linux')) and \
                        pgold.os_version.startswith('8'):
                    for pkg in pgold.all_packages_in_repo[:]:
                        if ('jit' in pkg):
                            pgold.all_packages_in_repo.remove(pkg)
                if (pgold.os_name.startswith('SLES')
                        and pgold.os_version.startswith('15')):
                    for pkg in pgold.all_packages_in_repo[:]:
                        if 'zstd' in pkg:
                            pgold.all_packages_in_repo.remove(pkg)
                # PGPRO-2954
                for pkg in pgold.all_packages_in_repo[:]:
                    if 'bouncer' in pkg or 'badger' in pkg:
                        pgold.all_packages_in_repo.remove(pkg)
                if pgnew.os_name == 'ROSA Enterprise Linux Server' \
                        and pgnew.os_version.startswith('7.3') \
                        and edition == 'std' \
                        and version == '9.6' \
                        and compare_versions(oldversion, '9.6.13.1') == 0:
                    for pkg in pgold.all_packages_in_repo[:]:
                        if 'probackup' in pkg:
                            pgold.all_packages_in_repo.remove(pkg)
                pgold.install_full()
                pgold.initdb_start()
            else:
                pgold.install_postgres_win()
            pgold.load_shared_libraries()
            with open(os.path.join(tempdir, 'load-%s.log' % oldversion),
                      'wb') as out:
                pgold.exec_psql_file(
                    dump_file_name,
                    '-q%s' %
                    ('' if pgold.os_arch == 'x86' else ' -v ON_ERROR_STOP=1'),
                    stdout=out)

            expected_file_name = os.path.join(tempdir, "%s-expected.sql" % key)
            dumpall(pgold, expected_file_name)
            pgold.delete_repo()
            pgnew = PgInstall(product=name,
                              edition=edition,
                              version=version,
                              milestone=milestone,
                              branch=None,
                              windows=windows_os)
            if pgnew.os.is_altlinux() and pgnew.os.os_arch == 'aarch64':
                os.environ['LANG'] = 'en_US.UTF-8'
            pgnew.setup_repo()
            pgold.stop_service()
            if not windows_os:
                pgnew.update_all_packages()
                pgnew.start_service()
            else:
                pgnew.install_postgres_win()

            result_file_name = os.path.join(tempdir, "%s-result.sql" % key)
            dumpall(pgnew, result_file_name)
            diff_dbs(expected_file_name, result_file_name,
                     os.path.join(tempdir, "%s.sql.diff" % key))
            pgnew.stop_service()

            repo_diff = list(
                set(pgold.all_packages_in_repo) -
                set(pgnew.all_packages_in_repo))
            print("repo diff is %s" % repo_diff)
            for package in repo_diff:
                try:
                    pgold.remove_package(package)
                except Exception:
                    pass

            pgnew.remove_full(True)
            # PGPRO-3310
            if pgnew.os_name in DEBIAN_BASED:
                remove_alternatives()
            if pgold.os_name in DEBIAN_BASED and version == '9.6':
                try:
                    subprocess.check_call("apt-get purge -y 'postgres*'",
                                          shell=True)
                except Exception:
                    pass
            # PGPRO-2563
            if pgold.os_name == 'Ubuntu' and version == '9.6' and \
                    edition == 'ent':
                time.sleep(20)
Exemplo n.º 8
0
    def test_dump_restore(self, request):
        """
        Scenario:
        3. if route install upgradeble version
        7. Check that upgrade successfull (select from table)
        :return:
        """
        product_info = request.cls.product_info
        tag_mark = allure.label(LabelType.TAG, product_info)
        request.node.add_marker(tag_mark)

        key = request.cls.key
        dist = request.cls.dist

        print("Test dump-restore %s" % product_info)

        if dist in FIRST_RELEASE and key in FIRST_RELEASE[dist] and \
                FIRST_RELEASE[dist][key] is None:
            print("Platform not supported")
            return

        if key not in DUMP_RESTORE_ROUTES:
            print('No routes for dump-restore')
            return

        dump_restore_route = DUMP_RESTORE_ROUTES[key]

        pg = request.cls.pg

        if pg.os_name in DEBIAN_BASED and pg.version == '9.6':
            print("Two products 9.6 cannot be "
                  "installed simultaneously on debian-based")
            return

        for route in dump_restore_route['from']:
            initdb_params = route['initdb-params'] if \
                'initdb-params' in route else ''
            init_cluster(pg, True, initdb_params, True, False)
            stop(pg)

            old_name = route['name']
            old_edition = route['edition']
            old_version = route['version']
            old_key = "-".join([old_name, old_edition, old_version])
            if dist in FIRST_RELEASE and old_key in FIRST_RELEASE[dist]:
                if FIRST_RELEASE[dist][old_key] is None:
                    print("Distributive is not supported")
                    continue
                if compare_versions(FIRST_RELEASE[dist][old_key],
                                    get_last_version(old_edition,
                                                     old_version)) > 0:
                    print("Wait for %s" % FIRST_RELEASE[dist][old_key])
                    continue

            print("=====Check dump-restore from %s" % old_key)

            file_name = os.path.join(tempdir, "%s.sql" % old_key)

            if (os.path.isfile(file_name)):
                start(pg)
                with open(os.path.join(tempdir, 'load-dr-%s.log' % old_key),
                          'wb') as out:
                    pg.exec_psql_file(file_name, '-q', stdout=out)
                dump_and_diff_dbs(old_key, pg, 'dump-restore')
                stop(pg)
            else:
                pgold = install_server(product=old_name,
                                       edition=old_edition,
                                       version=old_version,
                                       milestone=None,
                                       branch=None,
                                       windows=(self.system == 'Windows'),
                                       old=True)
                if self.system != 'Windows':
                    init_cluster(pgold, True, initdb_params, None, True)

                generate_db(
                    pgold,
                    pg,
                    on_error_stop=False if pgold.os_arch == 'x86' else True)
                dumpall(pgold, file_name)
                stop(pgold)

                start(pg)
                with open(os.path.join(tempdir, 'load-dr-%s.log' % old_key),
                          'wb') as out:
                    pg.exec_psql_file(file_name, '-q', stdout=out)
                dump_and_diff_dbs(old_key, pg, 'dump-restore')
                stop(pg)
                pgold.remove_full(True,
                                  do_not_remove=[
                                      r"^libc.*", r".*icu.*", r".*zstd.*",
                                      r"^llvm.*"
                                  ])
                # PGPRO-2459
                if pgold.os_name in DEBIAN_BASED and \
                        old_name == "postgrespro" and old_version == "9.6":
                    subprocess.check_call(
                        "apt-get purge -y "
                        "postgrespro-common "
                        "postgrespro-client-common",
                        shell=True)
Exemplo n.º 9
0
    def test_upgrade(self, request):
        """
        Scenario:
        1. Install testible version
        2. if route install upgradeable version
        3. Create DB with covering dump
        4. Upgrade by pg_upgrade
        5. Check that upgrade successfull (calculate diff between dump)
        :return:
        """
        distro = get_distro()
        if distro[2] == 'x86_64' or self.system == 'Windows':
            distro = distro[:-1]
        dist = " ".join(distro)
        request.cls.dist = dist
        version = request.config.getoption('--product_version')
        name = request.config.getoption('--product_name')
        edition = request.config.getoption('--product_edition')
        milestone = request.config.getoption('--product_milestone')
        target = request.config.getoption('--target')
        product_info = " ".join([dist, name, edition, version])
        request.cls.product_info = product_info
        key = "-".join([name, edition, version])
        request.cls.key = key

        print("Running on %s." % target)

        if dist in FIRST_RELEASE and key in FIRST_RELEASE[dist] and \
                FIRST_RELEASE[dist][key] is None:
            print("Platform not supported")
            return

        if key not in UPGRADE_ROUTES:
            print('No routes for upgrade')
            return

        upgrade_route = UPGRADE_ROUTES[key]

        tag_mark = allure.label(LabelType.TAG, product_info)
        request.node.add_marker(tag_mark)
        # Install the tested version
        branch = request.config.getoption('--branch')
        pg = install_server(product=name,
                            edition=edition,
                            version=version,
                            milestone=milestone,
                            branch=branch,
                            windows=(self.system == 'Windows'))
        request.cls.pg = pg
        stop(pg)

        if pg.os_name in DEBIAN_BASED and pg.version == '9.6':
            print("Two products 9.6 cannot be "
                  "installed simultaneously on debian-based OS")
            return

        if self.system == 'Windows':
            backup_datadir_win(pg)

        for route in upgrade_route['from']:
            initdb_params = route['initdb-params'] if \
                'initdb-params' in route else ''
            init_cluster(pg, True, initdb_params, True, False)
            stop(pg)
            old_name = route['name']
            old_edition = route['edition']
            old_version = route['version']
            old_key = "-".join([old_name, old_edition, old_version])
            if dist in FIRST_RELEASE and old_key in FIRST_RELEASE[dist]:
                if FIRST_RELEASE[dist][old_key] is None:
                    print("Distributive is not supported")
                    continue
                if compare_versions(FIRST_RELEASE[dist][old_key],
                                    get_last_version(old_edition,
                                                     old_version)) > 0:
                    print("Wait for %s" % FIRST_RELEASE[dist][old_key])
                    continue

            print("=====Check upgrade from %s" % old_key)

            pgold = install_server(product=old_name,
                                   edition=old_edition,
                                   version=old_version,
                                   milestone=None,
                                   branch=None,
                                   windows=(self.system == 'Windows'),
                                   old=True)
            if self.system != 'Windows':
                init_cluster(pgold, True, initdb_params, None, True)

            generate_db(
                pgold,
                pg,
                on_error_stop=False if pgold.os_arch == 'x86' else True)
            dumpall(pgold, os.path.join(tempdir, "%s.sql" % old_key))
            stop(pgold)
            upgrade(pg, pgold)
            start(pg)
            after_upgrade(pg, pgold)
            dump_and_diff_dbs(old_key, pg, 'upgrade')
            stop(pg)
            pgold.remove_full(do_not_remove=[
                r"^libc.*", r".*icu.*", r".*zstd.*", r"^llvm.*"
            ])
            # PGPRO-2459
            if pgold.os_name in DEBIAN_BASED and \
                    old_name == "postgrespro" and old_version == "9.6" and \
                    old_edition != '1c':
                subprocess.check_call(
                    "apt-get purge -y postgrespro-common "
                    "postgrespro-client-common",
                    shell=True)