def test_invalid_bootaction_pkg_list(self, deckhand_ingester, drydock_state, setup, input_files, mock_get_build_data): input_file = input_files.join("invalid_bootaction_pkg.yaml") design_ref = "file://%s" % str(input_file) orch = Orchestrator(state_manager=drydock_state, ingester=deckhand_ingester) status, site_design = Orchestrator.get_effective_site(orch, design_ref) ba_doc = objects.DocumentReference( doc_type=hd_fields.DocumentType.Deckhand, doc_name="invalid_pkg_list", doc_schema="drydock/BootAction/v1") assert status.status == hd_fields.ValidationResult.Failure ba_msg = [msg for msg in status.message_list if ba_doc in msg.docs] assert len(ba_msg) > 0 for msg in ba_msg: LOG.debug(msg) assert ":) is not a valid format" in msg.message assert msg.error
def test_invalid_package_list(self, input_files, deckhand_ingester, setup): design_status, design_data = self.parse_design( "invalid_bootaction.yaml", input_files, deckhand_ingester) assert design_status.status == objects.fields.ActionResult.Failure pkg_list_bootaction = objects.DocumentReference( doc_type=objects.fields.DocumentType.Deckhand, doc_schema="drydock/BootAction/v1", doc_name="invalid_pkg_list") LOG.debug(design_status.to_dict()) pkg_list_errors = [ m for m in design_status.message_list if (m.error and pkg_list_bootaction in m.docs) ] assert len(pkg_list_errors) == 1
def parse_docs(self, doc_blob): """Translate a YAML string into the internal Drydock model. Returns a tuple of a objects.TaskStatus instance to summarize all document processing and a list of models yielded by successful processing :param doc_blob: bytes representing a utf-8 encoded YAML string """ models = [] yaml_string = doc_blob.decode() self.logger.debug("yamlingester:parse_docs - Parsing YAML string.") try: parsed_data = yaml.safe_load_all(yaml_string) except yaml.YAMLError as err: if hasattr(err, 'problem_mark'): mark = err.problem_mark raise errors.IngesterError( "Error parsing YAML at (l:%s, c:%s): %s" % (mark.line + 1, mark.column + 1, err)) else: raise errors.IngesterError("Error parsing YAML: %s" % (err)) # tracking processing status to provide a complete summary of issues ps = objects.Validation() ps.set_status(hd_fields.ValidationResult.Success) for d in parsed_data: try: (schema_ns, doc_kind, doc_version) = d.get('schema', '').split('/') except ValueError as ex: self.logger.error("Error with document structure.", exc_info=ex) self.logger.debug("Error document\n%s" % yaml.dump(d)) continue if schema_ns == 'drydock': try: doc_ref = objects.DocumentReference( doc_type=hd_fields.DocumentType.Deckhand, doc_schema=d.get('schema'), doc_name=d.get('metadata', {}).get('name', 'Unknown')) doc_errors = self.validate_drydock_document(d) if len(doc_errors) > 0: for e in doc_errors: ps.add_detail_msg( objects.ValidationMessage( msg="%s:%s schema validation error: %s" % (doc_kind, doc_version, e), name="DD001", docs=[doc_ref], error=True, level=hd_fields.MessageLevels.ERROR, diagnostic= "Invalid input file - see Drydock Troubleshooting Guide for DD001" )) ps.set_status(hd_fields.ActionResult.Failure) continue model = self.process_drydock_document(d) model.doc_ref = doc_ref models.append(model) except errors.IngesterError as ie: msg = "Error processing document: %s" % str(ie) self.logger.warning(msg) ps.add_detail_msg( objects.ValidationMessage( msg=msg, name="DD000", error=True, level=hd_fields.MessageLevels.ERROR, docs=[doc_ref], diagnostic="Exception during document processing " "- see Drydock Troubleshooting Guide " "for DD000")) ps.set_status(hd_fields.ActionResult.Failure) except Exception as ex: msg = "Unexpected error processing document: %s" % str(ex) self.logger.error(msg, exc_info=True) ps.add_detail_msg( objects.ValidationMessage( msg=msg, name="DD000", error=True, level=hd_fields.MessageLevels.ERROR, docs=[doc_ref], diagnostic="Unexpected exception during document " "processing - see Drydock Troubleshooting " "Guide for DD000")) ps.set_status(hd_fields.ActionResult.Failure) return (ps, models)