How to use create_vm method in lisa

Best Python code snippet using lisa_python

test_vm_power_control.py

Source:test_vm_power_control.py Github

copy

Full Screen

1import random2import time3import pytest4from cfme import test_requirements5from cfme.base.credential import Credential6from cfme.common import BaseLoggedInPage7from cfme.infrastructure.provider import InfraProvider8from cfme.infrastructure.provider.rhevm import RHEVMProvider9from cfme.infrastructure.provider.scvmm import SCVMMProvider10from cfme.infrastructure.provider.virtualcenter import VMwareProvider11from cfme.markers.env_markers.provider import ONE_PER_TYPE12from cfme.rest.gen_data import users as _users13from cfme.utils.appliance.implementations.ui import navigate_to14from cfme.utils.blockers import BZ15from cfme.utils.log import logger16from cfme.utils.wait import TimedOutError17from cfme.utils.wait import wait_for18pytestmark = [19 pytest.mark.long_running,20 pytest.mark.tier(2),21 pytest.mark.usefixtures('setup_provider'),22 test_requirements.power,23 pytest.mark.provider([InfraProvider], scope='class'),24]25@pytest.fixture(scope='function')26def vm_name(create_vm):27 return create_vm.name28@pytest.fixture(scope="function")29def archived_vm(create_vm):30 """Fixture to archive testing VM"""31 create_vm.mgmt.delete()32 create_vm.wait_for_vm_state_change(desired_state='archived', timeout=720,33 from_details=False, from_any_provider=True)34@pytest.fixture(scope="function")35def orphaned_vm(provider, create_vm):36 """Fixture to orphane VM by removing provider from CFME"""37 provider.delete_if_exists(cancel=False)38 create_vm.wait_for_vm_state_change(desired_state='orphaned', timeout=720,39 from_details=False, from_any_provider=True)40def if_scvmm_refresh_provider(provider):41 # No eventing from SCVMM so force a relationship refresh42 if provider.one_of(SCVMMProvider):43 provider.refresh_provider_relationships()44def check_power_options(provider, soft_assert, vm, power_state):45 must_be_available = {46 'on': [vm.POWER_OFF, vm.SUSPEND, vm.RESET],47 'off': [vm.POWER_ON]48 }49 mustnt_be_available = {50 'on': [vm.POWER_ON],51 'off': [vm.POWER_OFF, vm.SUSPEND, vm.RESET]52 }53 # VMware and RHEVM have extended power options54 if not provider.one_of(SCVMMProvider):55 mustnt_be_available['off'].extend([vm.GUEST_RESTART, vm.GUEST_SHUTDOWN])56 if not provider.one_of(SCVMMProvider, RHEVMProvider):57 mustnt_be_available['on'].extend([vm.GUEST_RESTART, vm.GUEST_SHUTDOWN])58 if provider.one_of(RHEVMProvider):59 must_be_available['on'].remove(vm.RESET)60 view = navigate_to(vm, 'Details')61 power_dropdown = view.toolbar.power62 for pwr_option in must_be_available[power_state]:63 soft_assert(power_dropdown.item_enabled(pwr_option),64 "'{}' must be available in current power state - '{}' ".format(pwr_option,65 power_state))66 for pwr_option in mustnt_be_available[power_state]:67 pwr_state = power_dropdown.has_item(pwr_option) and power_dropdown.item_enabled(pwr_option)68 soft_assert(not pwr_state,69 "'{}' must not be available in current power state - '{}' ".format(pwr_option,70 power_state))71def wait_for_last_boot_timestamp_refresh(vm, boot_time, timeout=300):72 """Timestamp update doesn't happen with state change so need a longer73 wait when expecting a last boot timestamp change"""74 view = navigate_to(vm, "Details")75 def _wait_for_timestamp_refresh():76 cur_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")77 return boot_time != cur_boot_time78 try:79 wait_for(_wait_for_timestamp_refresh, num_sec=timeout, delay=30,80 fail_func=view.toolbar.reload.click)81 return True82 except TimedOutError:83 return False84def ensure_state_changed_on_unchanged(vm, state_changed_on):85 """Returns True if current value of State Changed On in the Power Management86 is the same as the supplied (original) value."""87 view = navigate_to(vm, "Details")88 new_state_changed_on = view.entities.summary("Power Management").get_text_of("State Changed On")89 return state_changed_on == new_state_changed_on90def wait_for_vm_tools(vm, timeout=300):91 """Sometimes test opens VM details before it gets loaded and can't verify if vmtools are92 installed"""93 view = navigate_to(vm, "Details")94 def _wait_for_tools_ok():95 return view.entities.summary("Properties").get_text_of("Platform Tools") == 'toolsOk'96 try:97 wait_for(_wait_for_tools_ok, num_sec=timeout, delay=10, fail_func=view.toolbar.reload.click)98 except TimedOutError:99 return False100class TestControlOnQuadicons:101 def test_power_off_cancel(self, create_vm, ensure_vm_running, soft_assert):102 """Tests power off cancel103 Metadata:104 test_flag: power_control, provision105 Polarion:106 assignee: prichard107 casecomponent: Infra108 initialEstimate: 1/10h109 """110 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_ON, timeout=720)111 create_vm.power_control_from_cfme(option=create_vm.POWER_OFF, cancel=True)112 if_scvmm_refresh_provider(create_vm.provider)113 # TODO: assert no event.114 time.sleep(60)115 vm_state = create_vm.find_quadicon().data['state']116 soft_assert(vm_state == 'on')117 soft_assert(118 create_vm.mgmt.is_running, "vm not running")119 def test_power_off(self, appliance, create_vm, ensure_vm_running, soft_assert):120 """Tests power off121 Polarion:122 assignee: prichard123 initialEstimate: 1/6h124 casecomponent: Infra125 caseimportance: high126 tags: power127 """128 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_ON, timeout=720)129 create_vm.power_control_from_cfme(option=create_vm.POWER_OFF, cancel=False)130 view = appliance.browser.create_view(BaseLoggedInPage)131 view.flash.assert_success_message(text='Stop initiated', partial=True)132 if_scvmm_refresh_provider(create_vm.provider)133 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_OFF, timeout=900)134 vm_state = create_vm.find_quadicon().data['state']135 soft_assert(vm_state == 'off')136 soft_assert(not create_vm.mgmt.is_running, "vm running")137 def test_power_on_cancel(self, create_vm, ensure_vm_stopped, soft_assert):138 """Tests power on cancel139 Polarion:140 assignee: prichard141 initialEstimate: 1/4h142 casecomponent: Infra143 caseimportance: high144 tags: power145 """146 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_OFF, timeout=720)147 create_vm.power_control_from_cfme(option=create_vm.POWER_ON, cancel=True)148 if_scvmm_refresh_provider(create_vm.provider)149 time.sleep(60)150 vm_state = create_vm.find_quadicon().data['state']151 soft_assert(vm_state == 'off')152 soft_assert(not create_vm.mgmt.is_running, "vm running")153 @pytest.mark.tier(1)154 def test_power_on(self, appliance, create_vm, ensure_vm_stopped, soft_assert):155 """Tests power on156 Metadata:157 test_flag: power_control, provision158 Polarion:159 assignee: prichard160 initialEstimate: 1/6h161 casecomponent: Infra162 caseimportance: high163 tags: power164 """165 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_OFF, timeout=720)166 create_vm.power_control_from_cfme(option=create_vm.POWER_ON, cancel=False)167 view = appliance.browser.create_view(BaseLoggedInPage)168 view.flash.assert_success_message(text='Start initiated', partial=True)169 if_scvmm_refresh_provider(create_vm.provider)170 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_ON, timeout=900)171 vm_state = create_vm.find_quadicon().data['state']172 soft_assert(vm_state == 'on')173 soft_assert(create_vm.mgmt.is_running, "vm not running")174class TestVmDetailsPowerControlPerProvider:175 def test_power_off(self, appliance, create_vm, ensure_vm_running, soft_assert):176 """Tests power off177 Metadata:178 test_flag: power_control, provision179 Polarion:180 assignee: prichard181 initialEstimate: 1/6h182 casecomponent: Infra183 caseimportance: high184 tags: power185 """186 create_vm.wait_for_vm_state_change(187 desired_state=create_vm.STATE_ON, timeout=720, from_details=True)188 view = navigate_to(create_vm, "Details")189 last_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")190 create_vm.power_control_from_cfme(option=create_vm.POWER_OFF,191 cancel=False,192 from_details=True)193 view.flash.assert_success_message(text='Stop initiated', partial=True)194 if_scvmm_refresh_provider(create_vm.provider)195 create_vm.wait_for_vm_state_change(196 desired_state=create_vm.STATE_OFF, timeout=720, from_details=True)197 soft_assert(not create_vm.mgmt.is_running, "vm running")198 # BUG - https://bugzilla.redhat.com/show_bug.cgi?id=1101604199 if not create_vm.provider.one_of(RHEVMProvider):200 new_last_boot_time = view.entities.summary("Power Management").get_text_of(201 "Last Boot Time")202 soft_assert(new_last_boot_time == last_boot_time,203 f"ui: {new_last_boot_time} should == orig: {last_boot_time}")204 def test_power_on(self, appliance, create_vm, ensure_vm_stopped, soft_assert):205 """Tests power on206 Metadata:207 test_flag: power_control, provision208 Polarion:209 assignee: prichard210 initialEstimate: 1/6h211 casecomponent: Infra212 caseimportance: high213 tags: power214 """215 create_vm.wait_for_vm_state_change(216 desired_state=create_vm.STATE_OFF, timeout=720, from_details=True)217 create_vm.power_control_from_cfme(option=create_vm.POWER_ON,218 cancel=False,219 from_details=True)220 view = appliance.browser.create_view(BaseLoggedInPage)221 view.flash.assert_success_message(text='Start initiated', partial=True)222 if_scvmm_refresh_provider(create_vm.provider)223 create_vm.wait_for_vm_state_change(224 desired_state=create_vm.STATE_ON, timeout=720, from_details=True)225 soft_assert(create_vm.mgmt.is_running, "vm not running")226 @pytest.mark.meta(automates=[BZ(1174858)])227 def test_suspend(self, appliance, create_vm, ensure_vm_running, soft_assert):228 """Tests suspend229 Polarion:230 assignee: prichard231 initialEstimate: 1/6h232 casecomponent: Infra233 caseimportance: high234 tags: power235 Bugzilla:236 1174858237 """238 create_vm.wait_for_vm_state_change(239 desired_state=create_vm.STATE_ON, timeout=720, from_details=True)240 view = navigate_to(create_vm, "Details")241 last_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")242 create_vm.power_control_from_cfme(option=create_vm.SUSPEND,243 cancel=False,244 from_details=True)245 view.flash.assert_success_message(text='Suspend initiated', partial=True)246 if_scvmm_refresh_provider(create_vm.provider)247 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_SUSPENDED,248 timeout=450,249 from_details=True)250 soft_assert(create_vm.mgmt.is_suspended, "vm not suspended")251 if not create_vm.provider.one_of(RHEVMProvider):252 new_last_boot_time = view.entities.summary("Power Management").get_text_of(253 "Last Boot Time")254 soft_assert(new_last_boot_time == last_boot_time,255 f"ui: {new_last_boot_time} should == orig: {last_boot_time}")256 def test_start_from_suspend(self, appliance, create_vm, ensure_vm_suspended, soft_assert):257 """Tests start from suspend258 Polarion:259 assignee: prichard260 initialEstimate: 1/6h261 casecomponent: Infra262 caseimportance: high263 tags: power264 """265 try:266 create_vm.provider.refresh_provider_relationships()267 create_vm.wait_for_vm_state_change(268 desired_state=create_vm.STATE_SUSPENDED, timeout=450, from_details=True)269 except TimedOutError:270 if create_vm.provider.one_of(RHEVMProvider):271 logger.warning('working around bz1174858, ignoring timeout')272 else:273 raise274 view = navigate_to(create_vm, "Details")275 last_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")276 create_vm.power_control_from_cfme(option=create_vm.POWER_ON,277 cancel=False,278 from_details=True)279 view.flash.assert_success_message(text='Start initiated', partial=True)280 if_scvmm_refresh_provider(create_vm.provider)281 create_vm.wait_for_vm_state_change(282 desired_state=create_vm.STATE_ON, timeout=720, from_details=True)283 wait_for_last_boot_timestamp_refresh(create_vm, last_boot_time, timeout=600)284 soft_assert(create_vm.mgmt.is_running, "vm not running")285def test_no_template_power_control(provider, soft_assert):286 """ Ensures that no power button is displayed for templates.287 Polarion:288 assignee: prichard289 casecomponent: Infra290 initialEstimate: 1/10h291 setup:292 1. An infra provider that has some templates.293 testSteps:294 1. Open the view of all templates of the provider295 2. Verify the Power toolbar button is not visible296 3. Select some template using the checkbox297 4. Verify the Power toolbar button is not visible298 5. Click on some template to get into the details page299 6. Verify the Power toolbar button is not visible300 Bugzilla:301 1496383302 1634713303 """304 view = navigate_to(provider, 'ProviderTemplates')305 view.toolbar.view_selector.select('Grid View')306 soft_assert(not view.toolbar.power.is_displayed, "Power displayed in template grid view!")307 # Ensure selecting a template doesn't cause power menu to appear308 templates = view.entities.all_entity_names309 template_name = random.choice(templates)310 selected_template = provider.appliance.collections.infra_templates.instantiate(template_name,311 provider)312 # Check the power button with checking the quadicon313 view = navigate_to(selected_template, 'AllForProvider', use_resetter=False)314 entity = view.entities.get_entity(name=selected_template.name, surf_pages=True)315 entity.ensure_checked()316 for action in view.toolbar.power.items:317 # Performing power actions on template318 view.toolbar.power.item_select(action, handle_alert=True)319 if action == 'Power On':320 action = 'Start'321 elif action == 'Power Off':322 action = 'Stop'323 view.flash.assert_message(f'{action} action does not apply to selected items')324 view.flash.dismiss()325 # Ensure there isn't a power button on the details page326 entity.click()327 soft_assert(not view.toolbar.power.is_displayed, "Power displayed in template details!")328@pytest.mark.meta(329 blockers=[330 BZ(331 1723805,332 unblock=lambda provider: not provider.one_of(SCVMMProvider),333 )334 ]335)336def test_no_power_controls_on_archived_vm(appliance, create_vm, archived_vm, soft_assert):337 """ Ensures that no power button is displayed from details view of archived vm338 Polarion:339 assignee: prichard340 casecomponent: Infra341 initialEstimate: 1/10h342 setup:343 1. Archived VM should be available344 testSteps:345 1. Open the view of VM Details346 2. Verify the Power toolbar button is not visible347 Bugzilla:348 1520489349 1659340350 """351 view = navigate_to(create_vm, 'AnyProviderDetails', use_resetter=False)352 status = getattr(view.toolbar.power, "is_enabled")353 assert not status, "Power displayed in archived VM's details!"354def test_archived_vm_status(create_vm, archived_vm):355 """Tests archived vm status356 Metadata:357 test_flag: inventory358 Polarion:359 assignee: prichard360 casecomponent: Infra361 caseimportance: high362 initialEstimate: 1/8h363 tags: power364 """365 vm_state = create_vm.find_quadicon(from_any_provider=True).data['state']366 assert (vm_state == 'archived')367def test_orphaned_vm_status(create_vm, orphaned_vm):368 """Tests orphaned vm status369 Polarion:370 assignee: prichard371 initialEstimate: 1/10h372 casecomponent: Infra373 tags: power374 """375 vm_state = create_vm.find_quadicon(from_any_provider=True).data['state']376 assert (vm_state == 'orphaned')377def test_vm_power_options_from_on(provider, soft_assert, create_vm, ensure_vm_running):378 """Tests vm power options from on379 Metadata:380 test_flag: power_control381 Polarion:382 assignee: prichard383 casecomponent: Infra384 initialEstimate: 1/4h385 """386 create_vm.wait_for_vm_state_change(387 desired_state=create_vm.STATE_ON, timeout=720, from_details=True)388 check_power_options(provider, soft_assert, create_vm, create_vm.STATE_ON)389@pytest.mark.meta(automates=[BZ(1724062)])390def test_vm_power_options_from_off(provider, soft_assert, create_vm, ensure_vm_stopped):391 """Tests vm power options from off392 Metadata:393 test_flag: power_control394 Polarion:395 assignee: prichard396 casecomponent: Infra397 initialEstimate: 1/4h398 Bugzilla:399 1724062400 """401 # TODO(ghubale@redhat.com): Update this test case with power options(shutdown and restart guest)402 # for scvmm provider403 create_vm.wait_for_vm_state_change(404 desired_state=create_vm.STATE_OFF, timeout=720, from_details=True)405 check_power_options(provider, soft_assert, create_vm, create_vm.STATE_OFF)406@pytest.mark.provider([VMwareProvider, RHEVMProvider], scope='function')407@pytest.mark.meta(automates=[1571830, 1650506])408@pytest.mark.parametrize('create_vm', ['full_template'], indirect=True)409def test_guest_os_reset(appliance, provider, create_vm, ensure_vm_running, soft_assert):410 """Tests vm guest os reset411 Metadata:412 test_flag: power_control413 Polarion:414 assignee: prichard415 initialEstimate: 1/6h416 casecomponent: Infra417 tags: power418 Bugzilla:419 1571830420 1650506421 """422 # TODO(ghubale@redhat.com): Update this test case for power operation(restart guest) for scvmm423 wait_for_vm_tools(create_vm)424 view = navigate_to(create_vm, "Details")425 last_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")426 state_changed_on = view.entities.summary("Power Management").get_text_of("State Changed On")427 create_vm.power_control_from_cfme(428 option=create_vm.GUEST_RESTART, cancel=False, from_details=True)429 view.flash.assert_success_message(text='Restart Guest initiated', partial=True)430 if not (provider.one_of(RHEVMProvider) and BZ(1571830, forced_streams=["5.10", "5.11"]).blocks):431 soft_assert(432 wait_for_last_boot_timestamp_refresh(create_vm, last_boot_time),433 "Last Boot Time value has not been refreshed",434 )435 soft_assert(436 ensure_state_changed_on_unchanged(create_vm, state_changed_on),437 "Value of 'State Changed On' has changed after guest restart",438 )439 soft_assert(create_vm.mgmt.is_running, "vm not running")440@pytest.mark.meta(automates=[1723485, 1571895, 1650506])441@pytest.mark.provider([VMwareProvider, RHEVMProvider])442@pytest.mark.meta(blockers=[BZ(1723485, forced_streams=["5.11"],443 unblock=lambda provider: not (provider.one_of(RHEVMProvider)444 and not provider.version < 4.3))])445@pytest.mark.parametrize('create_vm', ['full_template'], indirect=True)446def test_guest_os_shutdown(appliance, provider, create_vm, ensure_vm_running, soft_assert):447 """Tests vm guest os reset448 Polarion:449 assignee: prichard450 initialEstimate: 1/6h451 caseimportance: high452 casecomponent: Infra453 tags: power454 Bugzilla:455 1723485456 1571895457 1650506458 """459 # TODO(ghubale@redhat.com): Update this test case for power operation(shutdown guest) for scvmm460 create_vm.wait_for_vm_state_change(461 desired_state=create_vm.STATE_ON, timeout=720, from_details=True)462 wait_for_vm_tools(create_vm)463 view = navigate_to(create_vm, "Details")464 last_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")465 create_vm.power_control_from_cfme(466 option=create_vm.GUEST_SHUTDOWN, cancel=False, from_details=True)467 view.flash.assert_success_message(text='Shutdown Guest initiated', partial=True)468 create_vm.wait_for_vm_state_change(469 desired_state=create_vm.STATE_OFF, timeout=720, from_details=True)470 soft_assert(471 not create_vm.mgmt.is_running, "vm running")472 # Blocking this assertion for RHEV providers because of BZ(1571895) not fixed yet473 if not (BZ(1571895, forced_streams=["5.10", "5.11"]).blocks and provider.one_of(RHEVMProvider)):474 new_last_boot_time = view.entities.summary("Power Management").get_text_of("Last Boot Time")475 soft_assert(new_last_boot_time == last_boot_time,476 f"ui: {new_last_boot_time} should == orig: {last_boot_time}")477@pytest.fixture(scope="function")478def new_user(request, appliance):479 user, user_data = _users(request, appliance, group="EvmGroup-vm_user")480 yield appliance.collections.users.instantiate(481 name=user[0].name,482 credential=Credential(principal=user_data[0]["userid"], secret=user_data[0]["password"]),483 )484 if user[0].exists:485 user[0].action.delete()486@pytest.mark.tier(1)487@pytest.mark.meta(automates=[1687597])488@pytest.mark.provider([VMwareProvider], selector=ONE_PER_TYPE)489def test_retire_vm_with_vm_user_role(new_user, appliance, create_vm):490 """491 Bugzilla:492 1687597493 Polarion:494 assignee: ghubale495 initialEstimate: 1/8h496 caseposneg: positive497 startsin: 5.10498 casecomponent: Automate499 setup:500 1. Provision vm501 testSteps:502 1. Create custom user with 'EvmRole_vm-user' role503 2. Retire VM by log-in to custom user504 """505 # Log in with new user to retire the vm506 with new_user:507 view = navigate_to(create_vm.parent, "All")508 view.entities.get_entity(name=create_vm.name, surf_pages=True).ensure_checked()509 assert view.toolbar.lifecycle.item_enabled("Retire selected items")510 create_vm.retire()511 assert create_vm.wait_for_vm_state_change(desired_state="retired",512 timeout=720,513 from_details=True)514@pytest.fixture(params=['archived', 'orphaned'])515def archive_orphan_vm(request, provider, create_vm):516 """This fixture is used to create archived or orphaned VM"""517 if request.param == "archived":518 # Archive VM by retiring it519 create_vm.mgmt.delete()520 create_vm.wait_for_vm_state_change(desired_state='archived',521 timeout=720,522 from_details=False,523 from_any_provider=True)524 else:525 # Orphan VM by removing provider from CFME526 provider.delete_if_exists(cancel=False)527 create_vm.wait_for_vm_state_change(desired_state='orphaned',528 timeout=720,529 from_details=False,530 from_any_provider=True)531 yield request.param, create_vm532@pytest.mark.meta(automates=[1655477, 1686015])533def test_power_options_on_archived_orphaned_vms_all_page(appliance, archive_orphan_vm):534 """This test case is to check Power option drop-down button is disabled on archived and orphaned535 VMs all page. Also it performs the power operations on vm and checked expected flash messages.536 Bugzilla:537 1655477538 1686015539 Polarion:540 assignee: prichard541 initialEstimate: 1/2h542 caseimportance: low543 caseposneg: positive544 testtype: functional545 startsin: 5.9546 casecomponent: Control547 tags: power548 testSteps:549 1. Add infrastructure provider550 2. Navigate to Archived or orphaned VMs all page551 3. Select any VM and click on power option drop-down552 """553 infra_vms = appliance.collections.infra_vms554 state, create_vm = archive_orphan_vm555 if state == "archived":556 view = navigate_to(infra_vms, 'ArchivedAll')557 # Selecting particular archived vm558 create_vm.find_quadicon(from_archived_all=True).ensure_checked()559 else:560 view = navigate_to(infra_vms, 'OrphanedAll')561 # Selecting particular orphaned vm562 create_vm.find_quadicon(from_orphaned_all=True).ensure_checked()563 # After selecting particular archived/orphaned vm; 'Power' drop down gets enabled.564 # Reading all the options available in 'power' drop down565 for action in view.toolbar.power.items:566 # Performing power actions on archived/orphaned vm567 view.toolbar.power.item_select(action, handle_alert=True)568 if action == 'Power On':569 action = 'Start'570 elif action == 'Power Off':571 action = 'Stop'572 view.flash.assert_message(f'{action} action does not apply to selected items')...

