Ejemplo n.º 1
0
 def test_start_postgres(self):
     """
     L{XPostgres.start_postgres} will wait for the data path to exist, clean
     up lock and socket files, and start postgres.
     """
     data_dir = self.mktemp()
     os.mkdir(data_dir, 0o700)
     dpr = DummyProcessReactor()
     xpg = XPostgres(dpr)
     sktd = self.mktemp()
     xpg.parse_command_line(['xpostgres', '-k', sktd], {'PGDATA': data_dir})
     xpg.preflight()
     started = xpg.start_postgres()
     self.assertEqual(len(dpr.spawnedProcesses), 1)
     self.assertEquals(
         list(dpr.spawnedProcesses[0]._args),
         [WAIT4PATH, os.path.abspath(xpg.data_directory)])
     # It waits for 'wait4path' to exit, then invokes PG ...
     dpr.spawnedProcesses[0].processEnded(0)
     self.assertEquals(len(dpr.spawnedProcesses), 2)
     self.assertEqual(dpr.spawnedProcesses[-1]._args,
                      [POSTGRES, '-k', sktd])
     self.assertEqual(dpr.spawnedProcesses[-1]._executable, POSTGRES)
     self.assertEqual(dpr.spawnedProcesses[-1]._environment,
                      {"PGDATA": data_dir})
     l = []
     started.addCallback(l.append)
     dpr.advance(5)
     self.assertEquals(l, [])
     sd = FilePath(sktd)
     dpr.advance(2)
     self.assertEquals(l, [])
     sd.child(".s.PGSQL.5432").touch()
     dpr.advance(2)
     self.assertEquals(l, [None])
 def test_start_postgres(self):
     """
     L{XPostgres.start_postgres} will wait for the data path to exist, clean
     up lock and socket files, and start postgres.
     """
     data_dir = self.mktemp()
     os.mkdir(data_dir, 0o700)
     dpr = DummyProcessReactor()
     xpg = XPostgres(dpr)
     sktd = self.mktemp()
     xpg.parse_command_line(
         ['xpostgres', '-k', sktd], {'PGDATA': data_dir})
     xpg.preflight()
     started = xpg.start_postgres()
     self.assertEqual(len(dpr.spawnedProcesses), 1)
     self.assertEquals(list(dpr.spawnedProcesses[0]._args),
                       [WAIT4PATH, os.path.abspath(xpg.data_directory)])
     # It waits for 'wait4path' to exit, then invokes PG ...
     dpr.spawnedProcesses[0].processEnded(0)
     self.assertEquals(len(dpr.spawnedProcesses), 2)
     self.assertEqual(dpr.spawnedProcesses[-1]._args,
                      [POSTGRES, '-k', sktd])
     self.assertEqual(dpr.spawnedProcesses[-1]._executable, POSTGRES)
     self.assertEqual(dpr.spawnedProcesses[-1]._environment,
                      {"PGDATA": data_dir})
     l = []
     started.addCallback(l.append)
     dpr.advance(5)
     self.assertEquals(l, [])
     sd = FilePath(sktd)
     dpr.advance(2)
     self.assertEquals(l, [])
     sd.child(".s.PGSQL.5432").touch()
     dpr.advance(2)
     self.assertEquals(l, [None])
Ejemplo n.º 3
0
 def test_data_directory_create(self):
     temp = self.mktemp()
     os.makedirs(temp)
     xpg = XPostgres(DummyProcessReactor())
     xpg.parse_command_line([
         "xpostgres", "-c", "unix_socket_directories=socket_dir", "-D", temp
     ], {})
     xpg.preflight()
     backup_dir = os.path.join(os.path.dirname(temp),
                               ARCHIVE_LOG_DIRECTORY_NAME)
     self.assertEqual(True, os.path.isdir(backup_dir))
     self.assertEqual(0o0700, os.stat(backup_dir).st_mode & 0o0777)
 def test_data_directory_create(self):
     temp = self.mktemp()
     os.makedirs(temp)
     xpg = XPostgres(DummyProcessReactor())
     xpg.parse_command_line(
         ["xpostgres", "-c", "unix_socket_directory=socket_dir",
          "-D", temp], {}
     )
     xpg.preflight()
     backup_dir = os.path.join(os.path.dirname(temp),
                               ARCHIVE_LOG_DIRECTORY_NAME)
     self.assertEqual(True, os.path.isdir(backup_dir))
     self.assertEqual(0o0700, os.stat(backup_dir).st_mode & 0o0777)
Ejemplo n.º 5
0
    def test_no_restore_if_tinkle_present(self):
        data_dir = self.mktemp()
        backup_dir = self.mktemp()
        os.mkdir(data_dir, 0o700)
        os.mkdir(backup_dir, 0o700)
        tinkle = os.path.join(data_dir, RESTORE_ON_ABSENCE_FILE)
        open(tinkle, "wb").close()

        xpg = XPostgres(DummyProcessReactor())
        xpg.parse_command_line([
            "xpostgres", "-c", "unix_socket_directories=socket_dir", "-D",
            data_dir
        ], {})
        xpg.preflight()
        self.assertEqual(False, xpg.restore_before_run)
    def test_no_restore_if_tinkle_present(self):
        data_dir = self.mktemp()
        backup_dir = self.mktemp()
        os.mkdir(data_dir, 0o700)
        os.mkdir(backup_dir, 0o700)
        tinkle = os.path.join(data_dir, RESTORE_ON_ABSENCE_FILE)
        open(tinkle, "wb").close()

        xpg = XPostgres(DummyProcessReactor())
        xpg.parse_command_line(
            ["xpostgres", "-c", "unix_socket_directory=socket_dir", "-D",
             data_dir], {}
        )
        xpg.preflight()
        self.assertEqual(False, xpg.restore_before_run)
Ejemplo n.º 7
0
    def test_set_restore_if_tinkle_missing(self):
        data_dir = self.mktemp()
        backup_dir = os.path.join(os.path.dirname(data_dir),
                                  ARCHIVE_LOG_DIRECTORY_NAME)
        os.mkdir(data_dir, 0o700)
        os.mkdir(backup_dir, 0o700)

        xpg = XPostgres(DummyProcessReactor())
        xpg.parse_command_line([
            "xpostgres", "-c", "unix_socket_directories=socket_dir", "-D",
            data_dir
        ], {})
        xpg.backup_zip_file.parent().createDirectory()
        xpg.backup_zip_file.touch()
        xpg.preflight()
        self.assertEqual(True, xpg.restore_before_run)
    def test_set_restore_if_tinkle_missing(self):
        data_dir = self.mktemp()
        backup_dir = os.path.join(os.path.dirname(data_dir),
                                  ARCHIVE_LOG_DIRECTORY_NAME)
        os.mkdir(data_dir, 0o700)
        os.mkdir(backup_dir, 0o700)

        xpg = XPostgres(DummyProcessReactor())
        xpg.parse_command_line([
            "xpostgres", "-c", "unix_socket_directory=socket_dir",
            "-D", data_dir],
            {}
        )
        xpg.backup_zip_file.parent().createDirectory()
        xpg.backup_zip_file.touch()
        xpg.preflight()
        self.assertEqual(True, xpg.restore_before_run)