예제 #1
0
 def setUp(self):
     self.buildMirrorSegs = GpMirrorListToBuild(
         toBuild = [],
         pool = None, 
         quiet = True, 
         parallelDegree = 0
         )
예제 #2
0
    def setUp(self):
        self.master = Segment(content=-1,
                              preferred_role='p',
                              dbid=1,
                              role='p',
                              mode='s',
                              status='u',
                              hostname='masterhost',
                              address='masterhost-1',
                              port=1111,
                              datadir='/masterdir')

        self.primary = Segment(content=0,
                               preferred_role='p',
                               dbid=2,
                               role='p',
                               mode='s',
                               status='u',
                               hostname='primaryhost',
                               address='primaryhost-1',
                               port=3333,
                               datadir='/primary')

        self.logger = Mock(
            spec=['log', 'warn', 'info', 'debug', 'error', 'warning', 'fatal'])
        self.apply_patches([])

        self.buildMirrorSegs = GpMirrorListToBuild(toBuild=[],
                                                   pool=None,
                                                   quiet=True,
                                                   parallelDegree=0,
                                                   logger=self.logger)
예제 #3
0
 def setUp(self):
     self.pool = Mock(spec=base.WorkerPool)
     self.buildMirrorSegs = GpMirrorListToBuild(
         toBuild=[],
         pool=self.pool,
         quiet=True,
         parallelDegree=0,
         logger=Mock(spec=logging.Logger))
