Towards a1 1.0.0; implement missing GETs 95/995/3
authorTommy Carpenter <tc677g@att.com>
Mon, 23 Sep 2019 13:48:23 +0000 (09:48 -0400)
committerTommy Carpenter <tc677g@att.com>
Wed, 25 Sep 2019 14:41:43 +0000 (10:41 -0400)
- Implement GET all policy type ids
- Implement GET all policy instance ids for a policy type
- fix a tiny bug in integration test receiver

Change-Id: I3d60415096a7d8df3392abdcdd100ef47b80ab51
Signed-off-by: Tommy Carpenter <tc677g@att.com>
Dockerfile-Unit-Test
a1/controller.py
a1/data.py
a1/openapi.yaml
container-tag.yaml
docs/release-notes.rst
integration_tests/a1mediator/Chart.yaml
integration_tests/receiver.py
integration_tests/test_a1.tavern.yaml
setup.py
tests/test_controller.py

index 00b87fa..dbaccbe 100644 (file)
@@ -26,14 +26,6 @@ RUN git clone --branch 1.3.0 https://gerrit.o-ran-sc.org/r/ric-plt/lib/rmr \
 
 FROM python:3.7-alpine
 
-# copies
-COPY --from=0 /usr/local/lib64/libnng.so /usr/local/lib64/libnng.so
-COPY --from=0 /usr/local/lib64/librmr_nng.so /usr/local/lib64/librmr_nng.so
-COPY a1/ /tmp/a1
-COPY tests/ /tmp/tests
-COPY setup.py tox.ini /tmp/
-WORKDIR /tmp
-
 # dir that rmr routing file temp goes into
 RUN mkdir -p /opt/route/
 
@@ -43,5 +35,13 @@ RUN apk add gcc musl-dev
 # Upgrade pip, install tox
 RUN pip install --upgrade pip && pip install tox
 
+# copies
+COPY --from=0 /usr/local/lib64/libnng.so /usr/local/lib64/libnng.so
+COPY --from=0 /usr/local/lib64/librmr_nng.so /usr/local/lib64/librmr_nng.so
+COPY a1/ /tmp/a1
+COPY tests/ /tmp/tests
+COPY setup.py tox.ini /tmp/
+WORKDIR /tmp
+
 # Run the unit tests
 RUN tox
index 9fd36d5..b189750 100644 (file)
@@ -74,7 +74,7 @@ def get_all_policy_types():
     """
     Handles GET /a1-p/policytypes
     """
-    return "", 501
+    return _try_func_return(lambda: data.get_type_list())
 
 
 def create_policy_type(policy_type_id):
@@ -111,7 +111,7 @@ def get_all_instances_for_type(policy_type_id):
     """
     Handles GET /a1-p/policytypes/policy_type_id/policies
     """
-    return "", 501
+    return _try_func_return(lambda: data.get_instance_list(policy_type_id))
 
 
 def get_policy_instance(policy_type_id, policy_instance_id):
index 6fa8b3f..5e2690d 100644 (file)
@@ -67,6 +67,13 @@ def get_policy_type(policy_type_id):
     return POLICY_DATA[policy_type_id][D]
 
 
+def get_type_list():
+    """
+    retrieve all type ids
+    """
+    return list(POLICY_DATA.keys())
+
+
 # Instances
 
 
