def test_check_files(request, compliance_vm, analysis_profile, condition_collection, policy_collection, policy_profile_collection): """This test checks presence and contents of a certain file. Due to caching, an existing file is checked. """ check_file_name = "/etc/hosts" check_file_contents = "127.0.0.1" condition = condition_collection.create( VMCondition, "Compliance testing condition {}".format(fauxfactory.gen_alphanumeric(8)), expression=("fill_find(VM and Instance.Files : Name, " "=, {}, Check Any, Contents, INCLUDES, {})".format( check_file_name, check_file_contents)) ) request.addfinalizer(lambda: diaper(condition.delete)) policy = policy_collection.create( VMCompliancePolicy, "Compliance {}".format(fauxfactory.gen_alphanumeric(8)) ) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = policy_profile_collection.create( "Compliance PP {}".format(fauxfactory.gen_alphanumeric(8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: compliance_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.files = [{"Name": check_file_name, "Collect Contents?": True}] do_scan(compliance_vm, ("Configuration", "Files")) compliance_vm.check_compliance() assert compliance_vm.compliant
def test_check_package_presence(request, compliance_vm, analysis_profile, policy_collection, policy_profile_collection, condition_collection): """This test checks compliance by presence of a certain "kernel" package which is expected to be present on the full_template.""" condition = condition_collection.create( VMCondition, "Compliance testing condition {}".format(fauxfactory.gen_alphanumeric(8)), expression=("fill_find(field=VM and Instance.Guest Applications : Name, " "skey=STARTS WITH, value=kernel, check=Check Count, ckey= = , cvalue=1)") ) request.addfinalizer(lambda: diaper(condition.delete)) policy = policy_collection.create( VMCompliancePolicy, "Compliance {}".format(fauxfactory.gen_alphanumeric(8)) ) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = policy_profile_collection.create( "Compliance PP {}".format(fauxfactory.gen_alphanumeric(8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: compliance_vm.unassign_policy_profiles(profile.description)) do_scan(compliance_vm) compliance_vm.check_compliance() assert compliance_vm.compliant
def test_check_files(request, compliance_vm, analysis_profile, condition_collection): """This test checks presence and contents of a certain file. Due to caching, an existing file is checked. """ check_file_name = "/etc/hosts" check_file_contents = "127.0.0.1" condition = condition_collection.create( VMCondition, "Compliance testing condition {}".format(fauxfactory.gen_alphanumeric(8)), expression=("fill_find(VM and Instance.Files : Name, " "=, {}, Check Any, Contents, INCLUDES, {})".format( check_file_name, check_file_contents)) ) request.addfinalizer(lambda: diaper(condition.delete)) policy = policy_collection.create( VMCompliancePolicy, "Compliance {}".format(fauxfactory.gen_alphanumeric(8)) ) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = policy_profile_collection.create( "Compliance PP {}".format(fauxfactory.gen_alphanumeric(8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: compliance_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.files = [{"Name": check_file_name, "Collect Contents?": True}] do_scan(compliance_vm, ("Configuration", "Files")) assert compliance_vm.check_compliance()
def test_check_package_presence(request, fleecing_vm, ssh_client, vm_analysis, analysis_profile): """This test checks compliance by presence of a certain cfme-appliance package which is expected to be present on an appliance.""" # TODO: If we step out from provisioning a full appliance for fleecing, this might need revisit condition = VMCondition( "Compliance testing condition {}".format( fauxfactory.gen_alphanumeric(8)), expression= ("fill_find(field=VM and Instance.Guest Applications : Name, " "skey=STARTS WITH, value=cfme-appliance, check=Check Count, ckey= = , cvalue=1)" )) request.addfinalizer(lambda: diaper(condition.delete)) policy = VMCompliancePolicy("Compliance {}".format( fauxfactory.gen_alphanumeric(8))) request.addfinalizer(lambda: diaper(policy.delete)) policy.create() policy.assign_conditions(condition) profile = PolicyProfile("Compliance PP {}".format( fauxfactory.gen_alphanumeric(8)), policies=[policy]) request.addfinalizer(lambda: diaper(profile.delete)) profile.create() fleecing_vm.assign_policy_profiles(profile.description) request.addfinalizer( lambda: fleecing_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.categories = [ "check_services", "check_accounts", "check_software", "check_vmconfig", "check_system" ] do_scan(fleecing_vm) assert fleecing_vm.check_compliance_and_wait()
def test_check_package_presence(request, compliance_vm, analysis_profile, policy_collection, policy_profile_collection, condition_collection): """This test checks compliance by presence of a certain "kernel" package which is expected to be present on the full_template.""" condition = condition_collection.create( VMCondition, "Compliance testing condition {}".format( fauxfactory.gen_alphanumeric(8)), expression= ("fill_find(field=VM and Instance.Guest Applications : Name, " "skey=STARTS WITH, value=kernel, check=Check Count, ckey= = , cvalue=1)" )) request.addfinalizer(lambda: diaper(condition.delete)) policy = policy_collection.create( VMCompliancePolicy, "Compliance {}".format(fauxfactory.gen_alphanumeric(8))) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = policy_profile_collection.create("Compliance PP {}".format( fauxfactory.gen_alphanumeric(8)), policies=[policy]) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer( lambda: compliance_vm.unassign_policy_profiles(profile.description)) do_scan(compliance_vm) assert compliance_vm.check_compliance()
def test_check_files(request, fleecing_vm, ssh_client, analysis_profile): """This test checks presence and contents of a certain file. Due to caching, an existing file is checked. """ check_file_name = "/etc/sudo.conf" check_file_contents = "sudoers_policy" # The file contains: `Plugin sudoers_policy sudoers.so` condition = VMCondition( "Compliance testing condition {}".format(fauxfactory.gen_alphanumeric(8)), expression=("fill_find(VM and Instance.Files : Name, " "=, {}, Check Any, Contents, INCLUDES, {})".format( check_file_name, check_file_contents)) ) request.addfinalizer(lambda: diaper(condition.delete)) policy = VMCompliancePolicy("Compliance {}".format(fauxfactory.gen_alphanumeric(8))) request.addfinalizer(lambda: diaper(policy.delete)) policy.create() policy.assign_conditions(condition) profile = PolicyProfile( "Compliance PP {}".format(fauxfactory.gen_alphanumeric(8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) profile.create() fleecing_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: fleecing_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.files = [(check_file_name, True)] analysis_profile.categories = [ "check_services", "check_accounts", "check_software", "check_vmconfig", "check_system"] do_scan(fleecing_vm, ("Configuration", "Files")) assert fleecing_vm.check_compliance_and_wait()
def test_check_package_presence(request, fleecing_vm, ssh_client, analysis_profile): """This test checks compliance by presence of a certain cfme-appliance package which is expected to be present on an appliance.""" # TODO: If we step out from provisioning a full appliance for fleecing, this might need revisit condition = VMCondition( "Compliance testing condition {}".format(fauxfactory.gen_alphanumeric(8)), expression=("fill_find(field=VM and Instance.Guest Applications : Name, " "skey=STARTS WITH, value=cfme-appliance, check=Check Count, ckey= = , cvalue=1)") ) request.addfinalizer(lambda: diaper(condition.delete)) policy = VMCompliancePolicy("Compliance {}".format(fauxfactory.gen_alphanumeric(8))) request.addfinalizer(lambda: diaper(policy.delete)) policy.create() policy.assign_conditions(condition) profile = PolicyProfile( "Compliance PP {}".format(fauxfactory.gen_alphanumeric(8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) profile.create() fleecing_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: fleecing_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.categories = [ "check_services", "check_accounts", "check_software", "check_vmconfig", "check_system"] do_scan(fleecing_vm) assert fleecing_vm.check_compliance_and_wait()
def test_check_files(request, appliance, compliance_vm, analysis_profile): """This test checks presence and contents of a certain file. Due to caching, an existing file is checked. Metadata: test_flag: provision, policy Bugzilla: 1730805 Polarion: assignee: jdupuy initialEstimate: 1/4h casecomponent: Control caseimportance: high """ check_file_name = "/etc/hosts" check_file_contents = "127.0.0.1" condition = appliance.collections.conditions.create( VMCondition, fauxfactory.gen_alphanumeric(40, start="Compliance testing condition "), expression=("fill_find(VM and Instance.Files : Name, " "=, {}, Check Any, Contents, INCLUDES, {})".format( check_file_name, check_file_contents))) request.addfinalizer(lambda: diaper(condition.delete)) policy = appliance.collections.policies.create( VMCompliancePolicy, fauxfactory.gen_alphanumeric(15, start="Compliance ")) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = appliance.collections.policy_profiles.create( fauxfactory.gen_alphanumeric(20, start="Compliance PP "), policies=[policy]) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer( lambda: compliance_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.files = [{ "Name": check_file_name, "Collect Contents?": True }] do_scan(compliance_vm, ("Configuration", "Files")) compliance_vm.check_compliance() assert compliance_vm.compliant
def fleecing_vm( request, compliance_vm, vm_analysis, provider_mgmt, provider_key, provider_crud, analysis_profile): logger.info("Provisioning an appliance for fleecing on {}".format(provider_key)) # TODO: When we get something smaller, use it! appliance = provision_appliance( vm_name_prefix=PREFIX + "for_fleece_", version=str(version.current_version()), provider_name=provider_key) request.addfinalizer(lambda: diaper(appliance.destroy)) logger.info("Appliance {} provisioned".format(appliance.vm_name)) vm = Vm(appliance.vm_name, provider_crud) provider_crud.refresh_provider_relationships() vm.wait_to_appear() # Assign the analysis profile action = Action( "Assign analysis profile {}".format(analysis_profile.name), "Assign Profile to Analysis Task", dict(analysis_profile=analysis_profile.name)) action.create() request.addfinalizer(action.delete) policy = VMControlPolicy("Analysis profile policy {}".format(generate_random_string())) policy.create() request.addfinalizer(policy.delete) policy.assign_actions_to_event("VM Analysis Start", action) analysis_pp = PolicyProfile( "Analysis profile PP {}".format(generate_random_string()), policies=[policy]) analysis_pp.create() request.addfinalizer(analysis_pp.delete) vm.assign_policy_profiles(analysis_pp.description) request.addfinalizer(lambda: vm.unassign_policy_profiles(analysis_pp.description)) return vm
def compliance_vm(request, provider_key, provider_crud): try: ip_addr = re.findall(r'[0-9]+(?:\.[0-9]+){3}', store.base_url)[0] appl_name = provider_crud.get_mgmt_system().get_vm_name_from_ip(ip_addr) appliance = Appliance(provider_key, appl_name) logger.info( "The tested appliance ({}) is already on this provider ({}) so reusing it.".format( appl_name, provider_key)) appliance.configure_fleecing() vm = Vm(appl_name, provider_crud) except VmNotFoundViaIP: logger.info("Provisioning a new appliance on provider {}.".format(provider_key)) appliance = provision_appliance( vm_name_prefix=PREFIX + "host_", version=str(version.current_version()), provider_name=provider_key) request.addfinalizer(lambda: diaper(appliance.destroy)) appliance.configure(setup_fleece=True) vm = Vm(appliance.vm_name, provider_crud) # Do the final touches with appliance.ipapp(browser_steal=True) as appl: appl.set_session_timeout(86400) provider_crud.refresh_provider_relationships() vm.wait_to_appear() vm.load_details() wait_for_ssa_enabled() yield vm
def _tag_item_through_selecting(request, location, tag): """Add a tag to an item with going through the details page. Prerequisities: * Have a tag category and tag created. * Be on the page you want to test. Steps: * Select any quadicon. * Select ``Policy/Edit Tags`` and assign the tag to it. * Click on the quadicon and verify the tag is assigned. (TODO) * Go back to the quadicon view and select ``Policy/Edit Tags`` and remove the tag. * Click on the quadicon and verify the tag is not present. (TODO) """ if not _navigate_and_check(location): pytest.skip("No Quadicon present, cannot test.") Quadicon.select_first_quad() def _delete(): # Ignoring the result of the check here _navigate_and_check(location) Quadicon.select_first_quad() mixins.remove_tag(tag) request.addfinalizer(lambda: diaper(_delete)) mixins.add_tag(tag) _delete()
def test_tag_item_through_details(request, location, tag): """Add a tag to an item.""" pytest.sel.force_navigate(location) tb.set_vms_grid_view() if not Quadicon.any_present: pytest.skip("No Quadicon present, cannot test.") pytest.sel.click(Quadicon.first()) request.addfinalizer(lambda: diaper(lambda: mixins.remove_tag(tag))) mixins.add_tag(tag) mixins.remove_tag(tag)
def test_check_package_presence(request, appliance, compliance_vm, analysis_profile): """This test checks compliance by presence of a certain "kernel" package which is expected to be present on the full_template. Metadata: test_flag: provision, policy Bugzilla: 1730805 Polarion: assignee: jdupuy initialEstimate: 1/4h casecomponent: Control caseimportance: high """ condition = appliance.collections.conditions.create( VMCondition, fauxfactory.gen_alphanumeric(40, start="Compliance testing condition "), expression= ("fill_find(field=VM and Instance.Guest Applications : Name, " "skey=STARTS WITH, value=kernel, check=Check Count, ckey= = , cvalue=1)" )) request.addfinalizer(lambda: diaper(condition.delete)) policy = appliance.collections.policies.create( VMCompliancePolicy, fauxfactory.gen_alphanumeric(15, start="Compliance ")) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = appliance.collections.policy_profiles.create( fauxfactory.gen_alphanumeric(20, start="Compliance PP "), policies=[policy]) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer( lambda: compliance_vm.unassign_policy_profiles(profile.description)) do_scan(compliance_vm) compliance_vm.check_compliance() assert compliance_vm.compliant
def fleecing_vm(request, compliance_vm, provider, analysis_profile): logger.info("Provisioning an appliance for fleecing on %s", provider.key) # TODO: When we get something smaller, use it! appliance = provision_appliance(vm_name_prefix=PREFIX + "for_fleece_", version=str(version.current_version()), provider_name=provider.key) request.addfinalizer(lambda: diaper(appliance.destroy)) logger.info("Appliance %s provisioned", appliance.vm_name) vm = VM.factory(appliance.vm_name, provider) provider.refresh_provider_relationships() vm.wait_to_appear() return vm
def fleecing_vm(request, compliance_vm, vm_analysis, provider_mgmt, provider_key, provider_crud, analysis_profile): logger.info("Provisioning an appliance for fleecing on {}".format(provider_key)) # TODO: When we get something smaller, use it! appliance = provision_appliance( vm_name_prefix=PREFIX + "for_fleece_", version=str(version.current_version()), provider_name=provider_key ) request.addfinalizer(lambda: diaper(appliance.destroy)) logger.info("Appliance {} provisioned".format(appliance.vm_name)) vm = Vm(appliance.vm_name, provider_crud) provider_crud.refresh_provider_relationships() vm.wait_to_appear() return vm
def test_check_files(request, fleecing_vm, ssh_client, check_file_name, analysis_profile): """This test checks presence and contents of a certain file. First the non-compliance is enforced by not having the file, then the compliance is checked against existing file and it is expected to be compliant. """ contents = generate_random_string(size=12) condition = VMCondition( "Compliance testing condition {}".format(generate_random_string(size=8)), expression=("fill_find(VM and Instance.Files : Name, " "=, {}, Check Any, Contents, INCLUDES, {})".format(check_file_name, contents)) ) request.addfinalizer(lambda: diaper(condition.delete)) policy = VMCompliancePolicy("Compliance {}".format(generate_random_string(size=8))) request.addfinalizer(lambda: diaper(policy.delete)) policy.create() policy.assign_conditions(condition) profile = PolicyProfile( "Compliance PP {}".format(generate_random_string(size=8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) profile.create() fleecing_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: fleecing_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.files = [("/root/*", True)] analysis_profile.categories = [ "check_services", "check_accounts", "check_software", "check_vmconfig", "check_system"] # Non-compliant ssh_client.run_command("rm -f {}".format(check_file_name)) do_scan(fleecing_vm) assert not fleecing_vm.check_compliance_and_wait() # Compliant ssh_client.run_command("echo {} > {}".format(contents, check_file_name)) do_scan(fleecing_vm) assert fleecing_vm.check_compliance_and_wait()
def fleecing_vm(request, compliance_vm, provider, analysis_profile): logger.info("Provisioning an appliance for fleecing on %s", provider.key) # TODO: When we get something smaller, use it! appliance = provision_appliance( vm_name_prefix=PREFIX + "for_fleece_", version=str(version.current_version()), provider_name=provider.key) request.addfinalizer(lambda: diaper(appliance.destroy)) logger.info("Appliance %s provisioned", appliance.vm_name) vm = VM.factory(appliance.vm_name, provider) provider.refresh_provider_relationships() vm.wait_to_appear() return vm
def test_check_package_presence(request, appliance, compliance_vm, analysis_profile): """This test checks compliance by presence of a certain "kernel" package which is expected to be present on the full_template. Metadata: test_flag: provision, policy Polarion: assignee: jdupuy initialEstimate: 1/4h casecomponent: Control caseimportance: high """ condition = appliance.collections.conditions.create( VMCondition, "Compliance testing condition {}".format(fauxfactory.gen_alphanumeric(8)), expression=("fill_find(field=VM and Instance.Guest Applications : Name, " "skey=STARTS WITH, value=kernel, check=Check Count, ckey= = , cvalue=1)") ) request.addfinalizer(lambda: diaper(condition.delete)) policy = appliance.collections.policies.create( VMCompliancePolicy, "Compliance {}".format(fauxfactory.gen_alphanumeric(8)) ) request.addfinalizer(lambda: diaper(policy.delete)) policy.assign_conditions(condition) profile = appliance.collections.policy_profiles.create( "Compliance PP {}".format(fauxfactory.gen_alphanumeric(8)), policies=[policy] ) request.addfinalizer(lambda: diaper(profile.delete)) compliance_vm.assign_policy_profiles(profile.description) request.addfinalizer(lambda: compliance_vm.unassign_policy_profiles(profile.description)) do_scan(compliance_vm) compliance_vm.check_compliance() assert compliance_vm.compliant
def test_check_files(request, fleecing_vm, ssh_client, analysis_profile): """This test checks presence and contents of a certain file. Due to caching, an existing file is checked. """ check_file_name = "/etc/sudo.conf" check_file_contents = "sudoers_policy" # The file contains: `Plugin sudoers_policy sudoers.so` condition = VMCondition( "Compliance testing condition {}".format( fauxfactory.gen_alphanumeric(8)), expression=("fill_find(VM and Instance.Files : Name, " "=, {}, Check Any, Contents, INCLUDES, {})".format( check_file_name, check_file_contents))) request.addfinalizer(lambda: diaper(condition.delete)) policy = VMCompliancePolicy("Compliance {}".format( fauxfactory.gen_alphanumeric(8))) request.addfinalizer(lambda: diaper(policy.delete)) policy.create() policy.assign_conditions(condition) profile = PolicyProfile("Compliance PP {}".format( fauxfactory.gen_alphanumeric(8)), policies=[policy]) request.addfinalizer(lambda: diaper(profile.delete)) profile.create() fleecing_vm.assign_policy_profiles(profile.description) request.addfinalizer( lambda: fleecing_vm.unassign_policy_profiles(profile.description)) with update(analysis_profile): analysis_profile.files = [(check_file_name, True)] analysis_profile.categories = [ "check_services", "check_accounts", "check_software", "check_vmconfig", "check_system" ] do_scan(fleecing_vm, ("Configuration", "Files")) assert fleecing_vm.check_compliance_and_wait()
def test_tag_item_through_selecting(request, location, tag): """Add a tag to an item.""" pytest.sel.force_navigate(location) tb.set_vms_grid_view() if not Quadicon.any_present: pytest.skip("No Quadicon present, cannot test.") Quadicon.select_first_quad() def _delete(): pytest.sel.force_navigate(location) tb.set_vms_grid_view() Quadicon.select_first_quad() mixins.remove_tag(tag) request.addfinalizer(lambda: diaper(_delete)) mixins.add_tag(tag) _delete()
def _tag_item_through_details(request, location, tag, appliance): """Add a tag to an item with going through the details page. Prerequisities: * Have a tag category and tag created. * Be on the page you want to test. Steps: * Click any quadicon. * On the details page, select ``Policy/Edit Tags`` and assign the tag to it. * Verify the tag is assigned. (TODO) * Select ``Policy/Edit Tags`` and remove the tag. * Verify the tag is not present. (TODO) """ entity = _navigate_and_check(location, appliance) entity.click() request.addfinalizer(lambda: diaper(lambda: mixins.remove_tag(tag))) mixins.add_tag(tag) mixins.remove_tag(tag)
def compliance_vm(request, provider): try: ip_addr = urlparse(store.base_url).hostname appl_name = provider.mgmt.get_vm_name_from_ip(ip_addr) appliance = Appliance(provider.key, appl_name) logger.info( "The tested appliance ({}) is already on this provider ({}) so reusing it." .format(appl_name, provider.key)) try: appliance.configure_fleecing() except (EOFError, ApplianceException) as e: # If something was happening, restart and wait for the UI to reappear to prevent errors appliance.ipapp.reboot() pytest.skip( "Error during appliance configuration. Skipping:\n{}: {}". format(type(e).__name__, str(e))) vm = Vm(appl_name, provider) except VmNotFoundViaIP: logger.info("Provisioning a new appliance on provider {}.".format( provider.key)) appliance = provision_appliance(vm_name_prefix=PREFIX + "host_", version=str(version.current_version()), provider_name=provider.key) request.addfinalizer(lambda: diaper(appliance.destroy)) try: appliance.configure(setup_fleece=True) except (EOFError, ApplianceException) as e: # Add known exceptions as needed. pytest.skip( "Error during appliance configuration. Skipping:\n{}: {}". format(type(e).__name__, str(e))) vm = Vm(appliance.vm_name, provider) if provider.type in {"rhevm"}: request.addfinalizer(appliance.remove_rhev_direct_lun_disk) # Do the final touches with appliance.ipapp(browser_steal=True) as appl: appl.set_session_timeout(86400) provider.refresh_provider_relationships() vm.wait_to_appear() vm.load_details() wait_for_ssa_enabled() yield vm
def test_tag_item_through_details(request, location, tag): """Add a tag to an item with going through the details page. Prerequisities: * Have a tag category and tag created. * Be on the page you want to test. Steps: * Click any quadicon. * On the details page, select ``Policy/Edit Tags`` and assign the tag to it. * Verify the tag is assigned. (TODO) * Select ``Policy/Edit Tags`` and remove the tag. * Verify the tag is not present. (TODO) """ if not navigate_and_check(location): pytest.skip("No Quadicon present, cannot test.") pytest.sel.click(Quadicon.first()) request.addfinalizer(lambda: diaper(lambda: mixins.remove_tag(tag))) mixins.add_tag(tag) mixins.remove_tag(tag)
def compliance_vm(request, provider): try: ip_addr = urlparse(store.base_url).hostname appl_name = provider.mgmt.get_vm_name_from_ip(ip_addr) appliance = Appliance(provider.key, appl_name) logger.info( "The tested appliance (%s) is already on this provider (%s) so reusing it.", appl_name, provider.key) try: appliance.configure_fleecing() except (EOFError, ApplianceException) as e: # If something was happening, restart and wait for the UI to reappear to prevent errors appliance.ipapp.reboot() pytest.skip( "Error during appliance configuration. Skipping:\n{}: {}".format( type(e).__name__, str(e))) vm = VM.factory(appl_name, provider) except exceptions.VMNotFoundViaIP: logger.info("Provisioning a new appliance on provider %s.", provider.key) appliance = provision_appliance( vm_name_prefix=PREFIX + "host_", version=str(version.current_version()), provider_name=provider.key) request.addfinalizer(lambda: diaper(appliance.destroy)) try: appliance.configure(setup_fleece=True) except (EOFError, ApplianceException) as e: # Add known exceptions as needed. pytest.skip( "Error during appliance configuration. Skipping:\n{}: {}".format( type(e).__name__, str(e))) vm = VM.factory(appliance.vm_name, provider) if provider.type in {"rhevm"}: request.addfinalizer(appliance.remove_rhev_direct_lun_disk) # Do the final touches with appliance.ipapp(browser_steal=True) as appl: appl.set_session_timeout(86400) provider.refresh_provider_relationships() vm.wait_to_appear() vm.load_details() wait_for_ssa_enabled() yield vm
def test_tag_item_through_details(request, location, tag): """Add a tag to an item with going through the details page. Prerequisities: * Have a tag category and tag created. * Be on the page you want to test. Steps: * Click any quadicon. * On the details page, select ``Policy/Edit Tags`` and assign the tag to it. * Verify the tag is assigned. (TODO) * Select ``Policy/Edit Tags`` and remove the tag. * Verify the tag is not present. (TODO) """ pytest.sel.force_navigate(location) tb.select('Grid View') if not Quadicon.any_present(): pytest.skip("No Quadicon present, cannot test.") pytest.sel.click(Quadicon.first()) request.addfinalizer(lambda: diaper(lambda: mixins.remove_tag(tag))) mixins.add_tag(tag) mixins.remove_tag(tag)
def at_exit(f, *args, **kwargs): """Diaper-protected atexit handler registering. Same syntax as atexit.register()""" return atexit.register(lambda: diaper(f, *args, **kwargs))
def test_diaper_callable(clean_diaper): store = {} diaper(explode_and_report, store, 'arg', key='value') assert diaper.smelly assert 'arg' in store['args'] assert store['kwargs'] == {'key': 'value'}
def test_diaper_autochange_func(dirty_diaper): # we should always start with a fresh diaper diaper(lambda: None) assert diaper.clean
def test_diaper_smell_func(clean_diaper): # If the diaper caught something, it should be smelly diaper(lambda: None [0]) assert diaper.smelly
def test_diaper_autochange_func(dirty_diaper): # we should always start with a fresh diaper diaper(lambda: None) assert not diaper.smelly
def test_diaper_smell_func(clean_diaper): # If the diaper caught something, it should be smelly diaper(lambda: None[0]) assert diaper.smelly