- 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"