Пример #1
0
 def tearDown(self):
     # failback_to_original_master responsible for removing standby, but
     # the newest activated standby has no relationship with oldest one.
     # so, need to stop the newest activated master, and fail back to oldest one
     with NewEnv(PGPORT=self.port, MASTER_DATA_DIRECTORY=self.mdd):
         pgutil.failback_to_original_master(origin_mdd,
                                            socket.gethostname(), self.mdd,
                                            self.port)
Пример #2
0
    def run_test(self):
        """
        Override of SQLTestCase.  Create a base backup and start standby,
        run some SQL in primary side then promote, check if the data is
        streamed correctly.
        """
        sql_file = self.sql_file
        ans_file = self.ans_file

        Command('gpinitstandby -r', 'gpinitstandby -ra').run()
        self.assertEqual(self.standby.create(), 0)
        gpact_stdby = GpactivateStandby()
        res = self.standby.start()
        self.assertTrue(res.wasSuccessful())

        # wait for the walreceiver to start
        num_walsender = self.wait_for_walsender()
        self.assertEqual(num_walsender, 1)

        # setup script is run on primary while standby is running.
        # .in file will be substitute with runtime information, if any.
        setup_file = sql_file.replace('.sql', '_setup.sql')
        if os.path.exists(setup_file + '.in'):
            self.preprocess_file(setup_file + '.in')
        self.assertTrue(PSQL.run_sql_file(setup_file, dbname=self.db_name))

        if self.promote_using_pg_ctl:
            self.assertTrue(self.standby.promote())
        else:
            self.assertTrue(self.standby.promote_manual())

        # fetch timelineids for both primary and standby (post-promote)
        primary_tli = self.fetch_tli(os.environ.get('MASTER_DATA_DIRECTORY'))
        standby_tli = self.fetch_tli(self.standby_datadir)

        logger.info("primary tli = " + primary_tli)
        logger.info("standby tli after promote = " + standby_tli)

        # primary_tli should be less than standby_tli by 1
        self.assertTrue(int(primary_tli) + 1 == int(standby_tli))

        # SQLTestCase doesn't allow to set port.  Use environ to tell it.
        with NewEnv(PGPORT=self.standby_port,
                    MASTER_DATA_DIRECTORY=self.standby_datadir) as env:
            result = super(PromoteTestCase, self).run_test()
            return result
        # always fail back to old master after test complete
        gpact_stdby.failback_to_original_master()
Пример #3
0
 def test_run_five(self):
     for i in xrange(5):
         with NewEnv(PGPORT=self.port, MASTER_DATA_DIRECTORY=self.mdd):
             pguti = GpUtility()
             if i == 0:
                 pguti.install_standby(socket.gethostname(), self.mdd)
             # starting from second time, init standby from new master, standby_dir will be like  master_newstandby_newstandby...
             else:
                 pguti.install_standby(socket.gethostname(),
                                       os.path.join(self.mdd, 'newstandby'))
             gpact = GpactivateStandby()
             self.mdd = gpact.get_standby_dd()
             self.port = gpact.get_standby_port()
             gpact.activate()
             tinctest.logger.info("self.mdd is %s, self.port is %s" %
                                  (self.mdd, self.port))
class gpactivatestandby(StandbyRunMixin, MPPTestCase):

    master_dd = os.environ.get('MASTER_DATA_DIRECTORY')
    standby_host = ''

    def setUp(self):
        # cleanup
        cmd = Command('gpinitstandby', 'gpinitstandby -ar')
        # don't care the result in case standby is not configured
        cmd.run()

    def tearDown(self):
        # cleanup
        cmd = Command('gpinitstandby', 'gpinitstandby -ar')
        cmd.run()

    def test_wrong_dataparam(self):
        """
        Test if conflicting -d option is reported.
        @tags sanity
        """

        cmd = Command('gpactivatestandby',
                      'gpactivatestandby -a -d invalid_directory')
        cmd.run()
        results = cmd.get_results()
        expected = 'Please make sure the command gpactivatestandby is executed on current Standby host'
        expected_regex = 'Error activating standby master: Critical required file on standby \".*\" is not present'

        self.assertIn(expected, results.stdout)
        self.assertRegexpMatches(results.stdout, expected_regex)
        self.assertEqual(results.rc, 2)

    def test_from_not_running(self):
        """
        Test gpactivatestandby -f while standby is not running.
        """

        dburl = dbconn.DbURL()
        array = GpArray.initFromCatalog(dburl, utility=True)
        self.standby_host = array.master.getSegmentHostName()
        # create standby locally
        shutil.rmtree(self.basepath, True)
        try:
            os.makedirs(self.basepath)
        except OSError, e:
            if e.errno != 17:
                raise
            pass
        cmd = Command(
            'gpinitstandby', ' '.join([
                'gpinitstandby', '-a', '-s', self.standby_host, '-P',
                self.standby_port, '-F', 'pg_system:' + self.standby_datadir
            ]))
        cmd.run(validateAfter=True)

        nsender = self.wait_for_walsender()
        self.assertEqual(nsender, 1, 'replication has not begun')

        # stop standby
        cmd_str = 'pg_ctl stop -D {0}'.format(self.standby_datadir)
        cmd = Command('pg_ctl stop', cmd_str)
        cmd.run(validateAfter=True)

        datadir = os.path.abspath(self.standby_datadir)
        with NewEnv(MASTER_DATA_DIRECTORY=datadir,
                    PGPORT=self.standby_port) as env:
            cmd_str = 'pg_ctl stop -D {0}'.format(self.master_dd)
            cmd = Command('stop master before activating standby', cmd_str)
            cmd.run(validateAfter=True)
            # -f is required
            cmd = Command('gpactivatestandby', 'gpactivatestandby -af')
            cmd.run()
            # It could return 1 in case warning is emitted.
            self.assertIn(cmd.get_results().rc, (0, 1))
        pgutil.failback_to_original_master(self.master_dd, self.standby_host,
                                           self.standby_datadir,
                                           self.standby_port)