+ @patch("osm_nbi.descriptor_topics.yaml")
+ def test_validate_descriptor_changes(self, mock_yaml):
+ descriptor_name = "test_descriptor"
+ self.fs.file_open.side_effect = lambda path, mode: open(
+ "/tmp/" + str(uuid4()), "a+b"
+ )
+ with self.subTest(i=1, t="VNFD has changes in day1-2 config primitive"):
+ old_vnfd, new_vnfd = self.create_desc_temp(db_vnfd_content)
+ new_vnfd["df"][0]["lcm-operations-configuration"]["operate-vnf-op-config"][
+ "day1-2"
+ ][0]["config-primitive"][0]["name"] = "new_action"
+ mock_yaml.load.side_effect = [old_vnfd, new_vnfd]
+ with self.assertNotRaises(EngineException):
+ self.topic._validate_descriptor_changes(
+ descriptor_name, "/tmp/", "/tmp:1/"
+ )
+ with self.subTest(i=2, t="VNFD sw version changed"):
+ # old vnfd uses the default software version: 1.0
+ new_vnfd["software-version"] = "1.3"
+ new_vnfd["sw-image-desc"][0]["name"] = "new-image"
+ mock_yaml.load.side_effect = [old_vnfd, new_vnfd]
+ with self.assertNotRaises(EngineException):
+ self.topic._validate_descriptor_changes(
+ descriptor_name, "/tmp/", "/tmp:1/"
+ )
+ with self.subTest(
+ i=3, t="VNFD sw version is not changed and mgmt-cp has changed"
+ ):
+ old_vnfd, new_vnfd = self.create_desc_temp(db_vnfd_content)
+ new_vnfd["mgmt-cp"] = "new-mgmt-cp"
+ mock_yaml.load.side_effect = [old_vnfd, new_vnfd]
+ with self.assertRaises(EngineException) as e:
+ self.topic._validate_descriptor_changes(
+ descriptor_name, "/tmp/", "/tmp:1/"
+ )
+ self.assertEqual(
+ e.exception.http_code,
+ HTTPStatus.UNPROCESSABLE_ENTITY,
+ "Wrong HTTP status code",
+ )
+ self.assertIn(
+ norm("there are disallowed changes in the vnf descriptor"),
+ norm(str(e.exception)),
+ "Wrong exception text",
+ )
+