예제 #4
0
    def test_pg_rewind_parallel_execution(self):
        self.apply_patches([
            # Mock CHECKPOINT command in run_pg_rewind() as successful
            patch('gppylib.db.dbconn.connect', return_value=Mock()),
            patch('gppylib.db.dbconn.execSQL', return_value=Mock()),
            # Mock the command to remove postmaster.pid as successful
            patch('gppylib.commands.base.Command.run', return_value=Mock()),
            patch('gppylib.commands.base.Command.get_return_code',
                  return_value=0),
            # Mock gplog which is used in RewindSegmentInfo below
            patch('gppylib.gplog.get_logger_dir', return_value=Mock()),
            # Mock all pg_rewind commands to be not successful
            patch('gppylib.commands.base.Command.was_successful',
                  return_value=False),
            patch('gppylib.commands.base.Command.get_stdout',
                  return_value='Mocking results'),
            patch('gppylib.commands.base.Command.results',
                  return_value=CommandResult(1, 'stdout:Failed',
                                             'stderr:Failed', True, False))
        ])
        from gppylib.operations.buildMirrorSegments import GpMirrorListToBuild
        # WorkerPool is the only valid parameter required in this test
        # case.  The test expects the workers to get a pg_rewind
        # command to run (and the command should fail to run).
        g = GpMirrorListToBuild(1, self.pool, 1, 1)
        rewindInfo = {}
        p0 = Segment.initFromString(
            "2|0|p|p|s|u|sdw1|sdw1|40000|/data/primary0")
        p1 = Segment.initFromString(
            "3|1|p|p|s|u|sdw2|sdw2|40001|/data/primary1")
        m0 = Segment.initFromString(
            "4|0|m|m|s|u|sdw2|sdw2|50000|/data/mirror0")
        m1 = Segment.initFromString(
            "5|1|m|m|s|u|sdw1|sdw1|50001|/data/mirror1")
        rewindInfo[p0.dbid] = GpMirrorListToBuild.RewindSegmentInfo(
            p0, p0.address, p0.port, "unused_timestamp")
        rewindInfo[p1.dbid] = GpMirrorListToBuild.RewindSegmentInfo(
            p1, p1.address, p1.port, "unused_timestamp")
        rewindInfo[m0.dbid] = GpMirrorListToBuild.RewindSegmentInfo(
            m0, m0.address, m0.port, "unused_timestamp")
        rewindInfo[m1.dbid] = GpMirrorListToBuild.RewindSegmentInfo(
            m1, m1.address, m1.port, "unused_timestamp")

        # Test1: all 4 pg_rewind commands should fail due the "was_successful" patch
        failedSegments = g.run_pg_rewind(rewindInfo)
        self.assertEqual(len(failedSegments), 4)
        # The returned list of failed segments should contain items of
        # type gparray.Segment
        failedSegments.remove(p0)
        self.assertTrue(failedSegments[0].getSegmentDbId() > 0)

        # Test2: patch it such that no failures this time
        patch('gppylib.commands.base.Command.was_successful',
              return_value=True).start()
        failedSegments = g.run_pg_rewind(rewindInfo)
        self.assertEqual(len(failedSegments), 0)
    def setUp(self):
        self.logger = Mock(
            spec=['log', 'warn', 'info', 'debug', 'error', 'warning', 'fatal'])
        self.apply_patches([])

        self.buildMirrorSegs = GpMirrorListToBuild(toBuild=[],
                                                   pool=None,
                                                   quiet=True,
                                                   parallelDegree=0,
                                                   logger=self.logger)
 def _run_buildMirrors(self, mirrors_to_build):
     buildMirrorSegs_obj = GpMirrorListToBuild(toBuild=mirrors_to_build,
                                               pool=None,
                                               quiet=True,
                                               parallelDegree=0,
                                               logger=self.mock_logger)
     self._setup_mocks(buildMirrorSegs_obj)
     self.assertTrue(
         buildMirrorSegs_obj.buildMirrors(self.action, self.gpEnv,
                                          self.gpArray))
     return buildMirrorSegs_obj
    def test_buildMirrors_noMirrors(self):
        buildMirrorSegs_obj = GpMirrorListToBuild(toBuild=[],
                                                  pool=None,
                                                  quiet=True,
                                                  parallelDegree=0,
                                                  logger=self.mock_logger)
        self.assertTrue(buildMirrorSegs_obj.buildMirrors(None, None, None))
        self.assertTrue(
            buildMirrorSegs_obj.buildMirrors(self.action, None, None))

        self.assertEqual(
            [call('No segments to None'),
             call('No segments to recover')],
            self.mock_logger.info.call_args_list)
 def test_buildMirrors_failed_seg_in_gparray_fail(self):
     tests = [{
         "name": "failed_seg_exists_in_gparray1",
         "failed": self.create_primary(status='d'),
         "failover": self.create_primary(status='d'),
         "live": self.create_mirror(),
         "forceFull": True,
         "forceoverwrite": False
     }, {
         "name": "failed_seg_exists_in_gparray2",
         "failed": self.create_primary(dbid='3', status='d'),
         "failover": self.create_primary(dbid='3', status='d'),
         "live": self.create_mirror(dbid='4'),
         "forceFull": False,
         "forceoverwrite": False
     }, {
         "name": "failed_seg_exists_in_gparray2",
         "failed": self.create_primary(dbid='3', status='d'),
         "failover": self.create_primary(dbid='3', status='d'),
         "live": self.create_mirror(dbid='4'),
         "forceFull": False,
         "forceoverwrite": True
     }]
     for test in tests:
         mirror_to_build = GpMirrorToBuild(test["failed"], test["live"],
                                           test["failover"],
                                           test["forceFull"])
         buildMirrorSegs_obj = GpMirrorListToBuild(
             toBuild=[
                 mirror_to_build,
             ],
             pool=None,
             quiet=True,
             parallelDegree=0,
             logger=self.mock_logger,
             forceoverwrite=test['forceoverwrite'])
         self._setup_mocks(buildMirrorSegs_obj)
         local_gp_array = GpArray([self.coordinator, test["failed"]])
         expected_error = "failed segment should not be in the new configuration if failing over to"
         with self.subTest(msg=test["name"]):
             with self.assertRaisesRegex(Exception, expected_error):
                 buildMirrorSegs_obj.buildMirrors(self.action, self.gpEnv,
                                                  local_gp_array)
    def test_buildMirrors_forceoverwrite_true(self):
        failed = self.create_primary(status='d')
        live = self.create_mirror()
        failover = self.create_primary(host='sdw3')

        buildMirrorSegs_obj = GpMirrorListToBuild(
            toBuild=[GpMirrorToBuild(failed, live, failover, False)],
            pool=None,
            quiet=True,
            parallelDegree=0,
            logger=self.mock_logger,
            forceoverwrite=True)
        self._setup_mocks(buildMirrorSegs_obj)
        self.assertTrue(
            buildMirrorSegs_obj.buildMirrors(self.action, self.gpEnv,
                                             self.gpArray))

        self._common_asserts_with_stop_and_logger(
            buildMirrorSegs_obj, "Ensuring 1 failed segment(s) are stopped",
            [failed], [failover], [], {1: True}, 0)
        self.assertEqual('n', live.getSegmentMode())
        self.assertEqual('d', failover.getSegmentStatus())
        self.assertEqual('n', failover.getSegmentMode())
    def test_clean_up_failed_segments_no_segs_to_cleanup(self):
        failed2 = self.create_primary(dbid='3', status='d')
        failover2 = self.create_primary(dbid='3', status='d')
        live2 = self.create_mirror(dbid='4')

        failed4 = self.create_primary(dbid='5')
        live4 = self.create_mirror(dbid='7')

        not_inplace_full = GpMirrorToBuild(failed2, live2, failover2, True)
        inplace_not_full = GpMirrorToBuild(failed4, live4, None, False)

        buildMirrorSegs_obj = GpMirrorListToBuild(
            toBuild=[not_inplace_full, inplace_not_full],
            pool=None,
            quiet=True,
            parallelDegree=0,
            logger=self.mock_logger,
            forceoverwrite=True)
        buildMirrorSegs_obj._GpMirrorListToBuild__runWaitAndCheckWorkerPoolForErrorsAndClear = Mock(
        )

        buildMirrorSegs_obj._clean_up_failed_segments()
        self.assertEqual(0, self.mock_get_segments_by_hostname.call_count)
        self.assertEqual(0, self.mock_logger.info.call_count)
    def test_clean_up_failed_segments(self):
        failed1 = self.create_primary(status='d')
        live1 = self.create_mirror()

        failed2 = self.create_primary(dbid='3', status='d')
        failover2 = self.create_primary(dbid='3', status='d')
        live2 = self.create_mirror(dbid='4')

        failed3 = self.create_primary(dbid='5')
        live3 = self.create_mirror(dbid='6')

        failed4 = self.create_primary(dbid='5')
        live4 = self.create_mirror(dbid='7')

        inplace_full1 = GpMirrorToBuild(failed1, live1, None, True)
        not_inplace_full = GpMirrorToBuild(failed2, live2, failover2, True)
        inplace_full2 = GpMirrorToBuild(failed3, live3, None, True)
        inplace_not_full = GpMirrorToBuild(failed4, live4, None, False)

        buildMirrorSegs_obj = GpMirrorListToBuild(toBuild=[
            inplace_full1, not_inplace_full, inplace_full2, inplace_not_full
        ],
                                                  pool=None,
                                                  quiet=True,
                                                  parallelDegree=0,
                                                  logger=self.mock_logger,
                                                  forceoverwrite=True)
        buildMirrorSegs_obj._GpMirrorListToBuild__runWaitAndCheckWorkerPoolForErrorsAndClear = Mock(
        )

        buildMirrorSegs_obj._clean_up_failed_segments()

        self.mock_get_segments_by_hostname.assert_called_once_with(
            [failed1, failed3])
        self.mock_logger.info.called_once_with(
            '"Cleaning files from 2 segment(s)')