def _validate_sequence(correlation_id, node_from, sequence): sequence_info = store_sequence( correlation_id, node_from, sequence ) validate_sequence(sequence_info)
def test_validate_sequence(self): good_sequence_info = SequenceInfo(self.id, self.node, "1,2") bad_sequence_info = SequenceInfo(self.id, self.node, "3,2") self.assertTrue(validate_sequence(good_sequence_info), "Correct sequence failed validation") failed = False try: validate_sequence(bad_sequence_info) failed = True except: self.assertTrue(True) if failed: self.fail("Incorrect sequence passed validation")
def initiate_ingest(dpn_object_id, size): """ Initiates an ingest operation by minting the correlation ID :param dpn_object_id: UUID of the DPN object to send to the federation (extracted from bag filename) :param size: Integer of the bag size :return: Correlation ID to be used by choose_and_send_location linked task. """ # NOTE: Before sending the request, when this is real, it should... # 1. Stage or confirm presence of bag in the staging area. # 2. Validate the bag before sending. action = IngestAction( correlation_id=str(uuid4()), object_id=dpn_object_id, state=STARTED ) headers = { "correlation_id": action.correlation_id, "date": dpn_strftime(datetime.now()), "ttl": str_expire_on(datetime.now()), "sequence": 0 } body = { "replication_size": size, "protocol": settings.DPN_XFER_OPTIONS, "dpn_object_id": dpn_object_id } sequence_info = store_sequence(headers['correlation_id'], settings.DPN_NODE_NAME, headers['sequence']) validate_sequence(sequence_info) try: msg = ReplicationInitQuery(headers, body) msg.send(settings.DPN_BROADCAST_KEY) action.state = SUCCESS except Exception as err: action.state = FAILED action.note = "%s" % err logger.error(err) action.save() return action.correlation_id