def test_bootaction_get(self, populateddb, drydock_state): """Test that a boot action status can be retrieved.""" id_key = os.urandom(32) action_id = ulid2.generate_binary_ulid() nodename = 'testnode' drydock_state.post_boot_action(nodename, populateddb.get_id(), id_key, action_id, 'helloworld') ba = drydock_state.get_boot_action(ulid2.encode_ulid_base32(action_id)) assert ba.get('identity_key') == id_key
def test_bootaction_put(self, populateddb, drydock_state): """Test that a boot action status can be updated.""" id_key = os.urandom(32) action_id = ulid2.generate_binary_ulid() nodename = 'testnode' drydock_state.post_boot_action(nodename, populateddb.get_id(), id_key, action_id, 'helloworld') result = drydock_state.put_bootaction_status( ulid2.encode_ulid_base32(action_id), action_status=objects.fields.ActionResult.Success) assert result
def seed_bootaction_status(self, blank_state, test_orchestrator, input_files): """Add a task and boot action to the database for testing.""" input_file = input_files.join("fullsite.yaml") design_ref = "file://%s" % input_file test_task = test_orchestrator.create_task( action=hd_fields.OrchestratorAction.Noop, design_ref=design_ref) id_key = os.urandom(32) action_id = ulid2.generate_binary_ulid() blank_state.post_boot_action('compute01', test_task.get_id(), id_key, action_id, 'helloworld') ba = dict(nodename='compute01', task_id=test_task.get_id(), identity_key=id_key.hex(), action_id=ulid2.encode_ulid_base32(action_id)) return ba
def on_post(self, req, resp, action_id): """Post status messages or final status for a boot action. This endpoint does not use the standard oslo_policy enforcement as this endpoint is accessed by unmanned nodes. Instead it uses a internal key authentication :param req: falcon request :param resp: falcone response :param action_id: ULID ID of the boot action """ try: ba_entry = self.state_manager.get_boot_action(action_id) except Exception as ex: self.logger.error("Error querying for boot action %s" % action_id, exc_info=ex) raise falcon.HTTPInternalServerError(str(ex)) if ba_entry is None: raise falcon.HTTPNotFound() BootactionUtils.check_auth(ba_entry, req) try: json_body = self.req_json(req) jsonschema.validate(json_body, BootactionResource.bootaction_schema) except Exception as ex: self.logger.error("Error processing boot action body", exc_info=ex) raise falcon.HTTPBadRequest(description="Error processing body.") if ba_entry.get('action_status').lower() != ActionResult.Incomplete: self.logger.info( "Attempt to update boot action %s after status finalized." % action_id) raise falcon.HTTPConflict( description= "Action %s status finalized, not available for update." % action_id) for m in json_body.get('details', []): rm = objects.TaskStatusMessage(m.get('message'), m.get('error'), 'bootaction', action_id) for f, v in m.items(): if f not in ['message', 'error']: rm['extra'] = dict() rm['extra'][f] = v self.state_manager.post_result_message(ba_entry['task_id'], rm) new_status = json_body.get('status', None) if new_status is not None: self.state_manager.put_bootaction_status( action_id, action_status=new_status.lower()) ba_entry = self.state_manager.get_boot_action(action_id) ba_entry.pop('identity_key') resp.status = falcon.HTTP_200 resp.content_type = 'application/json' ba_entry['task_id'] = str(ba_entry['task_id']) ba_entry['action_id'] = ulid2.encode_ulid_base32(ba_entry['action_id']) resp.body = json.dumps(ba_entry) return
def index(req, resp): await picoweb.start_response(resp) uid = ulid2.encode_ulid_base32(b"\x00"*10+machine.unique_id())[-10:] await resp.awrite(uid)