| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # |
| 4 | # Copyright 2016 RIFT.IO Inc |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | import argparse |
| 20 | import asyncio |
| 21 | import logging |
| 22 | import os |
| 23 | import sys |
| 24 | import time |
| 25 | import unittest |
| 26 | import uuid |
| 27 | |
| 28 | import xmlrunner |
| 29 | |
| 30 | import gi.repository.RwDts as rwdts |
| 31 | import gi.repository.RwNsmYang as rwnsmyang |
| 32 | import gi.repository.RwResourceMgrYang as RwResourceMgrYang |
| 33 | import gi.repository.RwLaunchpadYang as launchpadyang |
| 34 | import rift.tasklets |
| 35 | import rift.test.dts |
| 36 | |
| 37 | import mano_ut |
| 38 | |
| 39 | |
| 40 | if sys.version_info < (3, 4, 4): |
| 41 | asyncio.ensure_future = asyncio.async |
| 42 | |
| 43 | |
| 44 | class OutOfResourceError(Exception): |
| 45 | pass |
| 46 | |
| 47 | |
| 48 | class ComputeResourceRequestMockEventHandler(object): |
| 49 | def __init__(self): |
| 50 | self._pool_name = "vm_pool" |
| 51 | self._vdu_id = str(uuid.uuid4()) |
| 52 | self._vdu_info = { |
| 53 | "vdu_id": self._vdu_id, |
| 54 | "state": "active", |
| 55 | "management_ip": "1.1.1.1", |
| 56 | "public_ip": "1.1.1.1", |
| 57 | "connection_points": [], |
| 58 | } |
| 59 | |
| 60 | self._resource_state = "active" |
| 61 | |
| 62 | self._event_id = None |
| 63 | self._request_info = None |
| 64 | |
| 65 | def allocate(self, event_id, request_info): |
| 66 | self._event_id = event_id |
| 67 | self._request_info = request_info |
| 68 | |
| 69 | self._vdu_info.update({ |
| 70 | "name": self._request_info.name, |
| 71 | "flavor_id": self._request_info.flavor_id, |
| 72 | "image_id": self._request_info.image_id, |
| 73 | }) |
| 74 | |
| 75 | for cp in request_info.connection_points: |
| 76 | info_cp = dict( |
| 77 | name=cp.name, |
| 78 | virtual_link_id=cp.virtual_link_id, |
| 79 | vdu_id=self._vdu_id, |
| 80 | state="active", |
| 81 | ip_address="1.2.3.4", |
| 82 | ) |
| 83 | info_cp = self._vdu_info["connection_points"].append(info_cp) |
| 84 | |
| 85 | @property |
| 86 | def event_id(self): |
| 87 | return self._event_id |
| 88 | |
| 89 | @property |
| 90 | def resource_state(self): |
| 91 | return self._resource_state |
| 92 | |
| 93 | def set_active(self): |
| 94 | self._resource_state = "active" |
| 95 | |
| 96 | def set_failed(self): |
| 97 | self._resource_state = "failed" |
| 98 | |
| 99 | def set_pending(self): |
| 100 | self._resource_state = "pending" |
| 101 | |
| 102 | @property |
| 103 | def response_msg(self): |
| 104 | resource_info = dict( |
| 105 | pool_name=self._pool_name, |
| 106 | resource_state=self.resource_state, |
| 107 | ) |
| 108 | resource_info.update(self._vdu_info) |
| 109 | |
| 110 | response = RwResourceMgrYang.VDUEventData.from_dict(dict( |
| 111 | event_id=self._event_id, |
| 112 | request_info=self._request_info.as_dict(), |
| 113 | resource_info=resource_info, |
| 114 | )) |
| 115 | |
| 116 | return response.resource_info |
| 117 | |
| 118 | |
| 119 | class NetworkResourceRequestMockEventHandler(object): |
| 120 | def __init__(self): |
| 121 | self._pool_name = "network_pool" |
| 122 | self._link_id = str(uuid.uuid4()) |
| 123 | self._link_info = { |
| 124 | "virtual_link_id": self._link_id, |
| 125 | "state": "active", |
| 126 | } |
| 127 | |
| 128 | self._resource_state = "active" |
| 129 | |
| 130 | self._event_id = None |
| 131 | self._request_info = None |
| 132 | |
| 133 | def allocate(self, event_id, request_info): |
| 134 | self._event_id = event_id |
| 135 | self._request_info = request_info |
| 136 | |
| 137 | self._link_info.update({ |
| 138 | "name": self._request_info.name, |
| 139 | "subnet": self._request_info.subnet, |
| 140 | }) |
| 141 | |
| 142 | @property |
| 143 | def event_id(self): |
| 144 | return self._event_id |
| 145 | |
| 146 | @property |
| 147 | def resource_state(self): |
| 148 | return self._resource_state |
| 149 | |
| 150 | def set_active(self): |
| 151 | self._resource_state = "active" |
| 152 | |
| 153 | def set_failed(self): |
| 154 | self._resource_state = "failed" |
| 155 | |
| 156 | def set_pending(self): |
| 157 | self._resource_state = "pending" |
| 158 | |
| 159 | @property |
| 160 | def response_msg(self): |
| 161 | resource_info = dict( |
| 162 | pool_name=self._pool_name, |
| 163 | resource_state=self.resource_state, |
| 164 | ) |
| 165 | resource_info.update(self._link_info) |
| 166 | |
| 167 | response = RwResourceMgrYang.VirtualLinkEventData.from_dict(dict( |
| 168 | event_id=self._event_id, |
| 169 | request_info=self._request_info.as_dict(), |
| 170 | resource_info=resource_info, |
| 171 | )) |
| 172 | |
| 173 | return response.resource_info |
| 174 | |
| 175 | |
| 176 | class ResourceMgrMock(object): |
| 177 | VDU_REQUEST_XPATH = "D,/rw-resource-mgr:resource-mgmt/vdu-event/vdu-event-data" |
| 178 | VLINK_REQUEST_XPATH = "D,/rw-resource-mgr:resource-mgmt/vlink-event/vlink-event-data" |
| 179 | |
| 180 | def __init__(self, dts, log, loop): |
| 181 | self._log = log |
| 182 | self._dts = dts |
| 183 | self._loop = loop |
| 184 | self._vdu_reg = None |
| 185 | self._link_reg = None |
| 186 | |
| 187 | self._vdu_reg_event = asyncio.Event(loop=self._loop) |
| 188 | self._link_reg_event = asyncio.Event(loop=self._loop) |
| 189 | |
| 190 | self._available_compute_handlers = [] |
| 191 | self._available_network_handlers = [] |
| 192 | |
| 193 | self._used_compute_handlers = {} |
| 194 | self._used_network_handlers = {} |
| 195 | |
| 196 | self._compute_allocate_requests = 0 |
| 197 | self._network_allocate_requests = 0 |
| 198 | |
| 199 | self._registered = False |
| 200 | |
| 201 | def _allocate_virtual_compute(self, event_id, request_info): |
| 202 | self._compute_allocate_requests += 1 |
| 203 | |
| 204 | if not self._available_compute_handlers: |
| 205 | raise OutOfResourceError("No more compute handlers") |
| 206 | |
| 207 | handler = self._available_compute_handlers.pop() |
| 208 | handler.allocate(event_id, request_info) |
| 209 | self._used_compute_handlers[event_id] = handler |
| 210 | |
| 211 | return handler.response_msg |
| 212 | |
| 213 | def _allocate_virtual_network(self, event_id, request_info): |
| 214 | self._network_allocate_requests += 1 |
| 215 | |
| 216 | if not self._available_network_handlers: |
| 217 | raise OutOfResourceError("No more network handlers") |
| 218 | |
| 219 | handler = self._available_network_handlers.pop() |
| 220 | handler.allocate(event_id, request_info) |
| 221 | self._used_network_handlers[event_id] = handler |
| 222 | |
| 223 | return handler.response_msg |
| 224 | |
| 225 | def _release_virtual_network(self, event_id): |
| 226 | del self._used_network_handlers[event_id] |
| 227 | |
| 228 | def _release_virtual_compute(self, event_id): |
| 229 | del self._used_compute_handlers[event_id] |
| 230 | |
| 231 | def _read_virtual_network(self, event_id): |
| 232 | return self._used_network_handlers[event_id].response_msg |
| 233 | |
| 234 | def _read_virtual_compute(self, event_id): |
| 235 | return self._used_compute_handlers[event_id].response_msg |
| 236 | |
| 237 | @asyncio.coroutine |
| 238 | def on_link_request_prepare(self, xact_info, action, ks_path, request_msg): |
| 239 | if not self._registered: |
| 240 | self._log.error("Got a prepare callback when not registered!") |
| 241 | xact_info.respond_xpath(rwdts.XactRspCode.NA) |
| 242 | return |
| 243 | |
| 244 | self._log.debug("Received virtual-link on_prepare callback (self: %s, xact_info: %s, action: %s): %s", |
| 245 | self, xact_info, action, request_msg) |
| 246 | |
| 247 | response_info = None |
| 248 | response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" |
| 249 | |
| 250 | schema = RwResourceMgrYang.VirtualLinkEventData().schema() |
| 251 | pathentry = schema.keyspec_to_entry(ks_path) |
| 252 | |
| 253 | if action == rwdts.QueryAction.CREATE: |
| 254 | response_info = self._allocate_virtual_network( |
| 255 | pathentry.key00.event_id, |
| 256 | request_msg.request_info, |
| 257 | ) |
| 258 | |
| 259 | elif action == rwdts.QueryAction.DELETE: |
| 260 | self._release_virtual_network(pathentry.key00.event_id) |
| 261 | |
| 262 | elif action == rwdts.QueryAction.READ: |
| 263 | response_info = self._read_virtual_network( |
| 264 | pathentry.key00.event_id |
| 265 | ) |
| 266 | else: |
| 267 | raise ValueError("Only read/create/delete actions available. Received action: %s" %(action)) |
| 268 | |
| 269 | self._log.debug("Responding with VirtualLinkInfo at xpath %s: %s.", |
| 270 | response_xpath, response_info) |
| 271 | |
| 272 | xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info) |
| 273 | |
| 274 | @asyncio.coroutine |
| 275 | def on_vdu_request_prepare(self, xact_info, action, ks_path, request_msg): |
| 276 | if not self._registered: |
| 277 | self._log.error("Got a prepare callback when not registered!") |
| 278 | xact_info.respond_xpath(rwdts.XactRspCode.NA) |
| 279 | return |
| 280 | |
| 281 | @asyncio.coroutine |
| 282 | def monitor_vdu_state(response_xpath, pathentry): |
| 283 | self._log.info("Initiating VDU state monitoring for xpath: %s ", response_xpath) |
| 284 | loop_cnt = 120 |
| 285 | while loop_cnt > 0: |
| 286 | self._log.debug("VDU state monitoring: Sleeping for 1 second ") |
| 287 | yield from asyncio.sleep(1, loop = self._loop) |
| 288 | try: |
| 289 | response_info = self._read_virtual_compute( |
| 290 | pathentry.key00.event_id |
| 291 | ) |
| 292 | except Exception as e: |
| 293 | self._log.error( |
| 294 | "VDU state monitoring: Received exception %s " |
| 295 | "in VDU state monitoring for %s. Aborting monitoring", |
| 296 | str(e), response_xpath |
| 297 | ) |
| 298 | raise |
| 299 | |
| 300 | if response_info.resource_state == 'active' or response_info.resource_state == 'failed': |
| 301 | self._log.info( |
| 302 | "VDU state monitoring: VDU reached terminal state." |
| 303 | "Publishing VDU info: %s at path: %s", |
| 304 | response_info, response_xpath |
| 305 | ) |
| 306 | yield from self._dts.query_update(response_xpath, |
| 307 | rwdts.XactFlag.ADVISE, |
| 308 | response_info) |
| 309 | return |
| 310 | else: |
| 311 | loop_cnt -= 1 |
| 312 | |
| 313 | ### End of while loop. This is only possible if VDU did not reach active state |
| 314 | self._log.info("VDU state monitoring: VDU at xpath :%s did not reached active state in 120 seconds. Aborting monitoring", |
| 315 | response_xpath) |
| 316 | response_info = RwResourceMgrYang.VDUEventData_ResourceInfo() |
| 317 | response_info.resource_state = 'failed' |
| 318 | yield from self._dts.query_update(response_xpath, |
| 319 | rwdts.XactFlag.ADVISE, |
| 320 | response_info) |
| 321 | return |
| 322 | |
| 323 | self._log.debug("Received vdu on_prepare callback (xact_info: %s, action: %s): %s", |
| 324 | xact_info, action, request_msg) |
| 325 | |
| 326 | response_info = None |
| 327 | response_xpath = ks_path.to_xpath(RwResourceMgrYang.get_schema()) + "/resource-info" |
| 328 | |
| 329 | schema = RwResourceMgrYang.VDUEventData().schema() |
| 330 | pathentry = schema.keyspec_to_entry(ks_path) |
| 331 | |
| 332 | if action == rwdts.QueryAction.CREATE: |
| 333 | response_info = self._allocate_virtual_compute( |
| 334 | pathentry.key00.event_id, |
| 335 | request_msg.request_info, |
| 336 | ) |
| 337 | if response_info.resource_state == 'pending': |
| 338 | asyncio.ensure_future(monitor_vdu_state(response_xpath, pathentry), |
| 339 | loop = self._loop) |
| 340 | |
| 341 | elif action == rwdts.QueryAction.DELETE: |
| 342 | self._release_virtual_compute( |
| 343 | pathentry.key00.event_id |
| 344 | ) |
| 345 | |
| 346 | elif action == rwdts.QueryAction.READ: |
| 347 | response_info = self._read_virtual_compute( |
| 348 | pathentry.key00.event_id |
| 349 | ) |
| 350 | else: |
| 351 | raise ValueError("Only create/delete actions available. Received action: %s" %(action)) |
| 352 | |
| 353 | self._log.debug("Responding with VDUInfo at xpath %s: %s", |
| 354 | response_xpath, response_info) |
| 355 | |
| 356 | xact_info.respond_xpath(rwdts.XactRspCode.ACK, response_xpath, response_info) |
| 357 | |
| 358 | @asyncio.coroutine |
| 359 | def register(self): |
| 360 | @asyncio.coroutine |
| 361 | def on_request_ready(registration, status): |
| 362 | self._log.debug("Got request ready event (registration: %s) (status: %s)", |
| 363 | registration, status) |
| 364 | |
| 365 | if registration == self._link_reg: |
| 366 | self._link_reg_event.set() |
| 367 | elif registration == self._vdu_reg: |
| 368 | self._vdu_reg_event.set() |
| 369 | else: |
| 370 | self._log.error("Unknown registration ready event: %s", registration) |
| 371 | |
| 372 | |
| 373 | with self._dts.group_create() as group: |
| 374 | self._log.debug("Registering for Link Resource Request using xpath: %s", |
| 375 | ResourceMgrMock.VLINK_REQUEST_XPATH) |
| 376 | |
| 377 | self._link_reg = group.register( |
| 378 | xpath=ResourceMgrMock.VLINK_REQUEST_XPATH, |
| 379 | handler=rift.tasklets.DTS.RegistrationHandler(on_ready=on_request_ready, |
| 380 | on_prepare=self.on_link_request_prepare), |
| 381 | flags=rwdts.Flag.PUBLISHER) |
| 382 | |
| 383 | self._log.debug("Registering for VDU Resource Request using xpath: %s", |
| 384 | ResourceMgrMock.VDU_REQUEST_XPATH) |
| 385 | |
| 386 | self._vdu_reg = group.register( |
| 387 | xpath=ResourceMgrMock.VDU_REQUEST_XPATH, |
| 388 | handler=rift.tasklets.DTS.RegistrationHandler(on_ready=on_request_ready, |
| 389 | on_prepare=self.on_vdu_request_prepare), |
| 390 | flags=rwdts.Flag.PUBLISHER) |
| 391 | |
| 392 | self._registered = True |
| 393 | |
| 394 | def unregister(self): |
| 395 | self._link_reg.deregister() |
| 396 | self._vdu_reg.deregister() |
| 397 | self._registered = False |
| 398 | |
| 399 | @asyncio.coroutine |
| 400 | def wait_ready(self, timeout=5): |
| 401 | self._log.debug("Waiting for all request registrations to become ready.") |
| 402 | yield from asyncio.wait([self._link_reg_event.wait(), self._vdu_reg_event.wait()], |
| 403 | timeout=timeout, loop=self._loop) |
| 404 | |
| 405 | def create_compute_mock_event_handler(self): |
| 406 | handler = ComputeResourceRequestMockEventHandler() |
| 407 | self._available_compute_handlers.append(handler) |
| 408 | |
| 409 | return handler |
| 410 | |
| 411 | def create_network_mock_event_handler(self): |
| 412 | handler = NetworkResourceRequestMockEventHandler() |
| 413 | self._available_network_handlers.append(handler) |
| 414 | |
| 415 | return handler |
| 416 | |
| 417 | @property |
| 418 | def num_compute_requests(self): |
| 419 | return self._compute_allocate_requests |
| 420 | |
| 421 | @property |
| 422 | def num_network_requests(self): |
| 423 | return self._network_allocate_requests |
| 424 | |
| 425 | @property |
| 426 | def num_allocated_compute_resources(self): |
| 427 | return len(self._used_compute_handlers) |
| 428 | |
| 429 | @property |
| 430 | def num_allocated_network_resources(self): |
| 431 | return len(self._used_network_handlers) |
| 432 | |
| 433 | |
| 434 | @unittest.skip('failing and needs rework') |
| 435 | class ManoErrorTestCase(rift.test.dts.AbstractDTSTest): |
| 436 | """ |
| 437 | DTS GI interface unittests |
| 438 | |
| 439 | Note: Each tests uses a list of asyncio.Events for staging through the |
| 440 | test. These are required here because we are bring up each coroutine |
| 441 | ("tasklet") at the same time and are not implementing any re-try |
| 442 | mechanisms. For instance, this is used in numerous tests to make sure that |
| 443 | a publisher is up and ready before the subscriber sends queries. Such |
| 444 | event lists should not be used in production software. |
| 445 | """ |
| 446 | |
| 447 | @classmethod |
| 448 | def configure_suite(cls, rwmain): |
| 449 | plugin_dir = os.path.join(os.environ["RIFT_INSTALL"], "usr/lib/rift/plugins") |
| 450 | rwmain.add_tasklet( |
| 451 | os.path.join(plugin_dir, 'rwvns'), |
| 452 | 'rwvnstasklet' |
| 453 | ) |
| 454 | |
| 455 | rwmain.add_tasklet( |
| 456 | os.path.join(plugin_dir, 'rwvnfm'), |
| 457 | 'rwvnfmtasklet' |
| 458 | ) |
| 459 | |
| 460 | rwmain.add_tasklet( |
| 461 | os.path.join(plugin_dir, 'rwnsm'), |
| 462 | 'rwnsmtasklet' |
| 463 | ) |
| 464 | |
| 465 | cls.waited_for_tasklets = False |
| 466 | |
| 467 | @asyncio.coroutine |
| 468 | def register_mock_res_mgr(self): |
| 469 | self.res_mgr = ResourceMgrMock( |
| 470 | self.dts, |
| 471 | self.log, |
| 472 | self.loop, |
| 473 | ) |
| 474 | yield from self.res_mgr.register() |
| 475 | |
| 476 | self.log.info("Waiting for resource manager to be ready") |
| 477 | yield from self.res_mgr.wait_ready() |
| 478 | |
| 479 | def unregister_mock_res_mgr(self): |
| 480 | self.res_mgr.unregister() |
| 481 | |
| 482 | @classmethod |
| 483 | def configure_schema(cls): |
| 484 | return rwnsmyang.get_schema() |
| 485 | |
| 486 | @classmethod |
| 487 | def configure_timeout(cls): |
| 488 | return 240 |
| 489 | |
| 490 | @asyncio.coroutine |
| 491 | def wait_tasklets(self): |
| 492 | if not ManoErrorTestCase.waited_for_tasklets: |
| 493 | yield from asyncio.sleep(5, loop=self.loop) |
| 494 | ManoErrorTestCase.waited_for_tasklets = True |
| 495 | |
| 496 | @asyncio.coroutine |
| 497 | def publish_desciptors(self, num_external_vlrs=1, num_internal_vlrs=1, num_ping_vms=1): |
| 498 | yield from self.ping_pong.publish_desciptors( |
| 499 | num_external_vlrs, |
| 500 | num_internal_vlrs, |
| 501 | num_ping_vms |
| 502 | ) |
| 503 | |
| 504 | def unpublish_descriptors(self): |
| 505 | self.ping_pong.unpublish_descriptors() |
| 506 | |
| 507 | @asyncio.coroutine |
| 508 | def wait_until_nsr_active_or_failed(self, nsr_id, timeout_secs=20): |
| 509 | start_time = time.time() |
| 510 | while (time.time() - start_time) < timeout_secs: |
| 511 | nsrs = yield from self.querier.get_nsr_opdatas(nsr_id) |
| 512 | self.assertEqual(1, len(nsrs)) |
| 513 | if nsrs[0].operational_status in ['running', 'failed']: |
| 514 | return |
| 515 | |
| 516 | self.log.debug("Rcvd NSR with %s status", nsrs[0].operational_status) |
| 517 | yield from asyncio.sleep(2, loop=self.loop) |
| 518 | |
| 519 | self.assertIn(nsrs[0].operational_status, ['running', 'failed']) |
| 520 | |
| 521 | def verify_number_compute_requests(self, num_requests): |
| 522 | self.assertEqual(num_requests, self.res_mgr.num_compute_requests) |
| 523 | |
| 524 | def verify_number_network_requests(self, num_requests): |
| 525 | self.assertEqual(num_requests, self.res_mgr.num_network_requests) |
| 526 | |
| 527 | def verify_number_allocated_compute(self, num_allocated): |
| 528 | self.assertEqual(num_allocated, self.res_mgr.num_allocated_compute_resources) |
| 529 | |
| 530 | def verify_number_allocated_network(self, num_allocated): |
| 531 | self.assertEqual(num_allocated, self.res_mgr.num_allocated_network_resources) |
| 532 | |
| 533 | def allocate_network_handlers(self, num_networks): |
| 534 | return [self.res_mgr.create_network_mock_event_handler() for _ in range(num_networks)] |
| 535 | |
| 536 | def allocate_compute_handlers(self, num_computes): |
| 537 | return [self.res_mgr.create_compute_mock_event_handler() for _ in range(num_computes)] |
| 538 | |
| 539 | @asyncio.coroutine |
| 540 | def create_mock_launchpad_tasklet(self): |
| 541 | yield from mano_ut.create_mock_launchpad_tasklet(self.log, self.dts) |
| 542 | |
| 543 | def configure_test(self, loop, test_id): |
| 544 | self.log.debug("STARTING - %s", self.id()) |
| 545 | self.tinfo = self.new_tinfo(self.id()) |
| 546 | self.dts = rift.tasklets.DTS(self.tinfo, self.schema, self.loop) |
| 547 | self.ping_pong = mano_ut.PingPongDescriptorPublisher(self.log, self.loop, self.dts) |
| 548 | self.querier = mano_ut.ManoQuerier(self.log, self.dts) |
| 549 | |
| 550 | # Add a task to wait for tasklets to come up |
| 551 | asyncio.ensure_future(self.wait_tasklets(), loop=self.loop) |
| 552 | |
| 553 | @rift.test.dts.async_test |
| 554 | def test_fail_first_nsm_vlr(self): |
| 555 | yield from self.publish_desciptors(num_external_vlrs=2) |
| 556 | yield from self.register_mock_res_mgr() |
| 557 | |
| 558 | nsr_id = yield from self.ping_pong.create_nsr() |
| 559 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 560 | |
| 561 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 562 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 563 | yield from self.verify_num_vlrs(1) |
| 564 | yield from self.verify_num_nsr_vlrs(nsr_id, 2) |
| 565 | yield from self.verify_num_vnfrs(0) |
| 566 | |
| 567 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 568 | yield from self.verify_vlr_state(nsr_vlrs[0], "failed") |
| 569 | |
| 570 | self.verify_number_network_requests(1) |
| 571 | self.verify_number_compute_requests(0) |
| 572 | self.verify_number_allocated_network(0) |
| 573 | self.verify_number_allocated_compute(0) |
| 574 | |
| 575 | yield from self.terminate_nsr(nsr_id) |
| 576 | |
| 577 | yield from self.verify_nsr_deleted(nsr_id) |
| 578 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 579 | yield from self.verify_num_vlrs(0) |
| 580 | |
| 581 | self.verify_number_allocated_network(0) |
| 582 | self.verify_number_allocated_compute(0) |
| 583 | |
| 584 | self.unregister_mock_res_mgr() |
| 585 | self.unpublish_descriptors() |
| 586 | |
| 587 | @rift.test.dts.async_test |
| 588 | def test_fail_second_nsm_vlr(self): |
| 589 | yield from self.publish_desciptors(num_external_vlrs=2) |
| 590 | yield from self.register_mock_res_mgr() |
| 591 | self.allocate_network_handlers(1) |
| 592 | |
| 593 | nsr_id = yield from self.ping_pong.create_nsr() |
| 594 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 595 | |
| 596 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 597 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 598 | yield from self.verify_num_vlrs(2) |
| 599 | yield from self.verify_num_nsr_vlrs(nsr_id, 2) |
| 600 | |
| 601 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 602 | yield from self.verify_vlr_state(nsr_vlrs[0], "running") |
| 603 | yield from self.verify_vlr_state(nsr_vlrs[1], "failed") |
| 604 | |
| 605 | self.verify_number_network_requests(2) |
| 606 | self.verify_number_compute_requests(0) |
| 607 | self.verify_number_allocated_network(1) |
| 608 | self.verify_number_allocated_compute(0) |
| 609 | |
| 610 | yield from self.terminate_nsr(nsr_id) |
| 611 | |
| 612 | yield from self.verify_nsr_deleted(nsr_id) |
| 613 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 614 | yield from self.verify_num_vlrs(0) |
| 615 | |
| 616 | self.verify_number_allocated_network(0) |
| 617 | self.verify_number_allocated_compute(0) |
| 618 | |
| 619 | self.unregister_mock_res_mgr() |
| 620 | self.unpublish_descriptors() |
| 621 | |
| 622 | @rift.test.dts.async_test |
| 623 | def test_fail_first_vnf_first_vlr(self): |
| 624 | yield from self.publish_desciptors(num_internal_vlrs=2) |
| 625 | yield from self.register_mock_res_mgr() |
| 626 | self.allocate_network_handlers(1) |
| 627 | |
| 628 | nsr_id = yield from self.ping_pong.create_nsr() |
| 629 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 630 | |
| 631 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 632 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 633 | yield from self.verify_num_vlrs(2) |
| 634 | yield from self.verify_num_nsr_vlrs(nsr_id, 1) |
| 635 | |
| 636 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 637 | yield from self.verify_vlr_state(nsr_vlrs[0], "running") |
| 638 | |
| 639 | yield from self.verify_num_nsr_vnfrs(nsr_id, 2) |
| 640 | |
| 641 | # Verify only a single vnfr was instantiated and is failed |
| 642 | yield from self.verify_num_vnfrs(1) |
| 643 | nsr_vnfs = yield from self.get_nsr_vnfs(nsr_id) |
| 644 | yield from self.verify_vnf_state(nsr_vnfs[0], "failed") |
| 645 | |
| 646 | yield from self.verify_num_vnfr_vlrs(nsr_vnfs[0], 2) |
| 647 | vnf_vlrs = yield from self.get_vnf_vlrs(nsr_vnfs[0]) |
| 648 | yield from self.verify_vlr_state(vnf_vlrs[0], "failed") |
| 649 | |
| 650 | self.verify_number_network_requests(2) |
| 651 | self.verify_number_compute_requests(0) |
| 652 | self.verify_number_allocated_network(1) |
| 653 | self.verify_number_allocated_compute(0) |
| 654 | |
| 655 | yield from self.terminate_nsr(nsr_id) |
| 656 | |
| 657 | yield from self.verify_nsr_deleted(nsr_id) |
| 658 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 659 | yield from self.verify_num_vlrs(0) |
| 660 | |
| 661 | self.verify_number_allocated_network(0) |
| 662 | self.verify_number_allocated_compute(0) |
| 663 | |
| 664 | self.unregister_mock_res_mgr() |
| 665 | self.unpublish_descriptors() |
| 666 | |
| 667 | @rift.test.dts.async_test |
| 668 | def test_fail_first_vnf_second_vlr(self): |
| 669 | yield from self.publish_desciptors(num_internal_vlrs=2) |
| 670 | yield from self.register_mock_res_mgr() |
| 671 | self.allocate_network_handlers(2) |
| 672 | |
| 673 | nsr_id = yield from self.ping_pong.create_nsr() |
| 674 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 675 | |
| 676 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 677 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 678 | yield from self.verify_num_vlrs(3) |
| 679 | yield from self.verify_num_nsr_vlrs(nsr_id, 1) |
| 680 | |
| 681 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 682 | yield from self.verify_vlr_state(nsr_vlrs[0], "running") |
| 683 | |
| 684 | yield from self.verify_num_nsr_vnfrs(nsr_id, 2) |
| 685 | |
| 686 | # Verify only a single vnfr was instantiated and is failed |
| 687 | yield from self.verify_num_vnfrs(1) |
| 688 | nsr_vnfs = yield from self.get_nsr_vnfs(nsr_id) |
| 689 | yield from self.verify_vnf_state(nsr_vnfs[0], "failed") |
| 690 | |
| 691 | yield from self.verify_num_vnfr_vlrs(nsr_vnfs[0], 2) |
| 692 | vnf_vlrs = yield from self.get_vnf_vlrs(nsr_vnfs[0]) |
| 693 | yield from self.verify_vlr_state(vnf_vlrs[0], "running") |
| 694 | yield from self.verify_vlr_state(vnf_vlrs[1], "failed") |
| 695 | |
| 696 | self.verify_number_network_requests(3) |
| 697 | self.verify_number_compute_requests(0) |
| 698 | self.verify_number_allocated_network(2) |
| 699 | self.verify_number_allocated_compute(0) |
| 700 | |
| 701 | yield from self.terminate_nsr(nsr_id) |
| 702 | |
| 703 | yield from self.verify_nsr_deleted(nsr_id) |
| 704 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 705 | yield from self.verify_num_vlrs(0) |
| 706 | |
| 707 | self.verify_number_allocated_network(0) |
| 708 | self.verify_number_allocated_compute(0) |
| 709 | |
| 710 | self.unregister_mock_res_mgr() |
| 711 | self.unpublish_descriptors() |
| 712 | |
| 713 | @rift.test.dts.async_test |
| 714 | def test_fail_first_vnf_first_vdu(self): |
| 715 | yield from self.publish_desciptors(num_internal_vlrs=2, num_ping_vms=2) |
| 716 | yield from self.register_mock_res_mgr() |
| 717 | yield from self.create_mock_launchpad_tasklet() |
| 718 | self.allocate_network_handlers(3) |
| 719 | |
| 720 | nsr_id = yield from self.ping_pong.create_nsr() |
| 721 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 722 | |
| 723 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 724 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 725 | yield from self.verify_num_vlrs(3) |
| 726 | yield from self.verify_num_nsr_vlrs(nsr_id, 1) |
| 727 | |
| 728 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 729 | yield from self.verify_vlr_state(nsr_vlrs[0], "running") |
| 730 | |
| 731 | yield from self.verify_num_nsr_vnfrs(nsr_id, 2) |
| 732 | |
| 733 | # Verify only a single vnfr was instantiated and is failed |
| 734 | yield from self.verify_num_vnfrs(1) |
| 735 | nsr_vnfs = yield from self.get_nsr_vnfs(nsr_id) |
| 736 | yield from self.verify_vnf_state(nsr_vnfs[0], "failed") |
| 737 | |
| 738 | yield from self.verify_num_vnfr_vlrs(nsr_vnfs[0], 2) |
| 739 | vnf_vlrs = yield from self.get_vnf_vlrs(nsr_vnfs[0]) |
| 740 | yield from self.verify_vlr_state(vnf_vlrs[0], "running") |
| 741 | yield from self.verify_vlr_state(vnf_vlrs[1], "running") |
| 742 | |
| 743 | yield from self.verify_num_vnfr_vdus(nsr_vnfs[0], 2) |
| 744 | vdus = yield from self.get_vnf_vdus(nsr_vnfs[0]) |
| 745 | self.verify_vdu_state(vdus[0], "failed") |
| 746 | |
| 747 | self.verify_number_network_requests(3) |
| 748 | self.verify_number_compute_requests(1) |
| 749 | self.verify_number_allocated_network(3) |
| 750 | self.verify_number_allocated_compute(0) |
| 751 | |
| 752 | yield from self.terminate_nsr(nsr_id) |
| 753 | |
| 754 | yield from self.verify_nsr_deleted(nsr_id) |
| 755 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 756 | yield from self.verify_num_vlrs(0) |
| 757 | |
| 758 | self.verify_number_allocated_network(0) |
| 759 | self.verify_number_allocated_compute(0) |
| 760 | |
| 761 | self.unregister_mock_res_mgr() |
| 762 | self.unpublish_descriptors() |
| 763 | |
| 764 | @rift.test.dts.async_test |
| 765 | def test_fail_first_vnf_second_vdu(self): |
| 766 | yield from self.publish_desciptors(num_internal_vlrs=2, num_ping_vms=2) |
| 767 | yield from self.register_mock_res_mgr() |
| 768 | yield from self.create_mock_launchpad_tasklet() |
| 769 | self.allocate_network_handlers(3) |
| 770 | self.allocate_compute_handlers(1) |
| 771 | |
| 772 | nsr_id = yield from self.ping_pong.create_nsr() |
| 773 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 774 | |
| 775 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 776 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 777 | yield from self.verify_num_vlrs(3) |
| 778 | yield from self.verify_num_nsr_vlrs(nsr_id, 1) |
| 779 | |
| 780 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 781 | yield from self.verify_vlr_state(nsr_vlrs[0], "running") |
| 782 | |
| 783 | yield from self.verify_num_nsr_vnfrs(nsr_id, 2) |
| 784 | |
| 785 | # Verify only a single vnfr was instantiated and is failed |
| 786 | yield from self.verify_num_vnfrs(1) |
| 787 | nsr_vnfs = yield from self.get_nsr_vnfs(nsr_id) |
| 788 | yield from self.verify_vnf_state(nsr_vnfs[0], "failed") |
| 789 | |
| 790 | yield from self.verify_num_vnfr_vlrs(nsr_vnfs[0], 2) |
| 791 | vnf_vlrs = yield from self.get_vnf_vlrs(nsr_vnfs[0]) |
| 792 | yield from self.verify_vlr_state(vnf_vlrs[0], "running") |
| 793 | yield from self.verify_vlr_state(vnf_vlrs[1], "running") |
| 794 | |
| 795 | yield from self.verify_num_vnfr_vdus(nsr_vnfs[0], 2) |
| 796 | |
| 797 | vdus = yield from self.get_vnf_vdus(nsr_vnfs[0]) |
| 798 | self.verify_vdu_state(vdus[0], "running") |
| 799 | self.verify_vdu_state(vdus[1], "failed") |
| 800 | |
| 801 | self.verify_number_network_requests(3) |
| 802 | self.verify_number_compute_requests(2) |
| 803 | self.verify_number_allocated_network(3) |
| 804 | self.verify_number_allocated_compute(1) |
| 805 | |
| 806 | yield from self.terminate_nsr(nsr_id) |
| 807 | |
| 808 | yield from self.verify_nsr_deleted(nsr_id) |
| 809 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 810 | yield from self.verify_num_vlrs(0) |
| 811 | |
| 812 | self.verify_number_allocated_network(0) |
| 813 | self.verify_number_allocated_compute(0) |
| 814 | |
| 815 | self.unregister_mock_res_mgr() |
| 816 | self.unpublish_descriptors() |
| 817 | |
| 818 | @rift.test.dts.async_test |
| 819 | def test_fail_second_vnf_second_vdu(self): |
| 820 | yield from self.publish_desciptors(num_internal_vlrs=2, num_ping_vms=2) |
| 821 | yield from self.register_mock_res_mgr() |
| 822 | yield from self.create_mock_launchpad_tasklet() |
| 823 | self.allocate_network_handlers(5) |
| 824 | self.allocate_compute_handlers(3) |
| 825 | |
| 826 | nsr_id = yield from self.ping_pong.create_nsr() |
| 827 | yield from self.wait_until_nsr_active_or_failed(nsr_id) |
| 828 | |
| 829 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 1) |
| 830 | yield from self.verify_nsr_state(nsr_id, "failed") |
| 831 | yield from self.verify_num_vlrs(5) |
| 832 | yield from self.verify_num_nsr_vlrs(nsr_id, 1) |
| 833 | |
| 834 | nsr_vlrs = yield from self.get_nsr_vlrs(nsr_id) |
| 835 | yield from self.verify_vlr_state(nsr_vlrs[0], "running") |
| 836 | |
| 837 | yield from self.verify_num_nsr_vnfrs(nsr_id, 2) |
| 838 | |
| 839 | # Verify only a single vnfr was instantiated and is failed |
| 840 | yield from self.verify_num_vnfrs(2) |
| 841 | nsr_vnfs = yield from self.get_nsr_vnfs(nsr_id) |
| 842 | yield from self.verify_vnf_state(nsr_vnfs[0], "running") |
| 843 | yield from self.verify_vnf_state(nsr_vnfs[1], "failed") |
| 844 | |
| 845 | yield from self.verify_num_vnfr_vlrs(nsr_vnfs[0], 2) |
| 846 | |
| 847 | vnf_vlrs = yield from self.get_vnf_vlrs(nsr_vnfs[0]) |
| 848 | yield from self.verify_vlr_state(vnf_vlrs[0], "running") |
| 849 | yield from self.verify_vlr_state(vnf_vlrs[1], "running") |
| 850 | |
| 851 | vnf_vlrs = yield from self.get_vnf_vlrs(nsr_vnfs[1]) |
| 852 | yield from self.verify_vlr_state(vnf_vlrs[0], "running") |
| 853 | yield from self.verify_vlr_state(vnf_vlrs[1], "running") |
| 854 | |
| 855 | yield from self.verify_num_vnfr_vdus(nsr_vnfs[0], 2) |
| 856 | yield from self.verify_num_vnfr_vdus(nsr_vnfs[1], 2) |
| 857 | |
| 858 | vdus = yield from self.get_vnf_vdus(nsr_vnfs[0]) |
| 859 | self.verify_vdu_state(vdus[0], "running") |
| 860 | self.verify_vdu_state(vdus[1], "running") |
| 861 | |
| 862 | vdus = yield from self.get_vnf_vdus(nsr_vnfs[1]) |
| 863 | self.verify_vdu_state(vdus[0], "running") |
| 864 | self.verify_vdu_state(vdus[1], "failed") |
| 865 | |
| 866 | self.verify_number_network_requests(5) |
| 867 | self.verify_number_compute_requests(4) |
| 868 | self.verify_number_allocated_network(5) |
| 869 | self.verify_number_allocated_compute(3) |
| 870 | |
| 871 | yield from self.terminate_nsr(nsr_id) |
| 872 | |
| 873 | yield from self.verify_nsr_deleted(nsr_id) |
| 874 | yield from self.verify_nsd_ref_count(self.ping_pong.nsd_id, 0) |
| 875 | yield from self.verify_num_vlrs(0) |
| 876 | |
| 877 | self.verify_number_allocated_network(0) |
| 878 | self.verify_number_allocated_compute(0) |
| 879 | |
| 880 | self.unregister_mock_res_mgr() |
| 881 | self.unpublish_descriptors() |
| 882 | |
| 883 | |
| 884 | def main(): |
| 885 | runner = xmlrunner.XMLTestRunner(output=os.environ["RIFT_MODULE_TEST"]) |
| 886 | |
| 887 | parser = argparse.ArgumentParser() |
| 888 | parser.add_argument('-v', '--verbose', action='store_true') |
| 889 | args, _ = parser.parse_known_args() |
| 890 | |
| 891 | ManoErrorTestCase.log_level = logging.DEBUG if args.verbose else logging.WARN |
| 892 | |
| 893 | unittest.main(testRunner=runner) |
| 894 | |
| 895 | if __name__ == '__main__': |
| 896 | main() |
| 897 | |
| 898 | # vim: sw |