예제 #1
0
def policy_for_testing(policy_name, policy_profile_name, provider):
    policy = HostCompliancePolicy(policy_name)
    policy.create()
    policy_profile = PolicyProfile(policy_profile_name, policies=[policy])
    policy_profile.create()
    yield policy
    policy_profile.delete()
    policy.delete()
예제 #2
0
def policy_for_testing(policy_name, policy_profile_name, provider):
    policy = HostCompliancePolicy(policy_name)
    policy.create()
    policy_profile = PolicyProfile(policy_profile_name, policies=[policy])
    policy_profile.create()
    yield policy
    policy_profile.delete()
    policy.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 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()
예제 #5
0
def test_check_compliance_history(request, virtualcenter_provider, vmware_vm):
    """This test checks if compliance history link in a VM details screen work.

    Steps:
        * Create any VM compliance policy
        * Assign it to a policy profile
        * Assign the policy profile to any VM
        * Perform the compliance check for the VM
        * Go to the VM details screen
        * Click on "History" row in Compliance InfoBox

    Result:
        Compliance history screen with last 10 checks should be opened
    """
    policy = VMCompliancePolicy(
        "Check compliance history policy {}".format(fauxfactory.gen_alpha()),
        active=True,
        scope="fill_field(VM and Instance : Name, INCLUDES, {})".format(
            vmware_vm.name))
    request.addfinalizer(lambda: policy.delete() if policy.exists else None)
    policy.create()
    policy_profile = PolicyProfile(policy.description, policies=[policy])
    request.addfinalizer(lambda: policy_profile.delete()
                         if policy_profile.exists else None)
    policy_profile.create()
    virtualcenter_provider.assign_policy_profiles(policy_profile.description)
    request.addfinalizer(lambda: virtualcenter_provider.
                         unassign_policy_profiles(policy_profile.description))
    vmware_vm.check_compliance()
    vmware_vm.open_details(["Compliance", "History"])
    appliance = get_or_create_current_appliance()
    history_screen_title = Text(appliance.browser.widgetastic,
                                "//span[@id='explorer_title_text']").text
    assert history_screen_title == '"Compliance History" for Virtual Machine "{}"'.format(
        vmware_vm.name)
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))
예제 #7
0
def test_check_compliance_history(request, virtualcenter_provider, vmware_vm):
    """This test checks if compliance history link in a VM details screen work.

    Steps:
        * Create any VM compliance policy
        * Assign it to a policy profile
        * Assign the policy profile to any VM
        * Perform the compliance check for the VM
        * Go to the VM details screen
        * Click on "History" row in Compliance InfoBox

    Result:
        Compliance history screen with last 10 checks should be opened
    """
    policy = VMCompliancePolicy(
        "Check compliance history policy {}".format(fauxfactory.gen_alpha()),
        active=True,
        scope="fill_field(VM and Instance : Name, INCLUDES, {})".format(vmware_vm.name)
    )
    request.addfinalizer(lambda: policy.delete() if policy.exists else None)
    policy.create()
    policy_profile = PolicyProfile(
        policy.description,
        policies=[policy]
    )
    request.addfinalizer(lambda: policy_profile.delete() if policy_profile.exists else None)
    policy_profile.create()
    virtualcenter_provider.assign_policy_profiles(policy_profile.description)
    request.addfinalizer(lambda: virtualcenter_provider.unassign_policy_profiles(
        policy_profile.description))
    vmware_vm.check_compliance()
    vmware_vm.open_details(["Compliance", "History"])
    appliance = get_or_create_current_appliance()
    history_screen_title = Text(appliance.browser.widgetastic,
        "//span[@id='explorer_title_text']").text
    assert history_screen_title == '"Compliance History" for Virtual Machine "{}"'.format(
        vmware_vm.name)
예제 #8
0
def test_scope_windows_registry_stuck(request, setup_a_provider):
    """If you provide Scope checking windows registry, it messes CFME up. Recoverable."""
    policy = VMCompliancePolicy(
        "Windows registry scope glitch testing Compliance Policy",
        active=True,
        scope=r"fill_registry(HKLM\SOFTWARE\Microsoft\CurrentVersion\Uninstall\test, "
        r"some value, INCLUDES, some content)"
    )
    request.addfinalizer(lambda: policy.delete() if policy.exists else None)
    policy.create()
    profile = PolicyProfile(
        "Windows registry scope glitch testing Compliance Policy",
        policies=[policy]
    )
    request.addfinalizer(lambda: profile.delete() if profile.exists else None)
    profile.create()
    # Now assign this malformed profile to a VM
    vm = VM.factory(Vm.get_first_vm_title(provider=setup_a_provider), setup_a_provider)
    vm.assign_policy_profiles(profile.description)
    # It should be screwed here, but do additional check
    navigate_to(Server, 'Dashboard')
    navigate_to(Vm, 'All')
    assert "except" not in pytest.sel.title().lower()
    vm.unassign_policy_profiles(profile.description)
예제 #9
0
def test_scope_windows_registry_stuck(request, infra_provider):
    """If you provide Scope checking windows registry, it messes CFME up. Recoverable."""
    policy = VMCompliancePolicy(
        "Windows registry scope glitch testing Compliance Policy",
        active=True,
        scope=r"fill_registry(HKLM\SOFTWARE\Microsoft\CurrentVersion\Uninstall\test, "
        r"some value, INCLUDES, some content)"
    )
    request.addfinalizer(lambda: policy.delete() if policy.exists else None)
    policy.create()
    profile = PolicyProfile(
        "Windows registry scope glitch testing Compliance Policy",
        policies=[policy]
    )
    request.addfinalizer(lambda: profile.delete() if profile.exists else None)
    profile.create()
    # Now assign this malformed profile to a VM
    vm = VM.factory(Vm.get_first_vm(provider=infra_provider).name, infra_provider)
    vm.assign_policy_profiles(profile.description)
    # It should be screwed here, but do additional check
    navigate_to(Server, 'Dashboard')
    navigate_to(Vm, 'All')
    assert "except" not in pytest.sel.title().lower()
    vm.unassign_policy_profiles(profile.description)