Ejemplo n.º 1
0
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 = explorer.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 = explorer.Action("Evaluate Alerts for {}".format(vm_name),
                                 "Evaluate Alerts", alerts)
        action.create()
        request.addfinalizer(action.delete)
        policy = explorer.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 = explorer.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))
Ejemplo n.º 2
0
def test_action_tag(request, assign_policy_for_testing, vm, vm_off,
                    vm_crud_refresh):
    """ Tests action tag

    Metadata:
        test_flag: actions, provision
    """
    if "Service Level: Gold" in vm.crud.get_tags():
        vm.crud.remove_tag(("Service Level", "Gold"))

    tag_assign_action = explorer.Action(
        fauxfactory.gen_alphanumeric(),
        action_type="Tag",
        action_values={"tag": ("My Company Tags", "Service Level", "Gold")})
    assign_policy_for_testing.assign_actions_to_event("VM Power On",
                                                      [tag_assign_action])

    @request.addfinalizer
    def finalize():
        assign_policy_for_testing.assign_events()
        tag_assign_action.delete()

    vm.start_vm()
    vm_crud_refresh()
    try:
        wait_for(lambda: "Service Level: Gold" in vm.crud.get_tags(),
                 num_sec=600,
                 message="tag presence check")
    except TimedOutError:
        pytest.fail("Tags were not assigned!")
Ejemplo n.º 3
0
def test_action_untag(request, assign_policy_for_testing, vm, vm_off, vm_crud_refresh):
    """ Tests action untag

    Metadata:
        test_flag: actions, provision
    """
    tag_unassign_action = explorer.Action(
        fauxfactory.gen_alphanumeric(),
        action_type="Remove Tags",
        action_values={"cat_service_level": True}
    )
    assign_policy_for_testing.assign_actions_to_event("VM Power On", [tag_unassign_action])

    def finalize():
        assign_policy_for_testing.assign_events()
        tag_unassign_action.delete()
    request.addfinalizer(finalize)

    vm.start_vm()
    vm_crud_refresh()
    try:
        wait_for(
            lambda: not any(
                [tag.category == "service_level" and tag.tag_name == "gold" for tag in vm.soap.tags]
            ),
            num_sec=600,
            message="tag presence check"
        )
    except TimedOutError:
        pytest.fail("Tags were not unassigned!")
Ejemplo n.º 4
0
def setup_for_alerts(request, alerts, event, vm_name, provider):
    """This function takes alerts and sets up CFME for testing it

    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_data
    """
    setup_provider(provider.key)
    alert_profile = explorer.VMInstanceAlertProfile(
        "Alert profile for %s" % vm_name, alerts)
    alert_profile.create()
    request.addfinalizer(alert_profile.delete)
    alert_profile.assign_to("The Enterprise")
    action = explorer.Action("Evaluate Alerts for %s" % vm_name,
                             "Evaluate Alerts", alerts)
    action.create()
    request.addfinalizer(action.delete)
    policy = explorer.VMControlPolicy(
        "Evaluate Alerts policy for %s" % vm_name,
        scope="fill_field(VM and Instance : Name, INCLUDES, %s)" % vm_name)
    policy.create()
    request.addfinalizer(policy.delete)
    policy_profile = explorer.PolicyProfile("Policy profile for %s" % vm_name,
                                            [policy])
    policy_profile.create()
    request.addfinalizer(policy_profile.delete)
    policy.assign_actions_to_event(event, [action])
    prov = Provider(provider.data["name"])
    prov.assign_policy_profiles(policy_profile.description)
Ejemplo n.º 5
0
def test_action_create_snapshots_and_delete_them(request,
                                                 assign_policy_for_testing, vm,
                                                 vm_on, vm_crud_refresh):
    """ This test tests actions 'Create a Snapshot' (custom) and 'Delete all Snapshots'.

    This test sets the policy that it makes snapshot of VM after it's powered off and then it cycles
    several time that it generates a couple of snapshots. Then the 'Delete all Snapshots' is
    assigned to power on event, VM is powered on and it waits for all snapshots to disappear.

    Metadata:
        test_flag: actions, provision
    """
    # Set up the policy and prepare finalizer
    snapshot_name = fauxfactory.gen_alphanumeric()
    snapshot_create_action = explorer.Action(
        fauxfactory.gen_alphanumeric(),
        action_type="Create a Snapshot",
        action_values={"snapshot_name": snapshot_name})
    assign_policy_for_testing.assign_actions_to_event("VM Power Off",
                                                      [snapshot_create_action])

    @request.addfinalizer
    def finalize():
        assign_policy_for_testing.assign_events()
        snapshot_create_action.delete()

    def create_one_snapshot(n):
        """
        Args:
            n: Sequential number of snapshot for logging.
        """
        # Power off to invoke snapshot creation
        snapshots_before = vm.crud.total_snapshots
        vm.stop_vm()
        vm_crud_refresh()
        wait_for(lambda: vm.crud.total_snapshots > snapshots_before,
                 num_sec=800,
                 message="wait for snapshot %d to appear" % (n + 1),
                 delay=5)
        assert vm.crud.current_snapshot_name == snapshot_name
        vm.start_vm()
        vm_crud_refresh()

    for i in range(4):
        create_one_snapshot(i)
    assign_policy_for_testing.assign_events()
    vm.stop_vm()
    vm_crud_refresh()
    assign_policy_for_testing.assign_actions_to_event("VM Power On",
                                                      ["Delete all Snapshots"])
    # Power on to invoke all snapshots deletion
    vm.start_vm()
    vm_crud_refresh()
    wait_for(lambda: vm.crud.total_snapshots == 0,
             num_sec=800,
             message="wait for snapshots to be deleted",
             delay=5)
