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
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)
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)
# 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
# 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
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: >
* Represents a resillent version of 1.0.0 that uses Redis for persistence
-
[x.x.x] - TBD
-------------
* 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]
-------
+++ /dev/null
-{
- "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"
- ]
- }
- }
- }
- }
- ]
-}
+++ /dev/null
-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
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
+++ /dev/null
-# ==================================================================================
-# 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)
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)
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
- 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
- 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
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
- 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"
- 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:
# 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
- 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
- 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
- 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
- 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
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
- 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
- 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
- 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
- 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
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
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
---
data:
local.rt: |
newrt|start
- rte|21024|a1rmrservice:4562
+ rte|20011|a1rmrservice:4562
newrt|end
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",
# ==================================================================================
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]
"""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)
# 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)
# 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)
# 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):
"""
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