blob: ef87a4c4bc9e76b972c72059a672f6d75bd0cfa6 [file] [log] [blame]
tierno51d065c2019-08-26 16:48:23 +00001#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13#
14# For those usages not covered by the Apache License, Version 2.0 please
tiernoc231a872020-01-21 08:49:05 +000015# contact: alfonso.tiernosepulveda@telefonica.com
tierno51d065c2019-08-26 16:48:23 +000016##
17
18
garciadeblas5697b8b2021-03-24 09:17:02 +010019import asynctest # pip3 install asynctest --user
tierno51d065c2019-08-26 16:48:23 +000020import asyncio
21import yaml
bravof922c4172020-11-24 21:21:43 -030022import copy
tierno51d065c2019-08-26 16:48:23 +000023from os import getenv
tierno5ee730c2020-02-13 10:53:43 +000024from osm_lcm import ns
tierno51d065c2019-08-26 16:48:23 +000025from osm_common.msgkafka import MsgKafka
tierno51d065c2019-08-26 16:48:23 +000026from osm_lcm.lcm_utils import TaskRegistry
bravof922c4172020-11-24 21:21:43 -030027from osm_lcm.ng_ro import NgRoClient
28from osm_lcm.data_utils.database.database import Database
29from osm_lcm.data_utils.filesystem.filesystem import Filesystem
tierno51d065c2019-08-26 16:48:23 +000030from uuid import uuid4
31
kuuse951169e2019-10-03 15:27:51 +020032from osm_lcm.tests import test_db_descriptors as descriptors
33
tierno51d065c2019-08-26 16:48:23 +000034__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
35
tierno7ab529a2019-08-30 12:10:17 +000036""" Perform unittests using asynctest of osm_lcm.ns module
tierno51d065c2019-08-26 16:48:23 +000037It allows, if some testing ENV are supplied, testing without mocking some external libraries for debugging:
38 OSMLCMTEST_NS_PUBKEY: public ssh-key returned by N2VC to inject to VMs
tiernoe64f7fb2019-09-11 08:55:52 +000039 OSMLCMTEST_NS_NAME: change name of NS
tierno51d065c2019-08-26 16:48:23 +000040 OSMLCMTEST_PACKAGES_PATH: path where the vnf-packages are stored (de-compressed), each one on a 'vnfd_id' folder
41 OSMLCMTEST_NS_IPADDRESS: IP address where emulated VMs are reached. Comma separate list
tiernoe64f7fb2019-09-11 08:55:52 +000042 OSMLCMTEST_RO_VIMID: VIM id of RO target vim IP. Obtain it with openmano datcenter-list on RO container
tierno51d065c2019-08-26 16:48:23 +000043 OSMLCMTEST_VCA_NOMOCK: Do no mock the VCA, N2VC library, for debugging it
44 OSMLCMTEST_RO_NOMOCK: Do no mock the ROClient library, for debugging it
45 OSMLCMTEST_DB_NOMOCK: Do no mock the database library, for debugging it
tierno7ab529a2019-08-30 12:10:17 +000046 OSMLCMTEST_FS_NOMOCK: Do no mock the File Storage library, for debugging it
tierno51d065c2019-08-26 16:48:23 +000047 OSMLCMTEST_LOGGING_NOMOCK: Do no mock the logging
48 OSMLCM_VCA_XXX: configuration of N2VC
49 OSMLCM_RO_XXX: configuration of RO
50"""
51
tierno744303e2020-01-13 16:46:31 +000052lcm_config = {
garciadeblas5697b8b2021-03-24 09:17:02 +010053 "global": {"loglevel": "DEBUG"},
tierno744303e2020-01-13 16:46:31 +000054 "timeout": {},
garciadeblas5697b8b2021-03-24 09:17:02 +010055 "VCA": { # TODO replace with os.get_env to get other configurations
tierno744303e2020-01-13 16:46:31 +000056 "host": getenv("OSMLCM_VCA_HOST", "vca"),
57 "port": getenv("OSMLCM_VCA_PORT", 17070),
58 "user": getenv("OSMLCM_VCA_USER", "admin"),
59 "secret": getenv("OSMLCM_VCA_SECRET", "vca"),
60 "public_key": getenv("OSMLCM_VCA_PUBKEY", None),
garciadeblas5697b8b2021-03-24 09:17:02 +010061 "ca_cert": getenv("OSMLCM_VCA_CACERT", None),
62 "apiproxy": getenv("OSMLCM_VCA_APIPROXY", "192.168.1.1"),
tierno744303e2020-01-13 16:46:31 +000063 },
64 "ro_config": {
garciadeblas5697b8b2021-03-24 09:17:02 +010065 "uri": "http://{}:{}/openmano".format(
66 getenv("OSMLCM_RO_HOST", "ro"), getenv("OSMLCM_RO_PORT", "9090")
67 ),
tierno744303e2020-01-13 16:46:31 +000068 "tenant": getenv("OSMLCM_RO_TENANT", "osm"),
69 "logger_name": "lcm.ROclient",
70 "loglevel": "DEBUG",
garciadeblas5697b8b2021-03-24 09:17:02 +010071 "ng": True,
72 },
tierno51d065c2019-08-26 16:48:23 +000073}
74
tierno51d065c2019-08-26 16:48:23 +000075
76class TestMyNS(asynctest.TestCase):
garciadeblas5697b8b2021-03-24 09:17:02 +010077 async def _n2vc_DeployCharms(
78 self,
79 model_name,
80 application_name,
81 vnfd,
82 charm_path,
83 params={},
84 machine_spec={},
85 callback=None,
86 *callback_args
87 ):
tierno51d065c2019-08-26 16:48:23 +000088 if callback:
garciadeblas5697b8b2021-03-24 09:17:02 +010089 for status, message in (
90 ("maintenance", "installing sofwware"),
91 ("active", "Ready!"),
92 ):
tierno51d065c2019-08-26 16:48:23 +000093 # call callback after some time
94 asyncio.sleep(5, loop=self.loop)
95 callback(model_name, application_name, status, message, *callback_args)
96
97 @staticmethod
98 def _n2vc_FormatApplicationName(*args):
99 num_calls = 0
100 while True:
101 yield "app_name-{}".format(num_calls)
102 num_calls += 1
103
garciadeblas5697b8b2021-03-24 09:17:02 +0100104 def _n2vc_CreateExecutionEnvironment(
105 self, namespace, reuse_ee_id, db_dict, *args, **kwargs
106 ):
tierno51d065c2019-08-26 16:48:23 +0000107 k_list = namespace.split(".")
108 ee_id = k_list[1] + "."
109 if len(k_list) >= 2:
110 for k in k_list[2:4]:
111 ee_id += k[:8]
112 else:
113 ee_id += "_NS_"
tierno73d8bd02019-11-18 17:33:27 +0000114 return ee_id, {}
tierno51d065c2019-08-26 16:48:23 +0000115
bravof922c4172020-11-24 21:21:43 -0300116 def _ro_status(self, *args, **kwargs):
117 print("Args > {}".format(args))
118 print("kwargs > {}".format(kwargs))
tierno5ee730c2020-02-13 10:53:43 +0000119 if kwargs.get("delete"):
garciadeblas5697b8b2021-03-24 09:17:02 +0100120 ro_ns_desc = yaml.load(
121 descriptors.ro_delete_action_text, Loader=yaml.Loader
122 )
tierno5ee730c2020-02-13 10:53:43 +0000123 while True:
124 yield ro_ns_desc
125
126 ro_ns_desc = yaml.load(descriptors.ro_ns_text, Loader=yaml.Loader)
tierno51d065c2019-08-26 16:48:23 +0000127
128 # if ip address provided, replace descriptor
129 ip_addresses = getenv("OSMLCMTEST_NS_IPADDRESS", "")
130 if ip_addresses:
131 ip_addresses_list = ip_addresses.split(",")
132 for vnf in ro_ns_desc["vnfs"]:
133 if not ip_addresses_list:
134 break
135 vnf["ip_address"] = ip_addresses_list[0]
136 for vm in vnf["vms"]:
137 if not ip_addresses_list:
138 break
139 vm["ip_address"] = ip_addresses_list.pop(0)
140
141 while True:
142 yield ro_ns_desc
143 for net in ro_ns_desc["nets"]:
144 if net["status"] != "ACTIVE":
145 net["status"] = "ACTIVE"
146 break
147 else:
148 for vnf in ro_ns_desc["vnfs"]:
149 for vm in vnf["vms"]:
150 if vm["status"] != "ACTIVE":
151 vm["status"] = "ACTIVE"
152 break
153
bravof922c4172020-11-24 21:21:43 -0300154 def _ro_deploy(self, *args, **kwargs):
garciadeblas5697b8b2021-03-24 09:17:02 +0100155 return {"action_id": args[1]["action_id"], "nsr_id": args[0], "status": "ok"}
tierno51d065c2019-08-26 16:48:23 +0000156
157 def _return_uuid(self, *args, **kwargs):
158 return str(uuid4())
159
tierno5ee730c2020-02-13 10:53:43 +0000160 async def setUp(self):
161
tierno51d065c2019-08-26 16:48:23 +0000162 # Mock DB
163 if not getenv("OSMLCMTEST_DB_NOMOCK"):
bravof922c4172020-11-24 21:21:43 -0300164 # Cleanup singleton Database instance
165 Database.instance = None
166
garciadeblas5697b8b2021-03-24 09:17:02 +0100167 self.db = Database({"database": {"driver": "memory"}}).instance.db
168 self.db.create_list(
169 "vnfds", yaml.load(descriptors.db_vnfds_text, Loader=yaml.Loader)
170 )
171 self.db.create_list(
172 "nsds", yaml.load(descriptors.db_nsds_text, Loader=yaml.Loader)
173 )
174 self.db.create_list(
175 "nsrs", yaml.load(descriptors.db_nsrs_text, Loader=yaml.Loader)
176 )
177 self.db.create_list(
178 "vim_accounts",
179 yaml.load(descriptors.db_vim_accounts_text, Loader=yaml.Loader),
180 )
181 self.db.create_list(
182 "k8sclusters",
183 yaml.load(descriptors.db_k8sclusters_text, Loader=yaml.Loader),
184 )
185 self.db.create_list(
186 "nslcmops", yaml.load(descriptors.db_nslcmops_text, Loader=yaml.Loader)
187 )
188 self.db.create_list(
189 "vnfrs", yaml.load(descriptors.db_vnfrs_text, Loader=yaml.Loader)
190 )
191 self.db_vim_accounts = yaml.load(
192 descriptors.db_vim_accounts_text, Loader=yaml.Loader
193 )
tierno51d065c2019-08-26 16:48:23 +0000194
195 # Mock kafka
196 self.msg = asynctest.Mock(MsgKafka())
197
198 # Mock filesystem
199 if not getenv("OSMLCMTEST_FS_NOMOCK"):
garciadeblas5697b8b2021-03-24 09:17:02 +0100200 self.fs = asynctest.Mock(
201 Filesystem({"storage": {"driver": "local", "path": "/"}}).instance.fs
202 )
203 self.fs.get_params.return_value = {
204 "path": getenv("OSMLCMTEST_PACKAGES_PATH", "./test/temp/packages")
205 }
tierno51d065c2019-08-26 16:48:23 +0000206 self.fs.file_open = asynctest.mock_open()
207 # self.fs.file_open.return_value.__enter__.return_value = asynctest.MagicMock() # called on a python "with"
208 # self.fs.file_open.return_value.__enter__.return_value.read.return_value = "" # empty file
209
210 # Mock TaskRegistry
211 self.lcm_tasks = asynctest.Mock(TaskRegistry())
212 self.lcm_tasks.lock_HA.return_value = True
213 self.lcm_tasks.waitfor_related_HA.return_value = None
214 self.lcm_tasks.lookfor_related.return_value = ("", [])
215
tierno5ee730c2020-02-13 10:53:43 +0000216 # Mock VCA - K8s
217 if not getenv("OSMLCMTEST_VCA_K8s_NOMOCK"):
218 ns.K8sJujuConnector = asynctest.MagicMock(ns.K8sJujuConnector)
219 ns.K8sHelmConnector = asynctest.MagicMock(ns.K8sHelmConnector)
lloretgalleg18ebc3a2020-10-22 09:54:51 +0000220 ns.K8sHelm3Connector = asynctest.MagicMock(ns.K8sHelm3Connector)
tierno5ee730c2020-02-13 10:53:43 +0000221
222 if not getenv("OSMLCMTEST_VCA_NOMOCK"):
223 ns.N2VCJujuConnector = asynctest.MagicMock(ns.N2VCJujuConnector)
tierno588547c2020-07-01 15:30:20 +0000224 ns.LCMHelmConn = asynctest.MagicMock(ns.LCMHelmConn)
tierno5ee730c2020-02-13 10:53:43 +0000225
tierno51d065c2019-08-26 16:48:23 +0000226 # Create NsLCM class
bravof922c4172020-11-24 21:21:43 -0300227 self.my_ns = ns.NsLcm(self.msg, self.lcm_tasks, lcm_config, self.loop)
228 self.my_ns.fs = self.fs
229 self.my_ns.db = self.db
tierno5ee02052019-12-05 19:55:02 +0000230 self.my_ns._wait_dependent_n2vc = asynctest.CoroutineMock()
tierno51d065c2019-08-26 16:48:23 +0000231
232 # Mock logging
233 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
234 self.my_ns.logger = asynctest.Mock(self.my_ns.logger)
235
236 # Mock VCA - N2VC
237 if not getenv("OSMLCMTEST_VCA_NOMOCK"):
238 pub_key = getenv("OSMLCMTEST_NS_PUBKEY", "ssh-rsa test-pub-key t@osm.com")
tierno5ee730c2020-02-13 10:53:43 +0000239 # self.my_ns.n2vc = asynctest.Mock(N2VC())
garciadeblas5697b8b2021-03-24 09:17:02 +0100240 self.my_ns.n2vc.GetPublicKey.return_value = getenv(
241 "OSMLCM_VCA_PUBKEY", "public_key"
242 )
tierno51d065c2019-08-26 16:48:23 +0000243 # allow several versions of n2vc
garciadeblas5697b8b2021-03-24 09:17:02 +0100244 self.my_ns.n2vc.FormatApplicationName = asynctest.Mock(
245 side_effect=self._n2vc_FormatApplicationName()
246 )
247 self.my_ns.n2vc.DeployCharms = asynctest.CoroutineMock(
248 side_effect=self._n2vc_DeployCharms
249 )
tierno73d8bd02019-11-18 17:33:27 +0000250 self.my_ns.n2vc.create_execution_environment = asynctest.CoroutineMock(
garciadeblas5697b8b2021-03-24 09:17:02 +0100251 side_effect=self._n2vc_CreateExecutionEnvironment
252 )
253 self.my_ns.n2vc.install_configuration_sw = asynctest.CoroutineMock(
254 return_value=pub_key
255 )
256 self.my_ns.n2vc.get_ee_ssh_public__key = asynctest.CoroutineMock(
257 return_value=pub_key
258 )
259 self.my_ns.n2vc.exec_primitive = asynctest.CoroutineMock(
260 side_effect=self._return_uuid
261 )
262 self.my_ns.n2vc.exec_primitive = asynctest.CoroutineMock(
263 side_effect=self._return_uuid
264 )
265 self.my_ns.n2vc.GetPrimitiveStatus = asynctest.CoroutineMock(
266 return_value="completed"
267 )
268 self.my_ns.n2vc.GetPrimitiveOutput = asynctest.CoroutineMock(
269 return_value={"result": "ok", "pubkey": pub_key}
270 )
271 self.my_ns.n2vc.delete_execution_environment = asynctest.CoroutineMock(
272 return_value=None
273 )
tierno73d8bd02019-11-18 17:33:27 +0000274 self.my_ns.n2vc.get_public_key = asynctest.CoroutineMock(
garciadeblas5697b8b2021-03-24 09:17:02 +0100275 return_value=getenv("OSMLCM_VCA_PUBKEY", "public_key")
276 )
277 self.my_ns.n2vc.delete_namespace = asynctest.CoroutineMock(
278 return_value=None
279 )
tierno3bedc9b2019-11-27 15:46:57 +0000280
tierno51d065c2019-08-26 16:48:23 +0000281 # Mock RO
282 if not getenv("OSMLCMTEST_RO_NOMOCK"):
garciadeblas5697b8b2021-03-24 09:17:02 +0100283 self.my_ns.RO = asynctest.Mock(
284 NgRoClient(self.loop, **lcm_config["ro_config"])
285 )
tierno51d065c2019-08-26 16:48:23 +0000286 # TODO first time should be empty list, following should return a dict
bravof922c4172020-11-24 21:21:43 -0300287 # self.my_ns.RO.get_list = asynctest.CoroutineMock(self.my_ns.RO.get_list, return_value=[])
garciadeblas5697b8b2021-03-24 09:17:02 +0100288 self.my_ns.RO.deploy = asynctest.CoroutineMock(
289 self.my_ns.RO.deploy, side_effect=self._ro_deploy
290 )
bravof922c4172020-11-24 21:21:43 -0300291 # self.my_ns.RO.status = asynctest.CoroutineMock(self.my_ns.RO.status, side_effect=self._ro_status)
292 # self.my_ns.RO.create_action = asynctest.CoroutineMock(self.my_ns.RO.create_action,
293 # return_value={"vm-id": {"vim_result": 200,
294 # "description": "done"}})
295 self.my_ns.RO.delete = asynctest.CoroutineMock(self.my_ns.RO.delete)
tierno51d065c2019-08-26 16:48:23 +0000296
bravof922c4172020-11-24 21:21:43 -0300297 # @asynctest.fail_on(active_handles=True) # all async tasks must be completed
298 # async def test_instantiate(self):
299 # nsr_id = descriptors.test_ids["TEST-A"]["ns"]
300 # nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
301 # # print("Test instantiate started")
tierno51d065c2019-08-26 16:48:23 +0000302
bravof922c4172020-11-24 21:21:43 -0300303 # # delete deployed information of database
304 # if not getenv("OSMLCMTEST_DB_NOMOCK"):
305 # if self.db.get_list("nsrs")[0]["_admin"].get("deployed"):
306 # del self.db.get_list("nsrs")[0]["_admin"]["deployed"]
307 # for db_vnfr in self.db.get_list("vnfrs"):
308 # db_vnfr.pop("ip_address", None)
309 # for db_vdur in db_vnfr["vdur"]:
310 # db_vdur.pop("ip_address", None)
311 # db_vdur.pop("mac_address", None)
312 # if getenv("OSMLCMTEST_RO_VIMID"):
313 # self.db.get_list("vim_accounts")[0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
314 # if getenv("OSMLCMTEST_RO_VIMID"):
315 # self.db.get_list("nsrs")[0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
tierno51d065c2019-08-26 16:48:23 +0000316
bravof922c4172020-11-24 21:21:43 -0300317 # await self.my_ns.instantiate(nsr_id, nslcmop_id)
tierno51d065c2019-08-26 16:48:23 +0000318
bravof922c4172020-11-24 21:21:43 -0300319 # self.msg.aiowrite.assert_called_once_with("ns", "instantiated",
320 # {"nsr_id": nsr_id, "nslcmop_id": nslcmop_id,
321 # "operationState": "COMPLETED"},
322 # loop=self.loop)
323 # self.lcm_tasks.lock_HA.assert_called_once_with('ns', 'nslcmops', nslcmop_id)
324 # if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
325 # self.assertTrue(self.my_ns.logger.debug.called, "Debug method not called")
326 # self.my_ns.logger.error.assert_not_called()
327 # self.my_ns.logger.exception().assert_not_called()
tierno51d065c2019-08-26 16:48:23 +0000328
bravof922c4172020-11-24 21:21:43 -0300329 # if not getenv("OSMLCMTEST_DB_NOMOCK"):
330 # self.assertTrue(self.db.set_one.called, "db.set_one not called")
331 # db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
332 # db_vnfrs_list = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
333 # self.assertEqual(db_nsr["_admin"].get("nsState"), "INSTANTIATED", "Not instantiated")
334 # for vnfr in db_vnfrs_list:
335 # self.assertEqual(vnfr["_admin"].get("nsState"), "INSTANTIATED", "Not instantiated")
tierno51d065c2019-08-26 16:48:23 +0000336
bravof922c4172020-11-24 21:21:43 -0300337 # if not getenv("OSMLCMTEST_VCA_NOMOCK"):
338 # # check intial-primitives called
339 # self.assertTrue(self.my_ns.n2vc.exec_primitive.called,
340 # "Exec primitive not called for initial config primitive")
341 # for _call in self.my_ns.n2vc.exec_primitive.call_args_list:
342 # self.assertIn(_call[1]["primitive_name"], ("config", "touch"),
343 # "called exec primitive with a primitive different than config or touch")
lloretgalleg6d488782020-07-22 10:13:46 +0000344
bravof922c4172020-11-24 21:21:43 -0300345 # # TODO add more checks of called methods
346 # # TODO add a terminate
lloretgalleg6d488782020-07-22 10:13:46 +0000347
bravof922c4172020-11-24 21:21:43 -0300348 # async def test_instantiate_ee_list(self):
349 # # Using modern IM where configuration is in the new format of execution_environment_list
350 # ee_descriptor_id = "charm_simple"
351 # non_used_initial_primitive = {
352 # "name": "not_to_be_called",
353 # "seq": 3,
354 # "execution-environment-ref": "not_used_ee"
355 # }
356 # ee_list = [
357 # {
358 # "id": ee_descriptor_id,
359 # "juju": {"charm": "simple"},
tierno51d065c2019-08-26 16:48:23 +0000360
bravof922c4172020-11-24 21:21:43 -0300361 # },
362 # ]
tiernoa278b842020-07-08 15:33:55 +0000363
bravof922c4172020-11-24 21:21:43 -0300364 # self.db.set_one(
365 # "vnfds",
366 # q_filter={"_id": "7637bcf8-cf14-42dc-ad70-c66fcf1e6e77"},
367 # update_dict={"vnf-configuration.0.execution-environment-list": ee_list,
368 # "vnf-configuration.0.initial-config-primitive.0.execution-environment-ref": ee_descriptor_id,
369 # "vnf-configuration.0.initial-config-primitive.1.execution-environment-ref": ee_descriptor_id,
370 # "vnf-configuration.0.initial-config-primitive.2": non_used_initial_primitive,
371 # "vnf-configuration.0.config-primitive.0.execution-environment-ref": ee_descriptor_id,
372 # "vnf-configuration.0.config-primitive.0.execution-environment-primitive": "touch_charm",
373 # },
374 # unset={"vnf-configuration.juju": None})
375 # await self.test_instantiate()
376 # # this will check that the initial-congig-primitive 'not_to_be_called' is not called
tierno6cf25f52019-09-12 09:33:40 +0000377
kuuse951169e2019-10-03 15:27:51 +0200378 # Test scale() and related methods
garciadeblas5697b8b2021-03-24 09:17:02 +0100379 @asynctest.fail_on(active_handles=True) # all async tasks must be completed
tierno51d065c2019-08-26 16:48:23 +0000380 async def test_scale(self):
kuuse951169e2019-10-03 15:27:51 +0200381 # print("Test scale started")
382
383 # TODO: Add more higher-lever tests here, for example:
384 # scale-out/scale-in operations with success/error result
385
386 # Test scale() with missing 'scaleVnfData', should return operationState = 'FAILED'
tierno5ee730c2020-02-13 10:53:43 +0000387 nsr_id = descriptors.test_ids["TEST-A"]["ns"]
388 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
kuuse951169e2019-10-03 15:27:51 +0200389 await self.my_ns.scale(nsr_id, nslcmop_id)
garciadeblas5697b8b2021-03-24 09:17:02 +0100390 expected_value = "FAILED"
391 return_value = self.db.get_one("nslcmops", {"_id": nslcmop_id}).get(
392 "operationState"
393 )
kuuse951169e2019-10-03 15:27:51 +0200394 self.assertEqual(return_value, expected_value)
tierno3bedc9b2019-11-27 15:46:57 +0000395 # print("scale_result: {}".format(self.db.get_one("nslcmops", {"_id": nslcmop_id}).get("detailed-status")))
kuuse951169e2019-10-03 15:27:51 +0200396
aktas5f75f102021-03-15 11:26:10 +0300397 # Test scale() for native kdu
398 # this also includes testing _scale_kdu()
399 nsr_id = descriptors.test_ids["TEST-NATIVE-KDU"]["ns"]
400 nslcmop_id = descriptors.test_ids["TEST-NATIVE-KDU"]["instantiate"]
401
402 self.my_ns.k8sclusterjuju.scale = asynctest.mock.CoroutineMock()
403 self.my_ns.k8sclusterjuju.exec_primitive = asynctest.mock.CoroutineMock()
404 self.my_ns.k8sclusterjuju.get_scale_count = asynctest.mock.CoroutineMock(
405 return_value=1
406 )
407 await self.my_ns.scale(nsr_id, nslcmop_id)
408 expected_value = "COMPLETED"
409 return_value = self.db.get_one("nslcmops", {"_id": nslcmop_id}).get(
410 "operationState"
411 )
412 self.assertEqual(return_value, expected_value)
413 self.my_ns.k8sclusterjuju.scale.assert_called_once()
414
415 # Test scale() for native kdu with 2 resource
416 nsr_id = descriptors.test_ids["TEST-NATIVE-KDU-2"]["ns"]
417 nslcmop_id = descriptors.test_ids["TEST-NATIVE-KDU-2"]["instantiate"]
418
419 self.my_ns.k8sclusterjuju.get_scale_count.return_value = 2
420 await self.my_ns.scale(nsr_id, nslcmop_id)
421 expected_value = "COMPLETED"
422 return_value = self.db.get_one("nslcmops", {"_id": nslcmop_id}).get(
423 "operationState"
424 )
425 self.assertEqual(return_value, expected_value)
426 self.my_ns.k8sclusterjuju.scale.assert_called()
427
ksaikiranr43690582021-03-17 11:41:22 +0530428 async def test_vca_status_refresh(self):
429 nsr_id = descriptors.test_ids["TEST-A"]["ns"]
430 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
431 await self.my_ns.vca_status_refresh(nsr_id, nslcmop_id)
432 expected_value = dict()
433 return_value = dict()
434 vnf_descriptors = self.db.get_list("vnfds")
435 for i, _ in enumerate(vnf_descriptors):
436 for j, value in enumerate(vnf_descriptors[i]["df"]):
437 if "lcm-operations-configuration" in vnf_descriptors[i]["df"][j]:
garciadeblas5697b8b2021-03-24 09:17:02 +0100438 if (
439 "day1-2"
440 in value["lcm-operations-configuration"][
441 "operate-vnf-op-config"
442 ]
443 ):
444 for k, v in enumerate(
445 value["lcm-operations-configuration"][
446 "operate-vnf-op-config"
447 ]["day1-2"]
448 ):
aktas5f75f102021-03-15 11:26:10 +0300449 if (
450 v.get("execution-environment-list")
451 and "juju" in v["execution-environment-list"][k]
452 ):
garciadeblas5697b8b2021-03-24 09:17:02 +0100453 expected_value = self.db.get_list("nsrs")[i][
454 "vcaStatus"
455 ]
456 await self.my_ns._on_update_n2vc_db(
457 "nsrs", {"_id": nsr_id}, "_admin.deployed.VCA.0", {}
458 )
ksaikiranr43690582021-03-17 11:41:22 +0530459 return_value = self.db.get_list("nsrs")[i]["vcaStatus"]
460 self.assertEqual(return_value, expected_value)
461
tierno51183952020-04-03 15:48:18 +0000462 # Test _retry_or_skip_suboperation()
kuuse951169e2019-10-03 15:27:51 +0200463 # Expected result:
464 # - if a suboperation's 'operationState' is marked as 'COMPLETED', SUBOPERATION_STATUS_SKIP is expected
465 # - if marked as anything but 'COMPLETED', the suboperation index is expected
tierno51183952020-04-03 15:48:18 +0000466 def test_scale_retry_or_skip_suboperation(self):
kuuse951169e2019-10-03 15:27:51 +0200467 # Load an alternative 'nslcmops' YAML for this test
tierno5ee730c2020-02-13 10:53:43 +0000468 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
garciadeblas5697b8b2021-03-24 09:17:02 +0100469 db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
kuuse951169e2019-10-03 15:27:51 +0200470 op_index = 2
471 # Test when 'operationState' is 'COMPLETED'
garciadeblas5697b8b2021-03-24 09:17:02 +0100472 db_nslcmop["_admin"]["operations"][op_index]["operationState"] = "COMPLETED"
tierno51183952020-04-03 15:48:18 +0000473 return_value = self.my_ns._retry_or_skip_suboperation(db_nslcmop, op_index)
kuuse951169e2019-10-03 15:27:51 +0200474 expected_value = self.my_ns.SUBOPERATION_STATUS_SKIP
475 self.assertEqual(return_value, expected_value)
476 # Test when 'operationState' is not 'COMPLETED'
garciadeblas5697b8b2021-03-24 09:17:02 +0100477 db_nslcmop["_admin"]["operations"][op_index]["operationState"] = None
tierno51183952020-04-03 15:48:18 +0000478 return_value = self.my_ns._retry_or_skip_suboperation(db_nslcmop, op_index)
kuuse951169e2019-10-03 15:27:51 +0200479 expected_value = op_index
480 self.assertEqual(return_value, expected_value)
481
482 # Test _find_suboperation()
483 # Expected result: index of the found sub-operation, or SUBOPERATION_STATUS_NOT_FOUND if not found
484 def test_scale_find_suboperation(self):
485 # Load an alternative 'nslcmops' YAML for this test
tierno5ee730c2020-02-13 10:53:43 +0000486 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
garciadeblas5697b8b2021-03-24 09:17:02 +0100487 db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
kuuse951169e2019-10-03 15:27:51 +0200488 # Find this sub-operation
489 op_index = 2
garciadeblas5697b8b2021-03-24 09:17:02 +0100490 vnf_index = db_nslcmop["_admin"]["operations"][op_index]["member_vnf_index"]
491 primitive = db_nslcmop["_admin"]["operations"][op_index]["primitive"]
492 primitive_params = db_nslcmop["_admin"]["operations"][op_index][
493 "primitive_params"
494 ]
kuuse951169e2019-10-03 15:27:51 +0200495 match = {
garciadeblas5697b8b2021-03-24 09:17:02 +0100496 "member_vnf_index": vnf_index,
497 "primitive": primitive,
498 "primitive_params": primitive_params,
kuuse951169e2019-10-03 15:27:51 +0200499 }
500 found_op_index = self.my_ns._find_suboperation(db_nslcmop, match)
501 self.assertEqual(found_op_index, op_index)
502 # Test with not-matching params
503 match = {
garciadeblas5697b8b2021-03-24 09:17:02 +0100504 "member_vnf_index": vnf_index,
505 "primitive": "",
506 "primitive_params": primitive_params,
kuuse951169e2019-10-03 15:27:51 +0200507 }
508 found_op_index = self.my_ns._find_suboperation(db_nslcmop, match)
509 self.assertEqual(found_op_index, self.my_ns.SUBOPERATION_STATUS_NOT_FOUND)
510 # Test with None
511 match = None
512 found_op_index = self.my_ns._find_suboperation(db_nslcmop, match)
513 self.assertEqual(found_op_index, self.my_ns.SUBOPERATION_STATUS_NOT_FOUND)
514
515 # Test _update_suboperation_status()
516 def test_scale_update_suboperation_status(self):
tierno626e0152019-11-29 14:16:16 +0000517 self.db.set_one = asynctest.Mock()
tierno5ee730c2020-02-13 10:53:43 +0000518 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
garciadeblas5697b8b2021-03-24 09:17:02 +0100519 db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
kuuse951169e2019-10-03 15:27:51 +0200520 op_index = 0
521 # Force the initial values to be distinct from the updated ones
tierno3bedc9b2019-11-27 15:46:57 +0000522 q_filter = {"_id": db_nslcmop["_id"]}
kuuse951169e2019-10-03 15:27:51 +0200523 # Test to change 'operationState' and 'detailed-status'
garciadeblas5697b8b2021-03-24 09:17:02 +0100524 operationState = "COMPLETED"
525 detailed_status = "Done"
526 expected_update_dict = {
527 "_admin.operations.0.operationState": operationState,
528 "_admin.operations.0.detailed-status": detailed_status,
529 }
530 self.my_ns._update_suboperation_status(
531 db_nslcmop, op_index, operationState, detailed_status
532 )
533 self.db.set_one.assert_called_once_with(
534 "nslcmops",
535 q_filter=q_filter,
536 update_dict=expected_update_dict,
537 fail_on_empty=False,
538 )
kuuse951169e2019-10-03 15:27:51 +0200539
kuuse951169e2019-10-03 15:27:51 +0200540 def test_scale_add_suboperation(self):
tierno5ee730c2020-02-13 10:53:43 +0000541 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
garciadeblas5697b8b2021-03-24 09:17:02 +0100542 db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
543 vnf_index = "1"
544 num_ops_before = len(db_nslcmop.get("_admin", {}).get("operations", [])) - 1
kuuse951169e2019-10-03 15:27:51 +0200545 vdu_id = None
546 vdu_count_index = None
547 vdu_name = None
garciadeblas5697b8b2021-03-24 09:17:02 +0100548 primitive = "touch"
549 mapped_primitive_params = {
550 "parameter": [
551 {
552 "data-type": "STRING",
553 "name": "filename",
554 "default-value": "<touch_filename2>",
555 }
556 ],
557 "name": "touch",
558 }
559 operationState = "PROCESSING"
560 detailed_status = "In progress"
561 operationType = "PRE-SCALE"
kuuse951169e2019-10-03 15:27:51 +0200562 # Add a 'pre-scale' suboperation
garciadeblas5697b8b2021-03-24 09:17:02 +0100563 op_index_after = self.my_ns._add_suboperation(
564 db_nslcmop,
565 vnf_index,
566 vdu_id,
567 vdu_count_index,
568 vdu_name,
569 primitive,
570 mapped_primitive_params,
571 operationState,
572 detailed_status,
573 operationType,
574 )
kuuse951169e2019-10-03 15:27:51 +0200575 self.assertEqual(op_index_after, num_ops_before + 1)
576
577 # Delete all suboperations and add the same operation again
garciadeblas5697b8b2021-03-24 09:17:02 +0100578 del db_nslcmop["_admin"]["operations"]
579 op_index_zero = self.my_ns._add_suboperation(
580 db_nslcmop,
581 vnf_index,
582 vdu_id,
583 vdu_count_index,
584 vdu_name,
585 primitive,
586 mapped_primitive_params,
587 operationState,
588 detailed_status,
589 operationType,
590 )
kuuse951169e2019-10-03 15:27:51 +0200591 self.assertEqual(op_index_zero, 0)
592
593 # Add a 'RO' suboperation
garciadeblas5697b8b2021-03-24 09:17:02 +0100594 RO_nsr_id = "1234567890"
595 RO_scaling_info = [
596 {
597 "type": "create",
598 "count": 1,
599 "member-vnf-index": "1",
600 "osm_vdu_id": "dataVM",
601 }
602 ]
603 op_index = self.my_ns._add_suboperation(
604 db_nslcmop,
605 vnf_index,
606 vdu_id,
607 vdu_count_index,
608 vdu_name,
609 primitive,
610 mapped_primitive_params,
611 operationState,
612 detailed_status,
613 operationType,
614 RO_nsr_id,
615 RO_scaling_info,
616 )
617 db_RO_nsr_id = db_nslcmop["_admin"]["operations"][op_index]["RO_nsr_id"]
kuuse951169e2019-10-03 15:27:51 +0200618 self.assertEqual(op_index, 1)
619 self.assertEqual(RO_nsr_id, db_RO_nsr_id)
620
621 # Try to add an invalid suboperation, should return SUBOPERATION_STATUS_NOT_FOUND
garciadeblas5697b8b2021-03-24 09:17:02 +0100622 op_index_invalid = self.my_ns._add_suboperation(
623 None, None, None, None, None, None, None, None, None, None, None
624 )
kuuse951169e2019-10-03 15:27:51 +0200625 self.assertEqual(op_index_invalid, self.my_ns.SUBOPERATION_STATUS_NOT_FOUND)
626
627 # Test _check_or_add_scale_suboperation() and _check_or_add_scale_suboperation_RO()
628 # check the possible return values:
629 # - SUBOPERATION_STATUS_NEW: This is a new sub-operation
630 # - op_index (non-negative number): This is an existing sub-operation, operationState != 'COMPLETED'
631 # - SUBOPERATION_STATUS_SKIP: This is an existing sub-operation, operationState == 'COMPLETED'
632 def test_scale_check_or_add_scale_suboperation(self):
tierno5ee730c2020-02-13 10:53:43 +0000633 nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
garciadeblas5697b8b2021-03-24 09:17:02 +0100634 db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
635 operationType = "PRE-SCALE"
636 vnf_index = "1"
637 primitive = "touch"
638 primitive_params = {
639 "parameter": [
640 {
641 "data-type": "STRING",
642 "name": "filename",
643 "default-value": "<touch_filename2>",
644 }
645 ],
646 "name": "touch",
647 }
kuuse951169e2019-10-03 15:27:51 +0200648
649 # Delete all sub-operations to be sure this is a new sub-operation
garciadeblas5697b8b2021-03-24 09:17:02 +0100650 del db_nslcmop["_admin"]["operations"]
kuuse951169e2019-10-03 15:27:51 +0200651
652 # Add a new sub-operation
653 # For new sub-operations, operationState is set to 'PROCESSING' by default
654 op_index_new = self.my_ns._check_or_add_scale_suboperation(
garciadeblas5697b8b2021-03-24 09:17:02 +0100655 db_nslcmop, vnf_index, primitive, primitive_params, operationType
656 )
kuuse951169e2019-10-03 15:27:51 +0200657 self.assertEqual(op_index_new, self.my_ns.SUBOPERATION_STATUS_NEW)
658
659 # Use the same parameters again to match the already added sub-operation
660 # which has status 'PROCESSING' (!= 'COMPLETED') by default
661 # The expected return value is a non-negative number
662 op_index_existing = self.my_ns._check_or_add_scale_suboperation(
garciadeblas5697b8b2021-03-24 09:17:02 +0100663 db_nslcmop, vnf_index, primitive, primitive_params, operationType
664 )
kuuse951169e2019-10-03 15:27:51 +0200665 self.assertTrue(op_index_existing >= 0)
666
667 # Change operationState 'manually' for this sub-operation
garciadeblas5697b8b2021-03-24 09:17:02 +0100668 db_nslcmop["_admin"]["operations"][op_index_existing][
669 "operationState"
670 ] = "COMPLETED"
kuuse951169e2019-10-03 15:27:51 +0200671 # Then use the same parameters again to match the already added sub-operation,
672 # which now has status 'COMPLETED'
673 # The expected return value is SUBOPERATION_STATUS_SKIP
674 op_index_skip = self.my_ns._check_or_add_scale_suboperation(
garciadeblas5697b8b2021-03-24 09:17:02 +0100675 db_nslcmop, vnf_index, primitive, primitive_params, operationType
676 )
kuuse951169e2019-10-03 15:27:51 +0200677 self.assertEqual(op_index_skip, self.my_ns.SUBOPERATION_STATUS_SKIP)
678
679 # RO sub-operation test:
680 # Repeat tests for the very similar _check_or_add_scale_suboperation_RO(),
garciadeblas5697b8b2021-03-24 09:17:02 +0100681 RO_nsr_id = "1234567890"
682 RO_scaling_info = [
683 {
684 "type": "create",
685 "count": 1,
686 "member-vnf-index": "1",
687 "osm_vdu_id": "dataVM",
688 }
689 ]
kuuse951169e2019-10-03 15:27:51 +0200690 op_index_new_RO = self.my_ns._check_or_add_scale_suboperation(
garciadeblas5697b8b2021-03-24 09:17:02 +0100691 db_nslcmop, vnf_index, None, None, "SCALE-RO", RO_nsr_id, RO_scaling_info
692 )
kuuse951169e2019-10-03 15:27:51 +0200693 self.assertEqual(op_index_new_RO, self.my_ns.SUBOPERATION_STATUS_NEW)
694
695 # Use the same parameters again to match the already added RO sub-operation
696 op_index_existing_RO = self.my_ns._check_or_add_scale_suboperation(
garciadeblas5697b8b2021-03-24 09:17:02 +0100697 db_nslcmop, vnf_index, None, None, "SCALE-RO", RO_nsr_id, RO_scaling_info
698 )
kuuse951169e2019-10-03 15:27:51 +0200699 self.assertTrue(op_index_existing_RO >= 0)
700
701 # Change operationState 'manually' for this RO sub-operation
garciadeblas5697b8b2021-03-24 09:17:02 +0100702 db_nslcmop["_admin"]["operations"][op_index_existing_RO][
703 "operationState"
704 ] = "COMPLETED"
kuuse951169e2019-10-03 15:27:51 +0200705 # Then use the same parameters again to match the already added sub-operation,
706 # which now has status 'COMPLETED'
707 # The expected return value is SUBOPERATION_STATUS_SKIP
708 op_index_skip_RO = self.my_ns._check_or_add_scale_suboperation(
garciadeblas5697b8b2021-03-24 09:17:02 +0100709 db_nslcmop, vnf_index, None, None, "SCALE-RO", RO_nsr_id, RO_scaling_info
710 )
kuuse951169e2019-10-03 15:27:51 +0200711 self.assertEqual(op_index_skip_RO, self.my_ns.SUBOPERATION_STATUS_SKIP)
tierno51d065c2019-08-26 16:48:23 +0000712
tierno626e0152019-11-29 14:16:16 +0000713 async def test_deploy_kdus(self):
tierno5ee730c2020-02-13 10:53:43 +0000714 nsr_id = descriptors.test_ids["TEST-KDU"]["ns"]
tiernoe876f672020-02-13 14:34:48 +0000715 nslcmop_id = descriptors.test_ids["TEST-KDU"]["instantiate"]
tierno5ee730c2020-02-13 10:53:43 +0000716 db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
garciadeblas5697b8b2021-03-24 09:17:02 +0100717 db_vnfr = self.db.get_one(
718 "vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "multikdu"}
719 )
tierno626e0152019-11-29 14:16:16 +0000720 db_vnfrs = {"multikdu": db_vnfr}
tierno5ee730c2020-02-13 10:53:43 +0000721 db_vnfd = self.db.get_one("vnfds", {"_id": db_vnfr["vnfd-id"]})
David Garciad41dbd62020-12-10 12:52:52 +0100722 db_vnfds = [db_vnfd]
tiernoe876f672020-02-13 14:34:48 +0000723 task_register = {}
tierno626e0152019-11-29 14:16:16 +0000724 logging_text = "KDU"
David Garciad64e2742021-02-25 20:19:18 +0100725 self.my_ns.k8sclusterhelm3.generate_kdu_instance_name = asynctest.mock.Mock()
726 self.my_ns.k8sclusterhelm3.generate_kdu_instance_name.return_value = "k8s_id"
727 self.my_ns.k8sclusterhelm3.install = asynctest.CoroutineMock()
garciadeblas5697b8b2021-03-24 09:17:02 +0100728 self.my_ns.k8sclusterhelm3.synchronize_repos = asynctest.CoroutineMock(
729 return_value=("", "")
730 )
731 self.my_ns.k8sclusterhelm3.get_services = asynctest.CoroutineMock(
732 return_value=([])
733 )
734 await self.my_ns.deploy_kdus(
735 logging_text, nsr_id, nslcmop_id, db_vnfrs, db_vnfds, task_register
736 )
tiernoe876f672020-02-13 14:34:48 +0000737 await asyncio.wait(list(task_register.keys()), timeout=100)
tierno626e0152019-11-29 14:16:16 +0000738 db_nsr = self.db.get_list("nsrs")[1]
garciadeblas5697b8b2021-03-24 09:17:02 +0100739 self.assertIn(
740 "K8s",
741 db_nsr["_admin"]["deployed"],
742 "K8s entry not created at '_admin.deployed'",
743 )
744 self.assertIsInstance(
745 db_nsr["_admin"]["deployed"]["K8s"], list, "K8s entry is not of type list"
746 )
747 self.assertEqual(
748 len(db_nsr["_admin"]["deployed"]["K8s"]), 2, "K8s entry is not of type list"
749 )
750 k8s_instace_info = {
751 "kdu-instance": "k8s_id",
752 "k8scluster-uuid": "73d96432-d692-40d2-8440-e0c73aee209c",
753 "k8scluster-type": "helm-chart-v3",
754 "kdu-name": "ldap",
755 "member-vnf-index": "multikdu",
756 "namespace": None,
romeromonser4554a702021-05-28 12:00:08 +0200757 "kdu-deployment-name": None,
garciadeblas5697b8b2021-03-24 09:17:02 +0100758 }
tierno626e0152019-11-29 14:16:16 +0000759
bravof922c4172020-11-24 21:21:43 -0300760 nsr_result = copy.deepcopy(db_nsr["_admin"]["deployed"]["K8s"][0])
761 nsr_kdu_model_result = nsr_result.pop("kdu-model")
762 expected_kdu_model = "stable/openldap:1.2.1"
763 self.assertEqual(nsr_result, k8s_instace_info)
764 self.assertTrue(
garciadeblas5697b8b2021-03-24 09:17:02 +0100765 nsr_kdu_model_result in expected_kdu_model
766 or expected_kdu_model in nsr_kdu_model_result
bravof922c4172020-11-24 21:21:43 -0300767 )
768 nsr_result = copy.deepcopy(db_nsr["_admin"]["deployed"]["K8s"][1])
769 nsr_kdu_model_result = nsr_result.pop("kdu-model")
tierno626e0152019-11-29 14:16:16 +0000770 k8s_instace_info["kdu-name"] = "mongo"
bravof922c4172020-11-24 21:21:43 -0300771 expected_kdu_model = "stable/mongodb"
772 self.assertEqual(nsr_result, k8s_instace_info)
773 self.assertTrue(
garciadeblas5697b8b2021-03-24 09:17:02 +0100774 nsr_kdu_model_result in expected_kdu_model
775 or expected_kdu_model in nsr_kdu_model_result
bravof922c4172020-11-24 21:21:43 -0300776 )
tierno626e0152019-11-29 14:16:16 +0000777
bravof922c4172020-11-24 21:21:43 -0300778 # async def test_instantiate_pdu(self):
779 # nsr_id = descriptors.test_ids["TEST-A"]["ns"]
780 # nslcmop_id = descriptors.test_ids["TEST-A"]["instantiate"]
781 # # Modify vnfd/vnfr to change KDU for PDU. Adding keys that NBI will already set
782 # self.db.set_one("vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "1"},
783 # update_dict={"ip-address": "10.205.1.46",
784 # "vdur.0.pdu-id": "53e1ec21-2464-451e-a8dc-6e311d45b2c8",
785 # "vdur.0.pdu-type": "PDU-TYPE-1",
786 # "vdur.0.ip-address": "10.205.1.46",
787 # },
788 # unset={"vdur.status": None})
789 # self.db.set_one("vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "2"},
790 # update_dict={"ip-address": "10.205.1.47",
791 # "vdur.0.pdu-id": "53e1ec21-2464-451e-a8dc-6e311d45b2c8",
792 # "vdur.0.pdu-type": "PDU-TYPE-1",
793 # "vdur.0.ip-address": "10.205.1.47",
794 # },
795 # unset={"vdur.status": None})
tierno0e8c3f02020-03-12 17:18:21 +0000796
bravof922c4172020-11-24 21:21:43 -0300797 # await self.my_ns.instantiate(nsr_id, nslcmop_id)
798 # db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
799 # self.assertEqual(db_nsr.get("nsState"), "READY", str(db_nsr.get("errorDescription ")))
800 # self.assertEqual(db_nsr.get("currentOperation"), "IDLE", "currentOperation different than 'IDLE'")
801 # self.assertEqual(db_nsr.get("currentOperationID"), None, "currentOperationID different than None")
802 # self.assertEqual(db_nsr.get("errorDescription "), None, "errorDescription different than None")
803 # self.assertEqual(db_nsr.get("errorDetail"), None, "errorDetail different than None")
tierno0e8c3f02020-03-12 17:18:21 +0000804
bravof922c4172020-11-24 21:21:43 -0300805 # @asynctest.fail_on(active_handles=True) # all async tasks must be completed
806 # async def test_terminate_without_configuration(self):
807 # nsr_id = descriptors.test_ids["TEST-A"]["ns"]
808 # nslcmop_id = descriptors.test_ids["TEST-A"]["terminate"]
809 # # set instantiation task as completed
810 # self.db.set_list("nslcmops", {"nsInstanceId": nsr_id, "_id.ne": nslcmop_id},
811 # update_dict={"operationState": "COMPLETED"})
812 # self.db.set_one("nsrs", {"_id": nsr_id},
813 # update_dict={"_admin.deployed.VCA.0": None, "_admin.deployed.VCA.1": None})
tiernoe876f672020-02-13 14:34:48 +0000814
bravof922c4172020-11-24 21:21:43 -0300815 # await self.my_ns.terminate(nsr_id, nslcmop_id)
816 # db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
817 # self.assertEqual(db_nslcmop.get("operationState"), 'COMPLETED', db_nslcmop.get("detailed-status"))
818 # db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
819 # self.assertEqual(db_nsr.get("nsState"), "NOT_INSTANTIATED", str(db_nsr.get("errorDescription ")))
820 # self.assertEqual(db_nsr["_admin"].get("nsState"), "NOT_INSTANTIATED", str(db_nsr.get("errorDescription ")))
821 # self.assertEqual(db_nsr.get("currentOperation"), "IDLE", "currentOperation different than 'IDLE'")
822 # self.assertEqual(db_nsr.get("currentOperationID"), None, "currentOperationID different than None")
823 # self.assertEqual(db_nsr.get("errorDescription "), None, "errorDescription different than None")
824 # self.assertEqual(db_nsr.get("errorDetail"), None, "errorDetail different than None")
825 # db_vnfrs_list = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
826 # for vnfr in db_vnfrs_list:
827 # self.assertEqual(vnfr["_admin"].get("nsState"), "NOT_INSTANTIATED", "Not instantiated")
tiernoe876f672020-02-13 14:34:48 +0000828
bravof922c4172020-11-24 21:21:43 -0300829 # @asynctest.fail_on(active_handles=True) # all async tasks must be completed
830 # async def test_terminate_primitive(self):
831 # nsr_id = descriptors.test_ids["TEST-A"]["ns"]
832 # nslcmop_id = descriptors.test_ids["TEST-A"]["terminate"]
833 # # set instantiation task as completed
834 # self.db.set_list("nslcmops", {"nsInstanceId": nsr_id, "_id.ne": nslcmop_id},
835 # update_dict={"operationState": "COMPLETED"})
tiernoe876f672020-02-13 14:34:48 +0000836
bravof922c4172020-11-24 21:21:43 -0300837 # # modify vnfd descriptor to include terminate_primitive
838 # terminate_primitive = [{
839 # "name": "touch",
840 # "parameter": [{"name": "filename", "value": "terminate_filename"}],
841 # "seq": '1'
842 # }]
843 # db_vnfr = self.db.get_one("vnfrs", {"nsr-id-ref": nsr_id, "member-vnf-index-ref": "1"})
844 # self.db.set_one("vnfds", {"_id": db_vnfr["vnfd-id"]},
845 # {"vnf-configuration.0.terminate-config-primitive": terminate_primitive})
tiernoe876f672020-02-13 14:34:48 +0000846
bravof922c4172020-11-24 21:21:43 -0300847 # await self.my_ns.terminate(nsr_id, nslcmop_id)
848 # db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
849 # self.assertEqual(db_nslcmop.get("operationState"), 'COMPLETED', db_nslcmop.get("detailed-status"))
850 # db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
851 # self.assertEqual(db_nsr.get("nsState"), "NOT_INSTANTIATED", str(db_nsr.get("errorDescription ")))
852 # self.assertEqual(db_nsr["_admin"].get("nsState"), "NOT_INSTANTIATED", str(db_nsr.get("errorDescription ")))
853 # self.assertEqual(db_nsr.get("currentOperation"), "IDLE", "currentOperation different than 'IDLE'")
854 # self.assertEqual(db_nsr.get("currentOperationID"), None, "currentOperationID different than None")
855 # self.assertEqual(db_nsr.get("errorDescription "), None, "errorDescription different than None")
856 # self.assertEqual(db_nsr.get("errorDetail"), None, "errorDetail different than None")
tiernoe876f672020-02-13 14:34:48 +0000857
tierno51d065c2019-08-26 16:48:23 +0000858
garciadeblas5697b8b2021-03-24 09:17:02 +0100859if __name__ == "__main__":
tierno51d065c2019-08-26 16:48:23 +0000860 asynctest.main()