def policy_profile(request):
    policy = VMControlPolicy(fauxfactory.gen_alpha())
    policy.create()
    request.addfinalizer(policy.delete)
    profile = PolicyProfile(fauxfactory.gen_alpha(), policies=[policy])
    profile.create()
    request.addfinalizer(profile.delete)
    return profile
示例#2
0
def create_policy(request):
    policy = VMControlPolicy(fauxfactory.gen_alpha())
    policy.create()

    @request.addfinalizer
    def _delete():
        while policy.exists:
            policy.delete()

    return policy
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))
示例#4
0
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")
示例#5
0
def create_policy_profile(request):
    random_string = fauxfactory.gen_alpha()
    policy = VMControlPolicy(random_string)
    policy.create()
    policy_profile = PolicyProfile(random_string, [policy])
    policy_profile.create()

    @request.addfinalizer
    def _delete():
        while policy_profile.exists:
            policy_profile.delete()
        if policy.exists:
            policy.delete()

    return policy_profile
def policy_for_testing(vmware_vm, provider, ansible_action):
    policy = VMControlPolicy(
        fauxfactory.gen_alpha(),
        scope="fill_field(VM and Instance : Name, INCLUDES, {})".format(
            vmware_vm.name))
    policy.create()
    policy.assign_actions_to_event("Tag Complete",
                                   [ansible_action.description])
    policy_profile = PolicyProfile(fauxfactory.gen_alpha(), policies=[policy])
    policy_profile.create()
    provider.assign_policy_profiles(policy_profile.description)
    yield
    policy.assign_events()
    provider.unassign_policy_profiles(policy_profile.description)
    policy_profile.delete()
    policy.delete()