def diff_cibs_xml(runner, reporter, cib_old_xml, cib_new_xml): """ Return xml diff of two CIBs CommandRunner runner string cib_old_xml -- original CIB string cib_new_xml -- modified CIB """ try: cib_old_tmp_file = write_tmpfile(cib_old_xml) reporter.process( reports.tmp_file_write(cib_old_tmp_file.name, cib_old_xml)) cib_new_tmp_file = write_tmpfile(cib_new_xml) reporter.process( reports.tmp_file_write(cib_new_tmp_file.name, cib_new_xml)) except EnvironmentError as e: raise LibraryError(reports.cib_save_tmp_error(str(e))) command = [ __exec("crm_diff"), "--original", cib_old_tmp_file.name, "--new", cib_new_tmp_file.name, "--no-version", ] # dummy_retval == 1 means one of two things: # a) an error has occured # b) --original and --new differ # therefore it's of no use to see if an error occurred stdout, stderr, dummy_retval = runner.run(command) if stderr.strip(): raise LibraryError( reports.cib_diff_error(stderr.strip(), cib_old_xml, cib_new_xml)) return stdout.strip()
def diff_cibs_xml(runner, reporter, cib_old_xml, cib_new_xml): """ Return xml diff of two CIBs CommandRunner runner string cib_old_xml -- original CIB string cib_new_xml -- modified CIB """ try: cib_old_tmp_file = write_tmpfile(cib_old_xml) reporter.process( reports.tmp_file_write(cib_old_tmp_file.name, cib_old_xml)) cib_new_tmp_file = write_tmpfile(cib_new_xml) reporter.process( reports.tmp_file_write(cib_new_tmp_file.name, cib_new_xml)) except EnvironmentError as e: raise LibraryError(reports.cib_save_tmp_error(str(e))) command = [ __exec("crm_diff"), "--original", cib_old_tmp_file.name, "--new", cib_new_tmp_file.name, "--no-version", ] # 0 (CRM_EX_OK) - success with no difference # 1 (CRM_EX_ERROR) - success with difference # 64 (CRM_EX_USAGE) - usage error # 65 (CRM_EX_DATAERR) - XML fragments not parseable stdout, stderr, retval = runner.run(command) if retval == 0: return "" if retval > 1: raise LibraryError( reports.cib_diff_error(stderr.strip(), cib_old_xml, cib_new_xml)) return stdout.strip()
def cmd_runner(self): runner_env = { # make sure to get output of external processes in English and ASCII "LC_ALL": "C", } if self.user_login: runner_env["CIB_user"] = self.user_login if not self.is_cib_live: # Dump CIB data to a temporary file and set it up in the runner. # This way every called pacemaker tool can access the CIB and we # don't need to take care of it every time the runner is called. if not self._cib_data_tmp_file: try: cib_data = self._cib_data self._cib_data_tmp_file = write_tmpfile(cib_data) self.report_processor.process( reports.tmp_file_write( self._cib_data_tmp_file.name, cib_data ) ) except EnvironmentError as e: raise LibraryError(reports.cib_save_tmp_error(str(e))) runner_env["CIB_file"] = self._cib_data_tmp_file.name return CommandRunner(self.logger, self.report_processor, runner_env)
def diff_cibs_xml(runner, reporter, cib_old_xml, cib_new_xml): """ Return xml diff of two CIBs CommandRunner runner string cib_old_xml -- original CIB string cib_new_xml -- modified CIB """ try: cib_old_tmp_file = write_tmpfile(cib_old_xml) reporter.process( reports.tmp_file_write(cib_old_tmp_file.name, cib_old_xml) ) cib_new_tmp_file = write_tmpfile(cib_new_xml) reporter.process( reports.tmp_file_write(cib_new_tmp_file.name, cib_new_xml) ) except EnvironmentError as e: raise LibraryError(reports.cib_save_tmp_error(str(e))) command = [ __exec("crm_diff"), "--original", cib_old_tmp_file.name, "--new", cib_new_tmp_file.name, "--no-version", ] # 0 (CRM_EX_OK) - success with no difference # 1 (CRM_EX_ERROR) - success with difference # 64 (CRM_EX_USAGE) - usage error # 65 (CRM_EX_DATAERR) - XML fragments not parseable stdout, stderr, retval = runner.run(command) if retval == 0: return "" if retval > 1: raise LibraryError( reports.cib_diff_error(stderr.strip(), cib_old_xml, cib_new_xml) ) return stdout.strip()