Full Screen

Full Screen

test_power_control_rest.py

Source:test_power_control_rest.py Github

copy

Full Screen

1import pytest2from cfme import test_requirements3from cfme.cloud.provider import CloudProvider4from cfme.cloud.provider.azure import AzureProvider5from cfme.cloud.provider.ec2 import EC2Provider6from cfme.cloud.provider.gce import GCEProvider7from cfme.infrastructure.provider import InfraProvider8from cfme.infrastructure.provider.rhevm import RHEVMProvider9from cfme.infrastructure.provider.scvmm import SCVMMProvider10from cfme.markers.env_markers.provider import providers11from cfme.utils.providers import ProviderFilter12from cfme.utils.wait import wait_for13pytestmark = [14 test_requirements.rest,15 pytest.mark.usefixtures('uses_infra_providers', 'uses_cloud_providers'),16 pytest.mark.tier(2),17 pytest.mark.provider([CloudProvider, InfraProvider], scope='module'),18 pytest.mark.parametrize("from_detail", [True, False], ids=["from_detail", "from_collection"]),19]20@pytest.fixture(scope='function')21def vm_name(create_vm):22 return create_vm.name23def wait_for_vm_state_change(create_vm, state):24 if create_vm.provider.one_of(GCEProvider, EC2Provider, SCVMMProvider):25 num_sec = 4000 # extra time for slow providers26 else:27 num_sec = 120028 create_vm.wait_for_power_state_change_rest(desired_state=state, timeout=num_sec)29def verify_vm_power_state(vm, state):30 vm.reload()31 return vm.power_state == state32def verify_action_result(rest_api, assert_success=True):33 assert rest_api.response.status_code == 20034 response = rest_api.response.json()35 if 'results' in response:36 response = response['results'][0]37 message = response['message']38 success = response['success']39 if assert_success:40 assert success41 return success, message42@pytest.mark.parametrize('create_vm', ['small_template'], indirect=True)43def test_stop_vm_rest(appliance, create_vm, ensure_vm_running, soft_assert, from_detail):44 """Test stop of vm45 Prerequisities:46 * An appliance with ``/api`` available.47 * VM48 Steps:49 * POST /api/vms/<id> (method ``stop``)50 OR51 * POST /api/vms (method ``stop``) with ``href`` of the vm or vms52 Metadata:53 test_flag: rest54 Polarion:55 assignee: pvala56 casecomponent: Rest57 caseimportance: high58 initialEstimate: 1/4h59 """60 rest_api = appliance.rest_api61 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_ON)62 vm = rest_api.collections.vms.get(name=create_vm.name)63 if from_detail:64 vm.action.stop()65 else:66 rest_api.collections.vms.action.stop(vm)67 verify_action_result(rest_api)68 wait_for_vm_state_change(create_vm, create_vm.STATE_OFF)69 soft_assert(not verify_vm_power_state(vm, create_vm.STATE_ON), "vm still running")70@pytest.mark.parametrize('create_vm', ['small_template'], indirect=True)71def test_start_vm_rest(appliance, create_vm, ensure_vm_stopped, soft_assert, from_detail):72 """Test start vm73 Prerequisities:74 * An appliance with ``/api`` available.75 * VM76 Steps:77 * POST /api/vms/<id> (method ``start``)78 OR79 * POST /api/vms (method ``start``) with ``href`` of the vm or vms80 Metadata:81 test_flag: rest82 Polarion:83 assignee: pvala84 casecomponent: Rest85 caseimportance: high86 initialEstimate: 1/4h87 """88 rest_api = appliance.rest_api89 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_OFF, timeout=1200)90 vm = rest_api.collections.vms.get(name=create_vm.name)91 if from_detail:92 vm.action.start()93 else:94 rest_api.collections.vms.action.start(vm)95 verify_action_result(rest_api)96 wait_for_vm_state_change(create_vm, create_vm.STATE_ON)97 soft_assert(verify_vm_power_state(vm, create_vm.STATE_ON), "vm not running")98@pytest.mark.parametrize('create_vm', ['small_template'], indirect=True)99def test_suspend_vm_rest(appliance, create_vm, ensure_vm_running, soft_assert, from_detail):100 """Test suspend vm101 Prerequisities:102 * An appliance with ``/api`` available.103 * VM104 Steps:105 * POST /api/vms/<id> (method ``suspend``)106 OR107 * POST /api/vms (method ``suspend``) with ``href`` of the vm or vms108 Metadata:109 test_flag: rest110 Polarion:111 assignee: pvala112 casecomponent: Rest113 caseimportance: high114 initialEstimate: 1/4h115 """116 rest_api = appliance.rest_api117 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_ON)118 vm = rest_api.collections.vms.get(name=create_vm.name)119 if from_detail:120 vm.action.suspend()121 else:122 rest_api.collections.vms.action.suspend(vm)123 success, message = verify_action_result(rest_api, assert_success=False)124 if create_vm.provider.one_of(GCEProvider, EC2Provider):125 assert success is False126 assert "not available" in message127 else:128 assert success129 wait_for_vm_state_change(create_vm, create_vm.STATE_SUSPENDED)130 soft_assert(verify_vm_power_state(vm, create_vm.STATE_SUSPENDED), "vm not suspended")131@pytest.mark.provider(132 gen_func=providers,133 filters=[ProviderFilter(classes=[CloudProvider, InfraProvider]),134 ProviderFilter(classes=[RHEVMProvider, AzureProvider], inverted=True)],135)136@pytest.mark.parametrize('create_vm', ['small_template'], indirect=True)137def test_reset_vm_rest(create_vm, ensure_vm_running, from_detail, appliance, provider):138 """139 Test reset vm140 Prerequisities:141 * An appliance with ``/api`` available.142 * VM143 Steps:144 * POST /api/vms/<id> (method ``reset``)145 OR146 * POST /api/vms (method ``reset``) with ``href`` of the vm or vms147 Metadata:148 test_flag: rest149 Polarion:150 assignee: pvala151 casecomponent: Rest152 caseimportance: high153 initialEstimate: 1/4h154 """155 rest_api = appliance.rest_api156 create_vm.wait_for_vm_state_change(desired_state=create_vm.STATE_ON)157 vm = rest_api.collections.vms.get(name=create_vm.name)158 old_date = vm.updated_on159 if from_detail:160 vm.action.reset()161 else:162 rest_api.collections.vms.action.reset(vm)163 success, message = verify_action_result(rest_api, assert_success=False)164 unsupported_providers = (GCEProvider, EC2Provider)165 if create_vm.provider.one_of(*unsupported_providers):166 assert success is False167 assert "not available" in message168 else:169 assert success170 wait_for(lambda: vm.updated_on >= old_date,...

