X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Ftests%2Ftest_descriptor_topics.py;h=516c1786adf66c6c72fd3a62aba4bdc5305e4653;hp=5fbb33793e80e429cc70f3110577f7f9467b063e;hb=7cbd03c5c21202fff473ae943e75dd49a18f2516;hpb=960531ab7417bf6705399dae790899463a659da9 diff --git a/osm_nbi/tests/test_descriptor_topics.py b/osm_nbi/tests/test_descriptor_topics.py index 5fbb337..516c178 100755 --- a/osm_nbi/tests/test_descriptor_topics.py +++ b/osm_nbi/tests/test_descriptor_topics.py @@ -112,9 +112,9 @@ class Test_VnfdTopic(TestCase): self.assertEqual(db_args[1]["_admin"]["projects_read"], [test_pid], "Wrong read-only project list") self.assertEqual(db_args[1]["_admin"]["projects_write"], [test_pid], "Wrong read-write project list") tmp1 = test_vnfd["vdu"][0]["cloud-init-file"] - tmp2 = test_vnfd["vnf-configuration"]["juju"] + tmp2 = test_vnfd["vnf-configuration"][0]["juju"] del test_vnfd["vdu"][0]["cloud-init-file"] - del test_vnfd["vnf-configuration"]["juju"] + del test_vnfd["vnf-configuration"][0]["juju"] try: self.db.get_one.side_effect = [{"_id": did, "_admin": db_vnfd_content["_admin"]}, None] self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) @@ -145,21 +145,10 @@ class Test_VnfdTopic(TestCase): compare_desc(self, test_vnfd, db_args[2], "VNFD") finally: test_vnfd["vdu"][0]["cloud-init-file"] = tmp1 - test_vnfd["vnf-configuration"]["juju"] = tmp2 + test_vnfd["vnf-configuration"][0]["juju"] = tmp2 self.db.get_one.side_effect = lambda table, filter, fail_on_empty=None, fail_on_more=None: \ {"_id": did, "_admin": db_vnfd_content["_admin"]} - with self.subTest(i=2, t='Check Pyangbind Validation: required properties'): - tmp = test_vnfd["id"] - del test_vnfd["id"] - try: - with self.assertRaises(EngineException, msg="Accepted VNFD with a missing required property") as e: - self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error in pyangbind validation: '{}'".format("id")), - norm(str(e.exception)), "Wrong exception text") - finally: - test_vnfd["id"] = tmp - with self.subTest(i=3, t='Check Pyangbind Validation: additional properties'): + with self.subTest(i=2, t='Check Pyangbind Validation: additional properties'): test_vnfd["extra-property"] = 0 try: with self.assertRaises(EngineException, msg="Accepted VNFD with an additional property") as e: @@ -170,9 +159,9 @@ class Test_VnfdTopic(TestCase): norm(str(e.exception)), "Wrong exception text") finally: del test_vnfd["extra-property"] - with self.subTest(i=4, t='Check Pyangbind Validation: property types'): - tmp = test_vnfd["short-name"] - test_vnfd["short-name"] = {"key": 0} + with self.subTest(i=3, t='Check Pyangbind Validation: property types'): + tmp = test_vnfd["product-name"] + test_vnfd["product-name"] = {"key": 0} try: with self.assertRaises(EngineException, msg="Accepted VNFD with a wrongly typed property") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) @@ -181,215 +170,146 @@ class Test_VnfdTopic(TestCase): .format("json object contained a key that did not exist", "key")), norm(str(e.exception)), "Wrong exception text") finally: - test_vnfd["short-name"] = tmp - with self.subTest(i=5, t='Check Input Validation: cloud-init'): + test_vnfd["product-name"] = tmp + with self.subTest(i=4, t='Check Input Validation: cloud-init'): with self.assertRaises(EngineException, msg="Accepted non-existent cloud_init file") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.BAD_REQUEST, "Wrong HTTP status code") self.assertIn(norm("{} defined in vnf[id={}]:vdu[id={}] but not present in package" .format("cloud-init", test_vnfd["id"], test_vnfd["vdu"][0]["id"])), norm(str(e.exception)), "Wrong exception text") - with self.subTest(i=6, t='Check Input Validation: vnf-configuration[juju]'): + with self.subTest(i=5, t='Check Input Validation: vnf-configuration[juju]'): del test_vnfd["vdu"][0]["cloud-init-file"] with self.assertRaises(EngineException, msg="Accepted non-existent charm in VNF configuration") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.BAD_REQUEST, "Wrong HTTP status code") self.assertIn(norm("{} defined in vnf[id={}] but not present in package".format("charm", test_vnfd["id"])), norm(str(e.exception)), "Wrong exception text") - with self.subTest(i=7, t='Check Input Validation: mgmt-interface'): - del test_vnfd["vnf-configuration"]["juju"] - tmp = test_vnfd["mgmt-interface"] - del test_vnfd["mgmt-interface"] + del test_vnfd["vnf-configuration"][0]["juju"] + with self.subTest(i=6, t='Check Input Validation: mgmt-cp'): + tmp = test_vnfd["mgmt-cp"] + del test_vnfd["mgmt-cp"] try: with self.assertRaises(EngineException, msg="Accepted VNFD without management interface") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("'{}' is a mandatory field and it is not defined".format("mgmt-interface")), + self.assertIn(norm("'{}' is a mandatory field and it is not defined".format("mgmt-cp")), norm(str(e.exception)), "Wrong exception text") finally: - test_vnfd["mgmt-interface"] = tmp - with self.subTest(i=8, t='Check Input Validation: mgmt-interface[cp]'): - tmp = test_vnfd["mgmt-interface"]["cp"] - test_vnfd["mgmt-interface"]["cp"] = "wrong-cp" + test_vnfd["mgmt-cp"] = tmp + with self.subTest(i=7, t='Check Input Validation: mgmt-cp connection point'): + tmp = test_vnfd["mgmt-cp"] + test_vnfd["mgmt-cp"] = "wrong-cp" try: - with self.assertRaises(EngineException, - msg="Accepted wrong management interface connection point") as e: + with self.assertRaises(EngineException, msg="Accepted wrong mgmt-cp connection point") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("mgmt-interface:cp='{}' must match an existing connection-point" - .format(test_vnfd["mgmt-interface"]["cp"])), + self.assertIn(norm("mgmt-cp='{}' must match an existing ext-cpd".format(test_vnfd["mgmt-cp"])), norm(str(e.exception)), "Wrong exception text") finally: - test_vnfd["mgmt-interface"]["cp"] = tmp - with self.subTest(i=9, t='Check Input Validation: vdu[interface][external-connection-point-ref]'): - tmp = test_vnfd["vdu"][0]["interface"][0]["external-connection-point-ref"] - test_vnfd["vdu"][0]["interface"][0]["external-connection-point-ref"] = "wrong-cp" + test_vnfd["mgmt-cp"] = tmp + with self.subTest(i=8, t='Check Input Validation: vdu int-cpd'): + ext_cpd = test_vnfd["ext-cpd"][1] + tmp = ext_cpd["int-cpd"]["cpd"] + ext_cpd["int-cpd"]["cpd"] = "wrong-cpd" try: - with self.assertRaises(EngineException, - msg="Accepted wrong VDU interface external connection point reference") as e: + with self.assertRaises(EngineException, msg="Accepted wrong ext-cpd internal connection point") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("vdu[id='{}']:interface[name='{}']:external-connection-point-ref='{}'" - " must match an existing connection-point" - .format(test_vnfd["vdu"][0]["id"], test_vnfd["vdu"][0]["interface"][0]["name"], - test_vnfd["vdu"][0]["interface"][0]["external-connection-point-ref"])), - norm(str(e.exception)), "Wrong exception text") - finally: - test_vnfd["vdu"][0]["interface"][0]["external-connection-point-ref"] = tmp - with self.subTest(i=10, t='Check Input Validation: vdu[interface][internal-connection-point-ref]'): - tmp = test_vnfd["vdu"][1]["interface"][0]["internal-connection-point-ref"] - test_vnfd["vdu"][1]["interface"][0]["internal-connection-point-ref"] = "wrong-cp" - try: - with self.assertRaises(EngineException, - msg="Accepted wrong VDU interface internal connection point reference") as e: - self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("vdu[id='{}']:interface[name='{}']:internal-connection-point-ref='{}'" - " must match an existing vdu:internal-connection-point" - .format(test_vnfd["vdu"][1]["id"], test_vnfd["vdu"][1]["interface"][0]["name"], - test_vnfd["vdu"][1]["interface"][0]["internal-connection-point-ref"])), - norm(str(e.exception)), "Wrong exception text") - finally: - test_vnfd["vdu"][1]["interface"][0]["internal-connection-point-ref"] = tmp - with self.subTest(i=11, t='Check Input Validation: vdu[vdu-configuration][juju]'): - test_vnfd["vdu"][0]["vdu-configuration"] = {"juju": {"charm": "wrong-charm"}} - try: - with self.assertRaises(EngineException, msg="Accepted non-existent charm in VDU configuration") as e: - self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.BAD_REQUEST, "Wrong HTTP status code") - self.assertIn(norm("{} defined in vnf[id={}]:vdu[id={}] but not present in package" - .format("charm", test_vnfd["id"], test_vnfd["vdu"][0]["id"])), + self.assertIn(norm("ext-cpd[id='{}']:int-cpd must match an existing vdu int-cpd".format(ext_cpd["id"])), norm(str(e.exception)), "Wrong exception text") finally: - del test_vnfd["vdu"][0]["vdu-configuration"] - with self.subTest(i=12, t='Check Input Validation: Duplicated VLD name'): - test_vnfd["internal-vld"].append(deepcopy(test_vnfd["internal-vld"][0])) - test_vnfd["internal-vld"][1]["id"] = "wrong-internal-vld" + ext_cpd["int-cpd"]["cpd"] = tmp + with self.subTest(i=9, t='Check Input Validation: Duplicated VLD'): + test_vnfd['int-virtual-link-desc'].insert(0, {'id': 'internal'}) try: with self.assertRaises(EngineException, msg="Accepted duplicated VLD name") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Duplicated VLD name '{}' in vnfd[id={}]:internal-vld[id={}]" - .format(test_vnfd["internal-vld"][1]["name"], test_vnfd["id"], - test_vnfd["internal-vld"][1]["id"])), - norm(str(e.exception)), "Wrong exception text") + self.assertIn( + norm("identifier id '{}' is not unique".format(test_vnfd['int-virtual-link-desc'][0]["id"])), + norm(str(e.exception)), "Wrong exception text") finally: - del test_vnfd["internal-vld"][1] - with self.subTest(i=13, t='Check Input Validation: internal-vld[internal-connection-point][id-ref])'): - tmp = test_vnfd["internal-vld"][0]["internal-connection-point"][0]["id-ref"] - test_vnfd["internal-vld"][0]["internal-connection-point"][0]["id-ref"] = "wrong-icp-id-ref" + del test_vnfd['int-virtual-link-desc'][0] + with self.subTest(i=10, t='Check Input Validation: vdu int-virtual-link-desc'): + vdu = test_vnfd['vdu'][0] + int_cpd = vdu['int-cpd'][1] + tmp = int_cpd['int-virtual-link-desc'] + int_cpd['int-virtual-link-desc'] = 'non-existing-int-virtual-link-desc' try: - with self.assertRaises(EngineException, msg="Accepted non-existent internal VLD ICP id-ref") as e: + with self.assertRaises(EngineException, msg="Accepted int-virtual-link-desc") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("internal-vld[id='{}']:internal-connection-point='{}' must match an existing " - "vdu:internal-connection-point" - .format(test_vnfd["internal-vld"][0]["id"], - test_vnfd["internal-vld"][0]["internal-connection-point"][0]["id-ref"])), + self.assertIn(norm("vdu[id='{}']:int-cpd[id='{}']:int-virtual-link-desc='{}' must match an existing " + "int-virtual-link-desc".format(vdu["id"], int_cpd["id"], + int_cpd['int-virtual-link-desc'])), norm(str(e.exception)), "Wrong exception text") finally: - test_vnfd["internal-vld"][0]["internal-connection-point"][0]["id-ref"] = tmp - with self.subTest(i=14, t='Check Input Validation: internal-vld[ip-profile-ref])'): - test_vnfd["ip-profiles"] = [{"name": "fake-ip-profile-ref"}] - test_vnfd["internal-vld"][0]["ip-profile-ref"] = "wrong-ip-profile-ref" + int_cpd['int-virtual-link-desc'] = tmp + with self.subTest(i=11, t='Check Input Validation: virtual-link-profile)'): + fake_ivld_profile = {'id': 'fake-profile-ref', 'flavour': 'fake-flavour'} + df = test_vnfd['df'][0] + df['virtual-link-profile'] = [fake_ivld_profile] try: - with self.assertRaises(EngineException, msg="Accepted non-existent IP Profile Ref") as e: + with self.assertRaises(EngineException, msg="Accepted non-existent Profile Ref") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("internal-vld[id='{}']:ip-profile-ref='{}' does not exist" - .format(test_vnfd["internal-vld"][0]["id"], - test_vnfd["internal-vld"][0]["ip-profile-ref"])), + self.assertIn(norm("df[id='{}']:virtual-link-profile='{}' must match an existing " + "int-virtual-link-desc".format(df["id"], fake_ivld_profile["id"])), norm(str(e.exception)), "Wrong exception text") finally: - del test_vnfd["ip-profiles"] - del test_vnfd["internal-vld"][0]["ip-profile-ref"] - with self.subTest(i=15, t='Check Input Validation: vdu[monitoring-param])'): - test_vnfd["monitoring-param"] = [{"id": "fake-mp-id", "vdu-monitoring-param": { - "vdu-monitoring-param-ref": "fake-vdu-mp-ref", "vdu-ref": "fake-vdu-ref"}}] - test_vnfd["vdu"][0]["monitoring-param"] = [{"id": "wrong-vdu-mp-id"}] + del df['virtual-link-profile'] + with self.subTest(i=12, t='Check Input Validation: scaling-criteria monitoring-param-ref'): + vdu = test_vnfd['vdu'][1] + affected_df = test_vnfd['df'][0] + sa = affected_df['scaling-aspect'][0] + sp = sa['scaling-policy'][0] + sc = sp['scaling-criteria'][0] + tmp = vdu.pop('monitoring-parameter') try: - with self.assertRaises(EngineException, msg="Accepted non-existent VDU Monitorimg Param") as e: + with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group Policy Criteria") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - mp = test_vnfd["monitoring-param"][0]["vdu-monitoring-param"] - self.assertIn(norm("monitoring-param:vdu-monitoring-param:vdu-monitoring-param-ref='{}' not defined" - " at vdu[id='{}'] or vdu does not exist" - .format(mp["vdu-monitoring-param-ref"], mp["vdu-ref"])), + self.assertIn(norm("df[id='{}']:scaling-aspect[id='{}']:scaling-policy" + "[name='{}']:scaling-criteria[name='{}']: " + "vnf-monitoring-param-ref='{}' not defined in any monitoring-param" + .format(affected_df["id"], sa["id"], sp["name"], + sc["name"], sc["vnf-monitoring-param-ref"])), norm(str(e.exception)), "Wrong exception text") finally: - del test_vnfd["monitoring-param"] - del test_vnfd["vdu"][0]["monitoring-param"] - with self.subTest(i=16, t='Check Input Validation: vdu[vdu-configuration][metrics]'): - test_vnfd["monitoring-param"] = [{"id": "fake-mp-id", "vdu-metric": { - "vdu-metric-name-ref": "fake-vdu-mp-ref", "vdu-ref": "fake-vdu-ref"}}] - test_vnfd["vdu"][0]["vdu-configuration"] = {"metrics": [{"name": "wrong-vdu-mp-id"}]} + vdu['monitoring-parameter'] = tmp + with self.subTest(i=13, t='Check Input Validation: scaling-aspect vnf-configuration'): + df = test_vnfd['df'][0] + tmp = test_vnfd.pop('vnf-configuration') try: - with self.assertRaises(EngineException, msg="Accepted non-existent VDU Configuration Metric") as e: + with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group VDU ID Reference") \ + as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - mp = test_vnfd["monitoring-param"][0]["vdu-metric"] - self.assertIn(norm("monitoring-param:vdu-metric:vdu-metric-name-ref='{}' not defined" - " at vdu[id='{}'] or vdu does not exist" - .format(mp["vdu-metric-name-ref"], mp["vdu-ref"])), + self.assertIn(norm("'vnf-configuration' not defined in the descriptor but it is referenced " + "by df[id='{}']:scaling-aspect[id='{}']:scaling-config-action" + .format(df["id"], df['scaling-aspect'][0]["id"])), norm(str(e.exception)), "Wrong exception text") finally: - del test_vnfd["monitoring-param"] - del test_vnfd["vdu"][0]["vdu-configuration"] - with self.subTest(i=17, t='Check Input Validation: scaling-group-descriptor[scaling-policy][scaling-criteria]'): - test_vnfd["monitoring-param"] = [{"id": "fake-mp-id"}] - test_vnfd["scaling-group-descriptor"] = [{ - "name": "fake-vnf-sg-name", - "vdu": [{"vdu-id-ref": "wrong-vdu-id-ref"}], - "scaling-policy": [{"name": "fake-vnf-sp-name", "scaling-criteria": [{ - "name": "fake-vnf-sc-name", "vnf-monitoring-param-ref": "wrong-vnf-mp-id"}]}]}] - with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group Policy Criteria") as e: - self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - sg = test_vnfd["scaling-group-descriptor"][0] - sc = sg["scaling-policy"][0]["scaling-criteria"][0] - self.assertIn(norm("scaling-group-descriptor[name='{}']:scaling-criteria[name='{}']:" - "vnf-monitoring-param-ref='{}' not defined in any monitoring-param" - .format(sg["name"], sc["name"], sc["vnf-monitoring-param-ref"])), - norm(str(e.exception)), "Wrong exception text") - with self.subTest(i=18, t='Check Input Validation: scaling-group-descriptor[vdu][vdu-id-ref]'): - sc["vnf-monitoring-param-ref"] = "fake-mp-id" - with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group VDU ID Reference") as e: - self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("scaling-group-descriptor[name='{}']:vdu-id-ref={} does not match any vdu" - .format(sg["name"], sg["vdu"][0]["vdu-id-ref"])), - norm(str(e.exception)), "Wrong exception text") - with self.subTest(i=19, t='Check Input Validation: scaling-group-descriptor[scaling-config-action]'): - tmp = test_vnfd["vnf-configuration"] - del test_vnfd["vnf-configuration"] - sg["vdu"][0]["vdu-id-ref"] = test_vnfd["vdu"][0]["id"] - sg["scaling-config-action"] = [{"trigger": "pre-scale-in"}] + test_vnfd["vnf-configuration"] = tmp + with self.subTest(i=14, t='Check Input Validation: scaling-config-action'): + df = test_vnfd['df'][0] + tmp = test_vnfd['vnf-configuration'][0]['config-primitive'] + test_vnfd['vnf-configuration'][0]['config-primitive'] = [{'name': 'wrong-primitive'}] try: - with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group VDU ID Reference") \ - as e: + with self.assertRaises(EngineException, + msg="Accepted non-existent Scaling Group VDU ID Reference") as e: self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("'vnf-configuration' not defined in the descriptor but it is referenced" - " by scaling-group-descriptor[name='{}']:scaling-config-action" - .format(sg["name"])), + self.assertIn(norm("df[id='{}']:scaling-aspect[id='{}']:scaling-config-action:vnf-" + "config-primitive-name-ref='{}' does not match any " + "vnf-configuration:config-primitive:name" + .format(df["id"], df['scaling-aspect'][0]["id"], + sa['scaling-config-action'][0]['vnf-config-primitive-name-ref'])), norm(str(e.exception)), "Wrong exception text") finally: - test_vnfd["vnf-configuration"] = tmp - with self.subTest(i=20, t='Check Input Validation: scaling-group-descriptor[scaling-config-action]' - '[vnf-config-primitive-name-ref]'): - sg["scaling-config-action"][0]["vnf-config-primitive-name-ref"] = "wrong-sca-prim-name" - with self.assertRaises(EngineException, msg="Accepted non-existent Scaling Group VDU ID Reference") as e: - self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("scaling-group-descriptor[name='{}']:scaling-config-action:" - "vnf-config-primitive-name-ref='{}' does not match" - " any vnf-configuration:config-primitive:name" - .format(sg["name"], sg["scaling-config-action"][0]["vnf-config-primitive-name-ref"])), - norm(str(e.exception)), "Wrong exception text") - # del test_vnfd["monitoring-param"] - # del test_vnfd["scaling-group-descriptor"] - with self.subTest(i=21, t='Check Input Validation: everything right'): - sg["scaling-config-action"][0]["vnf-config-primitive-name-ref"] = "touch" + test_vnfd['vnf-configuration'][0]['config-primitive'] = tmp + with self.subTest(i=15, t='Check Input Validation: everything right'): test_vnfd["id"] = "fake-vnfd-id" self.db.get_one.side_effect = [{"_id": did, "_admin": db_vnfd_content["_admin"]}, None] rc = self.topic.upload_content(fake_session, did, test_vnfd, {}, {"Content-Type": []}) @@ -397,13 +317,14 @@ class Test_VnfdTopic(TestCase): return def test_edit_vnfd(self): - did = db_vnfd_content["_id"] + vnfd_content = deepcopy(db_vnfd_content) + did = vnfd_content["_id"] self.fs.file_exists.return_value = True self.fs.dir_ls.return_value = True with self.subTest(i=1, t='Normal Edition'): now = time() - self.db.get_one.side_effect = [db_vnfd_content, None] - data = {"id": "new-vnfd-id", "name": "new-vnfd-name"} + self.db.get_one.side_effect = [vnfd_content, None] + data = {"id": "new-vnfd-id", "product-name": "new-vnfd-name"} self.topic.edit(fake_session, did, data) db_args = self.db.replace.call_args[0] msg_args = self.msg.write.call_args[0] @@ -413,30 +334,30 @@ class Test_VnfdTopic(TestCase): self.assertEqual(msg_args[2], data, "Wrong message content") self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic") self.assertEqual(db_args[1], did, "Wrong DB ID") - self.assertEqual(db_args[2]["_admin"]["created"], db_vnfd_content["_admin"]["created"], + self.assertEqual(db_args[2]["_admin"]["created"], vnfd_content["_admin"]["created"], "Wrong creation time") self.assertGreater(db_args[2]["_admin"]["modified"], now, "Wrong modification time") - self.assertEqual(db_args[2]["_admin"]["projects_read"], db_vnfd_content["_admin"]["projects_read"], + self.assertEqual(db_args[2]["_admin"]["projects_read"], vnfd_content["_admin"]["projects_read"], "Wrong read-only project list") - self.assertEqual(db_args[2]["_admin"]["projects_write"], db_vnfd_content["_admin"]["projects_write"], + self.assertEqual(db_args[2]["_admin"]["projects_write"], vnfd_content["_admin"]["projects_write"], "Wrong read-write project list") self.assertEqual(db_args[2]["id"], data["id"], "Wrong VNFD ID") - self.assertEqual(db_args[2]["name"], data["name"], "Wrong VNFD Name") + self.assertEqual(db_args[2]["product-name"], data["product-name"], "Wrong VNFD Name") with self.subTest(i=2, t='Conflict on Edit'): - data = {"id": "fake-vnfd-id", "name": "new-vnfd-name"} - self.db.get_one.side_effect = [db_vnfd_content, {"_id": str(uuid4()), "id": data["id"]}] + data = {"id": "fake-vnfd-id", "product-name": "new-vnfd-name"} + self.db.get_one.side_effect = [vnfd_content, {"_id": str(uuid4()), "id": data["id"]}] with self.assertRaises(EngineException, msg="Accepted existing VNFD ID") as e: self.topic.edit(fake_session, did, data) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") self.assertIn(norm("{} with id '{}' already exists for this project".format("vnfd", data["id"])), norm(str(e.exception)), "Wrong exception text") with self.subTest(i=3, t='Check Envelope'): - data = {"vnfd": {"id": "new-vnfd-id-1", "name": "new-vnfd-name"}} + data = {"vnfd": [{"id": "new-vnfd-id-1", "product-name": "new-vnfd-name"}]} with self.assertRaises(EngineException, msg="Accepted VNFD with wrong envelope") as e: - self.topic.edit(fake_session, did, data) + self.topic.edit(fake_session, did, data, content=vnfd_content) self.assertEqual(e.exception.http_code, HTTPStatus.BAD_REQUEST, "Wrong HTTP status code") - self.assertIn("'vnfd' must be a list of only one element", norm(str(e.exception)), "Wrong exception text") + self.assertIn("'vnfd' must be dict", norm(str(e.exception)), "Wrong exception text") return def test_delete_vnfd(self): @@ -515,211 +436,205 @@ class Test_VnfdTopic(TestCase): self.fs.file_delete.assert_not_called() return - def test_validate_mgmt_interfaces_connection_points_on_valid_descriptor(self): + def test_validate_mgmt_interface_connection_point_on_valid_descriptor(self): indata = deepcopy(db_vnfd_content) - self.topic.validate_mgmt_interfaces_connection_points(indata) + self.topic.validate_mgmt_interface_connection_point(indata) - def test_validate_mgmt_interfaces_connection_points_when_missing_connection_point(self): + def test_validate_mgmt_interface_connection_point_when_missing_connection_point(self): indata = deepcopy(db_vnfd_content) - indata['connection-point'] = [] + indata['ext-cpd'] = [] with self.assertRaises(EngineException) as e: - self.topic.validate_mgmt_interfaces_connection_points(indata) + self.topic.validate_mgmt_interface_connection_point(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("mgmt-interface:cp='{}' must match an existing connection-point" - .format(indata["mgmt-interface"]["cp"])), + self.assertIn(norm("mgmt-cp='{}' must match an existing ext-cpd" + .format(indata["mgmt-cp"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_mgmt_interfaces_connection_points_when_missing_mgmt_interface(self): + def test_validate_mgmt_interface_connection_point_when_missing_mgmt_cp(self): indata = deepcopy(db_vnfd_content) - indata.pop('mgmt-interface') + indata.pop('mgmt-cp') with self.assertRaises(EngineException) as e: - self.topic.validate_mgmt_interfaces_connection_points(indata) + self.topic.validate_mgmt_interface_connection_point(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("'mgmt-interface' is a mandatory field and it is not defined"), + self.assertIn(norm("'mgmt-cp' is a mandatory field and it is not defined"), norm(str(e.exception)), "Wrong exception text") - def test_validate_vdu_connection_point_refs_on_valid_descriptor(self): + def test_validate_vdu_internal_connection_points_on_valid_descriptor(self): indata = db_vnfd_content vdu = indata['vdu'][0] - self.topic.validate_vdu_connection_point_refs(vdu, indata) + self.topic.validate_vdu_internal_connection_points(vdu) - def test_validate_vdu_connection_point_refs_when_missing_internal_connection_point(self): - indata = deepcopy(db_vnfd_content) - vdu = indata['vdu'][0] - vdu.pop('internal-connection-point') - with self.assertRaises(EngineException) as e: - self.topic.validate_vdu_connection_point_refs(vdu, indata) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("vdu[id='{}']:interface[name='{}']:internal-connection-point-ref='{}' " - "must match an existing vdu:internal-connection-point" - .format(vdu["id"], vdu['interface'][1]["name"], - vdu['interface'][1]["internal-connection-point-ref"])), - norm(str(e.exception)), "Wrong exception text") + def test_validate_external_connection_points_on_valid_descriptor(self): + indata = db_vnfd_content + self.topic.validate_external_connection_points(indata) - def test_validate_vdu_connection_point_refs_when_missing_external_connection_point(self): + def test_validate_external_connection_points_when_missing_internal_connection_point(self): indata = deepcopy(db_vnfd_content) vdu = indata['vdu'][0] - indata.pop('connection-point') + vdu.pop('int-cpd') + affected_ext_cpd = indata["ext-cpd"][0] with self.assertRaises(EngineException) as e: - self.topic.validate_vdu_connection_point_refs(vdu, indata) + self.topic.validate_external_connection_points(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("vdu[id='{}']:interface[name='{}']:external-connection-point-ref='{}' " - "must match an existing connection-point" - .format(vdu["id"], vdu['interface'][0]["name"], - vdu['interface'][0]["external-connection-point-ref"])), + self.assertIn(norm("ext-cpd[id='{}']:int-cpd must match an existing vdu int-cpd" + .format(affected_ext_cpd["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_vdu_connection_point_refs_on_duplicated_internal_connection_point_ref(self): + def test_validate_vdu_internal_connection_points_on_duplicated_internal_connection_point(self): indata = deepcopy(db_vnfd_content) vdu = indata['vdu'][0] - duplicated_interface = {'name': 'dup-mgmt-eth1', 'position': 3, - 'internal-connection-point-ref': 'mgmtVM-internal'} - vdu['interface'].insert(0, duplicated_interface) + duplicated_cpd = {'id': 'vnf-mgmt', 'order': 3, + 'virtual-network-interface-requirement': [{'name': 'duplicated'}]} + vdu['int-cpd'].insert(0, duplicated_cpd) with self.assertRaises(EngineException) as e: - self.topic.validate_vdu_connection_point_refs(vdu, indata) + self.topic.validate_vdu_internal_connection_points(vdu) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("vdu[id='{}']:interface[name='{}']:internal-connection-point-ref='{}' " - "is referenced by other interface" - .format(vdu["id"], vdu['interface'][2]["name"], - vdu['interface'][2]["internal-connection-point-ref"])), + self.assertIn(norm("vdu[id='{}']:int-cpd[id='{}'] is already used by other int-cpd" + .format(vdu["id"], duplicated_cpd["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_vdu_connection_point_refs_on_duplicated_external_connection_point_ref(self): + def test_validate_external_connection_points_on_duplicated_external_connection_point(self): indata = deepcopy(db_vnfd_content) - vdu = indata['vdu'][0] - duplicated_interface = {'name': 'dup-mgmt-eth0', 'position': 3, 'external-connection-point-ref': 'vnf-mgmt'} - vdu['interface'].insert(0, duplicated_interface) + duplicated_cpd = {'id': 'vnf-mgmt-ext', 'int-cpd': {'vdu-id': 'dataVM', 'cpd': 'vnf-data'}} + indata['ext-cpd'].insert(0, duplicated_cpd) with self.assertRaises(EngineException) as e: - self.topic.validate_vdu_connection_point_refs(vdu, indata) + self.topic.validate_external_connection_points(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("vdu[id='{}']:interface[name='{}']:external-connection-point-ref='{}' " - "is referenced by other interface" - .format(vdu["id"], vdu['interface'][1]["name"], - vdu['interface'][1]["external-connection-point-ref"])), + self.assertIn(norm("ext-cpd[id='{}'] is already used by other ext-cpd" + .format(duplicated_cpd["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_internal_vlds_on_valid_descriptor(self): + def test_validate_internal_virtual_links_on_valid_descriptor(self): indata = db_vnfd_content - self.topic.validate_internal_vlds(indata) + self.topic.validate_internal_virtual_links(indata) - def test_validate_internal_vlds_on_duplicated_vld(self): + def test_validate_internal_virtual_links_on_duplicated_ivld(self): indata = deepcopy(db_vnfd_content) - duplicated_vld = {'id': 'internal', 'name': 'internal', - 'internal-connection-point': [{'id-ref': 'mgmtVM-internal'}, {'id-ref': 'dataVM-internal'}]} - indata['internal-vld'].insert(0, duplicated_vld) + duplicated_vld = {'id': 'internal'} + indata['int-virtual-link-desc'].insert(0, duplicated_vld) with self.assertRaises(EngineException) as e: - self.topic.validate_internal_vlds(indata) + self.topic.validate_internal_virtual_links(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Duplicated VLD name '{}' in vnfd[id={}]:internal-vld[id={}]" - .format(indata['internal-vld'][1]["name"], indata["id"], indata['internal-vld'][1]["id"])), + self.assertIn(norm("Duplicated VLD id in int-virtual-link-desc[id={}]" + .format(duplicated_vld["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_internal_vlds_when_missing_internal_connection_point(self): + def test_validate_internal_virtual_links_when_missing_ivld_on_connection_point(self): indata = deepcopy(db_vnfd_content) - ivld = indata['internal-vld'][0] - icp = ivld['internal-connection-point'][0] - indata['vdu'][0]['internal-connection-point'].pop() + vdu = indata['vdu'][0] + affected_int_cpd = vdu['int-cpd'][0] + affected_int_cpd['int-virtual-link-desc'] = 'non-existing-int-virtual-link-desc' with self.assertRaises(EngineException) as e: - self.topic.validate_internal_vlds(indata) + self.topic.validate_internal_virtual_links(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("internal-vld[id='{}']:internal-connection-point='{}' must match an existing " - "vdu:internal-connection-point".format(ivld["id"], icp["id-ref"])), + self.assertIn(norm("vdu[id='{}']:int-cpd[id='{}']:int-virtual-link-desc='{}' must match an existing " + "int-virtual-link-desc".format(vdu["id"], affected_int_cpd["id"], + affected_int_cpd['int-virtual-link-desc'])), norm(str(e.exception)), "Wrong exception text") - def test_validate_internal_vlds_when_missing_ip_profile(self): + def test_validate_internal_virtual_links_when_missing_ivld_on_profile(self): indata = deepcopy(db_vnfd_content) - ivld = indata['internal-vld'][0] - ivld['ip-profile-ref'] = 'non-existing-ip-profile' + affected_ivld_profile = {'id': 'non-existing-int-virtual-link-desc'} + df = indata['df'][0] + df['virtual-link-profile'] = [affected_ivld_profile] with self.assertRaises(EngineException) as e: - self.topic.validate_internal_vlds(indata) + self.topic.validate_internal_virtual_links(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("internal-vld[id='{}']:ip-profile-ref='{}' does not exist".format( - ivld["id"], ivld["ip-profile-ref"])), - norm(str(e.exception)), "Wrong exception text") + self.assertIn(norm("df[id='{}']:virtual-link-profile='{}' must match an existing " + "int-virtual-link-desc".format(df["id"], affected_ivld_profile["id"])), + norm(str(e.exception)), "Wrong exception text") def test_validate_monitoring_params_on_valid_descriptor(self): indata = db_vnfd_content self.topic.validate_monitoring_params(indata) - def test_validate_monitoring_params_when_missing_vdu(self): + def test_validate_monitoring_params_on_duplicated_ivld_monitoring_param(self): indata = deepcopy(db_vnfd_content) - monitoring_param = indata['monitoring-param'][0] - indata['vdu'].pop() + duplicated_mp = {'id': 'cpu', 'name': 'cpu', 'performance_metric': 'cpu'} + affected_ivld = indata['int-virtual-link-desc'][0] + affected_ivld['monitoring-parameters'] = [duplicated_mp, duplicated_mp] with self.assertRaises(EngineException) as e: self.topic.validate_monitoring_params(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("monitoring-param:vdu-monitoring-param:vdu-monitoring-param-ref='{}' not " - "defined at vdu[id='{}'] or vdu does not exist" - .format(monitoring_param["vdu-monitoring-param"]["vdu-monitoring-param-ref"], - monitoring_param["vdu-monitoring-param"]["vdu-ref"])), + self.assertIn(norm("Duplicated monitoring-parameter id in " + "int-virtual-link-desc[id='{}']:monitoring-parameters[id='{}']" + .format(affected_ivld["id"], duplicated_mp["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_monitoring_params_when_missing_vdu_monitoring_param_ref(self): + def test_validate_monitoring_params_on_duplicated_vdu_monitoring_param(self): indata = deepcopy(db_vnfd_content) - monitoring_param = indata['monitoring-param'][0] - indata['vdu'][1]['monitoring-param'] = [] + duplicated_mp = {'id': 'dataVM_cpu_util', 'name': 'dataVM_cpu_util', 'performance_metric': 'cpu'} + affected_vdu = indata['vdu'][1] + affected_vdu['monitoring-parameter'].insert(0, duplicated_mp) with self.assertRaises(EngineException) as e: self.topic.validate_monitoring_params(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("monitoring-param:vdu-monitoring-param:vdu-monitoring-param-ref='{}' not " - "defined at vdu[id='{}'] or vdu does not exist" - .format(monitoring_param["vdu-monitoring-param"]["vdu-monitoring-param-ref"], - monitoring_param["vdu-monitoring-param"]["vdu-ref"])), + self.assertIn(norm("Duplicated monitoring-parameter id in " + "vdu[id='{}']:monitoring-parameter[id='{}']" + .format(affected_vdu["id"], duplicated_mp["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_scaling_group_descriptor_on_valid_descriptor(self): - indata = db_vnfd_content - self.topic.validate_scaling_group_descriptor(indata) - - def test_validate_scaling_group_descriptor_when_missing_vnf_monitoring_param_ref(self): + def test_validate_monitoring_params_on_duplicated_df_monitoring_param(self): indata = deepcopy(db_vnfd_content) - sgd = indata['scaling-group-descriptor'][0] - sc = sgd['scaling-policy'][0]['scaling-criteria'][0] - indata['monitoring-param'] = [] + duplicated_mp = {'id': 'memory', 'name': 'memory', 'performance_metric': 'memory'} + affected_df = indata['df'][0] + affected_df['monitoring-parameter'] = [duplicated_mp, duplicated_mp] with self.assertRaises(EngineException) as e: - self.topic.validate_scaling_group_descriptor(indata) + self.topic.validate_monitoring_params(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("scaling-group-descriptor[name='{}']:scaling-criteria[name='{}']:" - "vnf-monitoring-param-ref='{}' not defined in any monitoring-param" - .format(sgd["name"], sc["name"], sc["vnf-monitoring-param-ref"])), + self.assertIn(norm("Duplicated monitoring-parameter id in " + "df[id='{}']:monitoring-parameter[id='{}']" + .format(affected_df["id"], duplicated_mp["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_scaling_group_descriptor_when_missing_vdu(self): + def test_validate_scaling_group_descriptor_on_valid_descriptor(self): + indata = db_vnfd_content + self.topic.validate_scaling_group_descriptor(indata) + + def test_validate_scaling_group_descriptor_when_missing_monitoring_param(self): indata = deepcopy(db_vnfd_content) - sgd = indata['scaling-group-descriptor'][0] - sgd_vdu = sgd['vdu'][0] - indata['vdu'].pop() + vdu = indata['vdu'][1] + affected_df = indata['df'][0] + affected_sa = affected_df['scaling-aspect'][0] + affected_sp = affected_sa['scaling-policy'][0] + affected_sc = affected_sp['scaling-criteria'][0] + vdu.pop('monitoring-parameter') with self.assertRaises(EngineException) as e: self.topic.validate_scaling_group_descriptor(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("scaling-group-descriptor[name='{}']:vdu-id-ref={} does not match any vdu" - .format(sgd["name"], sgd_vdu["vdu-id-ref"])), + self.assertIn(norm("df[id='{}']:scaling-aspect[id='{}']:scaling-policy" + "[name='{}']:scaling-criteria[name='{}']: " + "vnf-monitoring-param-ref='{}' not defined in any monitoring-param" + .format(affected_df["id"], affected_sa["id"], affected_sp["name"], affected_sc["name"], + affected_sc["vnf-monitoring-param-ref"])), norm(str(e.exception)), "Wrong exception text") def test_validate_scaling_group_descriptor_when_missing_vnf_configuration(self): indata = deepcopy(db_vnfd_content) - sgd = indata['scaling-group-descriptor'][0] + df = indata['df'][0] + affected_sa = df['scaling-aspect'][0] indata.pop('vnf-configuration') with self.assertRaises(EngineException) as e: self.topic.validate_scaling_group_descriptor(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("'vnf-configuration' not defined in the descriptor but it is referenced by " - "scaling-group-descriptor[name='{}']:scaling-config-action" - .format(sgd["name"])), + self.assertIn(norm("'vnf-configuration' not defined in the descriptor but it is referenced " + "by df[id='{}']:scaling-aspect[id='{}']:scaling-config-action" + .format(df["id"], affected_sa["id"])), norm(str(e.exception)), "Wrong exception text") def test_validate_scaling_group_descriptor_when_missing_scaling_config_action_primitive(self): indata = deepcopy(db_vnfd_content) - sgd = indata['scaling-group-descriptor'][0] - sca = sgd['scaling-config-action'][0] - indata['vnf-configuration']['config-primitive'] = [] + df = indata['df'][0] + affected_sa = df['scaling-aspect'][0] + affected_sca_primitive = affected_sa['scaling-config-action'][0]['vnf-config-primitive-name-ref'] + indata['vnf-configuration'][0]['config-primitive'] = [] with self.assertRaises(EngineException) as e: self.topic.validate_scaling_group_descriptor(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("scaling-group-descriptor[name='{}']:scaling-config-action:vnf-config-" - "primitive-name-ref='{}' does not match any " + self.assertIn(norm("df[id='{}']:scaling-aspect[id='{}']:scaling-config-action:vnf-" + "config-primitive-name-ref='{}' does not match any " "vnf-configuration:config-primitive:name" - .format(sgd["name"], sca["vnf-config-primitive-name-ref"])), + .format(df["id"], affected_sa["id"], affected_sca_primitive)), norm(str(e.exception)), "Wrong exception text") @@ -821,8 +736,8 @@ class Test_NsdTopic(TestCase): finally: del test_nsd["extra-property"] with self.subTest(i=4, t='Check Pyangbind Validation: property types'): - tmp = test_nsd["short-name"] - test_nsd["short-name"] = {"key": 0} + tmp = test_nsd["designer"] + test_nsd["designer"] = {"key": 0} try: with self.assertRaises(EngineException, msg="Accepted NSD with a wrongly typed property") as e: self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) @@ -831,111 +746,65 @@ class Test_NsdTopic(TestCase): .format("json object contained a key that did not exist", "key")), norm(str(e.exception)), "Wrong exception text") finally: - test_nsd["short-name"] = tmp - with self.subTest(i=5, t='Check Input Validation: vld[mgmt-network+ip-profile]'): - tmp = test_nsd["vld"][0]["vim-network-name"] - del test_nsd["vld"][0]["vim-network-name"] - test_nsd["vld"][0]["ip-profile-ref"] = "fake-ip-profile" + test_nsd["designer"] = tmp + with self.subTest(i=5, t='Check Input Validation: mgmt-network+virtual-link-protocol-data'): + df = test_nsd['df'][0] + mgmt_profile = {'id': 'id', 'virtual-link-desc-id': 'mgmt', + 'virtual-link-protocol-data': {'associated-layer-protocol': 'ipv4'}} + df['virtual-link-profile'] = [mgmt_profile] try: with self.assertRaises(EngineException, msg="Accepted VLD with mgmt-network+ip-profile") as e: self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:ip-profile-ref" - " You cannot set an ip-profile when mgmt-network is True" - .format(test_nsd["vld"][0]["id"])), + self.assertIn(norm("Error at df[id='{}']:virtual-link-profile[id='{}']:virtual-link-protocol-data" + " You cannot set a virtual-link-protocol-data when mgmt-network is True" + .format(df["id"], mgmt_profile["id"])), norm(str(e.exception)), "Wrong exception text") finally: - test_nsd["vld"][0]["vim-network-name"] = tmp - del test_nsd["vld"][0]["ip-profile-ref"] - with self.subTest(i=6, t='Check Input Validation: vld[vnfd-connection-point-ref][vnfd-id-ref]'): - tmp = test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-id-ref"] - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-id-ref"] = "wrong-vnfd-id-ref" - try: - with self.assertRaises(EngineException, msg="Accepted VLD with wrong vnfd-connection-point-ref") as e: - self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:vnfd-connection-point-ref[vnfd-id-ref='{}']" - " does not match constituent-vnfd[member-vnf-index='{}']:vnfd-id-ref '{}'" - .format(test_nsd["vld"][0]["id"], - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-id-ref"], - test_nsd["constituent-vnfd"][0]["member-vnf-index"], - test_nsd["constituent-vnfd"][0]["vnfd-id-ref"])), - norm(str(e.exception)), "Wrong exception text") - finally: - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-id-ref"] = tmp - with self.subTest(i=7, t='Check Input Validation: vld[vnfd-connection-point-ref][member-vnf-index-ref]'): - tmp = test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["member-vnf-index-ref"] - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["member-vnf-index-ref"] = "wrong-member-vnf-index-ref" - try: - with self.assertRaises(EngineException, msg="Accepted VLD with wrong vnfd-connection-point-ref") as e: - self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:vnfd-connection-point-ref[member-vnf-index-ref='{}']" - " does not match any constituent-vnfd:member-vnf-index" - .format(test_nsd["vld"][0]["id"], - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["member-vnf-index-ref"])), - norm(str(e.exception)), "Wrong exception text") - finally: - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["member-vnf-index-ref"] = tmp - with self.subTest(i=8, t='Check Input Validation: vnffgd[classifier][rsp-id-ref]'): - test_nsd["vnffgd"] = [{"id": "fake-vnffgd-id", - "rsp": [{"id": "fake-rsp-id"}], - "classifier": [{"id": "fake-vnffgd-classifier-id", "rsp-id-ref": "wrong-rsp-id"}]}] - try: - with self.assertRaises(EngineException, msg="Accepted VNF FGD with wrong classifier rsp-id-ref") as e: - self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vnffgd[id='{}']:classifier[id='{}']:rsp-id-ref '{}'" - " does not match any rsp:id" - .format(test_nsd["vnffgd"][0]["id"], - test_nsd["vnffgd"][0]["classifier"][0]["id"], - test_nsd["vnffgd"][0]["classifier"][0]["rsp-id-ref"])), - norm(str(e.exception)), "Wrong exception text") - finally: - test_nsd["vnffgd"][0]["classifier"][0]["rsp-id-ref"] = "fake-rsp-id" - with self.subTest(i=9, t='Check Descriptor Dependencies: constituent-vnfd[vnfd-id-ref]'): + del df['virtual-link-profile'] + with self.subTest(i=6, t='Check Descriptor Dependencies: constituent-vnfd[vnfd-id-ref]'): self.db.get_one.side_effect = [{"_id": did, "_admin": db_nsd_content["_admin"]}, None] self.db.get_list.return_value = [] try: with self.assertRaises(EngineException, msg="Accepted wrong constituent VNFD ID reference") as e: self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") - self.assertIn(norm("Descriptor error at 'constituent-vnfd':'vnfd-id-ref'='{}'" - " references a non existing vnfd" - .format(test_nsd["constituent-vnfd"][0]["vnfd-id-ref"])), + self.assertIn(norm("'vnfd-id'='{}' references a non existing vnfd".format(test_nsd['vnfd-id'][0])), norm(str(e.exception)), "Wrong exception text") finally: pass - with self.subTest(i=10, t='Check Descriptor Dependencies: ' - 'vld[vnfd-connection-point-ref][vnfd-connection-point-ref]'): - tmp = test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-connection-point-ref"] - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-connection-point-ref"] = "wrong-vnfd-cp-ref" + with self.subTest(i=7, t='Check Descriptor Dependencies: ' + 'vld[vnfd-connection-point-ref][vnfd-connection-point-ref]'): + vnfd_descriptor = deepcopy(db_vnfd_content) + df = test_nsd['df'][0] + affected_vnf_profile = df['vnf-profile'][0] + affected_virtual_link = affected_vnf_profile['virtual-link-connectivity'][1] + affected_cpd = vnfd_descriptor['ext-cpd'].pop() self.db.get_one.side_effect = [{"_id": did, "_admin": db_nsd_content["_admin"]}, None] - self.db.get_list.return_value = [db_vnfd_content] + self.db.get_list.return_value = [vnfd_descriptor] try: with self.assertRaises(EngineException, msg="Accepted wrong VLD CP reference") as e: self.topic.upload_content(fake_session, did, test_nsd, {}, {"Content-Type": []}) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:vnfd-connection-point-ref[member-vnf-index-ref='{}']:" - "vnfd-connection-point-ref='{}' references a non existing conection-point:name" - " inside vnfd '{}'" - .format(test_nsd["vld"][0]["id"], - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["member-vnf-index-ref"], - test_nsd["vld"][0]["vnfd-connection-point-ref"][0] - ["vnfd-connection-point-ref"], - db_vnfd_content["id"])), + self.assertIn(norm("Error at df[id='{}']:vnf-profile[id='{}']:virtual-link-connectivity" + "[virtual-link-profile-id='{}']:constituent-cpd-id='{}' references a " + "non existing ext-cpd:id inside vnfd '{}'" + .format(df["id"], affected_vnf_profile["id"], + affected_virtual_link["virtual-link-profile-id"], affected_cpd["id"], + vnfd_descriptor["id"])), norm(str(e.exception)), "Wrong exception text") finally: - test_nsd["vld"][0]["vnfd-connection-point-ref"][0]["vnfd-connection-point-ref"] = tmp + pass return def test_edit_nsd(self): - did = db_nsd_content["_id"] + nsd_content = deepcopy(db_nsd_content) + did = nsd_content["_id"] self.fs.file_exists.return_value = True self.fs.dir_ls.return_value = True with self.subTest(i=1, t='Normal Edition'): now = time() - self.db.get_one.side_effect = [db_nsd_content, None] + self.db.get_one.side_effect = [nsd_content, None] self.db.get_list.return_value = [db_vnfd_content] data = {"id": "new-nsd-id", "name": "new-nsd-name"} self.topic.edit(fake_session, did, data) @@ -947,27 +816,28 @@ class Test_NsdTopic(TestCase): self.assertEqual(msg_args[2], data, "Wrong message content") self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic") self.assertEqual(db_args[1], did, "Wrong DB ID") - self.assertEqual(db_args[2]["_admin"]["created"], db_nsd_content["_admin"]["created"], + self.assertEqual(db_args[2]["_admin"]["created"], nsd_content["_admin"]["created"], "Wrong creation time") self.assertGreater(db_args[2]["_admin"]["modified"], now, "Wrong modification time") - self.assertEqual(db_args[2]["_admin"]["projects_read"], db_nsd_content["_admin"]["projects_read"], + self.assertEqual(db_args[2]["_admin"]["projects_read"], nsd_content["_admin"]["projects_read"], "Wrong read-only project list") - self.assertEqual(db_args[2]["_admin"]["projects_write"], db_nsd_content["_admin"]["projects_write"], + self.assertEqual(db_args[2]["_admin"]["projects_write"], nsd_content["_admin"]["projects_write"], "Wrong read-write project list") self.assertEqual(db_args[2]["id"], data["id"], "Wrong NSD ID") self.assertEqual(db_args[2]["name"], data["name"], "Wrong NSD Name") with self.subTest(i=2, t='Conflict on Edit'): data = {"id": "fake-nsd-id", "name": "new-nsd-name"} - self.db.get_one.side_effect = [db_nsd_content, {"_id": str(uuid4()), "id": data["id"]}] + self.db.get_one.side_effect = [nsd_content, {"_id": str(uuid4()), "id": data["id"]}] with self.assertRaises(EngineException, msg="Accepted existing NSD ID") as e: self.topic.edit(fake_session, did, data) self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") self.assertIn(norm("{} with id '{}' already exists for this project".format("nsd", data["id"])), norm(str(e.exception)), "Wrong exception text") with self.subTest(i=3, t='Check Envelope'): - data = {"nsd": {"id": "new-nsd-id", "name": "new-nsd-name"}} + data = {"nsd": {"nsd": {"id": "new-nsd-id", "name": "new-nsd-name"}}} + self.db.get_one.side_effect = [nsd_content, None] with self.assertRaises(EngineException, msg="Accepted NSD with wrong envelope") as e: - self.topic.edit(fake_session, did, data) + self.topic.edit(fake_session, did, data, content=nsd_content) self.assertEqual(e.exception.http_code, HTTPStatus.BAD_REQUEST, "Wrong HTTP status code") self.assertIn("'nsd' must be a list of only one element", norm(str(e.exception)), "Wrong exception text") return @@ -1047,95 +917,82 @@ class Test_NsdTopic(TestCase): self.fs.file_delete.assert_not_called() return - def test_validate_vld_mgmt_network_with_ip_profile_ref_on_valid_descriptor(self): + def test_validate_vld_mgmt_network_with_virtual_link_protocol_data_on_valid_descriptor(self): indata = deepcopy(db_nsd_content) - vld = indata['vld'][0] - self.topic.validate_vld_mgmt_network_with_ip_profile_ref(vld) + vld = indata['virtual-link-desc'][0] + self.topic.validate_vld_mgmt_network_with_virtual_link_protocol_data(vld, indata) - def test_validate_vld_mgmt_network_with_ip_profile_ref_when_both_defined(self): + def test_validate_vld_mgmt_network_with_virtual_link_protocol_data_when_both_defined(self): indata = deepcopy(db_nsd_content) - vld = indata['vld'][0] - vld['ip-profile-ref'] = 'a-profile-ref' + vld = indata['virtual-link-desc'][0] + df = indata['df'][0] + affected_vlp = {'id': 'id', 'virtual-link-desc-id': 'mgmt', + 'virtual-link-protocol-data': {'associated-layer-protocol': 'ipv4'}} + df['virtual-link-profile'] = [affected_vlp] with self.assertRaises(EngineException) as e: - self.topic.validate_vld_mgmt_network_with_ip_profile_ref(vld) + self.topic.validate_vld_mgmt_network_with_virtual_link_protocol_data(vld, indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:ip-profile-ref" - " You cannot set an ip-profile when mgmt-network is True" - .format(vld["id"])), + self.assertIn(norm("Error at df[id='{}']:virtual-link-profile[id='{}']:virtual-link-protocol-data" + " You cannot set a virtual-link-protocol-data when mgmt-network is True" + .format(df["id"], affected_vlp["id"])), norm(str(e.exception)), "Wrong exception text") - def test_validate_vld_connection_point_refs_on_valid_descriptor(self): + def test_validate_vnf_profiles_vnfd_id_on_valid_descriptor(self): indata = deepcopy(db_nsd_content) - vld = indata['vld'][0] - self.topic.validate_vld_connection_point_refs(vld, indata) - - def test_validate_vld_connection_point_refs_when_missing_constituent_vnfd(self): - indata = deepcopy(db_nsd_content) - vld = indata['vld'][0] - vnfd_cp = vld['vnfd-connection-point-ref'][0] - indata['constituent-vnfd'] = [] - with self.assertRaises(EngineException) as e: - self.topic.validate_vld_connection_point_refs(vld, indata) - self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:vnfd-connection-point-ref[member-vnf-index-ref='{}'] " - "does not match any constituent-vnfd:member-vnf-index" - .format(vld["id"], vnfd_cp["member-vnf-index-ref"])), - norm(str(e.exception)), "Wrong exception text") + self.topic.validate_vnf_profiles_vnfd_id(indata) - def test_validate_vld_connection_point_refs_on_unmatched_constituent_vnfd(self): + def test_validate_vnf_profiles_vnfd_id_when_missing_vnfd(self): indata = deepcopy(db_nsd_content) - vld = indata['vld'][0] - vnfd_cp = vld['vnfd-connection-point-ref'][0] - constituent_vnfd = indata['constituent-vnfd'][0] - constituent_vnfd['vnfd-id-ref'] = 'unmatched-vnfd-id-ref' + df = indata['df'][0] + affected_vnf_profile = df['vnf-profile'][0] + indata['vnfd-id'] = ['non-existing-vnfd'] with self.assertRaises(EngineException) as e: - self.topic.validate_vld_connection_point_refs(vld, indata) + self.topic.validate_vnf_profiles_vnfd_id(indata) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:vnfd-connection-point-ref[vnfd-id-ref='{}'] " - "does not match constituent-vnfd[member-vnf-index='{}']:vnfd-id-ref" - " '{}'".format(vld["id"], vnfd_cp["vnfd-id-ref"], - constituent_vnfd["member-vnf-index"], - constituent_vnfd["vnfd-id-ref"])), + self.assertIn(norm("Error at df[id='{}']:vnf_profile[id='{}']:vnfd-id='{}' " + "does not match any vnfd-id" + .format(df["id"], affected_vnf_profile["id"], affected_vnf_profile['vnfd-id'])), norm(str(e.exception)), "Wrong exception text") - def test_validate_vld_connection_point_refs_vnfd_connection_points_on_valid_descriptor(self): + def test_validate_df_vnf_profiles_constituent_connection_points_on_valid_descriptor(self): nsd_descriptor = deepcopy(db_nsd_content) - vnfd_1_descriptor = deepcopy(db_vnfd_content) - vnfd_2_descriptor = deepcopy(db_vnfd_content) - vld = nsd_descriptor['vld'][0] - member_vnfd_index = {'1': vnfd_1_descriptor, '2': vnfd_2_descriptor} - self.topic.validate_vld_connection_point_refs_vnfd_connection_points(vld, member_vnfd_index) + vnfd_descriptor = deepcopy(db_vnfd_content) + df = nsd_descriptor['df'][0] + vnfds_index = {vnfd_descriptor['id']: vnfd_descriptor} + self.topic.validate_df_vnf_profiles_constituent_connection_points(df, vnfds_index) - def test_validate_vld_connection_point_refs_vnfd_connection_points_when_missing_connection_point(self): + def test_validate_df_vnf_profiles_constituent_connection_points_when_missing_connection_point(self): nsd_descriptor = deepcopy(db_nsd_content) - vnfd_1_descriptor = deepcopy(db_vnfd_content) - vnfd_2_descriptor = deepcopy(db_vnfd_content) - vld = nsd_descriptor['vld'][0] - referenced_vnfd_cp = vld['vnfd-connection-point-ref'][0] - member_vnfd_index = {'1': vnfd_1_descriptor, '2': vnfd_2_descriptor} - vnfd_1_descriptor['connection-point'] = [] + vnfd_descriptor = deepcopy(db_vnfd_content) + df = nsd_descriptor['df'][0] + affected_vnf_profile = df['vnf-profile'][0] + affected_virtual_link = affected_vnf_profile['virtual-link-connectivity'][1] + vnfds_index = {vnfd_descriptor['id']: vnfd_descriptor} + affected_cpd = vnfd_descriptor['ext-cpd'].pop() with self.assertRaises(EngineException) as e: - self.topic.validate_vld_connection_point_refs_vnfd_connection_points(vld, member_vnfd_index) + self.topic.validate_df_vnf_profiles_constituent_connection_points(df, vnfds_index) self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code") - self.assertIn(norm("Error at vld[id='{}']:vnfd-connection-point-ref[member-vnf-index-ref='{}']:vnfd-" - "connection-point-ref='{}' references a non existing conection-point:name inside vnfd '{}'" - .format(vld["id"], referenced_vnfd_cp["member-vnf-index-ref"], - referenced_vnfd_cp["vnfd-connection-point-ref"], vnfd_1_descriptor["id"])), + self.assertIn(norm("Error at df[id='{}']:vnf-profile[id='{}']:virtual-link-connectivity" + "[virtual-link-profile-id='{}']:constituent-cpd-id='{}' references a " + "non existing ext-cpd:id inside vnfd '{}'" + .format(df["id"], affected_vnf_profile["id"], + affected_virtual_link["virtual-link-profile-id"], affected_cpd["id"], + vnfd_descriptor["id"])), norm(str(e.exception)), "Wrong exception text") - def test_check_conflict_on_edit_when_missing_vnfd_index(self): + def test_check_conflict_on_edit_when_missing_constituent_vnfd_id(self): nsd_descriptor = deepcopy(db_nsd_content) - invalid_vnfd_id_ref = 'invalid-vnfd-id-ref' + invalid_vnfd_id = 'invalid-vnfd-id' nsd_descriptor['id'] = 'invalid-vnfd-id-ns' - nsd_descriptor['constituent-vnfd'][0]['vnfd-id-ref'] = invalid_vnfd_id_ref - nsd_descriptor['vld'][0]['vnfd-connection-point-ref'][0]['vnfd-id-ref'] = invalid_vnfd_id_ref - nsd_descriptor['vld'][1]['vnfd-connection-point-ref'][0]['vnfd-id-ref'] = invalid_vnfd_id_ref + nsd_descriptor['vnfd-id'][0] = invalid_vnfd_id + nsd_descriptor['df'][0]['vnf-profile'][0]['vnfd-id'] = invalid_vnfd_id + nsd_descriptor['df'][0]['vnf-profile'][1]['vnfd-id'] = invalid_vnfd_id with self.assertRaises(EngineException) as e: self.db.get_list.return_value = [] self.topic.check_conflict_on_edit(fake_session, nsd_descriptor, [], 'id') self.assertEqual(e.exception.http_code, HTTPStatus.CONFLICT, "Wrong HTTP status code") - self.assertIn(norm("Descriptor error at 'constituent-vnfd':'vnfd-id-ref'='{}' references a non " - "existing vnfd".format(invalid_vnfd_id_ref)), + self.assertIn(norm("Descriptor error at 'vnfd-id'='{}' references a non " + "existing vnfd".format(invalid_vnfd_id)), norm(str(e.exception)), "Wrong exception text")