Fix vca_config parameter for N2VC.
[osm/LCM.git] / osm_lcm / tests / test_ns.py
1 #
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
15 # contact: esousa@whitestack.com or alfonso.tiernosepulveda@telefonica.com
16 ##
17
18
19 import asynctest # pip3 install asynctest --user
20 import asyncio
21 import yaml
22 # import logging
23 from os import getenv
24 from osm_lcm.ns import NsLcm
25 from osm_common.dbmemory import DbMemory
26 from osm_common.msgkafka import MsgKafka
27 from osm_common.fslocal import FsLocal
28 from osm_lcm.lcm_utils import TaskRegistry
29 from n2vc.vnf import N2VC
30 # from n2vc.k8s_helm_conn import K8sHelmConnector
31 from uuid import uuid4
32 from asynctest.mock import patch
33
34 from osm_lcm.tests import test_db_descriptors as descriptors
35
36 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
37
38 """ Perform unittests using asynctest of osm_lcm.ns module
39 It allows, if some testing ENV are supplied, testing without mocking some external libraries for debugging:
40 OSMLCMTEST_NS_PUBKEY: public ssh-key returned by N2VC to inject to VMs
41 OSMLCMTEST_NS_NAME: change name of NS
42 OSMLCMTEST_PACKAGES_PATH: path where the vnf-packages are stored (de-compressed), each one on a 'vnfd_id' folder
43 OSMLCMTEST_NS_IPADDRESS: IP address where emulated VMs are reached. Comma separate list
44 OSMLCMTEST_RO_VIMID: VIM id of RO target vim IP. Obtain it with openmano datcenter-list on RO container
45 OSMLCMTEST_VCA_NOMOCK: Do no mock the VCA, N2VC library, for debugging it
46 OSMLCMTEST_RO_NOMOCK: Do no mock the ROClient library, for debugging it
47 OSMLCMTEST_DB_NOMOCK: Do no mock the database library, for debugging it
48 OSMLCMTEST_FS_NOMOCK: Do no mock the File Storage library, for debugging it
49 OSMLCMTEST_LOGGING_NOMOCK: Do no mock the logging
50 OSMLCM_VCA_XXX: configuration of N2VC
51 OSMLCM_RO_XXX: configuration of RO
52 """
53
54
55 vca_config = { # TODO replace with os.get_env to get other configurations
56 "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 "pubkey": getenv("OSMLCM_VCA_PUBKEY", None),
61 'cacert': getenv("OSMLCM_VCA_CACERT", None)
62 }
63
64 ro_config = {
65 "endpoint_url": "http://{}:{}/openmano".format(getenv("OSMLCM_RO_HOST", "ro"), getenv("OSMLCM_RO_PORT", "9090")),
66 "tenant": getenv("OSMLCM_RO_TENANT", "osm"),
67 "logger_name": "lcm.ROclient",
68 "loglevel": "DEBUG",
69 }
70
71
72 class TestMyNS(asynctest.TestCase):
73
74 async def _n2vc_DeployCharms(self, model_name, application_name, vnfd, charm_path, params={}, machine_spec={},
75 callback=None, *callback_args):
76 if callback:
77 for status, message in (("maintenance", "installing sofwware"), ("active", "Ready!")):
78 # call callback after some time
79 asyncio.sleep(5, loop=self.loop)
80 callback(model_name, application_name, status, message, *callback_args)
81
82 @staticmethod
83 def _n2vc_FormatApplicationName(*args):
84 num_calls = 0
85 while True:
86 yield "app_name-{}".format(num_calls)
87 num_calls += 1
88
89 def _n2vc_CreateExecutionEnvironment(self, namespace, reuse_ee_id, db_dict):
90 k_list = namespace.split(".")
91 ee_id = k_list[1] + "."
92 if len(k_list) >= 2:
93 for k in k_list[2:4]:
94 ee_id += k[:8]
95 else:
96 ee_id += "_NS_"
97 return ee_id, {}
98
99 def _ro_show(self, *args, **kwargs):
100 ro_ns_desc = yaml.load(descriptors.db_ro_ns_text, Loader=yaml.Loader)
101
102 # if ip address provided, replace descriptor
103 ip_addresses = getenv("OSMLCMTEST_NS_IPADDRESS", "")
104 if ip_addresses:
105 ip_addresses_list = ip_addresses.split(",")
106 for vnf in ro_ns_desc["vnfs"]:
107 if not ip_addresses_list:
108 break
109 vnf["ip_address"] = ip_addresses_list[0]
110 for vm in vnf["vms"]:
111 if not ip_addresses_list:
112 break
113 vm["ip_address"] = ip_addresses_list.pop(0)
114
115 while True:
116 yield ro_ns_desc
117 for net in ro_ns_desc["nets"]:
118 if net["status"] != "ACTIVE":
119 net["status"] = "ACTIVE"
120 break
121 else:
122 for vnf in ro_ns_desc["vnfs"]:
123 for vm in vnf["vms"]:
124 if vm["status"] != "ACTIVE":
125 vm["status"] = "ACTIVE"
126 break
127
128 def _ro_create(self, *args, **kwargs):
129 while True:
130 yield {"uuid": str(uuid4())}
131
132 def _return_uuid(self, *args, **kwargs):
133 return str(uuid4())
134
135 @patch("osm_lcm.ns.K8sHelmConnector")
136 async def setUp(self, k8s_mock):
137 # Mock DB
138 if not getenv("OSMLCMTEST_DB_NOMOCK"):
139 self.db = DbMemory()
140 self.db.create_list("vnfds", yaml.load(descriptors.db_vnfds_text, Loader=yaml.Loader))
141 self.db.create_list("nsds", yaml.load(descriptors.db_nsds_text, Loader=yaml.Loader))
142 self.db.create_list("nsrs", yaml.load(descriptors.db_nsrs_text, Loader=yaml.Loader))
143 self.db.create_list("vim_accounts", yaml.load(descriptors.db_vim_accounts_text, Loader=yaml.Loader))
144 self.db.create_list("nslcmops", yaml.load(descriptors.db_nslcmops_text, Loader=yaml.Loader))
145 self.db.create_list("vnfrs", yaml.load(descriptors.db_vnfrs_text, Loader=yaml.Loader))
146 self.db.set_one = asynctest.Mock()
147
148 self.db_vim_accounts = yaml.load(descriptors.db_vim_accounts_text, Loader=yaml.Loader)
149
150 # Mock kafka
151 self.msg = asynctest.Mock(MsgKafka())
152
153 # Mock filesystem
154 if not getenv("OSMLCMTEST_FS_NOMOCK"):
155 self.fs = asynctest.Mock(FsLocal())
156 self.fs.get_params.return_value = {"path": getenv("OSMLCMTEST_PACKAGES_PATH", "./test/temp/packages")}
157 self.fs.file_open = asynctest.mock_open()
158 # self.fs.file_open.return_value.__enter__.return_value = asynctest.MagicMock() # called on a python "with"
159 # self.fs.file_open.return_value.__enter__.return_value.read.return_value = "" # empty file
160
161 # Mock TaskRegistry
162 self.lcm_tasks = asynctest.Mock(TaskRegistry())
163 self.lcm_tasks.lock_HA.return_value = True
164 self.lcm_tasks.waitfor_related_HA.return_value = None
165 self.lcm_tasks.lookfor_related.return_value = ("", [])
166
167 # Create NsLCM class
168 self.my_ns = NsLcm(self.db, self.msg, self.fs, self.lcm_tasks, ro_config, vca_config, self.loop)
169
170 # Mock logging
171 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
172 self.my_ns.logger = asynctest.Mock(self.my_ns.logger)
173
174 # Mock VCA - N2VC
175 if not getenv("OSMLCMTEST_VCA_NOMOCK"):
176 pub_key = getenv("OSMLCMTEST_NS_PUBKEY", "ssh-rsa test-pub-key t@osm.com")
177 self.my_ns.n2vc = asynctest.Mock(N2VC())
178 self.my_ns.n2vc.GetPublicKey.return_value = getenv("OSMLCM_VCA_PUBKEY", "public_key")
179 # allow several versions of n2vc
180 self.my_ns.n2vc.FormatApplicationName = asynctest.Mock(side_effect=self._n2vc_FormatApplicationName())
181 self.my_ns.n2vc.DeployCharms = asynctest.CoroutineMock(side_effect=self._n2vc_DeployCharms)
182 self.my_ns.n2vc.create_execution_environment = asynctest.CoroutineMock(
183 side_effect=self._n2vc_CreateExecutionEnvironment)
184 self.my_ns.n2vc.install_configuration_sw = asynctest.CoroutineMock(return_value=pub_key)
185 self.my_ns.n2vc.get_ee_ssh_public__key = asynctest.CoroutineMock(return_value=pub_key)
186 self.my_ns.n2vc.exec_primitive = asynctest.CoroutineMock(side_effect=self._return_uuid)
187 self.my_ns.n2vc.GetPrimitiveStatus = asynctest.CoroutineMock(return_value="completed")
188 self.my_ns.n2vc.GetPrimitiveOutput = asynctest.CoroutineMock(return_value={"result": "ok",
189 "pubkey": pub_key})
190 self.my_ns.n2vc.get_public_key = asynctest.CoroutineMock(
191 return_value=getenv("OSMLCM_VCA_PUBKEY", "public_key"))
192
193 # # Mock VCA - K8s
194 # if not getenv("OSMLCMTEST_VCA_K8s_NOMOCK"):
195 # pub_key = getenv("OSMLCMTEST_NS_PUBKEY", "ssh-rsa test-pub-key t@osm.com")
196 # self.my_ns.k8sclusterhelm = asynctest.Mock(K8sHelmConnector())
197
198 # Mock RO
199 if not getenv("OSMLCMTEST_RO_NOMOCK"):
200 # self.my_ns.RO = asynctest.Mock(ROclient.ROClient(self.loop, **ro_config))
201 # TODO first time should be empty list, following should return a dict
202 self.my_ns.RO.get_list = asynctest.CoroutineMock(self.my_ns.RO.get_list, return_value=[])
203 self.my_ns.RO.create = asynctest.CoroutineMock(self.my_ns.RO.create, side_effect=self._ro_create())
204 self.my_ns.RO.show = asynctest.CoroutineMock(self.my_ns.RO.show, side_effect=self._ro_show())
205 self.my_ns.RO.create_action = asynctest.CoroutineMock(self.my_ns.RO.create_action,
206 return_value={"vm-id": {"vim_result": 200,
207 "description": "done"}})
208
209 @asynctest.fail_on(active_handles=True) # all async tasks must be completed
210 async def test_instantiate(self):
211 nsr_id = self.db.get_list("nsrs")[0]["_id"]
212 nslcmop_id = self.db.get_list("nslcmops")[0]["_id"]
213 print("Test instantiate started")
214
215 # delete deployed information of database
216 if not getenv("OSMLCMTEST_DB_NOMOCK"):
217 if self.db.get_list("nsrs")[0]["_admin"].get("deployed"):
218 del self.db.get_list("nsrs")[0]["_admin"]["deployed"]
219 for db_vnfr in self.db.get_list("vnfrs"):
220 db_vnfr.pop("ip_address", None)
221 for db_vdur in db_vnfr["vdur"]:
222 db_vdur.pop("ip_address", None)
223 db_vdur.pop("mac_address", None)
224 if getenv("OSMLCMTEST_RO_VIMID"):
225 self.db.get_list("vim_accounts")[0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
226 if getenv("OSMLCMTEST_RO_VIMID"):
227 self.db.get_list("nsrs")[0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
228
229 await self.my_ns.instantiate(nsr_id, nslcmop_id)
230
231 print("instantiate_result: {}".format(self.db.get_one("nslcmops", {"_id": nslcmop_id}).get("detailed-status")))
232
233 self.msg.aiowrite.assert_called_once_with("ns", "instantiated",
234 {"nsr_id": nsr_id, "nslcmop_id": nslcmop_id,
235 "operationState": "COMPLETED"},
236 loop=self.loop)
237 self.lcm_tasks.lock_HA.assert_called_once_with('ns', 'nslcmops', nslcmop_id)
238 if not getenv("OSMLCMTEST_LOGGING_NOMOCK"):
239 self.assertTrue(self.my_ns.logger.debug.called, "Debug method not called")
240 self.my_ns.logger.error.assert_not_called()
241 self.my_ns.logger.exception().assert_not_called()
242
243 if not getenv("OSMLCMTEST_DB_NOMOCK"):
244 self.assertTrue(self.db.set_one.called, "db.set_one not called")
245
246 # TODO add more checks of called methods
247 # TODO add a terminate
248
249 def test_ns_params_2_RO(self):
250 vim = self.db.get_list("vim_accounts")[0]
251 vim_id = vim["_id"]
252 ro_vim_id = vim["_admin"]["deployed"]["RO"]
253 ns_params = {"vimAccountId": vim_id}
254 mgmt_interface = {"cp": "cp"}
255 vdu = [{"id": "vdu_id", "interface": [{"external-connection-point-ref": "cp"}]}]
256 vnfd_dict = {
257 "1": {"vdu": vdu, "mgmt-interface": mgmt_interface},
258 "2": {"vdu": vdu, "mgmt-interface": mgmt_interface, "vnf-configuration": None},
259 "3": {"vdu": vdu, "mgmt-interface": mgmt_interface, "vnf-configuration": {"config-access": None}},
260 "4": {"vdu": vdu, "mgmt-interface": mgmt_interface,
261 "vnf-configuration": {"config-access": {"ssh-access": None}}},
262 "5": {"vdu": vdu, "mgmt-interface": mgmt_interface,
263 "vnf-configuration": {"config-access": {"ssh-access": {"required": True, "default_user": "U"}}}},
264 }
265 nsd = {"constituent-vnfd": []}
266 for k in vnfd_dict.keys():
267 nsd["constituent-vnfd"].append({"vnfd-id-ref": k, "member-vnf-index": k})
268
269 n2vc_key_list = ["key"]
270 ro_ns_params = self.my_ns.ns_params_2_RO(ns_params, nsd, vnfd_dict, n2vc_key_list)
271 ro_params_expected = {'wim_account': None, "datacenter": ro_vim_id,
272 "vnfs": {"5": {"vdus": {"vdu_id": {"mgmt_keys": n2vc_key_list}}}}}
273 self.assertEqual(ro_ns_params, ro_params_expected)
274
275 # Test scale() and related methods
276 @asynctest.fail_on(active_handles=True) # all async tasks must be completed
277 async def test_scale(self):
278 # print("Test scale started")
279
280 # TODO: Add more higher-lever tests here, for example:
281 # scale-out/scale-in operations with success/error result
282
283 # Test scale() with missing 'scaleVnfData', should return operationState = 'FAILED'
284 nsr_id = self.db.get_list("nsrs")[0]["_id"]
285 nslcmop_id = self.db.get_list("nslcmops")[0]["_id"]
286 await self.my_ns.scale(nsr_id, nslcmop_id)
287 expected_value = 'FAILED'
288 return_value = self.db.get_one("nslcmops", {"_id": nslcmop_id}).get("operationState")
289 self.assertEqual(return_value, expected_value)
290 # print("scale_result: {}".format(self.db.get_one("nslcmops", {"_id": nslcmop_id}).get("detailed-status")))
291
292 # Test _reintent_or_skip_suboperation()
293 # Expected result:
294 # - if a suboperation's 'operationState' is marked as 'COMPLETED', SUBOPERATION_STATUS_SKIP is expected
295 # - if marked as anything but 'COMPLETED', the suboperation index is expected
296 def test_scale_reintent_or_skip_suboperation(self):
297 # Load an alternative 'nslcmops' YAML for this test
298 db_nslcmop = self.db.get_list('nslcmops')[0]
299 op_index = 2
300 # Test when 'operationState' is 'COMPLETED'
301 db_nslcmop['_admin']['operations'][op_index]['operationState'] = 'COMPLETED'
302 return_value = self.my_ns._reintent_or_skip_suboperation(db_nslcmop, op_index)
303 expected_value = self.my_ns.SUBOPERATION_STATUS_SKIP
304 self.assertEqual(return_value, expected_value)
305 # Test when 'operationState' is not 'COMPLETED'
306 db_nslcmop['_admin']['operations'][op_index]['operationState'] = None
307 return_value = self.my_ns._reintent_or_skip_suboperation(db_nslcmop, op_index)
308 expected_value = op_index
309 self.assertEqual(return_value, expected_value)
310
311 # Test _find_suboperation()
312 # Expected result: index of the found sub-operation, or SUBOPERATION_STATUS_NOT_FOUND if not found
313 def test_scale_find_suboperation(self):
314 # Load an alternative 'nslcmops' YAML for this test
315 db_nslcmop = self.db.get_list('nslcmops')[0]
316 # Find this sub-operation
317 op_index = 2
318 vnf_index = db_nslcmop['_admin']['operations'][op_index]['member_vnf_index']
319 primitive = db_nslcmop['_admin']['operations'][op_index]['primitive']
320 primitive_params = db_nslcmop['_admin']['operations'][op_index]['primitive_params']
321 match = {
322 'member_vnf_index': vnf_index,
323 'primitive': primitive,
324 'primitive_params': primitive_params,
325 }
326 found_op_index = self.my_ns._find_suboperation(db_nslcmop, match)
327 self.assertEqual(found_op_index, op_index)
328 # Test with not-matching params
329 match = {
330 'member_vnf_index': vnf_index,
331 'primitive': '',
332 'primitive_params': primitive_params,
333 }
334 found_op_index = self.my_ns._find_suboperation(db_nslcmop, match)
335 self.assertEqual(found_op_index, self.my_ns.SUBOPERATION_STATUS_NOT_FOUND)
336 # Test with None
337 match = None
338 found_op_index = self.my_ns._find_suboperation(db_nslcmop, match)
339 self.assertEqual(found_op_index, self.my_ns.SUBOPERATION_STATUS_NOT_FOUND)
340
341 # Test _update_suboperation_status()
342 def test_scale_update_suboperation_status(self):
343 db_nslcmop = self.db.get_list('nslcmops')[0]
344 op_index = 0
345 # Force the initial values to be distinct from the updated ones
346 q_filter = {"_id": db_nslcmop["_id"]}
347 # Test to change 'operationState' and 'detailed-status'
348 operationState = 'COMPLETED'
349 detailed_status = 'Done'
350 expected_update_dict = {'_admin.operations.0.operationState': operationState,
351 '_admin.operations.0.detailed-status': detailed_status,
352 }
353 self.my_ns._update_suboperation_status(db_nslcmop, op_index, operationState, detailed_status)
354 self.db.set_one.assert_called_once_with("nslcmops", q_filter=q_filter, update_dict=expected_update_dict,
355 fail_on_empty=False)
356
357 def test_scale_add_suboperation(self):
358 db_nslcmop = self.db.get_list('nslcmops')[0]
359 vnf_index = '1'
360 num_ops_before = len(db_nslcmop.get('_admin', {}).get('operations', [])) - 1
361 vdu_id = None
362 vdu_count_index = None
363 vdu_name = None
364 primitive = 'touch'
365 mapped_primitive_params = {'parameter':
366 [{'data-type': 'STRING',
367 'name': 'filename',
368 'default-value': '<touch_filename2>'}],
369 'name': 'touch'}
370 operationState = 'PROCESSING'
371 detailed_status = 'In progress'
372 operationType = 'PRE-SCALE'
373 # Add a 'pre-scale' suboperation
374 op_index_after = self.my_ns._add_suboperation(db_nslcmop, vnf_index, vdu_id, vdu_count_index,
375 vdu_name, primitive, mapped_primitive_params,
376 operationState, detailed_status, operationType)
377 self.assertEqual(op_index_after, num_ops_before + 1)
378
379 # Delete all suboperations and add the same operation again
380 del db_nslcmop['_admin']['operations']
381 op_index_zero = self.my_ns._add_suboperation(db_nslcmop, vnf_index, vdu_id, vdu_count_index,
382 vdu_name, primitive, mapped_primitive_params,
383 operationState, detailed_status, operationType)
384 self.assertEqual(op_index_zero, 0)
385
386 # Add a 'RO' suboperation
387 RO_nsr_id = '1234567890'
388 RO_scaling_info = [{'type': 'create', 'count': 1, 'member-vnf-index': '1', 'osm_vdu_id': 'dataVM'}]
389 op_index = self.my_ns._add_suboperation(db_nslcmop, vnf_index, vdu_id, vdu_count_index,
390 vdu_name, primitive, mapped_primitive_params,
391 operationState, detailed_status, operationType,
392 RO_nsr_id, RO_scaling_info)
393 db_RO_nsr_id = db_nslcmop['_admin']['operations'][op_index]['RO_nsr_id']
394 self.assertEqual(op_index, 1)
395 self.assertEqual(RO_nsr_id, db_RO_nsr_id)
396
397 # Try to add an invalid suboperation, should return SUBOPERATION_STATUS_NOT_FOUND
398 op_index_invalid = self.my_ns._add_suboperation(None, None, None, None, None,
399 None, None, None,
400 None, None, None)
401 self.assertEqual(op_index_invalid, self.my_ns.SUBOPERATION_STATUS_NOT_FOUND)
402
403 # Test _check_or_add_scale_suboperation() and _check_or_add_scale_suboperation_RO()
404 # check the possible return values:
405 # - SUBOPERATION_STATUS_NEW: This is a new sub-operation
406 # - op_index (non-negative number): This is an existing sub-operation, operationState != 'COMPLETED'
407 # - SUBOPERATION_STATUS_SKIP: This is an existing sub-operation, operationState == 'COMPLETED'
408 def test_scale_check_or_add_scale_suboperation(self):
409 db_nslcmop = self.db.get_list('nslcmops')[0]
410 operationType = 'PRE-SCALE'
411 vnf_index = '1'
412 primitive = 'touch'
413 primitive_params = {'parameter':
414 [{'data-type': 'STRING',
415 'name': 'filename',
416 'default-value': '<touch_filename2>'}],
417 'name': 'touch'}
418
419 # Delete all sub-operations to be sure this is a new sub-operation
420 del db_nslcmop['_admin']['operations']
421
422 # Add a new sub-operation
423 # For new sub-operations, operationState is set to 'PROCESSING' by default
424 op_index_new = self.my_ns._check_or_add_scale_suboperation(
425 db_nslcmop, vnf_index, primitive, primitive_params, operationType)
426 self.assertEqual(op_index_new, self.my_ns.SUBOPERATION_STATUS_NEW)
427
428 # Use the same parameters again to match the already added sub-operation
429 # which has status 'PROCESSING' (!= 'COMPLETED') by default
430 # The expected return value is a non-negative number
431 op_index_existing = self.my_ns._check_or_add_scale_suboperation(
432 db_nslcmop, vnf_index, primitive, primitive_params, operationType)
433 self.assertTrue(op_index_existing >= 0)
434
435 # Change operationState 'manually' for this sub-operation
436 db_nslcmop['_admin']['operations'][op_index_existing]['operationState'] = 'COMPLETED'
437 # Then use the same parameters again to match the already added sub-operation,
438 # which now has status 'COMPLETED'
439 # The expected return value is SUBOPERATION_STATUS_SKIP
440 op_index_skip = self.my_ns._check_or_add_scale_suboperation(
441 db_nslcmop, vnf_index, primitive, primitive_params, operationType)
442 self.assertEqual(op_index_skip, self.my_ns.SUBOPERATION_STATUS_SKIP)
443
444 # RO sub-operation test:
445 # Repeat tests for the very similar _check_or_add_scale_suboperation_RO(),
446 RO_nsr_id = '1234567890'
447 RO_scaling_info = [{'type': 'create', 'count': 1, 'member-vnf-index': '1', 'osm_vdu_id': 'dataVM'}]
448 op_index_new_RO = self.my_ns._check_or_add_scale_suboperation(
449 db_nslcmop, vnf_index, None, None, 'SCALE-RO', RO_nsr_id, RO_scaling_info)
450 self.assertEqual(op_index_new_RO, self.my_ns.SUBOPERATION_STATUS_NEW)
451
452 # Use the same parameters again to match the already added RO sub-operation
453 op_index_existing_RO = self.my_ns._check_or_add_scale_suboperation(
454 db_nslcmop, vnf_index, None, None, 'SCALE-RO', RO_nsr_id, RO_scaling_info)
455 self.assertTrue(op_index_existing_RO >= 0)
456
457 # Change operationState 'manually' for this RO sub-operation
458 db_nslcmop['_admin']['operations'][op_index_existing_RO]['operationState'] = 'COMPLETED'
459 # Then use the same parameters again to match the already added sub-operation,
460 # which now has status 'COMPLETED'
461 # The expected return value is SUBOPERATION_STATUS_SKIP
462 op_index_skip_RO = self.my_ns._check_or_add_scale_suboperation(
463 db_nslcmop, vnf_index, None, None, 'SCALE-RO', RO_nsr_id, RO_scaling_info)
464 self.assertEqual(op_index_skip_RO, self.my_ns.SUBOPERATION_STATUS_SKIP)
465
466
467 if __name__ == '__main__':
468 asynctest.main()