From a7672bf2165fe43e7dab1db8a41434fa6e610cc7 Mon Sep 17 00:00:00 2001 From: Tommy Carpenter Date: Thu, 21 Nov 2019 10:49:56 -0500 Subject: [PATCH] Use subid and const mts for routing, open id range Issue-ID: RICPLT-2630 Change-Id: I59c02ed3b2a510a5d5ca2ff799668bb5e197a7e9 Signed-off-by: Tommy Carpenter --- a1/a1rmr.py | 15 +++- a1/controller.py | 4 +- a1/openapi.yaml | 4 +- docs/release-notes.rst | 3 +- .../a1mediator/files/ricmanifest.json | 88 ---------------------- .../a1mediator/files/rmr_string_int_mapping.txt | 6 -- integration_tests/a1mediator/templates/config.yaml | 6 +- integration_tests/bombard.py | 47 ------------ integration_tests/receiver.py | 2 +- integration_tests/test_a1.tavern.yaml | 56 +++++++------- integration_tests/test_local.rt | 6 +- .../testreceiver/templates/config.yaml | 5 +- tests/conftest.py | 2 +- tests/test_controller.py | 39 ++++++---- 14 files changed, 82 insertions(+), 201 deletions(-) delete mode 100644 integration_tests/a1mediator/files/ricmanifest.json delete mode 100644 integration_tests/a1mediator/files/rmr_string_int_mapping.txt delete mode 100644 integration_tests/bombard.py diff --git a/a1/a1rmr.py b/a1/a1rmr.py index 98e3f8e..ae2bf00 100644 --- a/a1/a1rmr.py +++ b/a1/a1rmr.py @@ -32,6 +32,12 @@ mdc_logger = Logger(name=__name__) RETRY_TIMES = int(os.environ.get("A1_RMR_RETRY_TIMES", 4)) + +A1_POLICY_REQUEST = 20010 +A1_POLICY_RESPONSE = 20011 +A1_POLICY_QUERY = 20012 + + # Note; yes, globals are bad, but this is a private (to this module) global # No other module can import/access this (well, python doesn't enforce this, but all linters will complain) __RMR_LOOP__ = None @@ -62,7 +68,10 @@ class _RmrLoop: time.sleep(0.5) # set the receive function - self.rcv_func = rcv_func_override if rcv_func_override else lambda: helpers.rmr_rcvall_msgs(self.mrc, [21024]) + # TODO: when policy query is implemented, add A1_POLICY_QUERY + self.rcv_func = ( + rcv_func_override if rcv_func_override else lambda: helpers.rmr_rcvall_msgs(self.mrc, [A1_POLICY_RESPONSE]) + ) # start the work loop self.thread = Thread(target=self.loop) @@ -86,7 +95,9 @@ class _RmrLoop: pay = work_item["payload"].encode("utf-8") for _ in range(0, RETRY_TIMES): # Waiting on an rmr bugfix regarding the over-allocation: https://rancodev.atlassian.net/browse/RICPLT-2490 - sbuf = rmr.rmr_alloc_msg(self.mrc, 4096, pay, True, work_item["msg type"]) + sbuf = rmr.rmr_alloc_msg(self.mrc, 4096, pay, True, A1_POLICY_REQUEST) + # TODO: after next rmr is released, this can be done in the alloc call. but that's not avail in pypi yet + sbuf.contents.sub_id = work_item["ptid"] pre_send_summary = rmr.message_summary(sbuf) sbuf = rmr.rmr_send_msg(self.mrc, sbuf) # send post_send_summary = rmr.message_summary(sbuf) diff --git a/a1/controller.py b/a1/controller.py index 5fca23e..1022320 100644 --- a/a1/controller.py +++ b/a1/controller.py @@ -166,7 +166,7 @@ def create_or_replace_policy_instance(policy_type_id, policy_instance_id): # send rmr (best effort) body = _gen_body_to_handler("CREATE", policy_type_id, policy_instance_id, payload=instance) - a1rmr.queue_work({"payload": json.dumps(body), "msg type": policy_type_id}) + a1rmr.queue_work({"payload": json.dumps(body), "ptid": policy_type_id}) return "", 202 @@ -187,7 +187,7 @@ def delete_policy_instance(policy_type_id, policy_instance_id): # send rmr (best effort) body = _gen_body_to_handler("DELETE", policy_type_id, policy_instance_id) - a1rmr.queue_work({"payload": json.dumps(body), "msg type": policy_type_id}) + a1rmr.queue_work({"payload": json.dumps(body), "ptid": policy_type_id}) return "", 202 diff --git a/a1/openapi.yaml b/a1/openapi.yaml index 6975bf6..bc5ee12 100644 --- a/a1/openapi.yaml +++ b/a1/openapi.yaml @@ -321,8 +321,8 @@ components: description: > represents a policy type identifier. Currently this is restricted to an integer range. type: integer - minimum: 20000 - maximum: 21023 + minimum: 1 + maximum: 2147483647 policy_instance_id: description: > diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 42c2756..a886aaa 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -22,7 +22,6 @@ and this project adheres to `Semantic Versioning `__. * Represents a resillent version of 1.0.0 that uses Redis for persistence - [x.x.x] - TBD ------------- @@ -36,6 +35,8 @@ and this project adheres to `Semantic Versioning `__. * Clean up unused items in the integration tests helm chart * Removed "RMR_RCV_RETRY_INTERVAL" leftovers since this isn't used anymore * Uses the standard RIC logging library + * Switch the backend routing scheme to using subscription id with constant message types, per request. + * Given the above, policy type ids can be any valid 32bit greater than 0 [1.0.4] ------- diff --git a/integration_tests/a1mediator/files/ricmanifest.json b/integration_tests/a1mediator/files/ricmanifest.json deleted file mode 100644 index 7883c8a..0000000 --- a/integration_tests/a1mediator/files/ricmanifest.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "controls":[ - { - "name":20000, - "description":"various parameters to control admission of dual connection", - "control_state_request_rmr_type":"DC_ADM_GET_POLICY", - "control_state_request_reply_rmr_type":"DC_ADM_GET_POLICY_ACK", - "message_receives_rmr_type":"DC_ADM_INT_CONTROL", - "message_receives_payload_schema":{ - "$schema":"http://json-schema.org/draft-07/schema#", - "type":"object", - "properties":{ - "enforce":{ - "type":"boolean", - "default":true - }, - "window_length":{ - "type":"integer", - "default":1, - "minimum":1, - "maximum":60, - "description":"Sliding window length (in minutes)" - }, - "blocking_rate":{ - "type":"number", - "default":10, - "minimum":1, - "maximum":100, - "description":"% Connections to block" - }, - "trigger_threshold":{ - "type":"integer", - "default":10, - "minimum":1, - "description":"Minimum number of events in window to trigger blocking" - } - }, - "required":[ - "enforce", - "blocking_rate", - "trigger_threshold", - "window_length" - ], - "additionalProperties":false - }, - "message_sends_rmr_type":"DC_ADM_INT_CONTROL_ACK", - "message_sends_payload_schema":{ - "$schema":"http://json-schema.org/draft-07/schema#", - "type":"object", - "properties":{ - "status":{ - "type":"string", - "enum":[ - "SUCCESS", - "FAIL" - ] - }, - "message":{ - "type":"string" - } - }, - "required":[ - "status" - ], - "additionalProperties":false - } - }, - { - "name":20001, - "description":"for the purposes of testing", - "message_receives_rmr_type":"TEST_REQ", - "message_sends_rmr_type":"TEST_ACK", - "message_sends_payload_schema":{ - "$schema":"http://json-schema.org/draft-07/schema#", - "type":"object", - "properties":{ - "status":{ - "type":"string", - "enum":[ - "SUCCESS", - "FAIL" - ] - } - } - } - } - ] -} diff --git a/integration_tests/a1mediator/files/rmr_string_int_mapping.txt b/integration_tests/a1mediator/files/rmr_string_int_mapping.txt deleted file mode 100644 index cd8db8d..0000000 --- a/integration_tests/a1mediator/files/rmr_string_int_mapping.txt +++ /dev/null @@ -1,6 +0,0 @@ -DC_ADM_INT_CONTROL:20000 -DC_ADM_INT_CONTROL_ACK:20001 -DC_ADM_GET_POLICY: 20002 -DC_ADM_GET_POLICY_ACK: 20003 -TEST_REQ:10000 -TEST_ACK:10001 diff --git a/integration_tests/a1mediator/templates/config.yaml b/integration_tests/a1mediator/templates/config.yaml index 1bb639c..811c118 100644 --- a/integration_tests/a1mediator/templates/config.yaml +++ b/integration_tests/a1mediator/templates/config.yaml @@ -5,8 +5,8 @@ metadata: data: local.rt: | newrt|start - rte|20000|testreceiverrmrservice:4560 - rte|20001|delayreceiverrmrservice:4563 + mse|20010|6660666|testreceiverrmrservice:4560 + mse|20010|20001|delayreceiverrmrservice:4563 # purposefully bad route to make sure rmr doesn't block on non listening receivers: - rte|20002|testreceiverrmrservice:4563 + rte|20010|testreceiverrmrservice:4563 newrt|end diff --git a/integration_tests/bombard.py b/integration_tests/bombard.py deleted file mode 100644 index f0a501b..0000000 --- a/integration_tests/bombard.py +++ /dev/null @@ -1,47 +0,0 @@ -# ================================================================================== -# Copyright (c) 2019 Nokia -# Copyright (c) 2018-2019 AT&T Intellectual Property. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ================================================================================== -import time -import random -import string -import os -import signal -import sys -from rmr import rmr - - -DELAY_MS = int(os.environ.get("BOMBARD_DELAY_MS", 100)) - -# Init rmr -mrc = rmr.rmr_init(b"4565", rmr.RMR_MAX_RCV_BYTES, 0x00) -while rmr.rmr_ready(mrc) == 0: - time.sleep(1) - print("not yet ready") -rmr.rmr_set_stimeout(mrc, 2) -sbuf = rmr.rmr_alloc_msg(mrc, 256) - - -while True: - # generate a random value between 1 and 256 bytes, then gen some random bytes with several nulls thrown in - val = "BOMBS AWAY".encode("utf8") - rmr.set_payload_and_length(val, sbuf) - rmr.generate_and_set_transaction_id(sbuf) - sbuf.contents.state = 0 - sbuf.contents.mtype = random.choice([20001, 10001]) - print("Pre send summary: {}".format(rmr.message_summary(sbuf))) - sbuf = rmr.rmr_send_msg(mrc, sbuf) - print("Post send summary: {}".format(rmr.message_summary(sbuf))) - time.sleep(0.001 * DELAY_MS) diff --git a/integration_tests/receiver.py b/integration_tests/receiver.py index fedc690..5c3ceaf 100644 --- a/integration_tests/receiver.py +++ b/integration_tests/receiver.py @@ -62,7 +62,7 @@ while True: val = json.dumps(payload).encode("utf-8") rmr.set_payload_and_length(val, sbuf) - sbuf.contents.mtype = 21024 + sbuf.contents.mtype = 20011 print("Pre reply summary: {}".format(rmr.message_summary(sbuf))) time.sleep(DELAY) diff --git a/integration_tests/test_a1.tavern.yaml b/integration_tests/test_a1.tavern.yaml index 94fe0de..78628cd 100644 --- a/integration_tests/test_a1.tavern.yaml +++ b/integration_tests/test_a1.tavern.yaml @@ -17,7 +17,7 @@ test_name: test admission control stages: - name: type not there yet request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: GET response: status_code: 404 @@ -32,19 +32,19 @@ stages: - name: instance list 404 request: - url: http://localhost:10000/a1-p/policytypes/20000/policies + url: http://localhost:10000/a1-p/policytypes/6660666/policies method: GET response: status_code: 404 - name: put the type request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: PUT json: name: Admission Control description: various parameters to control admission of dual connection - policy_type_id: 20000 + policy_type_id: 6660666 create_schema: "$schema": http://json-schema.org/draft-07/schema# type: object @@ -80,7 +80,7 @@ stages: - name: type there now request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: GET response: status_code: 200 @@ -91,11 +91,11 @@ stages: method: GET response: status_code: 200 - body: [20000] + body: [6660666] - name: instance list 200 but empty request: - url: http://localhost:10000/a1-p/policytypes/20000/policies + url: http://localhost:10000/a1-p/policytypes/6660666/policies method: GET response: status_code: 200 @@ -103,21 +103,21 @@ stages: - name: test the admission control policy get not there yet request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: GET response: status_code: 404 - name: test the admission control policy status get not there yet request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy/status + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy/status method: GET response: status_code: 404 - name: bad body for admission control policy request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: PUT json: not: "expected" @@ -128,7 +128,7 @@ stages: - name: not a json request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: PUT data: "asdf" response: @@ -137,7 +137,7 @@ stages: # put it properly - name: put the admission control policy instance request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: PUT json: enforce: true @@ -152,14 +152,14 @@ stages: - name: cant delete type with instances delay_before: 3 # wait for the type acks to come back first request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: DELETE response: status_code: 400 - name: test the admission control policy get request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: GET response: status_code: 200 @@ -172,7 +172,7 @@ stages: - name: test the admission control policy status get delay_before: 3 # give it a few seconds for rmr request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy/status + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy/status method: GET response: status_code: 200 @@ -182,7 +182,7 @@ stages: - name: instance list 200 and contains the instance request: - url: http://localhost:10000/a1-p/policytypes/20000/policies + url: http://localhost:10000/a1-p/policytypes/6660666/policies method: GET response: status_code: 200 @@ -193,7 +193,7 @@ stages: - name: delete the instance delay_after: 4 request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: DELETE response: status_code: 202 @@ -202,7 +202,7 @@ stages: delay_before: 3 # give it a few seconds for rmr delay_after: 8 # 3 + 11 > 10; that is, wait until t2 expires request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy/status + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy/status method: GET response: status_code: 200 @@ -212,7 +212,7 @@ stages: - name: instance list 200 but no instance request: - url: http://localhost:10000/a1-p/policytypes/20000/policies + url: http://localhost:10000/a1-p/policytypes/6660666/policies method: GET response: status_code: 200 @@ -220,35 +220,35 @@ stages: - name: cant get instance status request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy/status + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy/status method: GET response: status_code: 404 - name: cant get instance request: - url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy + url: http://localhost:10000/a1-p/policytypes/6660666/policies/admission_control_policy method: GET response: status_code: 404 - name: delete ac type request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: DELETE response: status_code: 204 - name: cant delete again request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: DELETE response: status_code: 404 - name: cant get request: - url: http://localhost:10000/a1-p/policytypes/20000 + url: http://localhost:10000/a1-p/policytypes/6660666 method: DELETE response: status_code: 404 @@ -525,12 +525,12 @@ stages: - name: bad int range 1 request: - url: http://localhost:10000/a1-p/policytypes/19999 + url: http://localhost:10000/a1-p/policytypes/0 method: PUT json: name: test policy description: just for testing - policy_type_id: 19999 + policy_type_id: 0 create_schema: "$schema": http://json-schema.org/draft-07/schema# type: object @@ -539,12 +539,12 @@ stages: - name: bad int range 2 request: - url: http://localhost:10000/a1-p/policytypes/21024 + url: http://localhost:10000/a1-p/policytypes/2147483648 method: PUT json: name: test policy description: just for testing - policy_type_id: 21024 + policy_type_id: 2147483648 create_schema: "$schema": http://json-schema.org/draft-07/schema# type: object diff --git a/integration_tests/test_local.rt b/integration_tests/test_local.rt index 6055639..6e61fef 100644 --- a/integration_tests/test_local.rt +++ b/integration_tests/test_local.rt @@ -1,5 +1,5 @@ newrt|start -rte|20000|devarchwork:4560 -rte|20001|devarchwork:4563 -rte|21024|devarchwork:4562 +mse|20010|6660666|devarchwork:4560 +mse|20010|20001|devarchwork:4563 +rte|20011|devarchwork:4562 newrt|end diff --git a/integration_tests/testreceiver/templates/config.yaml b/integration_tests/testreceiver/templates/config.yaml index 78a9f60..caf4338 100644 --- a/integration_tests/testreceiver/templates/config.yaml +++ b/integration_tests/testreceiver/templates/config.yaml @@ -5,7 +5,8 @@ metadata: data: local.rt: | newrt|start - rte|21024|a1rmrservice:4562 + # we actaully use rts so i dont even think this is used + rte|20011|a1rmrservice:4562 newrt|end --- @@ -17,5 +18,5 @@ metadata: data: local.rt: | newrt|start - rte|21024|a1rmrservice:4562 + rte|20011|a1rmrservice:4562 newrt|end diff --git a/tests/conftest.py b/tests/conftest.py index 73573d0..cfbafca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -47,7 +47,7 @@ def adm_type_good(): return { "name": "Admission Control", "description": "various parameters to control admission of dual connection", - "policy_type_id": 20000, + "policy_type_id": 6660666, "create_schema": { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", diff --git a/tests/test_controller.py b/tests/test_controller.py index 0d31274..971ce3f 100644 --- a/tests/test_controller.py +++ b/tests/test_controller.py @@ -19,21 +19,24 @@ tests for controller # ================================================================================== import time +import json from rmr.rmr_mocks import rmr_mocks from a1 import a1rmr - -ADM_CTRL = "admission_control_policy" -ADM_CTRL_POLICIES = "/a1-p/policytypes/20000/policies" -ADM_CTRL_INSTANCE = ADM_CTRL_POLICIES + "/" + ADM_CTRL +RCV_ID = "test_receiver" +ADM_CRTL_TID = 6660666 +ADM_CTRL_IID = "admission_control_policy" +ADM_CTRL_POLICIES = "/a1-p/policytypes/{0}/policies".format(ADM_CRTL_TID) +ADM_CTRL_INSTANCE = ADM_CTRL_POLICIES + "/" + ADM_CTRL_IID ADM_CTRL_INSTANCE_STATUS = ADM_CTRL_INSTANCE + "/status" -ADM_CTRL_TYPE = "/a1-p/policytypes/20000" -TEST_TYPE = "/a1-p/policytypes/20001" +ADM_CTRL_TYPE = "/a1-p/policytypes/{0}".format(ADM_CRTL_TID) def _fake_dequeue(): """for monkeypatching with a good status""" - pay = b'{"policy_type_id": 20000, "policy_instance_id": "admission_control_policy", "handler_id": "test_receiver", "status": "OK"}' + pay = json.dumps( + {"policy_type_id": ADM_CRTL_TID, "policy_instance_id": ADM_CTRL_IID, "handler_id": RCV_ID, "status": "OK"} + ).encode() fake_msg = {"payload": pay} return [fake_msg] @@ -47,12 +50,16 @@ def _fake_dequeue_deleted(): """for monkeypatching with a DELETED status""" new_msgs = [] - # insert some that don't exist to make sure nothing blows up - pay = b'{"policy_type_id": 20666, "policy_instance_id": "admission_control_policy", "handler_id": "test_receiver", "status": "DELETED"}' + # non existent type + pay = json.dumps( + {"policy_type_id": 911, "policy_instance_id": ADM_CTRL_IID, "handler_id": RCV_ID, "status": "DELETED"} + ).encode() fake_msg = {"payload": pay} new_msgs.append(fake_msg) - pay = b'{"policy_type_id": 20000, "policy_instance_id": "darkness", "handler_id": "test_receiver", "status": "DELETED"}' + pay = json.dumps( + {"policy_type_id": ADM_CRTL_TID, "policy_instance_id": "darkness", "handler_id": RCV_ID, "status": "DELETED"} + ).encode() fake_msg = {"payload": pay} new_msgs.append(fake_msg) @@ -62,7 +69,9 @@ def _fake_dequeue_deleted(): # not even a json new_msgs.append("asdf") - pay = b'{"policy_type_id": 20000, "policy_instance_id": "admission_control_policy", "handler_id": "test_receiver", "status": "DELETED"}' + pay = json.dumps( + {"policy_type_id": ADM_CRTL_TID, "policy_instance_id": ADM_CTRL_IID, "handler_id": RCV_ID, "status": "DELETED"} + ).encode() fake_msg = {"payload": pay} new_msgs.append(fake_msg) @@ -130,7 +139,7 @@ def _put_ac_type(client, typedef): # type in type list res = client.get("/a1-p/policytypes") assert res.status_code == 200 - assert res.json == [20000] + assert res.json == [ADM_CRTL_TID] # instance 200 but empty list res = client.get(ADM_CTRL_POLICIES) @@ -172,7 +181,7 @@ def _put_ac_instance(client, monkeypatch, instancedef): # instance 200 and in list res = client.get(ADM_CTRL_POLICIES) assert res.status_code == 200 - assert res.json == [ADM_CTRL] + assert res.json == [ADM_CTRL_IID] def _delete_instance(client): @@ -354,9 +363,9 @@ def test_illegal_types(client, adm_type_good): """ Test illegal types """ - res = client.put("/a1-p/policytypes/19999", json=adm_type_good) + res = client.put("/a1-p/policytypes/0", json=adm_type_good) assert res.status_code == 400 - res = client.put("/a1-p/policytypes/21024", json=adm_type_good) + res = client.put("/a1-p/policytypes/2147483648", json=adm_type_good) assert res.status_code == 400 -- 2.16.6