def test_control_crud_ansible_playbook_action(request, catalog_item): action = Action( fauxfactory.gen_alphanumeric(), action_type="Run Ansible Playbook", action_values={ "run_ansible_playbook": { "playbook_catalog_item": catalog_item.name, "inventory": { "target_machine": True } } } ) action.create() request.addfinalizer(action.delete_if_exists) with update(action): ipaddr = fauxfactory.gen_ipaddr() new_descr = "edited_{}".format(fauxfactory.gen_alphanumeric()) action.description = new_descr action.run_ansible_playbook = { "inventory": { "specific_hosts": True, "hosts": ipaddr } } view = navigate_to(action, "Edit") assert view.description.value == new_descr assert view.run_ansible_playbook.inventory.hosts.value == ipaddr action.delete()
def test_invoke_custom_automation(request): """This test tests a bug that caused the ``Invoke Custom Automation`` fields to disappear. Steps: * Go create new action, select Invoke Custom Automation * The form with additional fields should appear """ # The action is to have all possible fields filled, that way we can ensure it is good action = Action( fauxfactory.gen_alpha(), "Invoke a Custom Automation", dict( message=fauxfactory.gen_alpha(), request=fauxfactory.gen_alpha(), attribute_1=fauxfactory.gen_alpha(), value_1=fauxfactory.gen_alpha(), attribute_2=fauxfactory.gen_alpha(), value_2=fauxfactory.gen_alpha(), attribute_3=fauxfactory.gen_alpha(), value_3=fauxfactory.gen_alpha(), attribute_4=fauxfactory.gen_alpha(), value_4=fauxfactory.gen_alpha(), attribute_5=fauxfactory.gen_alpha(), value_5=fauxfactory.gen_alpha(),)) @request.addfinalizer def _delete_action(): if action.exists: action.delete() action.create()
def test_invoke_custom_automation(request): """This test tests a bug that caused the ``Invoke Custom Automation`` fields to disappear. Steps: * Go create new action, select Invoke Custom Automation * The form with additional fields should appear """ # The action is to have all possible fields filled, that way we can ensure it is good action = Action( fauxfactory.gen_alpha(), "Invoke a Custom Automation", dict( message=fauxfactory.gen_alpha(), request=fauxfactory.gen_alpha(), attribute_1=fauxfactory.gen_alpha(), value_1=fauxfactory.gen_alpha(), attribute_2=fauxfactory.gen_alpha(), value_2=fauxfactory.gen_alpha(), attribute_3=fauxfactory.gen_alpha(), value_3=fauxfactory.gen_alpha(), attribute_4=fauxfactory.gen_alpha(), value_4=fauxfactory.gen_alpha(), attribute_5=fauxfactory.gen_alpha(), value_5=fauxfactory.gen_alpha(),)) @request.addfinalizer def _delete_action(): if action.exists: action.delete() action.create()
def ansible_action(ansible_catalog_item): action = Action(fauxfactory.gen_alphanumeric(), action_type="Run Ansible Playbook", action_values={ "run_ansible_playbook": { "playbook_catalog_item": ansible_catalog_item.name } }) action.create() yield action action.delete()
def policy_profile(request, instance): collected_files = [ { "Name": "/etc/redhat-access-insights/machine-id", "Collect Contents?": True }, { "Name": ssa_expect_file, "Collect Contents?": True }, ] analysis_profile_name = 'ssa_analysis_{}'.format( fauxfactory.gen_alphanumeric()) analysis_profile = configuration.AnalysisProfile( name=analysis_profile_name, description=analysis_profile_name, profile_type='VM', categories=["check_system"], files=collected_files) if analysis_profile.exists: analysis_profile.delete() analysis_profile.create() request.addfinalizer(analysis_profile.delete) action = Action('ssa_action_{}'.format(fauxfactory.gen_alpha()), "Assign Profile to Analysis Task", dict(analysis_profile=analysis_profile_name)) if action.exists: action.delete() action.create() request.addfinalizer(action.delete) policy = VMControlPolicy('ssa_policy_{}'.format(fauxfactory.gen_alpha())) if policy.exists: policy.delete() policy.create() request.addfinalizer(policy.delete) policy.assign_events("VM Analysis Start") request.addfinalizer(policy.assign_events) policy.assign_actions_to_event("VM Analysis Start", action) profile = PolicyProfile('ssa_policy_profile_{}'.format( fauxfactory.gen_alpha()), policies=[policy]) if profile.exists: profile.delete() profile.create() request.addfinalizer(profile.delete) instance.assign_policy_profiles(profile.description) request.addfinalizer( lambda: instance.unassign_policy_profiles(profile.description))
def test_vm_create(request, vm_crud, provider, register_event): """ Test whether vm_create_complete event is emitted. Prerequisities: * A provider that is set up and able to deploy VMs Steps: * Create a Control setup (action, policy, profile) that apply a tag on a VM when ``VM Create Complete`` event comes * Deploy the VM outside of CFME (directly in the provider) * Refresh provider relationships and wait for VM to appear * Assert the tag appears. Metadata: test_flag: provision """ action = Action( fauxfactory.gen_alpha(), "Tag", dict(tag=("My Company Tags", "Environment", "Development"))) action.create() request.addfinalizer(action.delete) policy = VMControlPolicy(fauxfactory.gen_alpha()) policy.create() request.addfinalizer(policy.delete) policy.assign_events("VM Create Complete") request.addfinalizer(policy.assign_events) policy.assign_actions_to_event("VM Create Complete", action) profile = PolicyProfile(fauxfactory.gen_alpha(), policies=[policy]) profile.create() request.addfinalizer(profile.delete) provider.assign_policy_profiles(profile.description) request.addfinalizer( lambda: provider.unassign_policy_profiles(profile.description)) register_event(target_type='VmOrTemplate', target_name=vm_crud.name, event_type='vm_create') vm_crud.create_on_provider() provider.refresh_provider_relationships() vm_crud.wait_to_appear() def _check(): return any(tag.category.display_name == "Environment" and tag.display_name == "Development" for tag in vm_crud.get_tags()) wait_for(_check, num_sec=300, delay=15, message="tags to appear")
def test_vm_create(request, vm_crud, provider, register_event): """ Test whether vm_create_complete event is emitted. Prerequisities: * A provider that is set up and able to deploy VMs Steps: * Create a Control setup (action, policy, profile) that apply a tag on a VM when ``VM Create Complete`` event comes * Deploy the VM outside of CFME (directly in the provider) * Refresh provider relationships and wait for VM to appear * Assert the tag appears. Metadata: test_flag: provision """ action = Action( fauxfactory.gen_alpha(), "Tag", dict(tag=("My Company Tags", "Environment", "Development"))) action.create() request.addfinalizer(action.delete) policy = VMControlPolicy(fauxfactory.gen_alpha()) policy.create() request.addfinalizer(policy.delete) policy.assign_events("VM Create Complete") request.addfinalizer(policy.assign_events) policy.assign_actions_to_event("VM Create Complete", action) profile = PolicyProfile(fauxfactory.gen_alpha(), policies=[policy]) profile.create() request.addfinalizer(profile.delete) provider.assign_policy_profiles(profile.description) request.addfinalizer(lambda: provider.unassign_policy_profiles(profile.description)) event = EventBuilder(get_or_create_current_appliance()).new_event(target_type='VmOrTemplate', target_name=vm_crud.name, event_type='vm_create') register_event(event) vm_crud.create_on_provider() provider.refresh_provider_relationships() vm_crud.wait_to_appear() def _check(): return any(tag.category.display_name == "Environment" and tag.display_name == "Development" for tag in vm_crud.get_tags()) wait_for(_check, num_sec=300, delay=15, message="tags to appear")
def create_action(request): action = Action( fauxfactory.gen_alpha(), action_type="Tag", action_values={"tag": ("My Company Tags", "Department", "Accounting")}) action.create() @request.addfinalizer def _delete(): while action.exists: action.delete() return action
def create_action(request): action = Action( fauxfactory.gen_alpha(), action_type="Tag", action_values={"tag": ("My Company Tags", "Department", "Accounting")} ) action.create() @request.addfinalizer def _delete(): while action.exists: action.delete() return action
def policy_profile(request, instance): collected_files = [ {"Name": "/etc/redhat-access-insights/machine-id", "Collect Contents?": True}, {"Name": ssa_expect_file, "Collect Contents?": True}, ] analysis_profile_name = 'ssa_analysis_{}'.format(fauxfactory.gen_alphanumeric()) analysis_profile = configuration.AnalysisProfile(name=analysis_profile_name, description=analysis_profile_name, profile_type='VM', categories=["check_system"], files=collected_files) if analysis_profile.exists: analysis_profile.delete() analysis_profile.create() request.addfinalizer(analysis_profile.delete) action = Action( 'ssa_action_{}'.format(fauxfactory.gen_alpha()), "Assign Profile to Analysis Task", dict(analysis_profile=analysis_profile_name)) if action.exists: action.delete() action.create() request.addfinalizer(action.delete) policy = VMControlPolicy('ssa_policy_{}'.format(fauxfactory.gen_alpha())) if policy.exists: policy.delete() policy.create() request.addfinalizer(policy.delete) policy.assign_events("VM Analysis Start") request.addfinalizer(policy.assign_events) policy.assign_actions_to_event("VM Analysis Start", action) profile = PolicyProfile('ssa_policy_profile_{}'.format(fauxfactory.gen_alpha()), policies=[policy]) if profile.exists: profile.delete() profile.create() request.addfinalizer(profile.delete) instance.assign_policy_profiles(profile.description) request.addfinalizer(lambda: instance.unassign_policy_profiles(profile.description))
def test_control_add_ansible_playbook_action_invalid_address( request, catalog_item): action = Action(fauxfactory.gen_alphanumeric(), action_type="Run Ansible Playbook", action_values={ "run_ansible_playbook": { "playbook_catalog_item": catalog_item.name, "inventory": { "specific_hosts": True, "hosts": "invalid_address_!@#$%^&*" } } }) action.create() request.addfinalizer(action.delete_if_exists) assert action.exists view = navigate_to(action, "Edit") assert view.run_ansible_playbook.inventory.hosts.value == "invalid_address_!@#$%^&*"
def test_folder_field_scope(request, vmware_provider, vmware_vm): """This test tests the bug that makes the folder filter in expression not work. Prerequisities: * A VMware provider. * A VM on the provider. * A tag to assign. Steps: * Read the VM's 'Parent Folder Path (VMs & Templates)' from its summary page. * Create an action for assigning the tag to the VM. * Create a policy, for scope use ``Field``, field name ``VM and Instance : Parent Folder Path (VMs & Templates)``, ``INCLUDES`` and the folder name as stated on the VM's summary page. * Assign the ``VM Discovery`` event to the policy. * Assign the action to the ``VM Discovery`` event. * Create a policy profile and assign the policy to it. * Assign the policy profile to the provider. * Delete the VM from the CFME database. * Initiate provider refresh and wait for VM to appear again. * Assert that the VM gets tagged by the tag. """ # Retrieve folder location folder = None tags = vmware_vm.get_tags() if any(tag.category.display_name == "Parent Folder Path (VMs & Templates)" for tag in tags): folder = ', '.join( item.display_name for item in [tag for tag in tags if tag.category.display_name == "Parent Folder Path (VMs & Templates)"]) logger.info("Detected folder: %s", folder) else: pytest.fail("Could not read the folder from the tags:\n{}".format(repr(tags))) # Create Control stuff action = Action( fauxfactory.gen_alpha(), "Tag", dict(tag=("My Company Tags", "Service Level", "Platinum"))) action.create() request.addfinalizer(action.delete) policy = VMControlPolicy( fauxfactory.gen_alpha(), scope=( "fill_field(VM and Instance : Parent Folder Path (VMs & Templates), " "INCLUDES, {})".format(folder))) policy.create() request.addfinalizer(policy.delete) policy.assign_events("VM Discovery") request.addfinalizer(policy.assign_events) # Unassigns policy.assign_actions_to_event("VM Discovery", action) profile = PolicyProfile(fauxfactory.gen_alpha(), policies=[policy]) profile.create() request.addfinalizer(profile.delete) # Assign policy profile to the provider vmware_provider.assign_policy_profiles(profile.description) request.addfinalizer(lambda: vmware_provider.unassign_policy_profiles(profile.description)) # Delete and rediscover the VM vmware_vm.delete() vmware_vm.wait_for_delete() vmware_provider.refresh_provider_relationships() vmware_vm.wait_to_appear() # Wait for the tag to appear wait_for( vmware_vm.get_tags, num_sec=600, delay=15, fail_condition=lambda tags: not any( tag.category.display_name == "Service Level" and tag.display_name == "Platinum" for tag in tags), message="vm be tagged")