Full Screen

Full Screen

observerVMTest.py

Source:observerVMTest.py Github

copy

Full Screen

...15 self.try_to_delete(Site, purge=True, name="testsite")16 def get_base_templates(self):17 return self.make_nodetemplate("testsite", "tosca.nodes.Site") + \18 self.make_nodetemplate("testsite_slice1", "tosca.nodes.Slice", reqs=[("testsite", "tosca.relationships.MemberOfSite")])19 def create_vm(self):20 self.assert_noobj(Instance, "test_compute1")21 self.execute(self.get_base_templates() +22 self.make_compute("testsite_slice1", "test_compute1", disk_size="1 GB", mem_size="513 MB"))23 instance = self.assert_obj(Instance, "test_compute1")24 assert(instance.flavor.name == "m1.small")25 # first pass makes the Networks26 self.run_model_policy(save_output="/tmp/instancetest:create_vm:model_policy_first")27 # second pass makes the NetworkControllers28 self.run_model_policy(save_output="/tmp/instancetest:create_vm:model_policy_second")29 # first observer pass should make any necessary networks or ports30 self.run_observer(save_output="/tmp/instancetest:create_vm:observer_first")31 # reset the exponential backoff32 instance = self.assert_obj(Instance, "test_compute1")33 instance.backend_register="{}"...

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 lisa 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