GetVimCloud,
GetVnfDescriptor,
GetVnfRecord,
+ GetModelNames,
ChangeVnfState,
ChangeVnfInstantiationState,
SetVnfModel,
class SendNotificationForVnfImpl(SendNotificationForVnf):
async def __call__(self, activity_input: SendNotificationForVnf.Input) -> None:
self.logger.debug("Send notification for VNF not implemented.")
+
+
+@activity.defn(name=GetModelNames.__name__)
+class GetModelNamesImpl(GetModelNames):
+ async def __call__(
+ self, activity_input: GetModelNames.Input
+ ) -> GetModelNames.Output:
+ ns_id = activity_input.ns_uuid
+
+ vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": ns_id})
+ self.logger.debug(
+ f"Retrieved {len(vnfrs)} vnf records matching {ns_id} from database."
+ )
+
+ return GetModelNames.Output(
+ model_names={vnfr["namespace"] for vnfr in vnfrs if "namespace" in vnfr}
+ )
from osm_lcm.temporal.vnf_activities import (
ChangeVnfInstantiationStateImpl,
ChangeVnfStateImpl,
+ GetModelNamesImpl,
GetTaskQueueImpl,
GetVimCloudImpl,
GetVnfDescriptorImpl,
model_name = "my-model-name"
set_vnf_model_input = SetVnfModelImpl.Input(vnfr_uuid=vnfr_uuid, model_name=model_name)
cloud = "microk8s"
-nsr_uuid = "583726d4-957d-47f5-8df5-199456f7afd0"
+nsr_uuid = "dcf4c922-5a73-41bf-a6ca-870c22d6336c"
sample_vim_record = {
"_id": vim_uuid,
"name": "juju",
sample_vnfr = {
"_id": vnfr_uuid,
"id": vnfr_uuid,
- "nsr-id-ref": "dcf4c922-5a73-41bf-a6ca-870c22d6336c",
+ "nsr-id-ref": nsr_uuid,
"vnfd-ref": "jar_vnfd_scalable",
"vnfd-id": "f1b38eac-190c-485d-9a74-c6e169c929d8",
"vim-account-id": vim_account_id,
self.assertEqual(result, {})
+class TestGetModelNames(asynctest.TestCase):
+ async def setUp(self):
+ self.db = Mock()
+ self.get_model_names = GetModelNamesImpl(self.db)
+ self.env = ActivityEnvironment()
+
+ async def test_activity__success(self):
+ # Two namespaces, one of them repeated
+ self.db.get_list.return_value = [
+ {
+ "nsr-id-ref": nsr_uuid,
+ "namespace": namespace,
+ }
+ for namespace in ["namespace1", "namespace1", "namespace2"]
+ ]
+
+ activity_result = await self.env.run(
+ self.get_model_names,
+ GetModelNamesImpl.Input(ns_uuid=nsr_uuid),
+ )
+
+ self.assertEqual(activity_result.model_names, {"namespace1", "namespace2"})
+
+ async def test_activity__raise_db_exception(self):
+ self.db.get_list.side_effect = DbException("Can not connect to Database.")
+
+ with self.assertRaises(DbException):
+ await self.env.run(
+ self.get_model_names,
+ GetModelNamesImpl.Input(ns_uuid=nsr_uuid),
+ )
+
+
if __name__ == "__main__":
asynctest.main()