示例#1
0
class GpConfig(GpTestCase):
    def setUp(self):

        self.gparray = self.createGpArrayWith2Primary2Mirrors()
        self.host_cache = Mock()

    def createGpArrayWith2Primary2Mirrors(self):
        master = Segment.initFromString(
            "1|-1|p|p|s|u|mdw|mdw|5432|/data/master")
        primary0 = Segment.initFromString(
            "2|0|p|p|s|u|sdw1|sdw1|40000|/data/primary0")
        primary1 = Segment.initFromString(
            "3|1|p|p|s|u|sdw2|sdw2|40001|/data/primary1")
        mirror0 = Segment.initFromString(
            "4|0|m|m|s|u|sdw2|sdw2|50000|/data/mirror0")
        mirror1 = Segment.initFromString(
            "5|1|m|m|s|u|sdw1|sdw1|50001|/data/mirror1")
        return GpArray([master, primary0, primary1, mirror0, mirror1])

    def test_GpReadConfig_creates_command_string(self):
        seg = self.gparray.master
        seg = self.gparray.master
        args = dict(name="my_command",
                    host="host",
                    seg=seg,
                    guc_name="statement_mem",)
        subject = GpReadConfig(**args)

        self.assertEquals(subject.cmdStr, "/bin/cat /data/master/postgresql.conf")

    @patch("gppylib.commands.base.Command.__init__", create=False)
    @patch("gppylib.commands.base.Command.get_results", return_value=CommandResult(0, "#statement_mem = 100\nstatement_mem = 200", "", True, False))
    @patch("gppylib.commands.base.Command.run")
    def test_GpReadConfig_returns_selected_guc(self, mock_run, mock_results, mock_init):
        seg = self.gparray.master
        args = dict(name="my_command",
                    host="host",
                    seg=seg,
                    guc_name="statement_mem",
        )

        subject = GpReadConfig(**args)

        subject.run(validateAfter=True)
        self.assertEquals('200', subject.get_guc_value())

    @patch("gppylib.commands.base.Command.__init__", create=False)
    @patch("gppylib.commands.base.Command.get_results", return_value=CommandResult(0, "statement_mem=100\n statement_mem=200 #blah", "", True, False))
    @patch("gppylib.commands.base.Command.run")
    def test_GpReadConfig_returns_selected_guc_with_whitespace_before_key(self, mock_run, mock_results, mock_init):
        seg = self.gparray.master
        args = dict(name="my_command",
                    host="host",
                    seg=seg,
                    guc_name="statement_mem",
        )

        subject = GpReadConfig(**args)

        subject.run(validateAfter=True)
        self.assertEquals('200', subject.get_guc_value())
    def test_get_stderr_after_running_returns_stderr(self):
        self.subject.set_results(CommandResult(0, "", "my stderr", True,
                                               False))

        self.assertEqual(self.subject.get_stderr(), "my stderr")
    def test_get_stdout_after_running_with_no_strip_returns_unstripped_stdout(
            self):
        self.subject.set_results(
            CommandResult(0, "  my stdout\n", "", True, False))

        self.assertEqual(self.subject.get_stdout(strip=False), "  my stdout\n")
    def test_get_stdout_after_running_returns_rc(self):
        self.subject.set_results(
            CommandResult(-23, "my stdout", "", True, False))

        self.assertEqual(self.subject.get_return_code(), -23)
示例#5
0
    def test_get_stdout_after_running_returns_stripped_stdout(self):
        self.subject.set_results(
            CommandResult(0, b"  my stdout\n", b"", True, False))

        self.assertEqual(self.subject.get_stdout(), "my stdout")