def test_create_error_info(self): '''Testing: ErrorInfo instantiation.''' for error_type in self.error_types: test_error = errsvc.ErrorInfo(self.mod_id, error_type) self.assertEqual(test_error.get_mod_id(), self.mod_id) self.assertEqual(test_error.get_error_type(), error_type)
def test_clear_error_list(self): '''Testing: clear_error_list().''' # Make sure there is some error stored, errsvc.ErrorInfo(self.mod_id, self.error_types[0]) # before clearing the error list. errsvc.clear_error_list() errors = errsvc.get_all_errors() self.assertEqual(len(errors), 0)
def test_clear_error_list_by_mod_id(self): '''Testing: clear_error_list_by_mod_id(mod_id)''' errsvc.clear_error_list() # add two errors, each with their own mod_id error1 = errsvc.ErrorInfo(self.mod_id, self.error_types[0]) error2 = errsvc.ErrorInfo("mod2", self.error_types[0]) # verify there are 2 errors in the list self.assertEqual(len(errsvc.get_all_errors()), 2) # remove all "mod1" mod_ids from the list errsvc.clear_error_list_by_mod_id(self.mod_id) # verify there is only 1 error in the list and that it's mod_id is # correct self.assertEqual(len(errsvc.get_all_errors()), 1) errors = errsvc.get_errors_by_mod_id("mod2") self.assertEqual(len(errors), 1) self.assertEqual(errors[0].mod_id, "mod2")
def test_get_all_errors(self): '''Testing: get_all_errors().''' errsvc.clear_error_list() for error_type in self.error_types: errsvc.ErrorInfo(self.mod_id, error_type) errors = errsvc.get_all_errors() for error in errors: mod_id = error.get_mod_id() error_type = error.get_error_type() self.assertEqual(mod_id, self.mod_id) self.assertEqual(error_type, self.error_types[error_type])
def test_get_errors_by_mod_id(self): '''Testing: get_errors_by_mod_id(mod_id).''' # Test if it returns the error/s expected, by creating three # errors with same mod_id and testing each step. errsvc.clear_error_list() for c in range(self.num_err_types): errsvc.ErrorInfo(self.mod_id, self.error_types[c]) errors = errsvc.get_errors_by_mod_id(self.mod_id) self.assertEqual(len(errors), c + 1) # Test if it returns an empty list if there are no errors. errsvc.clear_error_list() errors = errsvc.get_errors_by_type(self.error_types) self.assertEqual(len(errors), 0)
def setUp(self): self.mod_id = 'mod1' self.error_type = liberrsvc.ES_ERR self.test_error = errsvc.ErrorInfo(self.mod_id, self.error_type) self.err_data_type = liberrsvc.ES_DATA_OP_STR self.error_value = 'testing data'
def validate(profile_name, manifest_path, manifest_filename, dtd_filename, conversion_report, verbose): """Validate the generated manifest/profile based on the specified dtd""" is_valid = True if verbose: print _("Validating %(manifest)s" % \ {"manifest": manifest_filename}) try: # set up then parse the manifest and the allow the manifest # parser to validate the generated manifest based on the default dtd. if os.access(manifest_path, os.F_OK): manifest = os.path.join(manifest_path, manifest_filename) mani_parser = ManifestParser("manifest-parser", manifest, validate_from_docinfo=False, dtd_file=dtd_filename) logging.raiseExceptions = False mani_parser.parse(doc=None) logging.raiseExceptions = True else: raise IOError(_("file does not exist: %s\n") % manifest_filename) except ManifestError, err_msg: is_valid = False log_name, _ending = manifest_filename.rsplit(".", 1) log_name += "_validation" + ".log" log_file = os.path.join(manifest_path, log_name) err_lines = str(err_msg).split(" : ") try: if os.access(log_file, os.F_OK): os.remove(log_file) with open(log_file, "w+") as f_handle: f_handle.write(_("NOTE: The errors outputed in this file must " "be manually corrected before the resulting " "file can be used by the OmniOS " "automated installer. For information on the " "generated errors see installadm(1M) man " "page.\n\nOnce the errors have been corrected" " you can validate your changes via:\n\n" "# js2ai -V %(manifest_file)s\n\n") % \ {"manifest_file": manifest}) f_handle.write(_("Validation Errors:\n")) for line in err_lines: conversion_report.add_validation_error() f_handle.write(("%s\n") % line) except IOError: # We failed to create the log file, print the errors to the screen err(_("failed to create log file: %(logfile)s" % \ {"logfile": log_file})) sys.stderr.write(_("Validation failed:\n")) for line in err_lines: sys.stderr.write(line) if not is_valid: # Store the error information in the error service error_info = errsvc.ErrorInfo(ERR_VAL_MODID, liberrsvc.ES_ERR) error_info.set_error_data(liberrsvc.ES_DATA_FAILED_AT, "ManifestParser") error_info.set_error_data(liberrsvc.ES_DATA_FAILED_STR, (_("%(profile)s: validation of " "%(manifest)s failed. For details see " "%(logf)s\n") % \ {"profile": profile_name, "manifest": manifest, "logf": log_file}))
def set_error(self, exception): # pylint: disable-msg=E1101 error = errsvc.ErrorInfo(self.mod_id, liberrsvc.ES_ERR) error.set_error_data(liberrsvc.ES_DATA_EXCEPTION, exception)