CommandResult(1, b"", b"", False, False) ]) def test_is_pid_postmaster_pgrep_failed_remote(self, mock1, mock2): pid = '1234' datadir = '/data/primary/gpseg0' remoteHost = 'scdw' self.assertTrue(is_pid_postmaster(datadir, pid, remoteHost=remoteHost)) @patch('gppylib.commands.gp.Command.run') @patch( 'gppylib.commands.gp.Command.get_results', return_value=CommandResult( 0, b"gpadmin 1234 1 0 18:48 ? 00:00:00 /usr/local/greenplum-db-devel/bin/postgres -D /tmp -p", b"", True, False)) def test_get_postmaster_pid_locally(self, mock1, mock2): self.assertEqual(get_postmaster_pid_locally('/tmp'), 1234) @patch('gppylib.commands.gp.Command.run', side_effect=Exception('Error')) def test_get_postmaster_pid_locally_error(self, mock1): self.assertEqual(get_postmaster_pid_locally('/tmp'), -1) @patch('gppylib.commands.gp.Command.run', return_value=CommandResult(0, b"", b"", True, False)) def test_get_postmaster_pid_locally_empty(self, mock1): self.assertEqual(get_postmaster_pid_locally('/tmp'), -1) if __name__ == '__main__': run_tests()
pid = '1234' datadir = '/data/primary/gpseg0' remoteHost = 'smdw' self.assertTrue(is_pid_postmaster(datadir, pid, remoteHost=remoteHost)) @patch('gppylib.commands.gp.Command.run', side_effect=[None, None, Exception('Error')]) @patch('gppylib.commands.gp.Command.get_results', side_effect=[CommandResult(0, "", "", True, False), CommandResult(0, "", "", True, False), CommandResult(1, "", "", False, False)]) def test_is_pid_postmaster_pgrep_failed_remote(self, mock1, mock2): pid = '1234' datadir = '/data/primary/gpseg0' remoteHost = 'smdw' self.assertTrue(is_pid_postmaster(datadir, pid, remoteHost=remoteHost)) @patch('gppylib.commands.gp.Command.run') @patch('gppylib.commands.gp.Command.get_results', return_value=CommandResult(0, "1234", "", True, False)) def test_get_postmaster_pid_locally(self, mock1, mock2): self.assertEqual(get_postmaster_pid_locally('/tmp'), 1234) @patch('gppylib.commands.gp.Command.run', side_effect=Exception('Error')) def test_get_postmaster_pid_locally_error(self, mock1): self.assertEqual(get_postmaster_pid_locally('/tmp'), -1) @patch('gppylib.commands.gp.Command.run', return_value=CommandResult(0, "", "", True, False)) def test_get_postmaster_pid_locally_empty(self, mock1): self.assertEqual(get_postmaster_pid_locally('/tmp'), -1) if __name__ == '__main__': run_tests()