How to use create_host method in autotest

Best Python code snippet using autotest_python

test_fw_update_strategy.py

Source:test_fw_update_strategy.py Github

copy

Full Screen

...45 - ignore worker apply46 Verify:47 - stages not created ; fw update is only supported for worker nodes48 """49 self.create_host('controller-0')50 self.create_host('controller-1')51 self.create_host('storage-0')52 self.create_host('storage-1')53 self.create_host('compute-0')54 self.create_host('compute-1')55 # default apply type is 'ignore' for all node types.56 # Only worker nodes support firmware upgrade.57 strategy = create_fw_update_strategy()58 worker_hosts = []59 for host in list(self._host_table.values()):60 if HOST_PERSONALITY.WORKER in host.personality:61 worker_hosts.append(host)62 success, reason = strategy._add_worker_strategy_stages(63 sorted(worker_hosts, key=lambda host: host.name),64 reboot=True)65 assert success is True, "Strategy creation failed"66 apply_phase = strategy.apply_phase.as_dict()67 expected_results = {68 'completion_percentage': 100,69 'total_stages': 070 }71 sw_update_testcase.validate_strategy_persists(strategy)72 sw_update_testcase.validate_phase(apply_phase, expected_results)73 def test_fw_update_strategy_storage_serial_no_instances(self):74 """75 Test the fw_update strategy on a storage system:76 - 2 controllers77 - 2 storage hosts78 - 4 worker hosts79 options80 - serial apply81 - no instances82 """83 self.create_host('controller-0')84 self.create_host('controller-1')85 self.create_host('storage-0')86 self.create_host('storage-1')87 self.create_host('compute-0')88 self.create_host('compute-1')89 self.create_host('compute-2')90 self.create_host('compute-3')91 strategy = create_fw_update_strategy(92 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL)93 fw_update_host_list = []94 for host in list(self._host_table.values()):95 if HOST_PERSONALITY.WORKER in host.personality:96 fw_update_host_list.append(host)97 strategy._add_worker_strategy_stages(98 sorted(fw_update_host_list, key=lambda host: host.name),99 reboot=True)100 apply_phase = strategy.apply_phase.as_dict()101 expected_results = {102 'total_stages': 4,103 'stages': [104 {'name': 'fw-update-worker-hosts',105 'total_steps': 6,106 'steps': [107 {'name': 'query-alarms'},108 {'name': 'fw-update-hosts'},109 {'name': 'lock-hosts',110 'entity_names': ['compute-0']},111 {'name': 'system-stabilize',112 'timeout': 15},113 {'name': 'unlock-hosts',114 'entity_names': ['compute-0']},115 {'name': 'system-stabilize',116 'timeout': 60}117 ]118 },119 {'name': 'fw-update-worker-hosts',120 'total_steps': 6,121 'steps': [122 {'name': 'query-alarms'},123 {'name': 'fw-update-hosts'},124 {'name': 'lock-hosts',125 'entity_names': ['compute-1']},126 {'name': 'system-stabilize',127 'timeout': 15},128 {'name': 'unlock-hosts',129 'entity_names': ['compute-1']},130 {'name': 'system-stabilize',131 'timeout': 60}132 ]133 },134 {'name': 'fw-update-worker-hosts',135 'total_steps': 6,136 'steps': [137 {'name': 'query-alarms'},138 {'name': 'fw-update-hosts'},139 {'name': 'lock-hosts',140 'entity_names': ['compute-2']},141 {'name': 'system-stabilize',142 'timeout': 15},143 {'name': 'unlock-hosts',144 'entity_names': ['compute-2']},145 {'name': 'system-stabilize',146 'timeout': 60}147 ]148 },149 {'name': 'fw-update-worker-hosts',150 'total_steps': 6,151 'steps': [152 {'name': 'query-alarms'},153 {'name': 'fw-update-hosts'},154 {'name': 'lock-hosts',155 'entity_names': ['compute-3']},156 {'name': 'system-stabilize',157 'timeout': 15},158 {'name': 'unlock-hosts',159 'entity_names': ['compute-3']},160 {'name': 'system-stabilize',161 'timeout': 60}162 ]163 }164 ]165 }166 sw_update_testcase.validate_strategy_persists(strategy)167 sw_update_testcase.validate_phase(apply_phase, expected_results)168 def test_fw_update_strategy_storage_parallel_no_instances(self):169 """170 Test the fw_update strategy on a storage system:171 - 2 controllers172 - 2 storage hosts173 - 4 worker hosts174 options175 - parallel apply ; max 3176 - no instances177 """178 self.create_host('controller-0')179 self.create_host('controller-1')180 self.create_host('storage-0')181 self.create_host('storage-1')182 self.create_host('compute-0')183 self.create_host('compute-1')184 self.create_host('compute-2')185 self.create_host('compute-3')186 strategy = create_fw_update_strategy(187 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,188 max_parallel_worker_hosts=3)189 fw_update_host_list = []190 for host in list(self._host_table.values()):191 if HOST_PERSONALITY.WORKER in host.personality:192 fw_update_host_list.append(host)193 strategy._add_worker_strategy_stages(194 sorted(fw_update_host_list, key=lambda host: host.name),195 reboot=True)196 apply_phase = strategy.apply_phase.as_dict()197 expected_results = {198 'total_stages': 2,199 'stages': [200 {'name': 'fw-update-worker-hosts',201 'total_steps': 6,202 'steps': [203 {'name': 'query-alarms'},204 {'name': 'fw-update-hosts',205 'entity_names': ['compute-0', 'compute-1', 'compute-2']},206 {'name': 'lock-hosts',207 'entity_names': ['compute-0', 'compute-1', 'compute-2']},208 {'name': 'system-stabilize', 'timeout': 15},209 {'name': 'unlock-hosts',210 'entity_names': ['compute-0', 'compute-1', 'compute-2']},211 {'name': 'system-stabilize', 'timeout': 60}212 ]213 },214 {'name': 'fw-update-worker-hosts',215 'total_steps': 6,216 'steps': [217 {'name': 'query-alarms'},218 {'name': 'fw-update-hosts',219 'entity_names': ['compute-3']},220 {'name': 'lock-hosts',221 'entity_names': ['compute-3']},222 {'name': 'system-stabilize', 'timeout': 15},223 {'name': 'unlock-hosts',224 'entity_names': ['compute-3']},225 {'name': 'system-stabilize', 'timeout': 60}226 ]227 }228 ]229 }230 sw_update_testcase.validate_strategy_persists(strategy)231 sw_update_testcase.validate_phase(apply_phase, expected_results)232 def test_fw_update_strategy_storage_serial_migrate(self):233 """234 Test the fw_update strategy on a storage system:235 - 2 controllers236 - 2 storage hosts237 - 4 worker hosts238 options239 - serial apply240 - migrate 3 instances241 """242 self.create_host('controller-0')243 self.create_host('controller-1')244 self.create_host('storage-0')245 self.create_host('storage-1')246 self.create_host('compute-0')247 self.create_host('compute-1')248 self.create_host('compute-2')249 self.create_host('compute-3')250 self.create_instance('small', "test_instance_0", 'compute-0')251 self.create_instance('small', "test_instance_1", 'compute-1')252 self.create_instance('small', "test_instance_2", 'compute-3')253 strategy = create_fw_update_strategy(254 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,255 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE)256 fw_update_host_list = []257 for host in list(self._host_table.values()):258 if HOST_PERSONALITY.WORKER in host.personality:259 fw_update_host_list.append(host)260 strategy._add_worker_strategy_stages(261 sorted(fw_update_host_list, key=lambda host: host.name),262 reboot=True)263 apply_phase = strategy.apply_phase.as_dict()264 expected_results = {265 'total_stages': 4,266 'stages': [267 {'name': 'fw-update-worker-hosts',268 'total_steps': 6,269 'steps': [270 {'name': 'query-alarms'},271 {'name': 'fw-update-hosts', 'entity_names': ['compute-2']},272 {'name': 'lock-hosts', 'entity_names': ['compute-2']},273 {'name': 'system-stabilize', 'timeout': 15},274 {'name': 'unlock-hosts', 'entity_names': ['compute-2']},275 {'name': 'system-stabilize', 'timeout': 60}276 ]277 },278 {'name': 'fw-update-worker-hosts',279 'total_steps': 7,280 'steps': [281 {'name': 'query-alarms'},282 {'name': 'fw-update-hosts', 'entity_names': ['compute-0']},283 {'name': 'migrate-instances',284 'entity_names': ['test_instance_0']},285 {'name': 'lock-hosts', 'entity_names': ['compute-0']},286 {'name': 'system-stabilize', 'timeout': 15},287 {'name': 'unlock-hosts', 'entity_names': ['compute-0']},288 {'name': 'system-stabilize', 'timeout': 60}289 ]290 },291 {'name': 'fw-update-worker-hosts',292 'total_steps': 7,293 'steps': [294 {'name': 'query-alarms'},295 {'name': 'fw-update-hosts', 'entity_names': ['compute-1']},296 {'name': 'migrate-instances',297 'entity_names': ['test_instance_1']},298 {'name': 'lock-hosts', 'entity_names': ['compute-1']},299 {'name': 'system-stabilize', 'timeout': 15},300 {'name': 'unlock-hosts', 'entity_names': ['compute-1']},301 {'name': 'system-stabilize', 'timeout': 60}302 ]303 },304 {'name': 'fw-update-worker-hosts',305 'total_steps': 7,306 'steps': [307 {'name': 'query-alarms'},308 {'name': 'fw-update-hosts', 'entity_names': ['compute-3']},309 {'name': 'migrate-instances',310 'entity_names': ['test_instance_2']},311 {'name': 'lock-hosts', 'entity_names': ['compute-3']},312 {'name': 'system-stabilize', 'timeout': 15},313 {'name': 'unlock-hosts', 'entity_names': ['compute-3']},314 {'name': 'system-stabilize', 'timeout': 60},315 ]316 }317 ]318 }319 sw_update_testcase.validate_strategy_persists(strategy)320 sw_update_testcase.validate_phase(apply_phase, expected_results)321 def test_fw_update_strategy_storage_parallel_migrate(self):322 """323 Test the fw_update strategy on a storage system:324 - 2 controllers325 - 2 storage hosts326 - 4 worker hosts327 options328 - parallel apply ; max 4329 - migrate 4 instances330 """331 self.create_host('controller-0')332 self.create_host('controller-1')333 self.create_host('storage-0')334 self.create_host('storage-1')335 self.create_host('compute-0')336 self.create_host('compute-1')337 self.create_host('compute-2')338 self.create_host('compute-3')339 self.create_host('compute-4')340 self.create_host('compute-5')341 self.create_instance('small', "test_instance_1", 'compute-1')342 self.create_instance('small', "test_instance_2", 'compute-2')343 self.create_instance('small', "test_instance_3", 'compute-3')344 self.create_instance('small', "test_instance_4", 'compute-4')345 strategy = create_fw_update_strategy(346 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,347 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,348 max_parallel_worker_hosts=4)349 fw_update_host_list = []350 for host in list(self._host_table.values()):351 if HOST_PERSONALITY.WORKER in host.personality:352 fw_update_host_list.append(host)353 strategy._add_worker_strategy_stages(354 sorted(fw_update_host_list, key=lambda host: host.name),355 reboot=True)356 apply_phase = strategy.apply_phase.as_dict()357 expected_results = {358 'total_stages': 2,359 'stages': [360 {'name': 'fw-update-worker-hosts',361 'total_steps': 6,362 'steps': [363 {'name': 'query-alarms'},364 {'name': 'fw-update-hosts',365 'entity_names': ['compute-0', 'compute-5']},366 {'name': 'lock-hosts',367 'entity_names': ['compute-0', 'compute-5']},368 {'name': 'system-stabilize', 'timeout': 15},369 {'name': 'unlock-hosts',370 'entity_names': ['compute-0', 'compute-5']},371 {'name': 'system-stabilize', 'timeout': 60}372 ]373 },374 {'name': 'fw-update-worker-hosts',375 'total_steps': 8,376 'steps': [377 {'name': 'query-alarms'},378 {'name': 'fw-update-hosts',379 'entity_names': ['compute-1', 'compute-2',380 'compute-3', 'compute-4']},381 {'name': 'disable-host-services'},382 {'name': 'migrate-instances',383 'entity_names': ['test_instance_1',384 'test_instance_2',385 'test_instance_3',386 'test_instance_4']},387 {'name': 'lock-hosts',388 'entity_names': ['compute-1', 'compute-2',389 'compute-3', 'compute-4']},390 {'name': 'system-stabilize', 'timeout': 15},391 {'name': 'unlock-hosts',392 'entity_names': ['compute-1', 'compute-2',393 'compute-3', 'compute-4']},394 {'name': 'system-stabilize', 'timeout': 60}395 ]396 }397 ]398 }399 sw_update_testcase.validate_strategy_persists(strategy)400 sw_update_testcase.validate_phase(apply_phase, expected_results)401 def test_fw_update_strategy_standard_serial_stop_start(self):402 """403 Test the fw_update strategy on a storage system:404 - 2 controllers405 - 2 storage hosts406 - 4 worker hosts407 options408 - serial apply409 - stop start 4 instances410 """411 self.create_host('controller-0')412 self.create_host('controller-1')413 self.create_host('compute-0')414 self.create_host('compute-1')415 self.create_host('compute-2')416 self.create_host('compute-3')417 self.create_host('compute-4')418 self.create_host('compute-5')419 self.create_host('compute-6')420 self.create_host('compute-7')421 self.create_instance('small', "test_instance_0", 'compute-0')422 self.create_instance('small', "test_instance_1", 'compute-2')423 self.create_instance('small', "test_instance_2", 'compute-4')424 self.create_instance('small', "test_instance_3", 'compute-6')425 strategy = create_fw_update_strategy(426 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,427 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START)428 fw_update_host_list = []429 for host in list(self._host_table.values()):430 if HOST_PERSONALITY.WORKER in host.personality:431 fw_update_host_list.append(host)432 strategy._add_worker_strategy_stages(433 sorted(fw_update_host_list, key=lambda host: host.name),434 reboot=True)435 apply_phase = strategy.apply_phase.as_dict()436 expected_results = {437 'total_stages': 8,438 'stages': [439 {'name': 'fw-update-worker-hosts',440 'total_steps': 6,441 'steps': [442 {'name': 'query-alarms'},443 {'name': 'fw-update-hosts', 'entity_names': ['compute-1']},444 {'name': 'lock-hosts', 'entity_names': ['compute-1']},445 {'name': 'system-stabilize', 'timeout': 15},446 {'name': 'unlock-hosts', 'entity_names': ['compute-1']},447 {'name': 'system-stabilize', 'timeout': 60}448 ]449 },450 {'name': 'fw-update-worker-hosts',451 'total_steps': 6,452 'steps': [453 {'name': 'query-alarms'},454 {'name': 'fw-update-hosts', 'entity_names': ['compute-3']},455 {'name': 'lock-hosts', 'entity_names': ['compute-3']},456 {'name': 'system-stabilize', 'timeout': 15},457 {'name': 'unlock-hosts', 'entity_names': ['compute-3']},458 {'name': 'system-stabilize', 'timeout': 60}459 ]460 },461 {'name': 'fw-update-worker-hosts',462 'total_steps': 6,463 'steps': [464 {'name': 'query-alarms'},465 {'name': 'fw-update-hosts', 'entity_names': ['compute-5']},466 {'name': 'lock-hosts', 'entity_names': ['compute-5']},467 {'name': 'system-stabilize', 'timeout': 15},468 {'name': 'unlock-hosts', 'entity_names': ['compute-5']},469 {'name': 'system-stabilize', 'timeout': 60}470 ]471 },472 {'name': 'fw-update-worker-hosts',473 'total_steps': 6,474 'steps': [475 {'name': 'query-alarms'},476 {'name': 'fw-update-hosts', 'entity_names': ['compute-7']},477 {'name': 'lock-hosts', 'entity_names': ['compute-7']},478 {'name': 'system-stabilize', 'timeout': 15},479 {'name': 'unlock-hosts', 'entity_names': ['compute-7']},480 {'name': 'system-stabilize', 'timeout': 60}481 ]482 },483 {'name': 'fw-update-worker-hosts',484 'total_steps': 8,485 'steps': [486 {'name': 'query-alarms'},487 {'name': 'fw-update-hosts', 'entity_names': ['compute-0']},488 {'name': 'stop-instances',489 'entity_names': ['test_instance_0']},490 {'name': 'lock-hosts', 'entity_names': ['compute-0']},491 {'name': 'system-stabilize', 'timeout': 15},492 {'name': 'unlock-hosts', 'entity_names': ['compute-0']},493 {'name': 'start-instances',494 'entity_names': ['test_instance_0']},495 {'name': 'system-stabilize', 'timeout': 60}496 ]497 },498 {'name': 'fw-update-worker-hosts',499 'total_steps': 8,500 'steps': [501 {'name': 'query-alarms'},502 {'name': 'fw-update-hosts', 'entity_names': ['compute-2']},503 {'name': 'stop-instances',504 'entity_names': ['test_instance_1']},505 {'name': 'lock-hosts', 'entity_names': ['compute-2']},506 {'name': 'system-stabilize', 'timeout': 15},507 {'name': 'unlock-hosts', 'entity_names': ['compute-2']},508 {'name': 'start-instances',509 'entity_names': ['test_instance_1']},510 {'name': 'system-stabilize', 'timeout': 60}511 ]512 },513 {'name': 'fw-update-worker-hosts',514 'total_steps': 8,515 'steps': [516 {'name': 'query-alarms'},517 {'name': 'fw-update-hosts', 'entity_names': ['compute-4']},518 {'name': 'stop-instances',519 'entity_names': ['test_instance_2']},520 {'name': 'lock-hosts', 'entity_names': ['compute-4']},521 {'name': 'system-stabilize', 'timeout': 15},522 {'name': 'unlock-hosts', 'entity_names': ['compute-4']},523 {'name': 'start-instances',524 'entity_names': ['test_instance_2']},525 {'name': 'system-stabilize', 'timeout': 60}526 ]527 },528 {'name': 'fw-update-worker-hosts',529 'total_steps': 8,530 'steps': [531 {'name': 'query-alarms'},532 {'name': 'fw-update-hosts', 'entity_names': ['compute-6']},533 {'name': 'stop-instances',534 'entity_names': ['test_instance_3']},535 {'name': 'lock-hosts', 'entity_names': ['compute-6']},536 {'name': 'system-stabilize', 'timeout': 15},537 {'name': 'unlock-hosts', 'entity_names': ['compute-6']},538 {'name': 'start-instances',539 'entity_names': ['test_instance_3']},540 {'name': 'system-stabilize', 'timeout': 60}541 ]542 }543 ]544 }545 sw_update_testcase.validate_strategy_persists(strategy)546 sw_update_testcase.validate_phase(apply_phase, expected_results)547 def test_fw_update_strategy_standard_parallel_stop_start(self):548 """549 Test the fw_update strategy on a standard system:550 - 2 controllers551 - 8 worker hosts552 options553 - parallel apply ; max 10554 - stop start 8 instances555 """556 self.create_host('controller-0')557 self.create_host('controller-1')558 self.create_host('compute-0')559 self.create_host('compute-1')560 self.create_host('compute-2')561 self.create_host('compute-3')562 self.create_host('compute-4')563 self.create_host('compute-5')564 self.create_host('compute-6')565 self.create_host('compute-7')566 self.create_instance('small', "test_instance_0", 'compute-0')567 self.create_instance('small', "test_instance_1", 'compute-1')568 self.create_instance('small', "test_instance_2", 'compute-2')569 self.create_instance('small', "test_instance_3", 'compute-3')570 self.create_instance('small', "test_instance_4", 'compute-4')571 self.create_instance('small', "test_instance_5", 'compute-5')572 self.create_instance('small', "test_instance_6", 'compute-6')573 self.create_instance('small', "test_instance_7", 'compute-7')574 strategy = create_fw_update_strategy(575 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,576 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,577 max_parallel_worker_hosts=10)578 fw_update_host_list = []579 for host in list(self._host_table.values()):580 if HOST_PERSONALITY.WORKER in host.personality:581 fw_update_host_list.append(host)582 strategy._add_worker_strategy_stages(583 sorted(fw_update_host_list, key=lambda host: host.name),584 reboot=True)585 apply_phase = strategy.apply_phase.as_dict()586 expected_results = {587 'total_stages': 1,588 'stages': [589 {'name': 'fw-update-worker-hosts',590 'total_steps': 8,591 'steps': [592 {'name': 'query-alarms'},593 {'name': 'fw-update-hosts',594 'entity_names': ['compute-0', 'compute-1',595 'compute-2', 'compute-3',596 'compute-4', 'compute-5',597 'compute-6', 'compute-7']},598 {'name': 'stop-instances',599 'entity_names': ['test_instance_0', 'test_instance_1',600 'test_instance_2', 'test_instance_3',601 'test_instance_4', 'test_instance_5',602 'test_instance_6', 'test_instance_7']},603 {'name': 'lock-hosts',604 'entity_names': ['compute-0', 'compute-1',605 'compute-2', 'compute-3',606 'compute-4', 'compute-5',607 'compute-6', 'compute-7']},608 {'name': 'system-stabilize', 'timeout': 15},609 {'name': 'unlock-hosts',610 'entity_names': ['compute-0', 'compute-1',611 'compute-2', 'compute-3',612 'compute-4', 'compute-5',613 'compute-6', 'compute-7']},614 {'name': 'start-instances',615 'entity_names': ['test_instance_0', 'test_instance_1',616 'test_instance_2', 'test_instance_3',617 'test_instance_4', 'test_instance_5',618 'test_instance_6', 'test_instance_7']},619 {'name': 'system-stabilize', 'timeout': 60},620 ]621 }622 ]623 }624 sw_update_testcase.validate_strategy_persists(strategy)625 sw_update_testcase.validate_phase(apply_phase, expected_results)626 def test_fw_update_strategy_standard_parallel_migrate_host_aggregate(self):627 """628 Test the fw_update strategy on a storage system:629 - 2 controllers630 - 10 worker hosts631 options632 - parallel apply ; max 10633 - migrate instances ; 1 per host ; 1 locked634 - hosts with no instances updated first635 - host aggregate limits enforced636 """637 self.create_host('controller-0')638 self.create_host('controller-1')639 self.create_host('compute-0')640 self.create_host('compute-1')641 self.create_host('compute-2')642 self.create_host('compute-3')643 self.create_host('compute-4')644 self.create_host('compute-5')645 self.create_host('compute-6')646 self.create_host('compute-7')647 self.create_host('compute-8')648 self.create_host('compute-9')649 self.create_host_aggregate('aggregate-1', ['compute-0', 'compute-2',650 'compute-4', 'compute-6'])651 self.create_host_aggregate('aggregate-2', ['compute-1', 'compute-3',652 'compute-5', 'compute-7'])653 self.create_instance('small', "test_instance_0", 'compute-0')654 self.create_instance('small', "test_instance_1", 'compute-1')655 self.create_instance('small', "test_instance_2", 'compute-2')656 self.create_instance('small', "test_instance_3", 'compute-3',657 admin_state=nfvi.objects.v1.INSTANCE_ADMIN_STATE.LOCKED)658 self.create_instance('small', "test_instance_4", 'compute-4')659 self.create_instance('small', "test_instance_5", 'compute-5')660 self.create_instance('small', "test_instance_6", 'compute-6')661 self.create_instance('small', "test_instance_7", 'compute-7')662 strategy = create_fw_update_strategy(663 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,664 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,665 max_parallel_worker_hosts=10)666 fw_update_host_list = []667 for host in list(self._host_table.values()):668 if HOST_PERSONALITY.WORKER in host.personality:669 fw_update_host_list.append(host)670 strategy._add_worker_strategy_stages(671 sorted(fw_update_host_list, key=lambda host: host.name),672 reboot=True)673 apply_phase = strategy.apply_phase.as_dict()674 expected_results = {675 'total_stages': 3,676 'stages': [677 {'name': 'fw-update-worker-hosts',678 'total_steps': 6,679 'steps': [680 {'name': 'query-alarms'},681 {'name': 'fw-update-hosts',682 'entity_names': ['compute-8', 'compute-9']},683 {'name': 'lock-hosts',684 'entity_names': ['compute-8', 'compute-9']},685 {'name': 'system-stabilize', 'timeout': 15},686 {'name': 'unlock-hosts',687 'entity_names': ['compute-8', 'compute-9']},688 {'name': 'system-stabilize', 'timeout': 60}689 ]690 },691 {'name': 'fw-update-worker-hosts',692 'total_steps': 8,693 'steps': [694 {'name': 'query-alarms'},695 {'name': 'fw-update-hosts',696 'entity_names': ['compute-0', 'compute-1',697 'compute-2', 'compute-3']},698 {'name': 'disable-host-services',699 'entity_names': ['compute-0', 'compute-1',700 'compute-2', 'compute-3']},701 {'name': 'migrate-instances',702 'entity_names': ['test_instance_0', 'test_instance_1',703 'test_instance_2']},704 {'name': 'lock-hosts',705 'entity_names': ['compute-0', 'compute-1',706 'compute-2', 'compute-3']},707 {'name': 'system-stabilize', 'timeout': 15},708 {'name': 'unlock-hosts',709 'entity_names': ['compute-0', 'compute-1',710 'compute-2', 'compute-3']},711 {'name': 'system-stabilize', 'timeout': 60}712 ]713 },714 {'name': 'fw-update-worker-hosts',715 'total_steps': 8,716 'steps': [717 {'name': 'query-alarms'},718 {'name': 'fw-update-hosts',719 'entity_names': ['compute-4', 'compute-5',720 'compute-6', 'compute-7']},721 {'name': 'disable-host-services',722 'entity_names': ['compute-4', 'compute-5',723 'compute-6', 'compute-7']},724 {'name': 'migrate-instances',725 'entity_names': ['test_instance_4', 'test_instance_5',726 'test_instance_6', 'test_instance_7']},727 {'name': 'lock-hosts',728 'entity_names': ['compute-4', 'compute-5',729 'compute-6', 'compute-7']},730 {'name': 'system-stabilize', 'timeout': 15},731 {'name': 'unlock-hosts',732 'entity_names': ['compute-4', 'compute-5',733 'compute-6', 'compute-7']},734 {'name': 'system-stabilize', 'timeout': 60}735 ]736 }737 ]738 }739 sw_update_testcase.validate_strategy_persists(strategy)740 sw_update_testcase.validate_phase(apply_phase, expected_results)741 def test_fw_update_strategy_standard_parallel_stop_start_host_aggregate(self):742 """743 Test the fw_update strategy on a standard system:744 - 2 controllers745 - 10 worker hosts746 options747 - parallel apply ; max 4748 - stop start instances ; 1 per host ; 1 locked749 - locked instances or hosts with no instances updated first750 - 2x4 host aggregate groups751 - hosts with locked instances or none at all are grouped752 """753 self.create_host('controller-0')754 self.create_host('controller-1')755 self.create_host('compute-0')756 self.create_host('compute-1')757 self.create_host('compute-2')758 self.create_host('compute-3')759 self.create_host('compute-4')760 self.create_host('compute-5')761 self.create_host('compute-6')762 self.create_host('compute-7')763 self.create_host('compute-8')764 self.create_host('compute-9')765 self.create_host_aggregate('aggregate-1', ['compute-0', 'compute-2',766 'compute-4', 'compute-6'])767 self.create_host_aggregate('aggregate-2', ['compute-1', 'compute-3',768 'compute-5', 'compute-7'])769 self.create_instance('small', "test_instance_0", 'compute-0', admin_state=nfvi.objects.v1.INSTANCE_ADMIN_STATE.LOCKED)770 self.create_instance('small', "test_instance_1", 'compute-1', admin_state=nfvi.objects.v1.INSTANCE_ADMIN_STATE.LOCKED)771 self.create_instance('small', "test_instance_2", 'compute-2')772 self.create_instance('small', "test_instance_3", 'compute-3')773 self.create_instance('small', "test_instance_4", 'compute-4')774 self.create_instance('small', "test_instance_5", 'compute-5')775 self.create_instance('small', "test_instance_6", 'compute-6')776 self.create_instance('small', "test_instance_7", 'compute-7')777 self.create_instance('small', "test_instance_8", 'compute-8')778 self.create_instance('small', "test_instance_9", 'compute-9')779 strategy = create_fw_update_strategy(780 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,781 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,782 max_parallel_worker_hosts=4)783 fw_update_host_list = []784 for host in list(self._host_table.values()):785 if HOST_PERSONALITY.WORKER in host.personality:786 fw_update_host_list.append(host)787 strategy._add_worker_strategy_stages(788 sorted(fw_update_host_list, key=lambda host: host.name),789 reboot=True)790 apply_phase = strategy.apply_phase.as_dict()791 expected_results = {792 'total_stages': 4,793 'stages': [794 {'name': 'fw-update-worker-hosts',795 'total_steps': 8,796 'steps': [797 {'name': 'query-alarms'},798 {'name': 'fw-update-hosts',799 'entity_names': ['compute-0', 'compute-1',800 'compute-8', 'compute-9']},801 {'name': 'stop-instances',802 'entity_names': ['test_instance_8', 'test_instance_9']},803 {'name': 'lock-hosts',804 'entity_names': ['compute-0', 'compute-1',805 'compute-8', 'compute-9']},806 {'name': 'system-stabilize', 'timeout': 15},807 {'name': 'unlock-hosts',808 'entity_names': ['compute-0', 'compute-1',809 'compute-8', 'compute-9']},810 {'name': 'start-instances',811 'entity_names': ['test_instance_8', 'test_instance_9']},812 {'name': 'system-stabilize', 'timeout': 60},813 ]814 },815 {'name': 'fw-update-worker-hosts',816 'total_steps': 8,817 'steps': [818 {'name': 'query-alarms'},819 {'name': 'fw-update-hosts',820 'entity_names': ['compute-2', 'compute-3']},821 {'name': 'stop-instances',822 'entity_names': ['test_instance_2', 'test_instance_3']},823 {'name': 'lock-hosts',824 'entity_names': ['compute-2', 'compute-3']},825 {'name': 'system-stabilize', 'timeout': 15},826 {'name': 'unlock-hosts',827 'entity_names': ['compute-2', 'compute-3']},828 {'name': 'start-instances',829 'entity_names': ['test_instance_2', 'test_instance_3']},830 {'name': 'system-stabilize', 'timeout': 60},831 ]832 },833 {'name': 'fw-update-worker-hosts',834 'total_steps': 8,835 'steps': [836 {'name': 'query-alarms'},837 {'name': 'fw-update-hosts',838 'entity_names': ['compute-4', 'compute-5']},839 {'name': 'stop-instances',840 'entity_names': ['test_instance_4', 'test_instance_5']},841 {'name': 'lock-hosts',842 'entity_names': ['compute-4', 'compute-5']},843 {'name': 'system-stabilize', 'timeout': 15},844 {'name': 'unlock-hosts',845 'entity_names': ['compute-4', 'compute-5']},846 {'name': 'start-instances',847 'entity_names': ['test_instance_4', 'test_instance_5']},848 {'name': 'system-stabilize', 'timeout': 60},849 ]850 },851 {'name': 'fw-update-worker-hosts',852 'total_steps': 8,853 'steps': [854 {'name': 'query-alarms'},855 {'name': 'fw-update-hosts',856 'entity_names': ['compute-6', 'compute-7']},857 {'name': 'stop-instances',858 'entity_names': ['test_instance_6', 'test_instance_7']},859 {'name': 'lock-hosts',860 'entity_names': ['compute-6', 'compute-7']},861 {'name': 'system-stabilize', 'timeout': 15},862 {'name': 'unlock-hosts',863 'entity_names': ['compute-6', 'compute-7']},864 {'name': 'start-instances',865 'entity_names': ['test_instance_6', 'test_instance_7']},866 {'name': 'system-stabilize', 'timeout': 60},867 ]868 }869 ]870 }871 sw_update_testcase.validate_strategy_persists(strategy)872 sw_update_testcase.validate_phase(apply_phase, expected_results)873 def test_fw_update_strategy_standard_parallel_migrate_overlap_host_aggregate(self):874 """875 Test the fw_update strategy on a standard system:876 - 2 controllers877 - 10 worker hosts878 options879 - parallel apply ; max 2880 - migrate 10 instances ; 1 per worker host881 - locked instances or hosts with no instances updated first882 - 3 host aggregate groups with overlap ; 4, 3, 10883 - hosts with locked instances or none at all are grouped884 """885 self.create_host('controller-0')886 self.create_host('controller-1')887 self.create_host('compute-0')888 self.create_host('compute-1')889 self.create_host('compute-2')890 self.create_host('compute-3')891 self.create_host('compute-4')892 self.create_host('compute-5')893 self.create_host('compute-6')894 self.create_host('compute-7')895 self.create_host('compute-8')896 self.create_host('compute-9')897 self.create_host_aggregate('aggregate-1', ['compute-0',898 'compute-1',899 'compute-2',900 'compute-3',901 'compute-4'])902 self.create_host_aggregate('aggregate-2', ['compute-5',903 'compute-6',904 'compute-7',905 'compute-8',906 'compute-9'])907 self.create_host_aggregate('aggregate-3', ['compute-0',908 'compute-1',909 'compute-2',910 'compute-3',911 'compute-4',912 'compute-5',913 'compute-6',914 'compute-7',915 'compute-8',916 'compute-9'])917 self.create_instance('small', "test_instance_0", 'compute-0')918 self.create_instance('small', "test_instance_2", 'compute-2')919 self.create_instance('small', "test_instance_3", 'compute-3')920 self.create_instance('small', "test_instance_4", 'compute-4')921 self.create_instance('small', "test_instance_6", 'compute-6')922 self.create_instance('small', "test_instance_7", 'compute-7')923 self.create_instance('small', "test_instance_8", 'compute-8')924 self.create_instance('small', "test_instance_9", 'compute-9')925 strategy = create_fw_update_strategy(926 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,927 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,928 max_parallel_worker_hosts=2)929 fw_update_host_list = []930 for host in list(self._host_table.values()):931 if HOST_PERSONALITY.WORKER in host.personality:932 fw_update_host_list.append(host)933 strategy._add_worker_strategy_stages(934 sorted(fw_update_host_list, key=lambda host: host.name),935 reboot=True)936 apply_phase = strategy.apply_phase.as_dict()937 expected_results = {938 'total_stages': 5,939 'stages': [940 {'name': 'fw-update-worker-hosts',941 'total_steps': 6,942 'steps': [943 {'name': 'query-alarms'},944 {'name': 'fw-update-hosts',945 'entity_names': ['compute-1', 'compute-5']},946 {'name': 'lock-hosts',947 'entity_names': ['compute-1', 'compute-5']},948 {'name': 'system-stabilize',949 'timeout': 15},950 {'name': 'unlock-hosts',951 'entity_names': ['compute-1', 'compute-5']},952 {'name': 'system-stabilize',953 'timeout': 60}954 ]955 },956 {'name': 'fw-update-worker-hosts',957 'total_steps': 8,958 'steps': [959 {'name': 'query-alarms'},960 {'name': 'fw-update-hosts',961 'entity_names': ['compute-0', 'compute-6']},962 {'name': 'disable-host-services'},963 {'name': 'migrate-instances',964 'entity_names': ['test_instance_0',965 'test_instance_6']},966 {'name': 'lock-hosts',967 'entity_names': ['compute-0', 'compute-6']},968 {'name': 'system-stabilize',969 'timeout': 15},970 {'name': 'unlock-hosts',971 'entity_names': ['compute-0', 'compute-6']},972 {'name': 'system-stabilize',973 'timeout': 60}974 ]975 },976 {'name': 'fw-update-worker-hosts',977 'total_steps': 8,978 'steps': [979 {'name': 'query-alarms'},980 {'name': 'fw-update-hosts',981 'entity_names': ['compute-2', 'compute-7']},982 {'name': 'disable-host-services'},983 {'name': 'migrate-instances',984 'entity_names': ['test_instance_2',985 'test_instance_7']},986 {'name': 'lock-hosts',987 'entity_names': ['compute-2', 'compute-7']},988 {'name': 'system-stabilize',989 'timeout': 15},990 {'name': 'unlock-hosts',991 'entity_names': ['compute-2', 'compute-7']},992 {'name': 'system-stabilize',993 'timeout': 60}994 ]995 },996 {'name': 'fw-update-worker-hosts',997 'total_steps': 8,998 'steps': [999 {'name': 'query-alarms'},1000 {'name': 'fw-update-hosts',1001 'entity_names': ['compute-3', 'compute-8']},1002 {'name': 'disable-host-services'},1003 {'name': 'migrate-instances',1004 'entity_names': ['test_instance_3',1005 'test_instance_8']},1006 {'name': 'lock-hosts',1007 'entity_names': ['compute-3', 'compute-8']},1008 {'name': 'system-stabilize',1009 'timeout': 15},1010 {'name': 'unlock-hosts',1011 'entity_names': ['compute-3', 'compute-8']},1012 {'name': 'system-stabilize',1013 'timeout': 60}1014 ]1015 },1016 {'name': 'fw-update-worker-hosts',1017 'total_steps': 8,1018 'steps': [1019 {'name': 'query-alarms'},1020 {'name': 'fw-update-hosts',1021 'entity_names': ['compute-4', 'compute-9']},1022 {'name': 'disable-host-services'},1023 {'name': 'migrate-instances',1024 'entity_names': ['test_instance_4',1025 'test_instance_9']},1026 {'name': 'lock-hosts',1027 'entity_names': ['compute-4', 'compute-9']},1028 {'name': 'system-stabilize',1029 'timeout': 15},1030 {'name': 'unlock-hosts',1031 'entity_names': ['compute-4', 'compute-9']},1032 {'name': 'system-stabilize',1033 'timeout': 60}1034 ]1035 }1036 ]1037 }1038 sw_update_testcase.validate_strategy_persists(strategy)1039 sw_update_testcase.validate_phase(apply_phase, expected_results)1040 def test_fw_update_strategy_aio_sx(self):1041 """1042 Test the fw_update strategy on an All-In-One system:1043 - 1 all-in-one controller1044 options1045 - serial apply1046 - no instances1047 """1048 self.create_host('controller-0', aio=True)1049 strategy = create_fw_update_strategy(1050 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1051 single_controller=True)1052 fw_update_host_list = []1053 for host in list(self._host_table.values()):1054 if HOST_PERSONALITY.WORKER in host.personality:1055 fw_update_host_list.append(host)1056 strategy._add_worker_strategy_stages(1057 sorted(fw_update_host_list, key=lambda host: host.name),1058 reboot=True)1059 apply_phase = strategy.apply_phase.as_dict()1060 expected_results = {1061 'total_stages': 1,1062 'stages': [1063 {'name': 'fw-update-worker-hosts',1064 'total_steps': 6,1065 'steps': [1066 {'name': 'query-alarms'},1067 {'name': 'fw-update-hosts',1068 'entity_names': ['controller-0']},1069 {'name': 'lock-hosts',1070 'entity_names': ['controller-0']},1071 {'name': 'system-stabilize', 'timeout': 15},1072 {'name': 'unlock-hosts',1073 'entity_names': ['controller-0']},1074 {'name': 'system-stabilize', 'timeout': 60},1075 ]1076 }1077 ]1078 }1079 sw_update_testcase.validate_strategy_persists(strategy)1080 sw_update_testcase.validate_phase(apply_phase, expected_results)1081 def test_fw_update_strategy_aio_sx_stop_start(self):1082 """1083 Test the fw_update strategy on an All-In-One system:1084 - 1 all-in-one controller1085 options1086 - serial apply1087 - stop start 1 instance1088 """1089 self.create_host('controller-0', aio=True)1090 self.create_instance('small', "test_instance_0", 'controller-0')1091 strategy = create_fw_update_strategy(1092 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1093 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,1094 single_controller=True)1095 fw_update_host_list = []1096 for host in list(self._host_table.values()):1097 if HOST_PERSONALITY.WORKER in host.personality:1098 fw_update_host_list.append(host)1099 strategy._add_worker_strategy_stages(1100 sorted(fw_update_host_list, key=lambda host: host.name),1101 reboot=True)1102 apply_phase = strategy.apply_phase.as_dict()1103 expected_results = {1104 'total_stages': 1,1105 'stages': [1106 {'name': 'fw-update-worker-hosts',1107 'total_steps': 8,1108 'steps': [1109 {'name': 'query-alarms'},1110 {'name': 'fw-update-hosts',1111 'entity_names': ['controller-0']},1112 {'name': 'stop-instances',1113 'entity_names': ['test_instance_0']},1114 {'name': 'lock-hosts',1115 'entity_names': ['controller-0']},1116 {'name': 'system-stabilize', 'timeout': 15},1117 {'name': 'unlock-hosts',1118 'entity_names': ['controller-0']},1119 {'name': 'start-instances',1120 'entity_names': ['test_instance_0']},1121 {'name': 'system-stabilize', 'timeout': 60},1122 ]1123 }1124 ]1125 }1126 sw_update_testcase.validate_strategy_persists(strategy)1127 sw_update_testcase.validate_phase(apply_phase, expected_results)1128 def test_fw_update_strategy_aio_sx_migrate_reject(self):1129 """1130 Test the fw_update strategy on an All-In-One system:1131 - 1 all-in-one controller1132 options1133 - serial apply1134 - migrate instances ; not possible in sx1135 """1136 self.create_host('controller-0', aio=True)1137 self.create_instance('small', "test_instance_0", 'controller-0')1138 self.create_instance('small', "test_instance_1", 'controller-0')1139 strategy = create_fw_update_strategy(1140 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1141 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,1142 single_controller=True)1143 fw_update_host_list = []1144 for host in list(self._host_table.values()):1145 if HOST_PERSONALITY.WORKER in host.personality:1146 fw_update_host_list.append(host)1147 success, reason = strategy._add_worker_strategy_stages(1148 sorted(fw_update_host_list, key=lambda host: host.name),1149 reboot=True)1150 assert success is False, "Strategy creation failed"1151 apply_phase = strategy.apply_phase.as_dict()1152 expected_results = {1153 'completion_percentage': 100,1154 'total_stages': 01155 }1156 sw_update_testcase.validate_strategy_persists(strategy)1157 sw_update_testcase.validate_phase(apply_phase, expected_results)1158 def test_fw_update_strategy_aio_sx_serial_migrate_no_openstack(self):1159 """1160 Test the sw_patch strategy add worker strategy stages:1161 - 1 all-in-one controller host1162 - no openstack1163 - serial apply1164 - migrate instance action with no instance1165 """1166 self.create_host('controller-0', aio=True, openstack_installed=False)1167 strategy = create_fw_update_strategy(1168 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1169 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,1170 single_controller=True)1171 fw_update_host_list = []1172 for host in list(self._host_table.values()):1173 if HOST_PERSONALITY.WORKER in host.personality:1174 fw_update_host_list.append(host)1175 strategy._add_worker_strategy_stages(1176 sorted(fw_update_host_list, key=lambda host: host.name),1177 reboot=True)1178 apply_phase = strategy.apply_phase.as_dict()1179 expected_results = {1180 'total_stages': 1,1181 'stages': [1182 {'name': 'fw-update-worker-hosts',1183 'total_steps': 6,1184 'steps': [1185 {'name': 'query-alarms'},1186 {'name': 'fw-update-hosts',1187 'entity_names': ['controller-0']},1188 {'name': 'lock-hosts',1189 'entity_names': ['controller-0']},1190 {'name': 'system-stabilize',1191 'timeout': 15},1192 {'name': 'unlock-hosts',1193 'entity_names': ['controller-0']},1194 {'name': 'system-stabilize',1195 'timeout': 60},1196 ]1197 },1198 ]1199 }1200 sw_update_testcase.validate_strategy_persists(strategy)1201 sw_update_testcase.validate_phase(apply_phase, expected_results)1202 def test_fw_update_strategy_aio_dx_no_instances(self):1203 """1204 Test the fw_update strategy on an All-In-One system:1205 - 2 all-in-one controllers1206 options1207 - serial apply1208 - no instances1209 """1210 self.create_host('controller-0', aio=True)1211 self.create_host('controller-1', aio=True)1212 strategy = create_fw_update_strategy(1213 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL)1214 fw_update_host_list = []1215 for host in list(self._host_table.values()):1216 if HOST_PERSONALITY.WORKER in host.personality:1217 fw_update_host_list.append(host)1218 strategy._add_worker_strategy_stages(1219 sorted(fw_update_host_list, key=lambda host: host.name),1220 reboot=True)1221 apply_phase = strategy.apply_phase.as_dict()1222 expected_results = {1223 'total_stages': 2,1224 'stages': [1225 {'name': 'fw-update-worker-hosts',1226 'total_steps': 7,1227 'steps': [1228 {'name': 'query-alarms'},1229 {'name': 'fw-update-hosts',1230 'entity_names': ['controller-0']},1231 {'name': 'swact-hosts',1232 'entity_names': ['controller-0']},1233 {'name': 'lock-hosts',1234 'entity_names': ['controller-0']},1235 {'name': 'system-stabilize', 'timeout': 15},1236 {'name': 'unlock-hosts',1237 'entity_names': ['controller-0']},1238 {'name': 'system-stabilize', 'timeout': 60},1239 ]1240 },1241 {'name': 'fw-update-worker-hosts',1242 'total_steps': 7,1243 'steps': [1244 {'name': 'query-alarms'},1245 {'name': 'fw-update-hosts',1246 'entity_names': ['controller-1']},1247 {'name': 'swact-hosts',1248 'entity_names': ['controller-1']},1249 {'name': 'lock-hosts',1250 'entity_names': ['controller-1']},1251 {'name': 'system-stabilize', 'timeout': 15},1252 {'name': 'unlock-hosts',1253 'entity_names': ['controller-1']},1254 {'name': 'system-stabilize', 'timeout': 60},1255 ]1256 }1257 ]1258 }1259 sw_update_testcase.validate_strategy_persists(strategy)1260 sw_update_testcase.validate_phase(apply_phase, expected_results)1261 def test_fw_update_strategy_aio_dx_migrate_instance(self):1262 """1263 Test the fw_update strategy on an All-In-One system:1264 - 2 all-in-one controllers1265 options1266 - serial apply1267 - migrate 1 instance1268 """1269 self.create_host('controller-0', aio=True)1270 self.create_host('controller-1', aio=True)1271 self.create_instance('small', "test_instance_0", 'controller-0')1272 strategy = create_fw_update_strategy(1273 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1274 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,1275 single_controller=False)1276 fw_update_host_list = []1277 for host in list(self._host_table.values()):1278 if HOST_PERSONALITY.WORKER in host.personality:1279 fw_update_host_list.append(host)1280 strategy._add_worker_strategy_stages(1281 sorted(fw_update_host_list, key=lambda host: host.name),1282 reboot=True)1283 apply_phase = strategy.apply_phase.as_dict()1284 expected_results = {1285 'total_stages': 2,1286 'stages': [1287 {'name': 'fw-update-worker-hosts',1288 'total_steps': 8,1289 'steps': [1290 {'name': 'query-alarms'},1291 {'name': 'fw-update-hosts',1292 'entity_names': ['controller-0']},1293 {'name': 'swact-hosts',1294 'entity_names': ['controller-0']},1295 {'name': 'migrate-instances',1296 'entity_names': ['test_instance_0']},1297 {'name': 'lock-hosts',1298 'entity_names': ['controller-0']},1299 {'name': 'system-stabilize', 'timeout': 15},1300 {'name': 'unlock-hosts',1301 'entity_names': ['controller-0']},1302 {'name': 'system-stabilize', 'timeout': 60}1303 ]1304 },1305 {'name': 'fw-update-worker-hosts',1306 'total_steps': 7,1307 'steps': [1308 {'name': 'query-alarms'},1309 {'name': 'fw-update-hosts',1310 'entity_names': ['controller-1']},1311 {'name': 'swact-hosts',1312 'entity_names': ['controller-1']},1313 {'name': 'lock-hosts',1314 'entity_names': ['controller-1']},1315 {'name': 'system-stabilize', 'timeout': 15},1316 {'name': 'unlock-hosts',1317 'entity_names': ['controller-1']},1318 {'name': 'system-stabilize', 'timeout': 60}1319 ]1320 }1321 ]1322 }1323 sw_update_testcase.validate_strategy_persists(strategy)1324 sw_update_testcase.validate_phase(apply_phase, expected_results)1325 def test_fw_update_strategy_aio_dx_migrate_instances(self):1326 """1327 Test the fw_update strategy on an All-In-One system:1328 - 2 all-in-one controllers1329 options1330 - serial apply1331 - migrate 2 instances which switches the controller update order1332 """1333 self.create_host('controller-0', aio=True)1334 self.create_host('controller-1', aio=True)1335 self.create_instance('small', "test_instance_0", 'controller-0')1336 self.create_instance('small', "test_instance_1", 'controller-1')1337 strategy = create_fw_update_strategy(1338 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1339 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,1340 single_controller=False)1341 fw_update_host_list = []1342 for host in list(self._host_table.values()):1343 if HOST_PERSONALITY.WORKER in host.personality:1344 fw_update_host_list.append(host)1345 strategy._add_worker_strategy_stages(1346 sorted(fw_update_host_list, key=lambda host: host.name),1347 reboot=True)1348 apply_phase = strategy.apply_phase.as_dict()1349 expected_results = {1350 'total_stages': 2,1351 'stages': [1352 {'name': 'fw-update-worker-hosts',1353 'total_steps': 8,1354 'steps': [1355 {'name': 'query-alarms'},1356 {'name': 'fw-update-hosts',1357 'entity_names': ['controller-0']},1358 {'name': 'swact-hosts',1359 'entity_names': ['controller-0']},1360 {'name': 'migrate-instances',1361 'entity_names': ['test_instance_0']},1362 {'name': 'lock-hosts',1363 'entity_names': ['controller-0']},1364 {'name': 'system-stabilize', 'timeout': 15},1365 {'name': 'unlock-hosts',1366 'entity_names': ['controller-0']},1367 {'name': 'system-stabilize', 'timeout': 60}1368 ]1369 },1370 {'name': 'fw-update-worker-hosts',1371 'total_steps': 8,1372 'steps': [1373 {'name': 'query-alarms'},1374 {'name': 'fw-update-hosts',1375 'entity_names': ['controller-1']},1376 {'name': 'swact-hosts',1377 'entity_names': ['controller-1']},1378 {'name': 'migrate-instances',1379 'entity_names': ['test_instance_1']},1380 {'name': 'lock-hosts',1381 'entity_names': ['controller-1']},1382 {'name': 'system-stabilize', 'timeout': 15},1383 {'name': 'unlock-hosts',1384 'entity_names': ['controller-1']},1385 {'name': 'system-stabilize', 'timeout': 60}1386 ]1387 }1388 ]1389 }1390 sw_update_testcase.validate_strategy_persists(strategy)1391 sw_update_testcase.validate_phase(apply_phase, expected_results)1392 def test_fw_update_strategy_aio_dx_stop_start_instance(self):1393 """1394 Test the fw_update strategy on an All-In-One system:1395 - 2 all-in-one controllers1396 options1397 - serial1398 - stop start 1 instance1399 """1400 self.create_host('controller-0', aio=True)1401 self.create_host('controller-1', aio=True)1402 self.create_instance('small', "test_instance_0", 'controller-0')1403 strategy = create_fw_update_strategy(1404 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1405 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,1406 single_controller=False)1407 fw_update_host_list = []1408 for host in list(self._host_table.values()):1409 if HOST_PERSONALITY.WORKER in host.personality:1410 fw_update_host_list.append(host)1411 strategy._add_worker_strategy_stages(1412 sorted(fw_update_host_list, key=lambda host: host.name),1413 reboot=True)1414 # assert success is False, "Strategy creation failed"1415 apply_phase = strategy.apply_phase.as_dict()1416 expected_results = {1417 'total_stages': 2,1418 'stages': [1419 {'name': 'fw-update-worker-hosts',1420 'total_steps': 9,1421 'steps': [1422 {'name': 'query-alarms'},1423 {'name': 'fw-update-hosts',1424 'entity_names': ['controller-0']},1425 {'name': 'swact-hosts',1426 'entity_names': ['controller-0']},1427 {'name': 'stop-instances',1428 'entity_names': ['test_instance_0']},1429 {'name': 'lock-hosts',1430 'entity_names': ['controller-0']},1431 {'name': 'system-stabilize', 'timeout': 15},1432 {'name': 'unlock-hosts',1433 'entity_names': ['controller-0']},1434 {'name': 'start-instances',1435 'entity_names': ['test_instance_0']},1436 {'name': 'system-stabilize', 'timeout': 60}1437 ]1438 },1439 {'name': 'fw-update-worker-hosts',1440 'total_steps': 7,1441 'steps': [1442 {'name': 'query-alarms'},1443 {'name': 'fw-update-hosts',1444 'entity_names': ['controller-1']},1445 {'name': 'swact-hosts',1446 'entity_names': ['controller-1']},1447 {'name': 'lock-hosts',1448 'entity_names': ['controller-1']},1449 {'name': 'system-stabilize', 'timeout': 15},1450 {'name': 'unlock-hosts',1451 'entity_names': ['controller-1']},1452 {'name': 'system-stabilize', 'timeout': 60}1453 ]1454 }1455 ]1456 }1457 sw_update_testcase.validate_strategy_persists(strategy)1458 sw_update_testcase.validate_phase(apply_phase, expected_results)1459 def test_fw_update_strategy_aio_dx_stop_start_instances(self):1460 """1461 Test the fw_update strategy on an All-In-One system:1462 - 2 all-in-one controllers1463 options1464 - serial1465 - stop start instances1466 """1467 self.create_host('controller-0', aio=True)1468 self.create_host('controller-1', aio=True)1469 self.create_instance('small', "test_instance_0", 'controller-0')1470 self.create_instance('small', "test_instance_1", 'controller-1')1471 strategy = create_fw_update_strategy(1472 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1473 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,1474 single_controller=False)1475 fw_update_host_list = []1476 for host in list(self._host_table.values()):1477 if HOST_PERSONALITY.WORKER in host.personality:1478 fw_update_host_list.append(host)1479 strategy._add_worker_strategy_stages(1480 sorted(fw_update_host_list, key=lambda host: host.name),1481 reboot=True)1482 apply_phase = strategy.apply_phase.as_dict()1483 expected_results = {1484 'total_stages': 2,1485 'stages': [1486 {'name': 'fw-update-worker-hosts',1487 'total_steps': 9,1488 'steps': [1489 {'name': 'query-alarms'},1490 {'name': 'fw-update-hosts',1491 'entity_names': ['controller-0']},1492 {'name': 'swact-hosts',1493 'entity_names': ['controller-0']},1494 {'name': 'stop-instances',1495 'entity_names': ['test_instance_0']},1496 {'name': 'lock-hosts',1497 'entity_names': ['controller-0']},1498 {'name': 'system-stabilize', 'timeout': 15},1499 {'name': 'unlock-hosts',1500 'entity_names': ['controller-0']},1501 {'name': 'start-instances',1502 'entity_names': ['test_instance_0']},1503 {'name': 'system-stabilize', 'timeout': 60}1504 ]1505 },1506 {'name': 'fw-update-worker-hosts',1507 'total_steps': 9,1508 'steps': [1509 {'name': 'query-alarms'},1510 {'name': 'fw-update-hosts',1511 'entity_names': ['controller-1']},1512 {'name': 'swact-hosts',1513 'entity_names': ['controller-1']},1514 {'name': 'stop-instances',1515 'entity_names': ['test_instance_1']},1516 {'name': 'lock-hosts',1517 'entity_names': ['controller-1']},1518 {'name': 'system-stabilize', 'timeout': 15},1519 {'name': 'unlock-hosts',1520 'entity_names': ['controller-1']},1521 {'name': 'start-instances',1522 'entity_names': ['test_instance_1']},1523 {'name': 'system-stabilize', 'timeout': 60}1524 ]1525 }1526 ]1527 }1528 sw_update_testcase.validate_strategy_persists(strategy)1529 sw_update_testcase.validate_phase(apply_phase, expected_results)1530 def test_fw_update_strategy_aio_dx_plus_parallel_locked_hosts(self):1531 """1532 Test the fw_update strategy on an All-In-One system:1533 - 2 all-in-one controllers1534 - 6 computes ; 2 are locked1535 options1536 - parallel apply ; max 21537 - no instances1538 """1539 self.create_host('controller-0', aio=True)1540 self.create_host('controller-1', aio=True)1541 self.create_host('compute-0')1542 self.create_host('compute-1',1543 admin_state=nfvi.objects.v1.HOST_ADMIN_STATE.LOCKED,1544 oper_state=nfvi.objects.v1.HOST_OPER_STATE.DISABLED,1545 avail_status=nfvi.objects.v1.HOST_AVAIL_STATUS.ONLINE)1546 self.create_host('compute-2')1547 self.create_host('compute-3')1548 self.create_host('compute-4')1549 self.create_host('compute-5',1550 admin_state=nfvi.objects.v1.HOST_ADMIN_STATE.LOCKED,1551 oper_state=nfvi.objects.v1.HOST_OPER_STATE.DISABLED,1552 avail_status=nfvi.objects.v1.HOST_AVAIL_STATUS.ONLINE)1553 strategy = create_fw_update_strategy(1554 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,1555 max_parallel_worker_hosts=2)1556 fw_update_worker_host_list = []1557 for host in list(self._host_table.values()):1558 if host._nfvi_host.admin_state == nfvi.objects.v1.HOST_ADMIN_STATE.UNLOCKED:1559 if HOST_PERSONALITY.WORKER in host.personality:1560 fw_update_worker_host_list.append(host)1561 strategy._add_worker_strategy_stages(1562 sorted(fw_update_worker_host_list, key=lambda host: host.name),1563 reboot=True)1564 apply_phase = strategy.apply_phase.as_dict()1565 expected_results = {1566 'total_stages': 4,1567 'stages': [1568 {'name': 'fw-update-worker-hosts',1569 'total_steps': 7,1570 'steps': [1571 {'name': 'query-alarms'},1572 {'name': 'fw-update-hosts',1573 'entity_names': ['controller-0']},1574 {'name': 'swact-hosts',1575 'entity_names': ['controller-0']},1576 {'name': 'lock-hosts',1577 'entity_names': ['controller-0']},1578 {'name': 'system-stabilize', 'timeout': 15},1579 {'name': 'unlock-hosts',1580 'entity_names': ['controller-0']},1581 {'name': 'system-stabilize', 'timeout': 60}1582 ]1583 },1584 {'name': 'fw-update-worker-hosts',1585 'total_steps': 7,1586 'steps': [1587 {'name': 'query-alarms'},1588 {'name': 'fw-update-hosts',1589 'entity_names': ['controller-1']},1590 {'name': 'swact-hosts',1591 'entity_names': ['controller-1']},1592 {'name': 'lock-hosts',1593 'entity_names': ['controller-1']},1594 {'name': 'system-stabilize', 'timeout': 15},1595 {'name': 'unlock-hosts',1596 'entity_names': ['controller-1']},1597 {'name': 'system-stabilize', 'timeout': 60},1598 ]1599 },1600 {'name': 'fw-update-worker-hosts',1601 'total_steps': 6,1602 'steps': [1603 {'name': 'query-alarms'},1604 {'name': 'fw-update-hosts',1605 'entity_names': ['compute-0', 'compute-2']},1606 {'name': 'lock-hosts',1607 'entity_names': ['compute-0', 'compute-2']},1608 {'name': 'system-stabilize', 'timeout': 15},1609 {'name': 'unlock-hosts',1610 'entity_names': ['compute-0', 'compute-2']},1611 {'name': 'system-stabilize', 'timeout': 60},1612 ]1613 },1614 {'name': 'fw-update-worker-hosts',1615 'total_steps': 6,1616 'steps': [1617 {'name': 'query-alarms'},1618 {'name': 'fw-update-hosts',1619 'entity_names': ['compute-3', 'compute-4']},1620 {'name': 'lock-hosts',1621 'entity_names': ['compute-3', 'compute-4']},1622 {'name': 'system-stabilize', 'timeout': 15},1623 {'name': 'unlock-hosts',1624 'entity_names': ['compute-3', 'compute-4']},1625 {'name': 'system-stabilize', 'timeout': 60}1626 ]1627 }1628 ]1629 }1630 sw_update_testcase.validate_strategy_persists(strategy)1631 sw_update_testcase.validate_phase(apply_phase, expected_results)1632 def test_fw_update_strategy_aio_plus_parallel_migrate_anti_affinity(self):1633 """1634 Test the fw_update strategy on an All-In-One Plus system:1635 - 2 all-in-one controllers1636 - 6 worker hosts1637 options1638 - parallel apply ; max 21639 - migrate instances with 2 anti affinity groups1640 """1641 self.create_host('controller-0', aio=True)1642 self.create_host('controller-1', aio=True)1643 self.create_host('compute-0')1644 self.create_host('compute-1')1645 self.create_host('compute-2')1646 self.create_host('compute-3')1647 self.create_host('compute-4')1648 self.create_host('compute-5')1649 self.create_instance('small', "test_instance_0", 'compute-0')1650 self.create_instance('small', "test_instance_1", 'compute-1')1651 self.create_instance('small', "test_instance_2", 'compute-2')1652 self.create_instance('small', "test_instance_3", 'compute-3')1653 self.create_instance('small', "test_instance_4", 'compute-4')1654 self.create_instance('small', "test_instance_5", 'compute-5')1655 self.create_instance_group('instance_group_1',1656 ['test_instance_0', 'test_instance_1'],1657 [nfvi.objects.v1.INSTANCE_GROUP_POLICY.ANTI_AFFINITY])1658 self.create_instance_group('instance_group_2',1659 ['test_instance_3', 'test_instance_5'],1660 [nfvi.objects.v1.INSTANCE_GROUP_POLICY.ANTI_AFFINITY])1661 strategy = create_fw_update_strategy(1662 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,1663 default_instance_action=SW_UPDATE_INSTANCE_ACTION.MIGRATE,1664 max_parallel_worker_hosts=2)1665 fw_update_worker_host_list = []1666 for host in list(self._host_table.values()):1667 if host._nfvi_host.admin_state == nfvi.objects.v1.HOST_ADMIN_STATE.UNLOCKED:1668 if HOST_PERSONALITY.WORKER in host.personality:1669 fw_update_worker_host_list.append(host)1670 strategy._add_worker_strategy_stages(1671 sorted(fw_update_worker_host_list, key=lambda host: host.name),1672 reboot=True)1673 apply_phase = strategy.apply_phase.as_dict()1674 expected_results = {1675 'total_stages': 5,1676 'stages': [1677 {'name': 'fw-update-worker-hosts',1678 'total_steps': 7,1679 'steps': [1680 {'name': 'query-alarms'},1681 {'name': 'fw-update-hosts',1682 'entity_names': ['controller-0']},1683 {'name': 'swact-hosts',1684 'entity_names': ['controller-0']},1685 {'name': 'lock-hosts',1686 'entity_names': ['controller-0']},1687 {'name': 'system-stabilize', 'timeout': 15},1688 {'name': 'unlock-hosts',1689 'entity_names': ['controller-0']},1690 {'name': 'system-stabilize', 'timeout': 60}1691 ]1692 },1693 {'name': 'fw-update-worker-hosts',1694 'total_steps': 7,1695 'steps': [1696 {'name': 'query-alarms'},1697 {'name': 'fw-update-hosts',1698 'entity_names': ['controller-1']},1699 {'name': 'swact-hosts',1700 'entity_names': ['controller-1']},1701 {'name': 'lock-hosts',1702 'entity_names': ['controller-1']},1703 {'name': 'system-stabilize', 'timeout': 15},1704 {'name': 'unlock-hosts',1705 'entity_names': ['controller-1']},1706 {'name': 'system-stabilize', 'timeout': 60}1707 ]1708 },1709 {'name': 'fw-update-worker-hosts',1710 'total_steps': 8,1711 'steps': [1712 {'name': 'query-alarms'},1713 {'name': 'fw-update-hosts',1714 'entity_names': ['compute-0', 'compute-2']},1715 {'name': 'disable-host-services'},1716 {'name': 'migrate-instances',1717 'entity_names': ['test_instance_0', 'test_instance_2']},1718 {'name': 'lock-hosts',1719 'entity_names': ['compute-0', 'compute-2']},1720 {'name': 'system-stabilize', 'timeout': 15},1721 {'name': 'unlock-hosts',1722 'entity_names': ['compute-0', 'compute-2']},1723 {'name': 'system-stabilize', 'timeout': 60}1724 ]1725 },1726 {'name': 'fw-update-worker-hosts',1727 'total_steps': 8,1728 'steps': [1729 {'name': 'query-alarms'},1730 {'name': 'fw-update-hosts',1731 'entity_names': ['compute-1', 'compute-3']},1732 {'name': 'disable-host-services'},1733 {'name': 'migrate-instances',1734 'entity_names': ['test_instance_1', 'test_instance_3']},1735 {'name': 'lock-hosts',1736 'entity_names': ['compute-1', 'compute-3']},1737 {'name': 'system-stabilize', 'timeout': 15},1738 {'name': 'unlock-hosts',1739 'entity_names': ['compute-1', 'compute-3']},1740 {'name': 'system-stabilize', 'timeout': 60}1741 ]1742 },1743 {'name': 'fw-update-worker-hosts',1744 'total_steps': 8,1745 'steps': [1746 {'name': 'query-alarms'},1747 {'name': 'fw-update-hosts',1748 'entity_names': ['compute-4', 'compute-5']},1749 {'name': 'disable-host-services'},1750 {'name': 'migrate-instances',1751 'entity_names': ['test_instance_4', 'test_instance_5']},1752 {'name': 'lock-hosts',1753 'entity_names': ['compute-4', 'compute-5']},1754 {'name': 'system-stabilize', 'timeout': 15},1755 {'name': 'unlock-hosts',1756 'entity_names': ['compute-4', 'compute-5']},1757 {'name': 'system-stabilize', 'timeout': 60}1758 ]1759 }1760 ]1761 }1762 sw_update_testcase.validate_strategy_persists(strategy)1763 sw_update_testcase.validate_phase(apply_phase, expected_results)1764 def test_fw_update_strategy_aio_plus_parallel_stop_start(self):1765 """1766 Test the fw_update strategy on an All-In-One Plus system:1767 - 2 all-in-one controllers1768 - 8 worker hosts1769 options1770 - parallel apply ; max 101771 - stop start 8 instances1772 """1773 self.create_host('controller-0', aio=True)1774 self.create_host('controller-1', aio=True)1775 self.create_host('compute-0')1776 self.create_host('compute-1')1777 self.create_host('compute-2')1778 self.create_host('compute-3')1779 self.create_host('compute-4')1780 self.create_host('compute-5')1781 self.create_host('compute-6')1782 self.create_host('compute-7')1783 self.create_instance('small', "test_instance_0", 'compute-0')1784 self.create_instance('small', "test_instance_1", 'compute-1')1785 self.create_instance('small', "test_instance_2", 'compute-2')1786 self.create_instance('small', "test_instance_3", 'compute-3')1787 self.create_instance('small', "test_instance_4", 'compute-4')1788 self.create_instance('small', "test_instance_5", 'compute-5')1789 self.create_instance('small', "test_instance_6", 'compute-6')1790 self.create_instance('small', "test_instance_7", 'compute-7')1791 strategy = create_fw_update_strategy(1792 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,1793 default_instance_action=SW_UPDATE_INSTANCE_ACTION.STOP_START,1794 max_parallel_worker_hosts=10)1795 fw_update_controller_host_list = []1796 fw_update_worker_host_list = []...

Full Screen

Full Screen

test_sw_upgrade_strategy.py

Source:test_sw_upgrade_strategy.py Github

copy

Full Screen

...71 - ignore apply72 Verify:73 - stages not created74 """75 self.create_host('compute-0')76 self.create_host('compute-1')77 self.create_host('compute-2')78 self.create_host('compute-3')79 self.create_instance('small',80 "test_instance_0",81 'compute-0')82 self.create_instance('small',83 "test_instance_1",84 'compute-1')85 self.create_instance_group(86 'instance_group_1',87 ['test_instance_0', 'test_instance_1'],88 [nfvi.objects.v1.INSTANCE_GROUP_POLICY.ANTI_AFFINITY])89 worker_hosts = []90 for host in list(self._host_table.values()):91 if HOST_PERSONALITY.WORKER in host.personality:92 worker_hosts.append(host)93 # Sort worker hosts so the order of the steps is deterministic94 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)95 strategy = self.create_sw_upgrade_strategy(96 worker_apply_type=SW_UPDATE_APPLY_TYPE.IGNORE97 )98 success, reason = strategy._add_worker_strategy_stages(99 worker_hosts=sorted_worker_hosts,100 reboot=True)101 assert success is True, "Strategy creation failed"102 apply_phase = strategy.apply_phase.as_dict()103 expected_results = {104 'total_stages': 0105 }106 sw_update_testcase.validate_strategy_persists(strategy)107 sw_update_testcase.validate_phase(apply_phase, expected_results)108 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',109 sw_update_testcase.fake_host_name_controller_1)110 def test_sw_upgrade_strategy_worker_stages_parallel_migrate_anti_affinity(self):111 """112 Test the sw_upgrade strategy add worker strategy stages:113 - parallel apply114 - migrate instance action115 Verify:116 - hosts with no instances upgraded first117 - anti-affinity policy enforced118 """119 self.create_host('compute-0')120 self.create_host('compute-1')121 self.create_host('compute-2')122 self.create_host('compute-3')123 self.create_instance('small',124 "test_instance_0",125 'compute-0')126 self.create_instance('small',127 "test_instance_1",128 'compute-1')129 self.create_instance_group('instance_group_1',130 ['test_instance_0', 'test_instance_1'],131 [nfvi.objects.v1.INSTANCE_GROUP_POLICY.ANTI_AFFINITY])132 worker_hosts = []133 for host in list(self._host_table.values()):134 if HOST_PERSONALITY.WORKER in host.personality:135 worker_hosts.append(host)136 # Sort worker hosts so the order of the steps is deterministic137 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)138 strategy = self.create_sw_upgrade_strategy(139 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,140 max_parallel_worker_hosts=2141 )142 strategy._add_worker_strategy_stages(143 worker_hosts=sorted_worker_hosts,144 reboot=True)145 apply_phase = strategy.apply_phase.as_dict()146 expected_results = {147 'total_stages': 3,148 'stages': [149 {'name': 'sw-upgrade-worker-hosts',150 'total_steps': 5,151 'steps': [152 {'name': 'query-alarms'},153 {'name': 'lock-hosts',154 'entity_names': ['compute-2', 'compute-3']},155 {'name': 'upgrade-hosts',156 'entity_names': ['compute-2', 'compute-3']},157 _unlock_hosts_stage_as_dict(['compute-2', 'compute-3']),158 {'name': 'wait-alarms-clear',159 'timeout': 600}160 ]161 },162 {'name': 'sw-upgrade-worker-hosts',163 'total_steps': 7,164 'steps': [165 {'name': 'query-alarms'},166 {'name': 'disable-host-services'},167 {'name': 'migrate-instances',168 'entity_names': ['test_instance_0']},169 {'name': 'lock-hosts',170 'entity_names': ['compute-0']},171 {'name': 'upgrade-hosts',172 'entity_names': ['compute-0']},173 _unlock_hosts_stage_as_dict(['compute-0']),174 {'name': 'wait-alarms-clear',175 'timeout': 600}176 ]177 },178 {'name': 'sw-upgrade-worker-hosts',179 'total_steps': 7,180 'steps': [181 {'name': 'query-alarms'},182 {'name': 'disable-host-services'},183 {'name': 'migrate-instances',184 'entity_names': ['test_instance_1']},185 {'name': 'lock-hosts',186 'entity_names': ['compute-1']},187 {'name': 'upgrade-hosts',188 'entity_names': ['compute-1']},189 _unlock_hosts_stage_as_dict(['compute-1']),190 {'name': 'wait-alarms-clear',191 'timeout': 600}192 ]193 }194 ]195 }196 sw_update_testcase.validate_strategy_persists(strategy)197 sw_update_testcase.validate_phase(apply_phase, expected_results)198 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',199 sw_update_testcase.fake_host_name_controller_1)200 def test_sw_upgrade_strategy_worker_stages_parallel_migrate_ten_hosts(self):201 """202 Test the sw_upgrade strategy add worker strategy stages:203 - parallel apply204 - migrate instance action205 Verify:206 - hosts with no instances upgraded first207 - instances migrated208 """209 self.create_host('compute-0')210 self.create_host('compute-1')211 self.create_host('compute-2')212 self.create_host('compute-3')213 self.create_host('compute-4')214 self.create_host('compute-5')215 self.create_host('compute-6')216 self.create_host('compute-7')217 self.create_host('compute-8')218 self.create_host('compute-9')219 self.create_instance('small', "test_instance_0", 'compute-0')220 self.create_instance('small', "test_instance_2", 'compute-2')221 self.create_instance('small', "test_instance_3", 'compute-3')222 self.create_instance('small', "test_instance_4", 'compute-4')223 self.create_instance('small', "test_instance_6", 'compute-6')224 self.create_instance('small', "test_instance_7", 'compute-7')225 self.create_instance('small', "test_instance_8", 'compute-8')226 self.create_instance('small', "test_instance_9", 'compute-9')227 worker_hosts = []228 for host in list(self._host_table.values()):229 if HOST_PERSONALITY.WORKER in host.personality:230 worker_hosts.append(host)231 # Sort worker hosts so the order of the steps is deterministic232 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)233 strategy = self.create_sw_upgrade_strategy(234 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,235 max_parallel_worker_hosts=3236 )237 strategy._add_worker_strategy_stages(238 worker_hosts=sorted_worker_hosts,239 reboot=True)240 apply_phase = strategy.apply_phase.as_dict()241 expected_results = {242 'total_stages': 4,243 'stages': [244 {'name': 'sw-upgrade-worker-hosts',245 'total_steps': 5,246 'steps': [247 {'name': 'query-alarms'},248 {'name': 'lock-hosts',249 'entity_names': ['compute-1', 'compute-5']},250 {'name': 'upgrade-hosts',251 'entity_names': ['compute-1', 'compute-5']},252 _unlock_hosts_stage_as_dict(['compute-1', 'compute-5']),253 {'name': 'wait-alarms-clear',254 'timeout': 600}255 ]256 },257 {'name': 'sw-upgrade-worker-hosts',258 'total_steps': 7,259 'steps': [260 {'name': 'query-alarms'},261 {'name': 'disable-host-services'},262 {'name': 'migrate-instances',263 'entity_names': ['test_instance_0',264 'test_instance_2',265 'test_instance_3']},266 {'name': 'lock-hosts',267 'entity_names': ['compute-0', 'compute-2', 'compute-3']},268 {'name': 'upgrade-hosts',269 'entity_names': ['compute-0', 'compute-2', 'compute-3']},270 _unlock_hosts_stage_as_dict(271 ['compute-0', 'compute-2', 'compute-3']),272 {'name': 'wait-alarms-clear',273 'timeout': 600}274 ]275 },276 {'name': 'sw-upgrade-worker-hosts',277 'total_steps': 7,278 'steps': [279 {'name': 'query-alarms'},280 {'name': 'disable-host-services'},281 {'name': 'migrate-instances',282 'entity_names': ['test_instance_4',283 'test_instance_6',284 'test_instance_7']},285 {'name': 'lock-hosts',286 'entity_names': ['compute-4', 'compute-6', 'compute-7']},287 {'name': 'upgrade-hosts',288 'entity_names': ['compute-4', 'compute-6', 'compute-7']},289 _unlock_hosts_stage_as_dict(290 ['compute-4', 'compute-6', 'compute-7']),291 {'name': 'wait-alarms-clear',292 'timeout': 600}293 ]294 },295 {'name': 'sw-upgrade-worker-hosts',296 'total_steps': 7,297 'steps': [298 {'name': 'query-alarms'},299 {'name': 'disable-host-services'},300 {'name': 'migrate-instances',301 'entity_names': ['test_instance_8',302 'test_instance_9']},303 {'name': 'lock-hosts',304 'entity_names': ['compute-8', 'compute-9']},305 {'name': 'upgrade-hosts',306 'entity_names': ['compute-8', 'compute-9']},307 _unlock_hosts_stage_as_dict(308 ['compute-8', 'compute-9']),309 {'name': 'wait-alarms-clear',310 'timeout': 600}311 ]312 }313 ]314 }315 sw_update_testcase.validate_strategy_persists(strategy)316 sw_update_testcase.validate_phase(apply_phase, expected_results)317 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',318 sw_update_testcase.fake_host_name_controller_1)319 def test_sw_upgrade_strategy_worker_stages_parallel_migrate_for_aio(self):320 """321 Test the sw_upgrade strategy add worker strategy stages:322 - parallel apply323 - migrate instance action324 Verify:325 - AIO hosts upgraded first in serial326 - hosts with no instances upgraded next327 - instances migrated328 - for AIO controllers, the last step is wait-data-sync329 - for workers, the last step is wait-alarms-clear (openstack workers)330 """331 self.create_host('compute-0')332 self.create_host('compute-1')333 self.create_host('compute-2')334 self.create_host('compute-3')335 self.create_host('compute-4')336 self.create_host('controller-0', aio=True)337 self.create_host('controller-1', aio=True)338 self.create_instance('small', "test_instance_0", 'compute-0')339 self.create_instance('small', "test_instance_2", 'compute-2')340 self.create_instance('small', "test_instance_3", 'compute-3')341 self.create_instance('small', "test_instance_4", 'compute-4')342 self.create_instance('small', "test_instance_6", 'controller-0')343 self.create_instance('small', "test_instance_7", 'controller-1')344 worker_hosts = []345 for host in list(self._host_table.values()):346 if HOST_PERSONALITY.WORKER in host.personality:347 worker_hosts.append(host)348 # Sort worker hosts so the order of the steps is deterministic349 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)350 strategy = self.create_sw_upgrade_strategy(351 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,352 max_parallel_worker_hosts=3353 )354 strategy._add_worker_strategy_stages(355 worker_hosts=sorted_worker_hosts,356 reboot=True)357 apply_phase = strategy.apply_phase.as_dict()358 expected_results = {359 'total_stages': 5,360 'stages': [361 {'name': 'sw-upgrade-worker-hosts',362 'total_steps': 8,363 'steps': [364 {'name': 'query-alarms'},365 {'name': 'disable-host-services'},366 {'name': 'migrate-instances',367 'entity_names': ['test_instance_6']},368 {'name': 'swact-hosts',369 'entity_names': ['controller-0']},370 {'name': 'lock-hosts',371 'entity_names': ['controller-0']},372 {'name': 'upgrade-hosts',373 'entity_names': ['controller-0']},374 _unlock_hosts_stage_as_dict(['controller-0']),375 {'name': 'wait-data-sync',376 'timeout': 14400}377 ]378 },379 {'name': 'sw-upgrade-worker-hosts',380 'total_steps': 8,381 'steps': [382 {'name': 'query-alarms'},383 {'name': 'disable-host-services'},384 {'name': 'migrate-instances',385 'entity_names': ['test_instance_7']},386 {'name': 'swact-hosts',387 'entity_names': ['controller-1']},388 {'name': 'lock-hosts',389 'entity_names': ['controller-1']},390 {'name': 'upgrade-hosts',391 'entity_names': ['controller-1']},392 _unlock_hosts_stage_as_dict(['controller-1']),393 {'name': 'wait-data-sync',394 'timeout': 14400}395 ]396 },397 {'name': 'sw-upgrade-worker-hosts',398 'total_steps': 5,399 'steps': [400 {'name': 'query-alarms'},401 {'name': 'lock-hosts',402 'entity_names': ['compute-1']},403 {'name': 'upgrade-hosts',404 'entity_names': ['compute-1']},405 _unlock_hosts_stage_as_dict(['compute-1']),406 {'name': 'wait-alarms-clear',407 'timeout': 600}408 ]409 },410 {'name': 'sw-upgrade-worker-hosts',411 'total_steps': 7,412 'steps': [413 {'name': 'query-alarms'},414 {'name': 'disable-host-services'},415 {'name': 'migrate-instances',416 'entity_names': ['test_instance_0',417 'test_instance_2',418 'test_instance_3']},419 {'name': 'lock-hosts',420 'entity_names': ['compute-0', 'compute-2', 'compute-3']},421 {'name': 'upgrade-hosts',422 'entity_names': ['compute-0', 'compute-2', 'compute-3']},423 _unlock_hosts_stage_as_dict(424 ['compute-0', 'compute-2', 'compute-3']),425 {'name': 'wait-alarms-clear',426 'timeout': 600}427 ]428 },429 {'name': 'sw-upgrade-worker-hosts',430 'total_steps': 7,431 'steps': [432 {'name': 'query-alarms'},433 {'name': 'disable-host-services'},434 {'name': 'migrate-instances',435 'entity_names': ['test_instance_4']},436 {'name': 'lock-hosts',437 'entity_names': ['compute-4']},438 {'name': 'upgrade-hosts',439 'entity_names': ['compute-4']},440 _unlock_hosts_stage_as_dict(['compute-4']),441 {'name': 'wait-alarms-clear',442 'timeout': 600}443 ]444 }445 ]446 }447 sw_update_testcase.validate_strategy_persists(strategy)448 sw_update_testcase.validate_phase(apply_phase, expected_results)449 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',450 sw_update_testcase.fake_host_name_controller_1)451 def test_sw_upgrade_strategy_worker_stages_parallel_migrate_fifty_hosts(self):452 """453 Test the sw_upgrade strategy add worker strategy stages:454 - parallel apply455 - migrate instance action456 Verify:457 - hosts with no instances upgraded first458 - host aggregate limits enforced459 """460 for x in range(0, 50):461 self.create_host('compute-%02d' % x)462 for x in range(2, 47):463 self.create_instance('small',464 "test_instance_%02d" % x,465 'compute-%02d' % x)466 self.create_host_aggregate('aggregate-1',467 ["compute-%02d" % x for x in range(0, 25)])468 self.create_host_aggregate('aggregate-2',469 ["compute-%02d" % x for x in range(25, 50)])470 worker_hosts = []471 for host in list(self._host_table.values()):472 if HOST_PERSONALITY.WORKER in host.personality:473 worker_hosts.append(host)474 # Sort worker hosts so the order of the steps is deterministic475 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)476 strategy = self.create_sw_upgrade_strategy(477 worker_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL,478 max_parallel_worker_hosts=5479 )480 strategy._add_worker_strategy_stages(481 worker_hosts=sorted_worker_hosts,482 reboot=True)483 apply_phase = strategy.apply_phase.as_dict()484 host_sets = [[0, 1, 47, 48, 49],485 [2, 3, 25, 26],486 [4, 5, 27, 28],487 [6, 7, 29, 30],488 [8, 9, 31, 32],489 [10, 11, 33, 34],490 [12, 13, 35, 36],491 [14, 15, 37, 38],492 [16, 17, 39, 40],493 [18, 19, 41, 42],494 [20, 21, 43, 44],495 [22, 23, 45, 46],496 [24]497 ]498 instance_sets = list(host_sets)499 instance_sets[0] = []500 stage_hosts = list()501 stage_instances = list()502 for x in range(0, len(host_sets) - 1):503 stage_hosts.append(["compute-%02d" % host_num for host_num in host_sets[x]])504 stage_instances.append(505 ["test_instance_%02d" % host_num for host_num in instance_sets[x]])506 expected_results = {507 'total_stages': 13,508 'stages': [509 {'name': 'sw-upgrade-worker-hosts',510 'total_steps': 5,511 'steps': [512 {'name': 'query-alarms'},513 {'name': 'lock-hosts',514 'entity_names': stage_hosts[0]},515 {'name': 'upgrade-hosts',516 'entity_names': stage_hosts[0]},517 _unlock_hosts_stage_as_dict(stage_hosts[0]),518 {'name': 'wait-alarms-clear',519 'timeout': 600}520 ]521 },522 ]523 }524 for x in range(1, len(stage_hosts)):525 expected_results['stages'].append(526 {'name': 'sw-upgrade-worker-hosts',527 'total_steps': 7,528 'steps': [529 {'name': 'query-alarms'},530 {'name': 'disable-host-services'},531 {'name': 'migrate-instances',532 'entity_names': stage_instances[x]},533 {'name': 'lock-hosts',534 'entity_names': stage_hosts[x]},535 {'name': 'upgrade-hosts',536 'entity_names': stage_hosts[x]},537 _unlock_hosts_stage_as_dict(stage_hosts[x]),538 {'name': 'wait-alarms-clear',539 'timeout': 600}540 ]541 }542 )543 sw_update_testcase.validate_strategy_persists(strategy)544 sw_update_testcase.validate_phase(apply_phase, expected_results)545 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',546 sw_update_testcase.fake_host_name_controller_1)547 def test_sw_upgrade_strategy_worker_stages_serial_migrate(self):548 """549 Test the sw_upgrade strategy add worker strategy stages:550 - serial apply551 - migrate instance action552 Verify:553 - hosts with no instances upgraded first554 """555 self.create_host('compute-0')556 self.create_host('compute-1')557 self.create_host('compute-2')558 self.create_host('compute-3')559 self.create_instance('small',560 "test_instance_0",561 'compute-0')562 self.create_instance('small',563 "test_instance_1",564 'compute-1')565 self.create_instance_group('instance_group_1',566 ['test_instance_0', 'test_instance_1'],567 [nfvi.objects.v1.INSTANCE_GROUP_POLICY.ANTI_AFFINITY])568 worker_hosts = []569 for host in list(self._host_table.values()):570 if HOST_PERSONALITY.WORKER in host.personality:571 worker_hosts.append(host)572 # Sort worker hosts so the order of the steps is deterministic573 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)574 strategy = self.create_sw_upgrade_strategy(575 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL576 )577 strategy._add_worker_strategy_stages(worker_hosts=sorted_worker_hosts,578 reboot=True)579 apply_phase = strategy.apply_phase.as_dict()580 expected_results = {581 'total_stages': 4,582 'stages': [583 {'name': 'sw-upgrade-worker-hosts',584 'total_steps': 5,585 'steps': [586 {'name': 'query-alarms'},587 {'name': 'lock-hosts',588 'entity_names': ['compute-2']},589 {'name': 'upgrade-hosts',590 'entity_names': ['compute-2']},591 _unlock_hosts_stage_as_dict(['compute-2']),592 {'name': 'wait-alarms-clear',593 'timeout': 600}594 ]595 },596 {'name': 'sw-upgrade-worker-hosts',597 'total_steps': 5,598 'steps': [599 {'name': 'query-alarms'},600 {'name': 'lock-hosts',601 'entity_names': ['compute-3']},602 {'name': 'upgrade-hosts',603 'entity_names': ['compute-3']},604 _unlock_hosts_stage_as_dict(['compute-3']),605 {'name': 'wait-alarms-clear',606 'timeout': 600}607 ]608 },609 {'name': 'sw-upgrade-worker-hosts',610 'total_steps': 6,611 'steps': [612 {'name': 'query-alarms'},613 {'name': 'migrate-instances',614 'entity_names': ['test_instance_0']},615 {'name': 'lock-hosts',616 'entity_names': ['compute-0']},617 {'name': 'upgrade-hosts',618 'entity_names': ['compute-0']},619 _unlock_hosts_stage_as_dict(['compute-0']),620 {'name': 'wait-alarms-clear',621 'timeout': 600}622 ]623 },624 {'name': 'sw-upgrade-worker-hosts',625 'total_steps': 6,626 'steps': [627 {'name': 'query-alarms'},628 {'name': 'migrate-instances',629 'entity_names': ['test_instance_1']},630 {'name': 'lock-hosts',631 'entity_names': ['compute-1']},632 {'name': 'upgrade-hosts',633 'entity_names': ['compute-1']},634 _unlock_hosts_stage_as_dict(['compute-1']),635 {'name': 'wait-alarms-clear',636 'timeout': 600}637 ]638 }639 ]640 }641 sw_update_testcase.validate_strategy_persists(strategy)642 sw_update_testcase.validate_phase(apply_phase, expected_results)643 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',644 sw_update_testcase.fake_host_name_controller_1)645 def test_sw_upgrade_strategy_non_openstack_worker_stages_serial(self):646 """647 Test the sw_upgrade strategy add worker strategy stages:648 - workers with no openstack installed649 - serial apply650 - no migrate instance action651 Verify:652 - final step is SystemStabilize653 """654 self.create_host('compute-0', openstack_installed=False)655 self.create_host('compute-1', openstack_installed=False)656 self.create_host('compute-2', openstack_installed=False)657 self.create_host('compute-3', openstack_installed=False)658 worker_hosts = []659 for host in list(self._host_table.values()):660 if HOST_PERSONALITY.WORKER in host.personality:661 worker_hosts.append(host)662 # Sort worker hosts so the order of the steps is deterministic663 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)664 strategy = self.create_sw_upgrade_strategy(665 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL666 )667 strategy._add_worker_strategy_stages(worker_hosts=sorted_worker_hosts,668 reboot=True)669 apply_phase = strategy.apply_phase.as_dict()670 expected_results = {671 'total_stages': 4,672 'stages': [673 {'name': 'sw-upgrade-worker-hosts',674 'total_steps': 5,675 'steps': [676 {'name': 'query-alarms'},677 {'name': 'lock-hosts',678 'entity_names': ['compute-0']},679 {'name': 'upgrade-hosts',680 'entity_names': ['compute-0']},681 _unlock_hosts_stage_as_dict(['compute-0']),682 {'name': 'system-stabilize'}683 ]684 },685 {'name': 'sw-upgrade-worker-hosts',686 'total_steps': 5,687 'steps': [688 {'name': 'query-alarms'},689 {'name': 'lock-hosts',690 'entity_names': ['compute-1']},691 {'name': 'upgrade-hosts',692 'entity_names': ['compute-1']},693 _unlock_hosts_stage_as_dict(['compute-1']),694 {'name': 'system-stabilize'}695 ]696 },697 {'name': 'sw-upgrade-worker-hosts',698 'total_steps': 5,699 'steps': [700 {'name': 'query-alarms'},701 {'name': 'lock-hosts',702 'entity_names': ['compute-2']},703 {'name': 'upgrade-hosts',704 'entity_names': ['compute-2']},705 _unlock_hosts_stage_as_dict(['compute-2']),706 {'name': 'system-stabilize'}707 ]708 },709 {'name': 'sw-upgrade-worker-hosts',710 'total_steps': 5,711 'steps': [712 {'name': 'query-alarms'},713 {'name': 'lock-hosts',714 'entity_names': ['compute-3']},715 {'name': 'upgrade-hosts',716 'entity_names': ['compute-3']},717 _unlock_hosts_stage_as_dict(['compute-3']),718 {'name': 'system-stabilize'}719 ]720 }721 ]722 }723 sw_update_testcase.validate_strategy_persists(strategy)724 sw_update_testcase.validate_phase(apply_phase, expected_results)725 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',726 sw_update_testcase.fake_host_name_controller_1)727 def test_sw_upgrade_strategy_worker_stages_serial_migrate_locked_instance(self):728 """729 Test the sw_upgrade strategy add worker strategy stages:730 - serial apply731 - migrate instance action732 - locked instance in instance group733 Verify:734 - stages not created735 """736 self.create_host('compute-0')737 self.create_host('compute-1')738 self.create_host('compute-2')739 self.create_host('compute-3')740 self.create_instance('small',741 "test_instance_0",742 'compute-0',743 admin_state=nfvi.objects.v1.INSTANCE_ADMIN_STATE.LOCKED)744 self.create_instance('small',745 "test_instance_1",746 'compute-1')747 self.create_instance_group('instance_group_1',748 ['test_instance_0', 'test_instance_1'],749 [nfvi.objects.v1.INSTANCE_GROUP_POLICY.ANTI_AFFINITY])750 worker_hosts = []751 for host in list(self._host_table.values()):752 if HOST_PERSONALITY.WORKER in host.personality:753 worker_hosts.append(host)754 # Sort worker hosts so the order of the steps is deterministic755 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)756 strategy = self.create_sw_upgrade_strategy(757 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL758 )759 success, reason = strategy._add_worker_strategy_stages(760 worker_hosts=sorted_worker_hosts,761 reboot=True)762 assert success is False, "Strategy creation did not fail"763 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',764 sw_update_testcase.fake_host_name_controller_1)765 def test_sw_upgrade_strategy_storage_stages_ignore(self):766 """767 Test the sw_upgrade strategy add storage strategy stages:768 - ignore apply769 Verify:770 - stages not created771 """772 self.create_host('storage-0')773 self.create_host('storage-1')774 self.create_host('storage-2')775 self.create_host('storage-3')776 self.create_host_group('group-0',777 ['storage-0', 'storage-1'],778 [nfvi.objects.v1.HOST_GROUP_POLICY.STORAGE_REPLICATION])779 self.create_host_group('group-1',780 ['storage-2', 'storage-3'],781 [nfvi.objects.v1.HOST_GROUP_POLICY.STORAGE_REPLICATION])782 storage_hosts = []783 for host in list(self._host_table.values()):784 if HOST_PERSONALITY.STORAGE in host.personality:785 storage_hosts.append(host)786 # Sort hosts so the order of the steps is deterministic787 sorted_storage_hosts = sorted(storage_hosts, key=lambda host: host.name)788 strategy = self.create_sw_upgrade_strategy(789 storage_apply_type=SW_UPDATE_APPLY_TYPE.IGNORE790 )791 success, reason = strategy._add_storage_strategy_stages(792 storage_hosts=sorted_storage_hosts,793 reboot=True)794 assert success is True, "Strategy creation failed"795 apply_phase = strategy.apply_phase.as_dict()796 expected_results = {797 'total_stages': 0798 }799 sw_update_testcase.validate_strategy_persists(strategy)800 sw_update_testcase.validate_phase(apply_phase, expected_results)801 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',802 sw_update_testcase.fake_host_name_controller_1)803 def test_sw_upgrade_strategy_storage_stages_parallel_host_group(self):804 """805 Test the sw_upgrade strategy add storage strategy stages:806 - parallel apply807 Verify:808 - storage-0 upgraded first809 - host groups enforced810 """811 self.create_host('storage-0')812 self.create_host('storage-1')813 self.create_host('storage-2')814 self.create_host('storage-3')815 self.create_host_group('group-0',816 ['storage-0', 'storage-1'],817 [nfvi.objects.v1.HOST_GROUP_POLICY.STORAGE_REPLICATION])818 self.create_host_group('group-1',819 ['storage-2', 'storage-3'],820 [nfvi.objects.v1.HOST_GROUP_POLICY.STORAGE_REPLICATION])821 storage_hosts = []822 for host in list(self._host_table.values()):823 if HOST_PERSONALITY.STORAGE in host.personality:824 storage_hosts.append(host)825 # Sort hosts so the order of the steps is deterministic826 sorted_storage_hosts = sorted(storage_hosts, key=lambda host: host.name)827 strategy = self.create_sw_upgrade_strategy(828 storage_apply_type=SW_UPDATE_APPLY_TYPE.PARALLEL829 )830 strategy._add_storage_strategy_stages(storage_hosts=sorted_storage_hosts,831 reboot=True)832 apply_phase = strategy.apply_phase.as_dict()833 expected_results = {834 'total_stages': 3,835 'stages': [836 {'name': 'sw-upgrade-storage-hosts',837 'total_steps': 5,838 'steps': [839 {'name': 'query-alarms'},840 {'name': 'lock-hosts',841 'entity_names': ['storage-0']},842 {'name': 'upgrade-hosts',843 'entity_names': ['storage-0']},844 _unlock_hosts_stage_as_dict(['storage-0']),845 {'name': 'wait-data-sync',846 'timeout': 7200}847 ]848 },849 {'name': 'sw-upgrade-storage-hosts',850 'total_steps': 5,851 'steps': [852 {'name': 'query-alarms'},853 {'name': 'lock-hosts',854 'entity_names': ['storage-1', 'storage-2']},855 {'name': 'upgrade-hosts',856 'entity_names': ['storage-1', 'storage-2']},857 _unlock_hosts_stage_as_dict(['storage-1', 'storage-2']),858 {'name': 'wait-data-sync',859 'timeout': 7200}860 ]861 },862 {'name': 'sw-upgrade-storage-hosts',863 'total_steps': 5,864 'steps': [865 {'name': 'query-alarms'},866 {'name': 'lock-hosts',867 'entity_names': ['storage-3']},868 {'name': 'upgrade-hosts',869 'entity_names': ['storage-3']},870 _unlock_hosts_stage_as_dict(['storage-3']),871 {'name': 'wait-data-sync',872 'timeout': 7200}873 ]874 }875 ]876 }877 sw_update_testcase.validate_strategy_persists(strategy)878 sw_update_testcase.validate_phase(apply_phase, expected_results)879 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',880 sw_update_testcase.fake_host_name_controller_1)881 def test_sw_upgrade_strategy_storage_stages_serial(self):882 """883 Test the sw_upgrade strategy add storage strategy stages:884 - serial apply885 """886 self.create_host('storage-0')887 self.create_host('storage-1')888 self.create_host('storage-2')889 self.create_host('storage-3')890 self.create_host_group('group-0',891 ['storage-0', 'storage-1'],892 [nfvi.objects.v1.HOST_GROUP_POLICY.STORAGE_REPLICATION])893 self.create_host_group('group-1',894 ['storage-2', 'storage-3'],895 [nfvi.objects.v1.HOST_GROUP_POLICY.STORAGE_REPLICATION])896 storage_hosts = []897 for host in list(self._host_table.values()):898 if HOST_PERSONALITY.STORAGE in host.personality:899 storage_hosts.append(host)900 # Sort hosts so the order of the steps is deterministic901 sorted_storage_hosts = sorted(storage_hosts, key=lambda host: host.name)902 strategy = self.create_sw_upgrade_strategy(903 storage_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL904 )905 strategy._add_storage_strategy_stages(storage_hosts=sorted_storage_hosts,906 reboot=True)907 apply_phase = strategy.apply_phase.as_dict()908 expected_results = {909 'total_stages': 4,910 'stages': [911 {'name': 'sw-upgrade-storage-hosts',912 'total_steps': 5,913 'steps': [914 {'name': 'query-alarms'},915 {'name': 'lock-hosts',916 'entity_names': ['storage-0']},917 {'name': 'upgrade-hosts',918 'entity_names': ['storage-0']},919 _unlock_hosts_stage_as_dict(['storage-0']),920 {'name': 'wait-data-sync',921 'ignore_alarms': ['900.005', '900.201', '750.006'],922 'timeout': 7200}923 ]924 },925 {'name': 'sw-upgrade-storage-hosts',926 'total_steps': 5,927 'steps': [928 {'name': 'query-alarms'},929 {'name': 'lock-hosts',930 'entity_names': ['storage-1']},931 {'name': 'upgrade-hosts',932 'entity_names': ['storage-1']},933 _unlock_hosts_stage_as_dict(['storage-1']),934 {'name': 'wait-data-sync',935 'ignore_alarms': ['900.005', '900.201', '750.006'],936 'timeout': 7200}937 ]938 },939 {'name': 'sw-upgrade-storage-hosts',940 'total_steps': 5,941 'steps': [942 {'name': 'query-alarms'},943 {'name': 'lock-hosts',944 'entity_names': ['storage-2']},945 {'name': 'upgrade-hosts',946 'entity_names': ['storage-2']},947 _unlock_hosts_stage_as_dict(['storage-2']),948 {'name': 'wait-data-sync',949 'ignore_alarms': ['900.005', '900.201', '750.006'],950 'timeout': 7200}951 ]952 },953 {'name': 'sw-upgrade-storage-hosts',954 'total_steps': 5,955 'steps': [956 {'name': 'query-alarms'},957 {'name': 'lock-hosts',958 'entity_names': ['storage-3']},959 {'name': 'upgrade-hosts',960 'entity_names': ['storage-3']},961 _unlock_hosts_stage_as_dict(['storage-3']),962 {'name': 'wait-data-sync',963 'ignore_alarms': ['900.005', '900.201', '750.006'],964 'timeout': 7200}965 ]966 },967 ]968 }969 sw_update_testcase.validate_strategy_persists(strategy)970 sw_update_testcase.validate_phase(apply_phase, expected_results)971 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',972 sw_update_testcase.fake_host_name_controller_1)973 def test_sw_upgrade_strategy_controller_stages_serial(self):974 """975 Test the sw_upgrade strategy add controller strategy stages:976 - serial apply977 Verify:978 - controller-0 upgraded979 """980 self.create_host('controller-0')981 self.create_host('controller-1')982 controller_hosts = []983 for host in list(self._host_table.values()):984 if (HOST_PERSONALITY.CONTROLLER in host.personality and985 HOST_NAME.CONTROLLER_0 == host.name):986 controller_hosts.append(host)987 strategy = self.create_sw_upgrade_strategy()988 strategy._add_controller_strategy_stages(controllers=controller_hosts,989 reboot=True)990 apply_phase = strategy.apply_phase.as_dict()991 expected_results = {992 'total_stages': 1,993 'stages': [994 {'name': 'sw-upgrade-controllers',995 'total_steps': 5,996 'steps': [997 {'name': 'query-alarms'},998 {'name': 'lock-hosts',999 'entity_names': ['controller-0']},1000 {'name': 'upgrade-hosts',1001 'entity_names': ['controller-0']},1002 _unlock_hosts_stage_as_dict(['controller-0']),1003 {'name': 'wait-data-sync',1004 'ignore_alarms': ['900.005', '900.201', '750.006'],1005 'timeout': 14400}1006 ]1007 }1008 ]1009 }1010 sw_update_testcase.validate_strategy_persists(strategy)1011 sw_update_testcase.validate_phase(apply_phase, expected_results)1012 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1013 sw_update_testcase.fake_host_name_controller_1)1014 def test_sw_upgrade_strategy_controller_stages_serial_start_upgrade(self):1015 """1016 Test the sw_upgrade strategy add controller strategy stages:1017 - serial apply1018 Verify:1019 - controller-1 and controller-0 upgraded1020 """1021 self.create_host('controller-0')1022 self.create_host('controller-1')1023 controller_hosts = []1024 for host in list(self._host_table.values()):1025 if (HOST_PERSONALITY.CONTROLLER in host.personality):1026 controller_hosts.append(host)1027 strategy = self.create_sw_upgrade_strategy()1028 strategy._add_controller_strategy_stages(controllers=controller_hosts,1029 reboot=True)1030 apply_phase = strategy.apply_phase.as_dict()1031 expected_results = {1032 'total_stages': 2,1033 'stages': [1034 {'name': 'sw-upgrade-controllers',1035 'total_steps': 5,1036 'steps': [1037 {'name': 'query-alarms'},1038 {'name': 'lock-hosts',1039 'entity_names': ['controller-1']},1040 {'name': 'upgrade-hosts',1041 'entity_names': ['controller-1']},1042 _unlock_hosts_stage_as_dict(['controller-1']),1043 {'name': 'wait-data-sync',1044 'ignore_alarms': ['900.005', '900.201', '750.006'],1045 'timeout': 14400}1046 ]1047 },1048 {'name': 'sw-upgrade-controllers',1049 'total_steps': 6,1050 'steps': [1051 {'name': 'query-alarms'},1052 {'name': 'swact-hosts',1053 'entity_names': ['controller-0']},1054 {'name': 'lock-hosts',1055 'entity_names': ['controller-0']},1056 {'name': 'upgrade-hosts',1057 'entity_names': ['controller-0']},1058 _unlock_hosts_stage_as_dict(['controller-0']),1059 {'name': 'wait-data-sync',1060 'ignore_alarms': ['900.005', '900.201', '750.006'],1061 'timeout': 14400}1062 ]1063 }1064 ]1065 }1066 sw_update_testcase.validate_strategy_persists(strategy)1067 sw_update_testcase.validate_phase(apply_phase, expected_results)1068 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1069 sw_update_testcase.fake_host_name_controller_1)1070 def test_sw_upgrade_strategy_aio_stages_serial(self):1071 """1072 Test the sw_upgrade strategy add controller strategy stages:1073 - aio hosts1074 - serial apply1075 Verify:1076 - controller-0 and controller-1 upgraded1077 """1078 self.create_host('controller-0', aio=True, openstack_installed=False)1079 self.create_host('controller-1', aio=True, openstack_installed=False)1080 controller_hosts = []1081 for host in list(self._host_table.values()):1082 if (HOST_PERSONALITY.CONTROLLER in host.personality and1083 HOST_NAME.CONTROLLER_0 == host.name):1084 controller_hosts.append(host)1085 worker_hosts = []1086 for host in list(self._host_table.values()):1087 if HOST_PERSONALITY.WORKER in host.personality:1088 worker_hosts.append(host)1089 # Sort worker hosts so the order of the steps is deterministic1090 sorted_worker_hosts = sorted(worker_hosts, key=lambda host: host.name)1091 strategy = self.create_sw_upgrade_strategy(worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL)1092 success, reason = strategy._add_controller_strategy_stages(1093 controllers=controller_hosts,1094 reboot=True)1095 assert success is True, ""1096 apply_phase = strategy.apply_phase.as_dict()1097 expected_results = {1098 'total_stages': 0,1099 }1100 sw_update_testcase.validate_strategy_persists(strategy)1101 sw_update_testcase.validate_phase(apply_phase, expected_results)1102 strategy._add_worker_strategy_stages(1103 worker_hosts=sorted_worker_hosts,1104 reboot=True)1105 apply_phase = strategy.apply_phase.as_dict()1106 expected_results = {1107 'total_stages': 2,1108 'stages': [1109 {'name': 'sw-upgrade-worker-hosts',1110 'total_steps': 6,1111 'steps': [1112 {'name': 'query-alarms'},1113 {'name': 'swact-hosts',1114 'entity_names': ['controller-0']},1115 {'name': 'lock-hosts',1116 'entity_names': ['controller-0']},1117 {'name': 'upgrade-hosts',1118 'entity_names': ['controller-0']},1119 _unlock_hosts_stage_as_dict(['controller-0']),1120 {'name': 'wait-data-sync',1121 'ignore_alarms': ['900.005', '900.201', '750.006'],1122 'timeout': 14400}1123 ]1124 },1125 {'name': 'sw-upgrade-worker-hosts',1126 'total_steps': 6,1127 'steps': [1128 {'name': 'query-alarms'},1129 {'name': 'swact-hosts',1130 'entity_names': ['controller-1']},1131 {'name': 'lock-hosts',1132 'entity_names': ['controller-1']},1133 {'name': 'upgrade-hosts',1134 'entity_names': ['controller-1']},1135 _unlock_hosts_stage_as_dict(['controller-1']),1136 {'name': 'wait-data-sync',1137 'ignore_alarms': ['900.005', '900.201', '750.006'],1138 'timeout': 14400}1139 ]1140 },1141 ]1142 }1143 sw_update_testcase.validate_strategy_persists(strategy)1144 sw_update_testcase.validate_phase(apply_phase, expected_results)1145 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1146 sw_update_testcase.fake_host_name_controller_1)1147 def test_sw_upgrade_strategy_aiosx_stages_serial(self):1148 """1149 Test the sw_upgrade strategy add controller strategy stages:1150 - aio-sx hosts1151 - serial apply1152 Verify:1153 - failure1154 """1155 self.create_host('controller-0', aio=True)1156 controller_hosts = []1157 for host in list(self._host_table.values()):1158 if (HOST_PERSONALITY.CONTROLLER in host.personality and1159 HOST_NAME.CONTROLLER_0 == host.name):1160 controller_hosts.append(host)1161 strategy = self.create_sw_upgrade_strategy(single_controller=True)1162 success, reason = strategy._add_controller_strategy_stages(1163 controllers=controller_hosts,1164 reboot=True)1165 assert success is False1166 assert reason == "not enough controllers to apply software upgrades"1167 apply_phase = strategy.apply_phase.as_dict()1168 expected_results = {1169 'total_stages': 0,1170 }1171 sw_update_testcase.validate_strategy_persists(strategy)1172 sw_update_testcase.validate_phase(apply_phase, expected_results)1173 @testtools.skip('No support for start_upgrade')1174 def test_sw_upgrade_strategy_build_complete_serial_migrate_start_complete(self):1175 """1176 Test the sw_upgrade strategy build_complete:1177 - serial apply1178 - migrate instance action1179 - start and complete upgrade1180 Verify:1181 - hosts with no instances upgraded first1182 """1183 self.create_host('controller-0')1184 self.create_host('controller-1')1185 self.create_host('storage-0')1186 self.create_host('storage-1')1187 self.create_host('compute-0')1188 self.create_host('compute-1')1189 self.create_instance('small',1190 "test_instance_0",1191 'compute-0')1192 strategy = self.create_sw_upgrade_strategy(1193 storage_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1194 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1195 start_upgrade=True,1196 complete_upgrade=True1197 )1198 fake_upgrade_obj = SwUpgrade()1199 strategy.sw_update_obj = fake_upgrade_obj1200 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1201 apply_phase = strategy.apply_phase.as_dict()1202 expected_results = {1203 'total_stages': 8,1204 'stages': [1205 {'name': 'sw-upgrade-start',1206 'total_steps': 4,1207 'steps': [1208 {'name': 'query-alarms'},1209 {'name': 'swact-hosts',1210 'entity_names': ['controller-1']},1211 {'name': 'start-upgrade'},1212 {'name': 'system-stabilize',1213 'timeout': 60}1214 ]1215 },1216 {'name': 'sw-upgrade-controllers',1217 'total_steps': 5,1218 'steps': [1219 {'name': 'query-alarms'},1220 {'name': 'lock-hosts',1221 'entity_names': ['controller-1']},1222 {'name': 'upgrade-hosts',1223 'entity_names': ['controller-1']},1224 _unlock_hosts_stage_as_dict(['controller-1']),1225 {'name': 'wait-data-sync',1226 'ignore_alarms': ['900.005', '900.201', '750.006'],1227 'timeout': 14400}1228 ]1229 },1230 {'name': 'sw-upgrade-controllers',1231 'total_steps': 5,1232 'steps': [1233 {'name': 'query-alarms'},1234 {'name': 'lock-hosts',1235 'entity_names': ['controller-0']},1236 {'name': 'upgrade-hosts',1237 'entity_names': ['controller-0']},1238 _unlock_hosts_stage_as_dict(['controller-0']),1239 {'name': 'wait-data-sync',1240 'ignore_alarms': ['900.005', '900.201', '750.006'],1241 'timeout': 14400}1242 ]1243 },1244 {'name': 'sw-upgrade-storage-hosts',1245 'total_steps': 5,1246 'steps': [1247 {'name': 'query-alarms'},1248 {'name': 'lock-hosts',1249 'entity_names': ['storage-0']},1250 {'name': 'upgrade-hosts',1251 'entity_names': ['storage-0']},1252 _unlock_hosts_stage_as_dict(['storage-0']),1253 {'name': 'wait-data-sync',1254 'ignore_alarms': ['900.005', '900.201', '750.006'],1255 'timeout': 7200}1256 ]1257 },1258 {'name': 'sw-upgrade-storage-hosts',1259 'total_steps': 5,1260 'steps': [1261 {'name': 'query-alarms'},1262 {'name': 'lock-hosts',1263 'entity_names': ['storage-1']},1264 {'name': 'upgrade-hosts',1265 'entity_names': ['storage-1']},1266 _unlock_hosts_stage_as_dict(['storage-1']),1267 {'name': 'wait-data-sync',1268 'ignore_alarms': ['900.005', '900.201', '750.006'],1269 'timeout': 7200}1270 ]1271 },1272 {'name': 'sw-upgrade-worker-hosts',1273 'total_steps': 5,1274 'steps': [1275 {'name': 'query-alarms'},1276 {'name': 'lock-hosts',1277 'entity_names': ['compute-1']},1278 {'name': 'upgrade-hosts',1279 'entity_names': ['compute-1']},1280 _unlock_hosts_stage_as_dict(['compute-1']),1281 {'name': 'system-stabilize',1282 'timeout': 60}1283 ]1284 },1285 {'name': 'sw-upgrade-worker-hosts',1286 'total_steps': 6,1287 'steps': [1288 {'name': 'query-alarms'},1289 {'name': 'migrate-instances',1290 'entity_names': ['test_instance_0']},1291 {'name': 'lock-hosts',1292 'entity_names': ['compute-0']},1293 {'name': 'upgrade-hosts',1294 'entity_names': ['compute-0']},1295 _unlock_hosts_stage_as_dict(['compute-0']),1296 {'name': 'system-stabilize',1297 'timeout': 60}1298 ]1299 },1300 {'name': 'sw-upgrade-complete',1301 'total_steps': 5,1302 'steps': [1303 {'name': 'query-alarms'},1304 {'name': 'swact-hosts',1305 'entity_names': ['controller-1']},1306 {'name': 'activate-upgrade'},1307 {'name': 'complete-upgrade'},1308 {'name': 'system-stabilize',1309 'timeout': 60}1310 ]1311 }1312 ]1313 }1314 sw_update_testcase.validate_strategy_persists(strategy)1315 sw_update_testcase.validate_phase(apply_phase, expected_results)1316 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1317 sw_update_testcase.fake_host_name_controller_1)1318 def test_sw_upgrade_strategy_build_complete_serial_migrate(self):1319 """1320 Test the sw_upgrade strategy build_complete:1321 - serial apply1322 - migrate instance action1323 Verify:1324 - hosts with no instances upgraded first1325 """1326 self.create_host('controller-0')1327 self.create_host('controller-1')1328 self.create_host('compute-0')1329 self.create_host('compute-1')1330 self.create_instance('small',1331 "test_instance_0",1332 'compute-0')1333 strategy = self.create_sw_upgrade_strategy(1334 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1335 nfvi_upgrade=nfvi.objects.v1.Upgrade(1336 UPGRADE_STATE.UPGRADING_CONTROLLERS,1337 '12.01',1338 '13.01')1339 )1340 fake_upgrade_obj = SwUpgrade()1341 strategy.sw_update_obj = fake_upgrade_obj1342 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1343 apply_phase = strategy.apply_phase.as_dict()1344 expected_results = {1345 'total_stages': 4,1346 'stages': [1347 {'name': 'sw-upgrade-controllers',1348 'total_steps': 5,1349 'steps': [1350 {'name': 'query-alarms'},1351 {'name': 'lock-hosts',1352 'entity_names': ['controller-1']},1353 {'name': 'upgrade-hosts',1354 'entity_names': ['controller-1']},1355 _unlock_hosts_stage_as_dict(['controller-1']),1356 {'name': 'wait-data-sync',1357 'ignore_alarms': ['900.005', '900.201', '750.006'],1358 'timeout': 14400}1359 ]1360 },1361 {'name': 'sw-upgrade-controllers',1362 'total_steps': 6,1363 'steps': [1364 {'name': 'query-alarms'},1365 {'name': 'swact-hosts',1366 'entity_names': ['controller-0']},1367 {'name': 'lock-hosts',1368 'entity_names': ['controller-0']},1369 {'name': 'upgrade-hosts',1370 'entity_names': ['controller-0']},1371 _unlock_hosts_stage_as_dict(['controller-0']),1372 {'name': 'wait-data-sync',1373 'ignore_alarms': ['900.005', '900.201', '750.006'],1374 'timeout': 14400}1375 ]1376 },1377 {'name': 'sw-upgrade-worker-hosts',1378 'total_steps': 5,1379 'steps': [1380 {'name': 'query-alarms'},1381 {'name': 'lock-hosts',1382 'entity_names': ['compute-1']},1383 {'name': 'upgrade-hosts',1384 'entity_names': ['compute-1']},1385 _unlock_hosts_stage_as_dict(['compute-1']),1386 {'name': 'wait-alarms-clear',1387 'timeout': 600}1388 ]1389 },1390 {'name': 'sw-upgrade-worker-hosts',1391 'total_steps': 6,1392 'steps': [1393 {'name': 'query-alarms'},1394 {'name': 'migrate-instances',1395 'entity_names': ['test_instance_0']},1396 {'name': 'lock-hosts',1397 'entity_names': ['compute-0']},1398 {'name': 'upgrade-hosts',1399 'entity_names': ['compute-0']},1400 _unlock_hosts_stage_as_dict(['compute-0']),1401 {'name': 'wait-alarms-clear',1402 'timeout': 600}1403 ]1404 }1405 ]1406 }1407 sw_update_testcase.validate_strategy_persists(strategy)1408 sw_update_testcase.validate_phase(apply_phase, expected_results)1409 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1410 sw_update_testcase.fake_host_name_controller_1)1411 def test_sw_upgrade_strategy_build_complete_invalid_state(self):1412 """1413 Test the sw_upgrade strategy build_complete:1414 - invalid upgrade state1415 Verify:1416 - build fails1417 """1418 self.create_host('controller-0')1419 self.create_host('controller-1')1420 self.create_host('compute-0')1421 self.create_host('compute-1')1422 self.create_host('compute-2')1423 self.create_host('compute-3')1424 self.create_instance('small',1425 "test_instance_0",1426 'compute-0')1427 self.create_instance('small',1428 "test_instance_1",1429 'compute-1')1430 strategy = self.create_sw_upgrade_strategy(1431 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1432 nfvi_upgrade=nfvi.objects.v1.Upgrade(1433 UPGRADE_STATE.DATA_MIGRATION_COMPLETE,1434 '12.01',1435 '13.01')1436 )1437 fake_upgrade_obj = SwUpgrade()1438 strategy.sw_update_obj = fake_upgrade_obj1439 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1440 build_phase = strategy.build_phase.as_dict()1441 expected_results = {1442 'total_stages': 0,1443 'result': 'failed',1444 'result_reason': 'invalid upgrade state for orchestration: data-migration-complete'1445 }1446 sw_update_testcase.validate_phase(build_phase, expected_results)1447 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1448 sw_update_testcase.fake_host_name_controller_1)1449 def test_sw_upgrade_strategy_build_complete_no_upgrade_required(self):1450 """1451 Test the sw_upgrade strategy build_complete:1452 - no upgrade required1453 Verify:1454 - build fails1455 """1456 self.create_host('controller-0')1457 self.create_host('controller-1')1458 self.create_host('compute-0')1459 self.create_host('compute-1')1460 self.create_host('compute-2')1461 self.create_host('compute-3')1462 self.create_instance('small',1463 "test_instance_0",1464 'compute-0')1465 self.create_instance('small',1466 "test_instance_1",1467 'compute-1')1468 strategy = self.create_sw_upgrade_strategy(1469 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL1470 )1471 fake_upgrade_obj = SwUpgrade()1472 strategy.sw_update_obj = fake_upgrade_obj1473 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1474 build_phase = strategy.build_phase.as_dict()1475 expected_results = {1476 'total_stages': 0,1477 'result': 'failed',1478 'result_reason': 'no upgrade in progress'1479 }1480 sw_update_testcase.validate_phase(build_phase, expected_results)1481 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1482 sw_update_testcase.fake_host_name_controller_1)1483 def test_sw_upgrade_strategy_build_complete_unupgraded_controller_1(self):1484 """1485 Test the sw_upgrade strategy build_complete:1486 - unupgraded controller host1487 Verify:1488 - build fails1489 """1490 self.create_host('controller-0')1491 self.create_host('controller-1')1492 self.create_host('compute-0')1493 self.create_host('compute-1')1494 self.create_host('compute-2')1495 self.create_host('compute-3')1496 self.create_instance('small',1497 "test_instance_0",1498 'compute-0')1499 self.create_instance('small',1500 "test_instance_1",1501 'compute-1')1502 strategy = self.create_sw_upgrade_strategy(1503 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1504 nfvi_upgrade=nfvi.objects.v1.Upgrade(1505 UPGRADE_STATE.DATA_MIGRATION_COMPLETE,1506 '12.01',1507 '13.01')1508 )1509 fake_upgrade_obj = SwUpgrade()1510 strategy.sw_update_obj = fake_upgrade_obj1511 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1512 build_phase = strategy.build_phase.as_dict()1513 expected_results = {1514 'total_stages': 0,1515 'result': 'failed',1516 'result_reason': 'invalid upgrade state for orchestration: data-migration-complete'1517 }1518 sw_update_testcase.validate_phase(build_phase, expected_results)1519 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1520 sw_update_testcase.fake_host_name_controller_0)1521 def test_sw_upgrade_strategy_build_complete_from_controller_0(self):1522 """1523 Test the sw_upgrade strategy build_complete:1524 - attempting build from controller-01525 Verify:1526 - build fails1527 """1528 self.create_host('controller-0')1529 self.create_host('controller-1')1530 self.create_host('compute-0')1531 self.create_host('compute-1')1532 self.create_host('compute-2')1533 self.create_host('compute-3')1534 self.create_instance('small',1535 "test_instance_0",1536 'compute-0')1537 self.create_instance('small',1538 "test_instance_1",1539 'compute-1')1540 strategy = self.create_sw_upgrade_strategy(1541 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1542 nfvi_upgrade=nfvi.objects.v1.Upgrade(1543 UPGRADE_STATE.UPGRADING_CONTROLLERS,1544 '12.01',1545 '13.01')1546 )1547 fake_upgrade_obj = SwUpgrade()1548 strategy.sw_update_obj = fake_upgrade_obj1549 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1550 build_phase = strategy.build_phase.as_dict()1551 expected_results = {1552 'total_stages': 0,1553 'result': 'failed',1554 'result_reason': 'controller-1 must be active for orchestration '1555 'to upgrade controller-0'1556 }1557 sw_update_testcase.validate_phase(build_phase, expected_results)1558 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1559 sw_update_testcase.fake_host_name_controller_1)1560 def test_sw_upgrade_strategy_build_complete_locked_controller(self):1561 """1562 Test the sw_upgrade strategy build_complete:1563 - locked controller host1564 Verify:1565 - build fails1566 """1567 self.create_host('controller-0',1568 admin_state=nfvi.objects.v1.HOST_ADMIN_STATE.LOCKED)1569 self.create_host('controller-1')1570 self.create_host('compute-0')1571 self.create_host('compute-1')1572 self.create_host('compute-2')1573 self.create_host('compute-3')1574 self.create_instance('small',1575 "test_instance_0",1576 'compute-0')1577 self.create_instance('small',1578 "test_instance_1",1579 'compute-1')1580 strategy = self.create_sw_upgrade_strategy(1581 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1582 nfvi_upgrade=nfvi.objects.v1.Upgrade(1583 UPGRADE_STATE.UPGRADING_CONTROLLERS,1584 '12.01',1585 '13.01')1586 )1587 fake_upgrade_obj = SwUpgrade()1588 strategy.sw_update_obj = fake_upgrade_obj1589 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1590 build_phase = strategy.build_phase.as_dict()1591 expected_results = {1592 'total_stages': 0,1593 'result': 'failed',1594 'result_reason':1595 'all controller hosts must be unlocked-enabled-available'1596 }1597 sw_update_testcase.validate_phase(build_phase, expected_results)1598 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1599 sw_update_testcase.fake_host_name_controller_1)1600 def test_sw_upgrade_strategy_build_complete_locked_worker(self):1601 """1602 Test the sw_upgrade strategy build_complete:1603 - locked worker host1604 Verify:1605 - build fails1606 """1607 self.create_host('controller-0')1608 self.create_host('controller-1')1609 self.create_host('compute-0')1610 self.create_host('compute-1')1611 self.create_host('compute-2')1612 self.create_host('compute-3',1613 admin_state=nfvi.objects.v1.HOST_ADMIN_STATE.LOCKED)1614 self.create_instance('small',1615 "test_instance_0",1616 'compute-0')1617 self.create_instance('small',1618 "test_instance_1",1619 'compute-1')1620 strategy = self.create_sw_upgrade_strategy(1621 worker_apply_type=SW_UPDATE_APPLY_TYPE.SERIAL,1622 nfvi_upgrade=nfvi.objects.v1.Upgrade(1623 UPGRADE_STATE.UPGRADING_CONTROLLERS,1624 '12.01',1625 '13.01')1626 )1627 fake_upgrade_obj = SwUpgrade()1628 strategy.sw_update_obj = fake_upgrade_obj1629 strategy.build_complete(common_strategy.STRATEGY_RESULT.SUCCESS, "")1630 build_phase = strategy.build_phase.as_dict()1631 expected_results = {1632 'total_stages': 0,1633 'result': 'failed',1634 'result_reason':1635 'all worker hosts must be unlocked-enabled-available'1636 }1637 sw_update_testcase.validate_phase(build_phase, expected_results)1638 @mock.patch('nfv_vim.strategy._strategy.get_local_host_name',1639 sw_update_testcase.fake_host_name_controller_1)1640 def test_sw_upgrade_strategy_controller_missing_strategy_fields(self):1641 """1642 Test the sw_upgrade strategy add controller strategy stages:1643 - serial apply1644 Verify:1645 - controller-0 upgraded1646 - the missing fields do not cause deserialization failures1647 """1648 self.create_host('controller-0')1649 self.create_host('controller-1')1650 controller_hosts = []1651 for host in list(self._host_table.values()):1652 if (HOST_PERSONALITY.CONTROLLER in host.personality and1653 HOST_NAME.CONTROLLER_0 == host.name):1654 controller_hosts.append(host)1655 strategy = self.create_sw_upgrade_strategy()1656 strategy._add_controller_strategy_stages(controllers=controller_hosts,1657 reboot=True)1658 strategy_dict = strategy.as_dict()1659 # remove the fields that do not exist in the previous version1660 # - the retry fields in 'unlock'1661 # in this strategy the unlock hosts stage is located at:1662 # - first stage of apply is sw-upgrade-controllers for controller-01663 # - 4th step (index 3) in that stage is the unlock-hosts step...

