def test_policy_profile_crud(random_vm_control_policy, random_host_control_policy): profile = policy_profiles.PolicyProfile( fauxfactory.gen_alphanumeric(), policies=[random_vm_control_policy, random_host_control_policy]) profile.create() with update(profile): profile.notes = "Modified!" profile.delete()
def policy_for_testing_for_vm_big(automate_role_set, vm_big, policy_name, policy_profile_name, provider): """ Takes care of setting the appliance up for testing """ policy = policies.VMControlPolicy( policy_name, scope="fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_big.name)) policy.create() policy_profile = policy_profiles.PolicyProfile(policy_profile_name, policies=[policy]) policy_profile.create() yield policy policy_profile.delete() policy.delete()
def policy_for_testing(vm_name, policy_name, policy_profile_name, provider): """Takes care of setting the appliance up for testing.""" policy = policies.VMControlPolicy( policy_name, scope="fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_name)) policy.create() policy_profile = policy_profiles.PolicyProfile(policy_profile_name, policies=[policy]) policy_profile.create() provider.assign_policy_profiles(policy_profile_name) yield policy provider.unassign_policy_profiles(policy_profile_name) policy_profile.delete() policy.delete()
def policy_for_testing(provider, vm_name, policy_name, policy_profile_name, compliance_policy, compliance_condition): control_policy = policies.VMControlPolicy( policy_name, scope="fill_field(VM and Instance : Name, INCLUDES, {})".format( vm_name)) control_policy.create() policy_profile = policy_profiles.PolicyProfile( policy_profile_name, policies=[control_policy, compliance_policy]) policy_profile.create() provider.assign_policy_profiles(policy_profile_name) yield control_policy provider.unassign_policy_profiles(policy_profile_name) policy_profile.delete() compliance_policy.assign_conditions() compliance_condition.delete() compliance_policy.delete() control_policy.delete()
def setup_for_alerts(request, alerts, event=None, vm_name=None, provider=None): """This function takes alerts and sets up CFME for testing it. If event and further args are not specified, it won't create the actions and policy profiles. Args: request: py.test funcarg request alerts: Alert objects event: Event to hook on (VM Power On, ...) vm_name: VM name to use for policy filtering provider: funcarg provider """ alert_profile = alert_profiles.VMInstanceAlertProfile( "Alert profile for {}".format(vm_name), alerts ) alert_profile.create() request.addfinalizer(alert_profile.delete) alert_profile.assign_to("The Enterprise") if event is not None: action = actions.Action( "Evaluate Alerts for {}".format(vm_name), "Evaluate Alerts", action_values={"alerts_to_evaluate": alerts} ) action.create() request.addfinalizer(action.delete) policy = policies.VMControlPolicy( "Evaluate Alerts policy for {}".format(vm_name), scope="fill_field(VM and Instance : Name, INCLUDES, {})".format(vm_name) ) policy.create() request.addfinalizer(policy.delete) policy_profile = policy_profiles.PolicyProfile( "Policy profile for {}".format(vm_name), [policy] ) policy_profile.create() request.addfinalizer(policy_profile.delete) policy.assign_actions_to_event(event, [action]) provider.assign_policy_profiles(policy_profile.description) request.addfinalizer(lambda: provider.unassign_policy_profiles(policy_profile.description))