def side_effect(*args): task_id = str(args[0]) LOG.debug(task_id) # Basic task if task_id == '11111111-1111-1111-1111-111111111111': new_task = objects.Task() new_task.task_id = '11111111-1111-1111-1111-111111111111' new_task.result = objects.TaskStatus() new_task.result.set_status(hd_fields.ActionResult.Failure) new_task.result.add_status_msg(msg='Test', error=True, ctx_type='N/A', ctx='N/A') return new_task # Task not found if task_id == '11111111-1111-1111-1111-111111111112': return None # Task layers if task_id == '11111111-1111-1111-1111-111111111113': new_task = objects.Task() new_task.task_id = '11111111-1111-1111-1111-111111111113' new_task.subtask_id_list = [ '11111111-1111-1111-1111-111111111114', '11111111-1111-1111-1111-111111111115' ] return new_task if task_id == '11111111-1111-1111-1111-111111111114': new_task = objects.Task() new_task.task_id = '11111111-1111-1111-1111-111111111114' return new_task if task_id == '11111111-1111-1111-1111-111111111115': new_task = objects.Task() new_task.task_id = '11111111-1111-1111-1111-111111111115' new_task.subtask_id_list = [ '11111111-1111-1111-1111-111111111116', '11111111-1111-1111-1111-111111111117' ] return new_task if task_id == '11111111-1111-1111-1111-111111111116': new_task = objects.Task() new_task.task_id = '11111111-1111-1111-1111-111111111116' new_task.result = objects.TaskStatus() new_task.result.set_status(hd_fields.ActionResult.Failure) new_task.result.add_status_msg(msg='Test', error=True, ctx_type='N/A', ctx='N/A') LOG.debug('error_count') LOG.debug(new_task.result.error_count) return new_task LOG.debug('returning None') return None
def _validate_design(self, site_design, result_status=None): """Validate the design in site_design passes all validation rules. Apply all validation rules to the design in site_design. If result_status is defined, update it with validation messages. Otherwise a new status instance will be created and returned. :param site_design: instance of objects.SiteDesign :param result_status: instance of objects.TaskStatus """ # TODO(sh8121att) actually implement the validation rules defined in the readme if result_status is not None: result_status = objects.TaskStatus() result_status.set_status(hd_fields.ActionResult.Success) return result_status
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 yields 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.TaskStatus() ps.set_status(hd_fields.ActionResult.Success) for d in parsed_data: api = d.get('apiVersion', '') if api.startswith('drydock/'): try: model = self.process_drydock_document(d) ps.add_status_msg( msg="Successfully processed Drydock document type %s." % d.get('kind'), error=False, ctx_type='document', ctx=model.get_id()) models.append(model) except errors.IngesterError as ie: msg = "Error processing document: %s" % str(ie) self.logger.warning(msg) if d.get('metadata', {}).get('name', None) is not None: ctx = d.get('metadata').get('name') else: ctx = 'Unknown' ps.add_status_msg(msg=msg, error=True, ctx_type='document', ctx=ctx) 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) if d.get('metadata', {}).get('name', None) is not None: ctx = d.get('metadata').get('name') else: ctx = 'Unknown' ps.add_status_msg(msg=msg, error=True, ctx_type='document', ctx=ctx) ps.set_status(hd_fields.ActionResult.Failure) elif api.startswith('promenade/'): (foo, api_version) = api.split('/') if api_version == 'v1': kind = d.get('kind') metadata = d.get('metadata', {}) target = metadata.get('target', 'all') name = metadata.get('name', None) model = objects.PromenadeConfig( target=target, name=name, kind=kind, document=base64.b64encode( bytearray(yaml.dump(d), encoding='utf-8')).decode('ascii')) ps.add_status_msg( msg="Successfully processed Promenade document.", error=False, ctx_type='document', ctx=name) models.append(model) return (ps, models)
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.TaskStatus() ps.set_status(hd_fields.ActionResult.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_errors = self.validate_drydock_document(d) if len(doc_errors) > 0: doc_ctx = d.get('metadata', {}).get('name', 'Unknown') for e in doc_errors: ps.add_status_msg( msg="%s:%s validation error: %s" % (doc_kind, doc_version, e), error=True, ctx_type='document', ctx=doc_ctx) ps.set_status(hd_fields.ActionResult.Failure) continue model = self.process_drydock_document(d) ps.add_status_msg( msg="Successfully processed Drydock document type %s." % doc_kind, error=False, ctx_type='document', ctx=model.get_id()) models.append(model) except errors.IngesterError as ie: msg = "Error processing document: %s" % str(ie) self.logger.warning(msg) if d.get('metadata', {}).get('name', None) is not None: ctx = d.get('metadata').get('name') else: ctx = 'Unknown' ps.add_status_msg( msg=msg, error=True, ctx_type='document', ctx=ctx) 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) if d.get('metadata', {}).get('name', None) is not None: ctx = d.get('metadata').get('name') else: ctx = 'Unknown' ps.add_status_msg( msg=msg, error=True, ctx_type='document', ctx=ctx) ps.set_status(hd_fields.ActionResult.Failure) return (ps, models)