@@ -119,3 +126,11 @@ def set_policy_instance_status(policy_type_id, policy_instance_id, handler_id, s
     instance_is_valid(policy_type_id, policy_instance_id)
 
     POLICY_DATA[policy_type_id][I][policy_instance_id][H][handler_id] = status
+
+
+def get_instance_list(policy_type_id):
+    """
+    retrieve all instance ids for a type
+    """
+    type_is_valid(policy_type_id)
+    return list(POLICY_DATA[policy_type_id][I].keys())
index 9dbe02b..2d0cdfe 100644 (file)
@@ -32,7 +32,7 @@ paths:
             A1 is healthy.
             Anything other than a 200 should be considered a1 as failing
 
-  '/a1-p/policytypes/':
+  '/a1-p/policytypes':
     get:
       description: "Get a list of all registered policy type ids"
       tags:
index fc3acb8..2d835b0 100644 (file)
@@ -1,4 +1,4 @@
 # The Jenkins job uses this string for the tag in the image name
 # for example nexus3.o-ran-sc.org:10004/my-image-name:my-tag
 ---
-tag: 0.12.1-NOT_FOR_USE_YET
+tag: 0.13.0-NOT_FOR_USE_YET
index a146357..8c9cc93 100644 (file)
@@ -29,6 +29,13 @@ and this project adheres to `Semantic Versioning <http://semver.org/>`__.
 
     * Release 1.0.0 will be the Release A version of A1
 
+[0.13.0] - 9/25/2019
+::
+
+    * Implement GET all policy type ids
+    * Implement GET all policy instance ids for a policy type
+    * fix a tiny bug in integration test receiver
+
 
 [0.12.1] - 9/20/2019
 ::
index 7e405b9..e95e934 100644 (file)
@@ -1,4 +1,4 @@
 apiVersion: v1
 description: A1 Helm chart for Kubernetes
 name: a1mediator
-version: 0.12.1
+version: 0.13.0
index 0dc5e4a..f1c324f 100644 (file)
@@ -35,8 +35,8 @@ while rmr.rmr_ready(mrc) == 0:
     print("not yet ready")
 
 print("listening ON {}".format(PORT))
-sbuf = None
 while True:
+    sbuf = rmr.rmr_alloc_msg(mrc, 4096)
     sbuf = rmr.rmr_torcv_msg(mrc, sbuf, 1000)
     summary = rmr.message_summary(sbuf)
     if summary["message state"] == 12 and summary["message status"] == "RMR_ERR_TIMEOUT":
index f2a454c..8510086 100644 (file)
@@ -22,6 +22,21 @@ stages:
     response:
       status_code: 404
 
+  - name: type list empty
+    request:
+      url: http://localhost:10000/a1-p/policytypes
+      method: GET
+    response:
+      status_code: 200
+      body: []
+
+  - name: instance list 404
+    request:
+      url: http://localhost:10000/a1-p/policytypes/20000/policies
+      method: GET
+    response:
+      status_code: 404
+
   - name: put the type
     request:
       url: http://localhost:10000/a1-p/policytypes/20000
@@ -68,6 +83,22 @@ stages:
     response:
       status_code: 200
 
+  - name: now in type list
+    request:
+      url: http://localhost:10000/a1-p/policytypes
+      method: GET
+    response:
+      status_code: 200
+      body: [20000]
+
+  - name: instance list 200 but empty
+    request:
+      url: http://localhost:10000/a1-p/policytypes/20000/policies
+      method: GET
+    response:
+      status_code: 200
+      body: []
+
   - name: test the admission control policy get not there yet
     request:
       url: http://localhost:10000/a1-p/policytypes/20000/policies/admission_control_policy
@@ -119,6 +150,17 @@ stages:
         - handler_id: test_receiver
           status: OK
 
+  - name: instance list 200 and contains the instance
+    request:
+      url: http://localhost:10000/a1-p/policytypes/20000/policies
+      method: GET
+    response:
+      status_code: 200
+      body:
+        - admission_control_policy
+
+
+
 ---
 
 test_name: test the delay receiver
@@ -132,6 +174,21 @@ stages:
     response:
       status_code: 404
 
+  - name: not yet in type list
+    request:
+      url: http://localhost:10000/a1-p/policytypes
+      method: GET
+    response:
+      status_code: 200
+      body: [20000]
+
+  - name: instance list 404
+    request:
+      url: http://localhost:10000/a1-p/policytypes/20001/policies
+      method: GET
+    response:
+      status_code: 404
+
   - name: put the type
     request:
       url: http://localhost:10000/a1-p/policytypes/20001
@@ -170,6 +227,24 @@ stages:
             - test
           additionalProperties: false
 
+  - name: now in type list
+    request:
+      url: http://localhost:10000/a1-p/policytypes
+      method: GET
+    response:
+      status_code: 200
+      body:
+       - 20000
+       - 20001
+
+  - name: instance list 200 but empty
+    request:
+      url: http://localhost:10000/a1-p/policytypes/20001/policies
+      method: GET
+    response:
+      status_code: 200
+      body: []
+
   - name: test the delay policy instance get not there yet
     request:
       url: http://localhost:10000/a1-p/policytypes/20001/policies/delaytest
@@ -216,6 +291,15 @@ stages:
         - handler_id: delay_receiver
           status: OK
 
+  - name: instance list 200 and there
+    request:
+      url: http://localhost:10000/a1-p/policytypes/20001/policies
+      method: GET
+    response:
+      status_code: 200
+      body:
+       - delaytest
+
 ---
 
 test_name: test bad routing file endpoint
index 6f7375e..f9b3f11 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@ from setuptools import setup, find_packages
 
 setup(
     name="a1",
-    version="0.12.1",
+    version="0.13.0",
     packages=find_packages(exclude=["tests.*", "tests"]),
     author="Tommy Carpenter",
     description="RIC A1 Mediator for policy/intent changes",
index 5bd3a08..3ef36a6 100644 (file)
@@ -23,7 +23,8 @@ import pytest
 
 
 ADM_CTRL = "admission_control_policy"
-ADM_CTRL_INSTANCE = "/a1-p/policytypes/20000/policies/" + ADM_CTRL
+ADM_CTRL_POLICIES = "/a1-p/policytypes/20000/policies"
+ADM_CTRL_INSTANCE = ADM_CTRL_POLICIES + "/" + ADM_CTRL
 ADM_CTRL_INSTANCE_STATUS = ADM_CTRL_INSTANCE + "/status"
 ADM_CTRL_TYPE = "/a1-p/policytypes/20000"
 TEST_TYPE = "/a1-p/policytypes/20001"
@@ -82,14 +83,31 @@ def test_xapp_put_good(client, monkeypatch, adm_type_good, adm_instance_good):
     res = client.get(ADM_CTRL_TYPE)
     assert res.status_code == 404
 
+    # no types at all
+    res = client.get("/a1-p/policytypes")
+    assert res.status_code == 200
+    assert res.json == []
+
+    # instance 404 because type not there yet
+    res = client.get(ADM_CTRL_POLICIES)
+    assert res.status_code == 404
+
     # put the type
     res = client.put(ADM_CTRL_TYPE, json=adm_type_good)
     assert res.status_code == 201
 
-    # there now
+    # type there now
     res = client.get(ADM_CTRL_TYPE)
     assert res.status_code == 200
     assert res.json == adm_type_good
+    res = client.get("/a1-p/policytypes")
+    assert res.status_code == 200
+    assert res.json == [20000]
+
+    # instance 200 but empty list
+    res = client.get(ADM_CTRL_POLICIES)
+    assert res.status_code == 200
+    assert res.json == []
 
     # no instance there yet
     res = client.get(ADM_CTRL_INSTANCE)
@@ -102,6 +120,11 @@ def test_xapp_put_good(client, monkeypatch, adm_type_good, adm_instance_good):
     res = client.put(ADM_CTRL_INSTANCE, json=adm_instance_good)
     assert res.status_code == 201
 
+    # instance 200 and in list
+    res = client.get(ADM_CTRL_POLICIES)
+    assert res.status_code == 200
+    assert res.json == [ADM_CTRL]
+
     # get the instance
     res = client.get(ADM_CTRL_INSTANCE)
     assert res.status_code == 200
@@ -123,47 +146,6 @@ def test_xapp_put_good(client, monkeypatch, adm_type_good, adm_instance_good):
     assert res.status_code == 201
 
 
-# def test_xapp_put_bad(client, monkeypatch):
-#     """Test policy put fails"""
-#     _test_put_patch(monkeypatch)
-#     # return from policy handler has a status indicating FAIL
-#     monkeypatch.setattr(
-#         "a1.a1rmr.dequeue_all_waiting_messages", _fake_dequeue(monkeypatch, msg_payload={"status": "FAIL", "foo": "bar"})
-#     )
-#     res = client.put("/a1-p/policies/admission_control_policy", json=testing_helpers.good_payload())
-#     assert res.status_code == 502
-#     assert res.json["reason"] == "BAD STATUS"
-#     assert res.json["return_payload"] == {"status": "FAIL", "foo": "bar"}
-#
-#     # return from policy handler has no status field
-#     monkeypatch.setattr("a1.a1rmr.dequeue_all_waiting_messages", _fake_dequeue(monkeypatch, msg_payload={"foo": "bar"}))
-#     res = client.put("/a1-p/policies/admission_control_policy", json=testing_helpers.good_payload())
-#     assert res.status_code == 502
-#     assert res.json["reason"] == "NO STATUS"
-#     assert res.json["return_payload"] == {"foo": "bar"}
-#
-#     # return from policy handler not a json
-#     monkeypatch.setattr(
-#         "a1.a1rmr.dequeue_all_waiting_messages", _fake_dequeue(monkeypatch, msg_payload="booger", jsonb=False)
-#     )
-#     res = client.put("/a1-p/policies/admission_control_policy", json=testing_helpers.good_payload())
-#     assert res.status_code == 502
-#     assert res.json["reason"] == "NOT JSON"
-#     assert res.json["return_payload"] == "booger"
-#
-#     # bad type
-#     monkeypatch.setattr("a1.a1rmr.dequeue_all_waiting_messages", _fake_dequeue(monkeypatch, msg_type=666))
-#     res = client.put("/a1-p/policies/admission_control_policy", json=testing_helpers.good_payload())
-#     assert res.status_code == 504
-#     assert res.data == b"\"A1 was expecting an ACK back but it didn't receive one or didn't recieve the expected ACK\"\n"
-#
-#     # bad state
-#     monkeypatch.setattr("a1.a1rmr.dequeue_all_waiting_messages", _fake_dequeue(monkeypatch, msg_state=666))
-#     res = client.put("/a1-p/policies/admission_control_policy", json=testing_helpers.good_payload())
-#     assert res.status_code == 504
-#     assert res.data == b"\"A1 was expecting an ACK back but it didn't receive one or didn't recieve the expected ACK\"\n"
-
-
 def test_bad_instances(client, monkeypatch, adm_type_good):
     """
     Test bad send failures