Ejemplo n.º 6
0
def test_action_create_snapshot_and_delete_last(request,
                                                assign_policy_for_testing, vm,
                                                vm_on, vm_crud_refresh):
    """ This test tests actions 'Create a Snapshot' (custom) and 'Delete Most Recent Snapshot'.

    This test sets the policy that it makes snapshot of VM after it's powered off and when it is
    powered back on, it deletes the last snapshot.

    Metadata:
        test_flag: actions, provision
    """
    if not hasattr(vm.crud, "total_snapshots"):
        pytest.skip("This provider does not support snapshots yet!")
    # Set up the policy and prepare finalizer
    snapshot_name = fauxfactory.gen_alphanumeric()
    snapshot_create_action = explorer.Action(
        fauxfactory.gen_alphanumeric(),
        action_type="Create a Snapshot",
        action_values={"snapshot_name": snapshot_name})
    assign_policy_for_testing.assign_actions_to_event("VM Power Off",
                                                      [snapshot_create_action])
    assign_policy_for_testing.assign_actions_to_event(
        "VM Power On", ["Delete Most Recent Snapshot"])

    @request.addfinalizer
    def finalize():
        assign_policy_for_testing.assign_events()
        snapshot_create_action.delete()

    snapshots_before = vm.crud.total_snapshots
    # Power off to invoke snapshot creation
    vm.stop_vm()
    vm_crud_refresh()
    wait_for(lambda: vm.crud.total_snapshots > snapshots_before,
             num_sec=800,
             message="wait for snapshot appear",
             delay=5)
    assert vm.crud.current_snapshot_description == "Created by EVM Policy Action"
    assert vm.crud.current_snapshot_name == snapshot_name
    # Snapshot created and validated, so let's delete it
    snapshots_before = vm.crud.total_snapshots
    # Power on to invoke last snapshot deletion
    vm.start_vm()
    wait_for(lambda: vm.crud.total_snapshots < snapshots_before,
             num_sec=800,
             message="wait for snapshot deleted",
             delay=5)
Ejemplo n.º 7
0
def test_action_create_snapshots_and_delete_them(request, assign_policy_for_testing, vm, vm_on):
    """ This test tests actions 'Create a Snapshot' (custom) and 'Delete all Snapshots'.

    This test sets the policy that it makes snapshot of VM after it's powered off and then it cycles
    several time that it generates a couple of snapshots. Then the 'Delete all Snapshots' is
    assigned to power on event, VM is powered on and it waits for all snapshots to disappear.
    """
    if isinstance(vm.provider, mgmt_system.RHEVMSystem):
        pytest.skip("No snapshots on RHEV")
    # Set up the policy and prepare finalizer
    snapshot_name = generate_random_string()
    snapshot_create_action = explorer.Action(
        generate_random_string(),
        action_type="Create a Snapshot",
        action_values={"snapshot_name": snapshot_name}
    )
    assign_policy_for_testing.assign_actions_to_event("VM Power Off", [snapshot_create_action])

    def finalize():
        assign_policy_for_testing.assign_events()
        snapshot_create_action.delete()
    request.addfinalizer(finalize)

    def create_one_snapshot(n):
        """
        Args:
            n: Sequential number of snapshot for logging.
        """
        # Power off to invoke snapshot creation
        snapshots_before = vm.soap.ws_attributes["v_total_snapshots"]
        vm.stop_vm()
        wait_for(lambda: vm.soap.ws_attributes["v_total_snapshots"] > snapshots_before, num_sec=500,
            message="wait for snapshot %d to appear" % (n + 1), delay=5)
        assert vm.soap.ws_attributes["v_snapshot_newest_name"] == snapshot_name
        vm.start_vm()

    for i in range(4):
        create_one_snapshot(i)
    assign_policy_for_testing.assign_events()
    vm.stop_vm()
    assign_policy_for_testing.assign_actions_to_event("VM Power On", ["Delete all Snapshots"])
    # Power on to invoke all snapshots deletion
    vm.start_vm()
    wait_for(lambda: vm.soap.ws_attributes["v_total_snapshots"] == 0, num_sec=500,
        message="wait for snapshots to be deleted", delay=5)