Full Screen

Full Screen

test___init__.py

Source:test___init__.py Github

copy

Full Screen

2from core.config import config3from core.hosts import Host, upload_video, upload_image4from PIL import Image5from os import path, remove6def create_host(comment_id, subject='username mention'):7 """Create a host from a comment"""8 comment = config.r.comment(comment_id)9 comment.subject = subject10 inbox_item = InboxItem(comment)11 return Host(inbox_item)12def test_set_media_details_one():13 """Gfycat"""14 vid_url = 'https://giant.gfycat.com/PeacefulPotableHochstettersfrog.mp4'15 name = 'PeacefulPotableHochstettersfrog'16 host = create_host('f87u2bi')17 host.set_media_details()18 assert host.vid_url == vid_url and not host.gif_url and not host.img_url and host.name == name19def test_set_media_details_one_alt():20 """Gfycat"""21 vid_url = 'https://giant.gfycat.com/PeacefulPotableHochstettersfrog.mp4'22 name = 'PeacefulPotableHochstettersfrog'23 host = create_host('f87u2bi')24 _ = host.inbox_item.submission.preview25 delattr(host.inbox_item.submission, 'preview')26 host.set_media_details()27 assert host.vid_url == vid_url and not host.gif_url and not host.img_url and host.name == name28def test_set_media_details_two():29 """vReddit"""30 vid_url = 'https://v.redd.it/g9nttzcty1031/DASH_480?source=fallback'31 name = 'bsbhhm'32 host = create_host('f55shpf')33 host.set_media_details()34 assert host.vid_url == vid_url and not host.gif_url and not host.img_url and host.name == name35def test_set_media_details_three():36 """iReddit"""37 vid_url = 'https://preview.redd.it/q6r8gnhkiym21.gif?format=mp4&s=066d0f888ac3fca23de912e6f2268ac3cfcef066'38 gif_url = 'https://i.redd.it/q6r8gnhkiym21.gif'39 name = 'b2pbl5'40 host = create_host('ez7yphl')41 host.set_media_details()42 assert host.vid_url == vid_url and host.gif_url == gif_url and not host.img_url and host.name == name43def test_set_media_details_four():44 """Imgur"""45 vid_url = 'https://i.imgur.com/v0iFRq1.mp4'46 name = 'v0iFRq1'47 host = create_host('ez7y6dd')48 host.set_media_details()49 assert host.vid_url == vid_url and not host.gif_url and not host.img_url and host.name == name50def test_set_media_details_four_alt():51 """Imgur"""52 vid_url = 'https://i.imgur.com/v0iFRq1.mp4'53 name = 'v0iFRq1'54 host = create_host('ez7y6dd')55 _ = host.inbox_item.submission.preview56 delattr(host.inbox_item.submission, 'preview')57 host.set_media_details()58 assert host.vid_url == vid_url and not host.gif_url and not host.img_url and host.name == name59def test_set_media_details_five():60 """Streamable"""61 name = 'agccr'62 host = create_host('fgpd8ug')63 host.set_media_details()64 assert 'video/mp4/agccr.mp4' in host.vid_url and not host.gif_url and not host.img_url and host.name == name65def test_set_media_details_six():66 """Youtube"""67 img_url = "https://img.youtube.com/vi/ebHqWaaLVdw/maxresdefault.jpg"68 name = 'ebHqWaaLVdw'69 host = create_host('f4rrsvj')70 host.set_media_details()71 assert not host.vid_url and not host.gif_url and host.img_url == img_url and host.name == name72def test_set_media_details_seven():73 """Generic"""74 vid_url = "https://external-preview.redd.it/D-jCWANkdTRqKk3I8BaAMQq9MIGR_S5_1h39EcBEuDA.gif?format=mp4&s=447f2485db3e767f1fe72834d30a4c4c7e0fb309"75 name = 'http:__www.slate.com_content_dam_slate_blogs_the_vault_2014_06_17_newmap.gif'76 host = create_host('f0phdv0')77 host.set_media_details()78 assert host.vid_url == vid_url and not host.gif_url and not host.img_url and host.name == name79def test_get_image_one():80 """vid_url"""81 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'82 host = create_host('ekaavid')83 seconds = '1.2'84 host.vid_url = vid_url85 img, seconds = host.get_image(seconds)86 assert isinstance(img, Image.Image) and seconds == 1.287def test_get_image_two():88 """gif_url"""89 gif_url = 'https://i.redd.it/q6r8gnhkiym21.gif'90 host = create_host('ez7yphl')91 host.gif_url = gif_url92 seconds = None93 img, seconds = host.get_image(seconds)94 assert isinstance(img, Image.Image)95def test_get_image_three():96 """img_url"""97 img_url = "https://img.youtube.com/vi/ebHqWaaLVdw/maxresdefault.jpg"98 host = create_host('f4rrsvj')99 seconds = None100 host.img_url = img_url101 img, seconds = host.get_image(seconds)102 assert isinstance(img, Image.Image)103def test_get_image_with_upload():104 """Image with upload"""105 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'106 host = create_host('ekaavid')107 host.vid_url = vid_url108 seconds = None109 img, seconds = host.get_image(seconds)110 url = upload_image(img)111 assert 'imgur' in url and seconds == 0.0112def test_get_slo_mo():113 """Slow mo"""114 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'115 host = create_host('ekaavid')116 host.vid_url = vid_url117 speed = None118 filename, speed = host.get_slo_mo(speed)119 worked = path.isfile(filename)120 remove(filename)121 assert worked and speed == 2.0122def test_get_freeze():123 """Freeze"""124 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'125 host = create_host('ekaavid')126 host.vid_url = vid_url127 filename = host.get_freeze()128 worked = path.isfile(filename)129 remove(filename)130 assert worked131def test_get_reverse():132 """Reverse"""133 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'134 host = create_host('ekaavid')135 host.vid_url = vid_url136 filename = host.get_reverse()137 worked = path.isfile(filename)138 remove(filename)139 assert worked140def test_get_reverse_with_upload():141 """Reverse with upload"""142 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'143 host = create_host('ekaavid')144 host.vid_url = vid_url145 filename = host.get_reverse()146 url = upload_video(filename, host.inbox_item)147 assert 'gfycat' in url148def test_get_section_one():149 """Section"""150 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'151 host = create_host('ekaavid')152 host.vid_url = vid_url153 section = ('*', '2.2')154 filename = host.get_section(section)155 worked = path.isfile(filename)156 remove(filename)157 assert worked158def test_get_section_two():159 """Section"""160 vid_url = 'https://preview.redd.it/qpmq6jpb7pq21.gif?format=mp4&s=907f91fc3433d42c4a21df7382621ac542a77b00'161 host = create_host('ekaavid')162 host.vid_url = vid_url163 section = ('2.2', '*')164 filename = host.get_section(section)165 worked = path.isfile(filename)166 remove(filename)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful