Esempio n. 1
0
 def pre_restore(self):
     self.stop_db(context=None)
     PgBaseBackupUtil.recreate_wal_archive_dir()
     datadir = self.pgsql_data_dir
     operating_system.remove(datadir, force=True, recursive=True,
                             as_root=True)
     operating_system.create_directory(datadir, user=self.PGSQL_OWNER,
                                       group=self.PGSQL_OWNER, force=True,
                                       as_root=True)
Esempio n. 2
0
    def install(self, context, packages):
        """Install one or more packages that postgresql needs to run.

        The packages parameter is a string representing the package names that
        should be given to the system's package manager.
        """

        LOG.debug(
            "{guest_id}: Beginning PgSql package installation.".format(
                guest_id=CONF.guest_id
            )
        )

        PgBaseBackupUtil.recreate_wal_archive_dir()

        packager = pkg.Package()
        if not packager.pkg_is_installed(packages):
            try:
                LOG.info(
                    _("{guest_id}: Installing ({packages}).").format(
                        guest_id=CONF.guest_id,
                        packages=packages,
                    )
                )
                packager.pkg_install(packages, {}, 1000)
            except (pkg.PkgAdminLockError, pkg.PkgPermissionError,
                    pkg.PkgPackageStateError, pkg.PkgNotFoundError,
                    pkg.PkgTimeout, pkg.PkgScriptletError,
                    pkg.PkgDownloadError, pkg.PkgSignError,
                    pkg.PkgBrokenError):
                LOG.exception(
                    "{guest_id}: There was a package manager error while "
                    "trying to install ({packages}).".format(
                        guest_id=CONF.guest_id,
                        packages=packages,
                    )
                )
                raise
            except Exception:
                LOG.exception(
                    "{guest_id}: The package manager encountered an unknown "
                    "error while trying to install ({packages}).".format(
                        guest_id=CONF.guest_id,
                        packages=packages,
                    )
                )
                raise
            else:
                self.start_db(context)
                LOG.debug(
                    "{guest_id}: Completed package installation.".format(
                        guest_id=CONF.guest_id,
                    )
                )
Esempio n. 3
0
 def pre_restore(self):
     self.stop_db(context=None)
     PgBaseBackupUtil.recreate_wal_archive_dir()
     datadir = self.pgsql_data_dir
     operating_system.remove(datadir,
                             force=True,
                             recursive=True,
                             as_root=True)
     operating_system.create_directory(datadir,
                                       user=self.PGSQL_OWNER,
                                       group=self.PGSQL_OWNER,
                                       force=True,
                                       as_root=True)
Esempio n. 4
0
    def setUp(self):
        super(PostgresqlBackupTests, self).setUp()
        self.bkutil = PgBaseBackupUtil()

        self.b1 = [
            '000000010000000000000003', '000000010000000000000004',
            '000000010000000000000005', '000000010000000000000006',
            '000000010000000000000006.00000168.backup'
        ]

        self.b2 = [
            '000000010000000000000007', '000000010000000000000008',
            '000000010000000000000009', '000000010000000000000010',
            '000000010000000000000009.0008A168.backup'
        ]
Esempio n. 5
0
    def setUp(self):
        super(PostgresqlBackupTests, self).setUp()
        self.bkutil = PgBaseBackupUtil()

        self.b1 = ['000000010000000000000003',
                   '000000010000000000000004',
                   '000000010000000000000005',
                   '000000010000000000000006',
                   '000000010000000000000006.00000168.backup']

        self.b2 = ['000000010000000000000007',
                   '000000010000000000000008',
                   '000000010000000000000009',
                   '000000010000000000000010',
                   '000000010000000000000009.0008A168.backup']
Esempio n. 6
0
class PostgresqlBackupTests(trove_testtools.TestCase):
    # TODO(atomic77) More tests for error scenarios, edge cases and timelines

    def setUp(self):
        super(PostgresqlBackupTests, self).setUp()
        self.bkutil = PgBaseBackupUtil()

        self.b1 = ['000000010000000000000003',
                   '000000010000000000000004',
                   '000000010000000000000005',
                   '000000010000000000000006',
                   '000000010000000000000006.00000168.backup']

        self.b2 = ['000000010000000000000007',
                   '000000010000000000000008',
                   '000000010000000000000009',
                   '000000010000000000000010',
                   '000000010000000000000009.0008A168.backup']

    def tearDown(self):
        super(PostgresqlBackupTests, self).tearDown()

    def test_check_most_recent_backup(self):

        with patch.object(os, 'listdir', return_value=self.b1):
            mrb = self.bkutil.most_recent_backup_file()
            self.assertEqual(mrb, self.b1[4])
            mrbfile = self.bkutil.most_recent_backup_wal()
            self.assertEqual(mrbfile, self.b1[3])

        with patch.object(os, 'listdir', return_value=self.b1 + self.b2):
            mrb = self.bkutil.most_recent_backup_file()
            self.assertEqual(mrb, self.b2[4])
            mrbfile = self.bkutil.most_recent_backup_wal()
            self.assertEqual(mrbfile, self.b2[2])

    def test_check_most_recent_wal_list(self):

        with patch.object(os, 'listdir', return_value=self.b1):
            logs = self.bkutil.log_files_since_last_backup()
            self.assertEqual(logs, [self.b1[3]])

        with patch.object(os, 'listdir', return_value=self.b2):
            logs = self.bkutil.log_files_since_last_backup()
            self.assertEqual(logs, [self.b2[2], self.b2[3]])

        with patch.object(os, 'listdir', return_value=self.b1 + self.b2):
            logs = self.bkutil.log_files_since_last_backup()
            self.assertEqual(logs, [self.b2[2], self.b2[3]])