- with self.subTest(i=1, t='Normal Creation'):
- self.db.create.return_value = did
- rollback = []
- did2, oid = self.topic.new(rollback, fake_session, {})
- db_args = self.db.create.call_args[0]
- msg_args = self.msg.write.call_args[0]
- self.assertEqual(len(rollback), 1, "Wrong rollback length")
- self.assertEqual(msg_args[0], self.topic.topic_msg, "Wrong message topic")
- self.assertEqual(msg_args[1], "created", "Wrong message action")
- self.assertEqual(msg_args[2], {"_id": did}, "Wrong message content")
- self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
- self.assertEqual(did2, did, "Wrong DB VNFD id")
- self.assertIsNotNone(db_args[1]["_admin"]["created"], "Wrong creation time")
- self.assertEqual(db_args[1]["_admin"]["modified"], db_args[1]["_admin"]["created"],
- "Wrong modification time")
- 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"]
- del test_vnfd["vdu"][0]["cloud-init-file"]
- del test_vnfd["vnf-configuration"]["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": []})
- msg_args = self.msg.write.call_args[0]
- test_vnfd["_id"] = did
- self.assertEqual(msg_args[0], self.topic.topic_msg, "Wrong message topic")
- self.assertEqual(msg_args[1], "edited", "Wrong message action")
- self.assertEqual(msg_args[2], test_vnfd, "Wrong message content")
- db_args = self.db.get_one.mock_calls[0][1]
- self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
- self.assertEqual(db_args[1]["_id"], did, "Wrong DB VNFD id")
- db_args = self.db.replace.call_args[0]
- self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
- self.assertEqual(db_args[1], did, "Wrong DB VNFD id")
- admin = db_args[2]["_admin"]
- db_admin = db_vnfd_content["_admin"]
- self.assertEqual(admin["type"], "vnfd", "Wrong descriptor type")
- self.assertEqual(admin["created"], db_admin["created"], "Wrong creation time")
- self.assertGreater(admin["modified"], db_admin["created"], "Wrong modification time")
- self.assertEqual(admin["projects_read"], db_admin["projects_read"], "Wrong read-only project list")
- self.assertEqual(admin["projects_write"], db_admin["projects_write"], "Wrong read-write project list")
- self.assertEqual(admin["onboardingState"], "ONBOARDED", "Wrong onboarding state")
- self.assertEqual(admin["operationalState"], "ENABLED", "Wrong operational state")
- self.assertEqual(admin["usageState"], "NOT_IN_USE", "Wrong usage state")
- storage = admin["storage"]
- self.assertEqual(storage["folder"], did, "Wrong storage folder")
- self.assertEqual(storage["descriptor"], "package", "Wrong storage descriptor")
- compare_desc(self, test_vnfd, db_args[2], "VNFD")
- finally:
- test_vnfd["vdu"][0]["cloud-init-file"] = tmp1
- test_vnfd["vnf-configuration"]["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'):
- test_vnfd["extra-property"] = 0
- try:
- with self.assertRaises(EngineException, msg="Accepted VNFD with an additional 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("json object contained a key that did not exist", "extra-property")),
- 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}
- 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": []})
- self.assertEqual(e.exception.http_code, HTTPStatus.UNPROCESSABLE_ENTITY, "Wrong HTTP status code")
- self.assertIn(norm("Error in pyangbind validation: {} ({})"
- .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'):
- 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]'):
- 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"]
- 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")),
- 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"
- try:
- with self.assertRaises(EngineException,
- msg="Accepted wrong management interface 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"])),
- 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"
- try:
- with self.assertRaises(EngineException,
- msg="Accepted wrong VDU interface external 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='{}']: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"])),
- 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"
- 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")
- 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"
- try:
- with self.assertRaises(EngineException, msg="Accepted non-existent internal VLD ICP id-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='{}']: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"])),
- 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"
- try:
- with self.assertRaises(EngineException, msg="Accepted non-existent IP 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"])),
- 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"}]
- try:
- with self.assertRaises(EngineException, msg="Accepted non-existent VDU Monitorimg Param") 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"])),
- 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"}]}
- try:
- with self.assertRaises(EngineException, msg="Accepted non-existent VDU Configuration Metric") 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"])),
- 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"}]
- try:
- 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"])),
- 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["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": []})
- self.assertTrue(rc, "Input Validation: Unexpected failure")
- return
+ del test_vnfd["vdu"][0]["cloud-init-file"]
+ del test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"][
+ "day1-2"
+ ][0]["execution-environment-list"][0]["juju"]
+ return test_vnfd
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_normal_creation(self, mock_rename, mock_shutil):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ rollback = []
+ did2, oid = self.topic.new(rollback, fake_session, {})
+ db_args = self.db.create.call_args[0]
+ msg_args = self.msg.write.call_args[0]
+
+ self.assertEqual(len(rollback), 1, "Wrong rollback length")
+ self.assertEqual(msg_args[0], self.topic.topic_msg, "Wrong message topic")
+ self.assertEqual(msg_args[1], "created", "Wrong message action")
+ self.assertEqual(msg_args[2], {"_id": did}, "Wrong message content")
+ self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
+ self.assertEqual(did2, did, "Wrong DB VNFD id")
+ self.assertIsNotNone(db_args[1]["_admin"]["created"], "Wrong creation time")
+ self.assertEqual(
+ db_args[1]["_admin"]["modified"],
+ db_args[1]["_admin"]["created"],
+ "Wrong modification time",
+ )
+ 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",
+ )
+
+ self.db.get_one.side_effect = [
+ {"_id": did, "_admin": deepcopy(db_vnfd_content["_admin"])},
+ None,
+ ]
+
+ self.topic.upload_content(
+ fake_session, did, test_vnfd, {}, {"Content-Type": []}
+ )
+ msg_args = self.msg.write.call_args[0]
+ test_vnfd["_id"] = did
+ self.assertEqual(msg_args[0], self.topic.topic_msg, "Wrong message topic")
+ self.assertEqual(msg_args[1], "edited", "Wrong message action")
+ self.assertEqual(msg_args[2], test_vnfd, "Wrong message content")
+
+ db_args = self.db.get_one.mock_calls[0][1]
+ self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
+ self.assertEqual(db_args[1]["_id"], did, "Wrong DB VNFD id")
+
+ db_args = self.db.replace.call_args[0]
+ self.assertEqual(db_args[0], self.topic.topic, "Wrong DB topic")
+ self.assertEqual(db_args[1], did, "Wrong DB VNFD id")
+
+ admin = db_args[2]["_admin"]
+ db_admin = deepcopy(db_vnfd_content["_admin"])
+ self.assertEqual(admin["type"], "vnfd", "Wrong descriptor type")
+ self.assertEqual(admin["created"], db_admin["created"], "Wrong creation time")
+ self.assertGreater(
+ admin["modified"], db_admin["created"], "Wrong modification time"
+ )
+ self.assertEqual(
+ admin["projects_read"],
+ db_admin["projects_read"],
+ "Wrong read-only project list",
+ )
+ self.assertEqual(
+ admin["projects_write"],
+ db_admin["projects_write"],
+ "Wrong read-write project list",
+ )
+ self.assertEqual(
+ admin["onboardingState"], "ONBOARDED", "Wrong onboarding state"
+ )
+ self.assertEqual(
+ admin["operationalState"], "ENABLED", "Wrong operational state"
+ )
+ self.assertEqual(admin["usageState"], "NOT_IN_USE", "Wrong usage state")
+
+ storage = admin["storage"]
+ self.assertEqual(storage["folder"], did + ":1", "Wrong storage folder")
+ self.assertEqual(storage["descriptor"], "package", "Wrong storage descriptor")
+ self.assertEqual(admin["revision"], 1, "Wrong revision number")
+ compare_desc(self, test_vnfd, db_args[2], "VNFD")
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_exploit(self, mock_rename, mock_shutil):
+ id, test_vnfd = self.prepare_vnfd(vnfd_exploit_text)
+
+ with self.assertRaises(EngineException):
+ self.topic.upload_content(
+ fake_session, id, test_vnfd, {}, {"Content-Type": []}
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_valid_helm_chart(self, mock_rename, mock_shutil):
+ id, test_vnfd = self.prepare_vnfd(vnfd_exploit_fixed_text)
+
+ with self.assertNotRaises():
+ self.topic.upload_content(
+ fake_session, id, test_vnfd, {}, {"Content-Type": []}
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_pyangbind_validation_additional_properties(
+ self, mock_rename, mock_shutil
+ ):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ self.topic.upload_content(
+ fake_session, did, test_vnfd, {}, {"Content-Type": []}
+ )
+ test_vnfd["_id"] = did
+ test_vnfd["extra-property"] = 0
+ self.db.get_one.side_effect = (
+ lambda table, filter, fail_on_empty=None, fail_on_more=None: {
+ "_id": did,
+ "_admin": deepcopy(db_vnfd_content["_admin"]),
+ }
+ )
+
+ with self.assertRaises(
+ EngineException, msg="Accepted VNFD with an additional 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(
+ "json object contained a key that did not exist", "extra-property"
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+ db_args = self.db.replace.call_args[0]
+ admin = db_args[2]["_admin"]
+ self.assertEqual(admin["revision"], 1, "Wrong revision number")
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_pyangbind_validation_property_types(
+ self, mock_rename, mock_shutil
+ ):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["_id"] = did
+ test_vnfd["product-name"] = {"key": 0}
+
+ 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": []}
+ )
+ self.assertEqual(
+ e.exception.http_code,
+ HTTPStatus.UNPROCESSABLE_ENTITY,
+ "Wrong HTTP status code",
+ )
+ self.assertIn(
+ norm(
+ "Error in pyangbind validation: {} ({})".format(
+ "json object contained a key that did not exist", "key"
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_cloud_init(self, mock_rename, mock_shutil):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ del test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"][
+ "day1-2"
+ ][0]["execution-environment-list"][0]["juju"]
+
+ 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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_day12_configuration(
+ self, mock_rename, mock_shutil
+ ):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ 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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_mgmt_cp(self, mock_rename, mock_shutil):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ del test_vnfd["mgmt-cp"]
+
+ 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-cp")),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_mgmt_cp_connection_point(
+ self, mock_rename, mock_shutil
+ ):
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["mgmt-cp"] = "wrong-cp"
+
+ 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-cp='{}' must match an existing ext-cpd".format(
+ test_vnfd["mgmt-cp"]
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_vdu_int_cpd(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for vdu internal connection point"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ ext_cpd = test_vnfd["ext-cpd"][1]
+ ext_cpd["int-cpd"]["cpd"] = "wrong-cpd"
+
+ 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(
+ "ext-cpd[id='{}']:int-cpd must match an existing vdu int-cpd".format(
+ ext_cpd["id"]
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_duplicated_vld(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for dublicated virtual link description"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["int-virtual-link-desc"].insert(0, {"id": "internal"})
+
+ 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(
+ "identifier id '{}' is not unique".format(
+ test_vnfd["int-virtual-link-desc"][0]["id"]
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_vdu_int_virtual_link_desc(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for vdu internal virtual link description"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ vdu = test_vnfd["vdu"][0]
+ int_cpd = vdu["int-cpd"][1]
+ int_cpd["int-virtual-link-desc"] = "non-existing-int-virtual-link-desc"
+
+ 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(
+ "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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_virtual_link_profile(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for virtual link profile"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ fake_ivld_profile = {"id": "fake-profile-ref", "flavour": "fake-flavour"}
+ df = test_vnfd["df"][0]
+ df["virtual-link-profile"] = [fake_ivld_profile]
+
+ 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(
+ "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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_scaling_criteria_vdu_id(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for scaling criteria with invalid vdu-id"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["df"][0]["scaling-aspect"][0]["aspect-delta-details"]["deltas"][0][
+ "vdu-delta"
+ ][0]["id"] = "vdudelta1"
+ affected_df = test_vnfd["df"][0]
+ sa = affected_df["scaling-aspect"][0]
+ delta = sa["aspect-delta-details"]["deltas"][0]
+ vdu_delta = delta["vdu-delta"][0]
+
+ with self.assertRaises(
+ EngineException, msg="Accepted invalid 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",
+ )
+ self.assertIn(
+ norm(
+ "df[id='{}']:scaling-aspect[id='{}']:aspect-delta-details"
+ "[delta='{}']: "
+ "vdu-id='{}' not defined in vdu".format(
+ affected_df["id"],
+ sa["id"],
+ delta["id"],
+ vdu_delta["id"],
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_scaling_criteria_monitoring_param_ref(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for scaling criteria without monitoring parameter"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ 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]
+ vdu.pop("monitoring-parameter")
+
+ 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",
+ )
+ 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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_scaling_aspect_vnf_configuration(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for scaling criteria without day12 configuration"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"][
+ "day1-2"
+ ].pop()
+ df = test_vnfd["df"][0]
+
+ 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(
+ "'day1-2 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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_scaling_config_action(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for scaling criteria wrong config primitive"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ df = test_vnfd["df"][0]
+ affected_df = test_vnfd["df"][0]
+ sa = affected_df["scaling-aspect"][0]
+ test_vnfd["df"][0].get("lcm-operations-configuration").get(
+ "operate-vnf-op-config"
+ )["day1-2"][0]["config-primitive"] = [{"name": "wrong-primitive"}]
+
+ 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(
+ "df[id='{}']:scaling-aspect[id='{}']:scaling-config-action:vnf-"
+ "config-primitive-name-ref='{}' does not match any "
+ "day1-2 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",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_healing_criteria_vdu_id(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for healing criteria with invalid vdu-id"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["df"][0]["healing-aspect"][0]["healing-policy"][0][
+ "vdu-id"
+ ] = "vduid1"
+ affected_df = test_vnfd["df"][0]
+ ha = affected_df["healing-aspect"][0]
+ hp = ha["healing-policy"][0]
+ hp_vdu_id = hp["vdu-id"]
+
+ with self.assertRaises(
+ EngineException, msg="Accepted invalid Healing 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",
+ )
+ self.assertIn(
+ norm(
+ "df[id='{}']:healing-aspect[id='{}']:healing-policy"
+ "[name='{}']: "
+ "vdu-id='{}' not defined in vdu".format(
+ affected_df["id"],
+ ha["id"],
+ hp["event-name"],
+ hp_vdu_id,
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_alarm_criteria_monitoring_param_ref(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for alarm with invalid monitoring parameter reference"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["vdu"][1]["alarm"][0]["vnf-monitoring-param-ref"] = "unit_test_alarm"
+ vdu = test_vnfd["vdu"][1]
+ alarm = vdu["alarm"][0]
+ alarm_monitoring_param = alarm["vnf-monitoring-param-ref"]
+
+ with self.assertRaises(
+ EngineException, msg="Accepted invalid Alarm 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",
+ )
+ self.assertIn(
+ norm(
+ "vdu[id='{}']:alarm[id='{}']:"
+ "vnf-monitoring-param-ref='{}' not defined in any monitoring-param".format(
+ vdu["id"],
+ alarm["alarm-id"],
+ alarm_monitoring_param,
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_storage_reference_criteria(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for invalid virtual-storge-desc reference"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["vdu"][1]["virtual-storage-desc"] = "unit_test_storage"
+ vdu = test_vnfd["vdu"][1]
+ vsd_ref = vdu["virtual-storage-desc"]
+
+ with self.assertRaises(
+ EngineException, msg="Accepted invalid virtual-storage-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(
+ "vdu[virtual-storage-desc='{}']"
+ "not defined in vnfd".format(
+ vsd_ref,
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_compute_reference_criteria(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ for invalid virtual-compute-desc reference"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["vdu"][1]["virtual-compute-desc"] = "unit_test_compute"
+ vdu = test_vnfd["vdu"][1]
+ vcd_ref = vdu["virtual-compute-desc"]
+
+ with self.assertRaises(
+ EngineException, msg="Accepted invalid virtual-compute-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(
+ "vdu[virtual-compute-desc='{}']"
+ "not defined in vnfd".format(
+ vcd_ref,
+ )
+ ),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+
+ @patch("osm_nbi.descriptor_topics.shutil")
+ @patch("osm_nbi.descriptor_topics.os.rename")
+ def test_new_vnfd_check_input_validation_everything_right(
+ self, mock_rename, mock_shutil
+ ):
+ """Testing input validation during new vnfd creation
+ everything correct"""
+ did, test_vnfd = self.prepare_vnfd_creation()
+ test_vnfd = self.prepare_test_vnfd(test_vnfd)
+ test_vnfd["id"] = "fake-vnfd-id"
+ test_vnfd["df"][0].get("lcm-operations-configuration").get(
+ "operate-vnf-op-config"
+ )["day1-2"][0]["id"] = "fake-vnfd-id"
+ self.db.get_one.side_effect = [
+ {"_id": did, "_admin": deepcopy(db_vnfd_content["_admin"])},
+ None,
+ ]
+ rc = self.topic.upload_content(
+ fake_session, did, test_vnfd, {}, {"Content-Type": []}
+ )
+ self.assertTrue(rc, "Input Validation: Unexpected failure")