Ejemplo n.º 8
0
def test_action_untag(request, assign_policy_for_testing, vm, vm_off,
                      vm_crud_refresh):
    """ Tests action untag

    Metadata:
        test_flag: actions, provision
    """
    if not any(tag.category.display_name == "Service Level"
               and tag.display_name == "Gold" for tag in vm.crud.get_tags()):
        vm.crud.add_tag(("Service Level", "Gold"), single_value=True)

    @request.addfinalizer
    def _remove_tag():
        if any(tag.category.display_name == "Service Level"
               and tag.display_name == "Gold" for tag in vm.crud.get_tags()):
            vm.crud.remove_tag(("Service Level", "Gold"))

    tag_unassign_action = explorer.Action(
        fauxfactory.gen_alphanumeric(),
        action_type="Remove Tags",
        action_values={"cat_service_level": True})
    assign_policy_for_testing.assign_actions_to_event("VM Power On",
                                                      [tag_unassign_action])

    @request.addfinalizer
    def finalize():
        assign_policy_for_testing.assign_events()
        tag_unassign_action.delete()

    vm.start_vm()
    vm_crud_refresh()
    try:

        wait_for(lambda: not any(tag.category.display_name == "Service Level"
                                 and tag.display_name == "Gold"
                                 for tag in vm.crud.get_tags()),
                 num_sec=600,
                 message="tag presence check")
    except TimedOutError:
        pytest.fail("Tags were not unassigned!")
Ejemplo n.º 9
0
def test_action_crud(request, soft_assert):
    action = explorer.Action(
        fauxfactory.gen_alphanumeric(),
        action_type="Tag",
        action_values={"tag": ("My Company Tags", "Department", "Accounting")})
    # CR
    action.create()
    soft_assert(action.exists,
                "The action {} does not exist!".format(action.description))
    # U
    with update(action):
        action.description = "w00t w00t"
    sel.force_navigate("control_explorer_action_edit",
                       context={"action_name": action.description})
    soft_assert(
        sel.get_attribute(action.form.description,
                          "value").strip() == "w00t w00t",
        "Modification failed!")
    # D
    action.delete()
    soft_assert(not action.exists,
                "The action {} exists!".format(action.description))
Ejemplo n.º 10
0
def test_action_create_snapshot_and_delete_last(request, assign_policy_for_testing, vm, vm_on):
    """ This test tests actions 'Create a Snapshot' (custom) and 'Delete Most Recent Snapshot'.

    This test sets the policy that it makes snapshot of VM after it's powered off and when it is
    powered back on, it deletes the last snapshot.
    """
    if isinstance(vm.provider, mgmt_system.RHEVMSystem):
        pytest.skip("No snapshots on RHEV")
    # Set up the policy and prepare finalizer
    snapshot_name = generate_random_string()
    snapshot_create_action = explorer.Action(
        generate_random_string(),
        action_type="Create a Snapshot",
        action_values={"snapshot_name": snapshot_name}
    )
    assign_policy_for_testing.assign_actions_to_event("VM Power Off", [snapshot_create_action])
    assign_policy_for_testing.assign_actions_to_event("VM Power On",
                                                      ["Delete Most Recent Snapshot"])

    def finalize():
        assign_policy_for_testing.assign_events()
        snapshot_create_action.delete()
    request.addfinalizer(finalize)

    snapshots_before = vm.soap.ws_attributes["v_total_snapshots"]
    # Power off to invoke snapshot creation
    vm.stop_vm()
    wait_for(lambda: vm.soap.ws_attributes["v_total_snapshots"] > snapshots_before, num_sec=500,
        message="wait for snapshot appear", delay=5)
    assert vm.soap.ws_attributes["v_snapshot_newest_description"] == "Created by EVM Policy Action"
    assert vm.soap.ws_attributes["v_snapshot_newest_name"] == snapshot_name
    # Snapshot created and validated, so let's delete it
    snapshots_before = vm.soap.ws_attributes["v_total_snapshots"]
    # Power on to invoke last snapshot deletion
    vm.start_vm()
    wait_for(lambda: vm.soap.ws_attributes["v_total_snapshots"] < snapshots_before, num_sec=500,
        message="wait for snapshot deleted", delay=5)
Ejemplo n.º 11
0
def test_action_untag(request, assign_policy_for_testing, vm, vm_off):
    tag_unassign_action = explorer.Action(
        generate_random_string(),
        action_type="Remove Tags",
        action_values={"cat_service_level": True}
    )
    assign_policy_for_testing.assign_actions_to_event("VM Power On", [tag_unassign_action])

    def finalize():
        assign_policy_for_testing.assign_events()
        tag_unassign_action.delete()
    request.addfinalizer(finalize)

    vm.start_vm()
    try:
        wait_for(
            lambda: not any(
                [tag.category == "service_level" and tag.tag_name == "gold" for tag in vm.soap.tags]
            ),
            num_sec=600,
            message="tag presence check"
        )
    except TimedOutError:
        pytest.fail("Tags were not unassigned!")