Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[WIP] Adding Collection of Assignments #8383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 28 additions & 33 deletions cfme/intelligence/chargeback/assignments.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
# Page model for Intel->Chargeback->Assignments.

from navmazing import NavigateToSibling, NavigateToAttribute
import attr
from navmazing import NavigateToAttribute
from widgetastic.widget import Text
from widgetastic_patternfly import BootstrapSelect, Button

from cfme.utils.appliance import Navigatable
from cfme.modeling.base import BaseCollection, BaseEntity
from cfme.utils.appliance.implementations.ui import navigator, navigate_to, CFMENavigateStep
from cfme.utils.pretty import Pretty
from cfme.utils.update import Updateable
from widgetastic_manageiq import Table
from widgetastic_manageiq.hacks import BootstrapSelectByLocator
Expand All @@ -20,8 +19,7 @@ class AssignmentsAllView(ChargebackView):
@property
def is_displayed(self):
return (
self.in_chargeback and
self.title.text == "All Assignments"
self.in_chargeback and self.title.text == "All Assignments"
)


Expand All @@ -35,11 +33,11 @@ def is_displayed(self):
return (
self.in_chargeback and
self.title.text == '{} Rate Assignments'.format(
self.context["object"].TYPE) and
self.context["object"].assign_type) and
self.assignments.is_opened and
self.assignments.tree.currently_selected == [
"Assignments",
self.context["object"].TYPE
self.context["object"].assign_type
]
)

Expand All @@ -56,7 +54,8 @@ def is_displayed(self):
)


class Assign(Updateable, Pretty, Navigatable):
@attr.s
class Assign(Updateable, BaseEntity):
"""
Model of Chargeback Assignment page in cfme.

Expand All @@ -69,24 +68,19 @@ class Assign(Updateable, Pretty, Navigatable):
providers the rate is to be assigned.

Usage:
enterprise = ComputeAssign(
assign_to="The Enterprise",
selections={
enterprise = appliance.collections.assignments.instantiate(
assign_to = "The Enterprise",
assign_type = "Compute", # or "Storage"
selections={
'Enterprise': {'Rate': 'Default'}
})
enterprise.assign()

enterprise.assign()
"""
def __init__(self, assign_to=None,
tag_category=None,
docker_labels=None,
selections=None,
appliance=None):
Navigatable.__init__(self, appliance=appliance)
self.assign_to = assign_to
self.tag_category = tag_category
self.docker_labels = docker_labels
self.selections = selections
assign_to = attr.ib()
assign_type = attr.ib()
tag_category = attr.ib(default=None)
docker_labels = attr.ib(default=None)
selections = attr.ib(default=None)

def assign(self):
view = navigate_to(self, 'Details')
Expand All @@ -107,15 +101,15 @@ def _fill(self, view):
return view.fill(fill_details)


class ComputeAssign(Assign):
TYPE = "Compute"
@attr.s
class AssignsCollection(BaseCollection):
"""Collection object for the
:py:class:'cfme.intelligence.chargeback.assignments.Assign'."""

ENTITY = Assign

class StorageAssign(Assign):
TYPE = "Storage"


@navigator.register(Assign, 'All')
@navigator.register(AssignsCollection, "All")
class AssignAll(CFMENavigateStep):
prerequisite = NavigateToAttribute('appliance.server', 'IntelChargeback')
VIEW = AssignmentsAllView
Expand All @@ -125,9 +119,10 @@ def step(self):


@navigator.register(Assign, 'Details')
class AssignStorage(CFMENavigateStep):
prerequisite = NavigateToSibling('All')
class AssignDetails(CFMENavigateStep):
prerequisite = NavigateToAttribute('parent', 'All')
VIEW = AssignmentsView

def step(self):
self.view.assignments.tree.click_path("Assignments", self.obj.TYPE)

self.view.assignments.tree.click_path("Assignments", self.obj.assign_type)
17 changes: 10 additions & 7 deletions cfme/tests/containers/test_chargeback.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest

from cfme.containers.provider import ContainersProvider
from cfme.intelligence.chargeback import assignments, rates
from cfme.intelligence.chargeback import rates

from cfme.utils.log import logger
from cfme.utils.units import CHARGEBACK_HEADER_NAMES, parse_number
Expand Down Expand Up @@ -124,23 +124,25 @@ def gen_report_base(appliance, obj_type, provider, rate_desc, rate_interval):
return report


def assign_custom_compute_rate(obj_type, chargeback_rate, provider):
def assign_custom_compute_rate(appliance, obj_type, chargeback_rate, provider):
"""Assign custom Compute rate for Labeled Container Images
Args:
:py:type:`str` obj_type: Object being tested; only 'Project' and 'Image' are supported
:py:class:`ComputeRate` chargeback_rate: The chargeback rate object
:py:class:`ContainersProvider` provider: The containers provider
"""
if obj_type == 'Image':
compute_assign = assignments.ComputeAssign(
compute_assign = appliance.collections.assignments.instantiate(
assign_type="Compute",
assign_to="Labeled Container Images",
docker_labels="architecture",
selections={
'x86_64': {'Rate': chargeback_rate.description}
})
logger.info('ASSIGNING COMPUTE RATE FOR LABELED CONTAINER IMAGES')
elif obj_type == 'Project':
compute_assign = assignments.ComputeAssign(
compute_assign = appliance.collections.assignments.instantiate(
assign_type="Compute",
assign_to="Selected Providers",
selections={
provider.name: {'Rate': chargeback_rate.description}
Expand Down Expand Up @@ -182,10 +184,11 @@ def compute_rate(appliance, rate_type, interval):


@pytest.fixture(scope='module')
def assign_compute_rate(obj_type, compute_rate, provider):
assign_custom_compute_rate(obj_type, compute_rate, provider)
def assign_compute_rate(appliance, obj_type, compute_rate, provider):
assign_custom_compute_rate(appliance, obj_type, compute_rate, provider)
yield compute_rate
assignments.ComputeAssign(assign_to="<Nothing>").assign()
appliance.collections.assignments.instantiate(assign_type="Compute",
assign_to="<Nothing>").assign()


@pytest.fixture(scope='module')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import pytest
from wrapanapi import VmState

import cfme.intelligence.chargeback.assignments as cb
import cfme.intelligence.chargeback.rates as rates
from cfme import test_requirements
from cfme.base.credential import Credential
Expand Down Expand Up @@ -97,28 +96,31 @@ def enable_candu(appliance):


@pytest.fixture(scope="module")
def assign_custom_rate(new_compute_rate):
def assign_custom_rate(appliance, new_compute_rate):
"""Assign custom Compute rate to the Enterprise and then queue the Chargeback report."""
description = new_compute_rate
# TODO Move this to a global fixture
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': description}
})
enterprise.assign()
logger.info('Assigning CUSTOM Compute rate')
assign_obj.assign()
logger.info('Assigning CUSTOM {} rate'.format(assign_type))
yield

# Resetting the Chargeback rate assignment
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': '<Nothing>'}
})
enterprise.assign()
assign_obj.assign()
logger.info('Re-setting {} rate to <Nothing>'.format(assign_type))


def verify_records_rollups_table(appliance, provider):
Expand Down
24 changes: 13 additions & 11 deletions cfme/tests/intelligence/chargeback/test_resource_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import pytest
from wrapanapi import VmState

import cfme.intelligence.chargeback.assignments as cb
import cfme.intelligence.chargeback.rates as rates
from cfme import test_requirements
from cfme.base.credential import Credential
Expand Down Expand Up @@ -115,28 +114,31 @@ def enable_candu(provider, appliance):


@pytest.yield_fixture(scope="module")
def assign_custom_rate(new_chargeback_rate, provider):
def assign_custom_rate(appliance, new_chargeback_rate):
"""Assign custom Compute rate to the Enterprise and then queue the Chargeback report."""
description = new_chargeback_rate
# TODO Move this to a global fixture
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': description}
})
enterprise.assign()
logger.info('Assigning CUSTOM Compute rate')
assign_obj.assign()
logger.info('Assigning CUSTOM {} rate'.format(assign_type))
yield

# Resetting the Chargeback rate assignment
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': '<Nothing>'}
})
enterprise.assign()
assign_obj.assign()
logger.info('Re-setting {} rate to <Nothing>'.format(assign_type))


def verify_vm_uptime(appliance, provider):
Expand Down Expand Up @@ -435,8 +437,8 @@ def generic_test_resource_alloc(resource_alloc, chargeback_report_custom, column
allocated_resource = resource_alloc[resource]
if 'GB' in chargeback_report_custom[0][column] and column == 'Memory Allocated over Time Period':
allocated_resource = allocated_resource * math.pow(2, -10)
resource_from_report = chargeback_report_custom[0][column].replace('MB', '').replace('GB', ''). \
replace(' ', '')
resource_from_report = chargeback_report_custom[0][column].replace('MB', ''). \
replace('GB', '').replace(' ', '')
soft_assert(allocated_resource - RESOURCE_ALLOC_DEVIATION <=
float(resource_from_report) <= allocated_resource + RESOURCE_ALLOC_DEVIATION,
'Estimated resource allocation and report resource allocation do not match')
Expand Down
40 changes: 22 additions & 18 deletions cfme/tests/intelligence/reports/test_validate_chargeback_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import math
import re
from datetime import date
from functools import partial

import fauxfactory
import pytest

import cfme.intelligence.chargeback.assignments as cb
import cfme.intelligence.chargeback.rates as rates
from cfme import test_requirements
from cfme.base.credential import Credential
Expand Down Expand Up @@ -125,54 +123,60 @@ def enable_candu(provider, appliance):


@pytest.fixture(scope="module")
def assign_default_rate(provider):
def assign_default_rate(appliance, provider):
# Assign default Compute rate to the Enterprise and then queue the Chargeback report.
# TODO Move this to a global fixture
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': 'Default'}
})
enterprise.assign()
logger.info('Assigning DEFAULT Compute rate')
assign_obj.assign()
logger.info('Assigning Default {} rate'.format(assign_type))

yield

# Resetting the Chargeback rate assignment
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': '<Nothing>'}
})
enterprise.assign()
assign_obj.assign()
logger.info('Re-setting {} rate to <Nothing>'.format(assign_type))


@pytest.fixture(scope="module")
def assign_custom_rate(new_compute_rate, provider):
def assign_custom_rate(appliance, new_compute_rate):
# Assign custom Compute rate to the Enterprise and then queue the Chargeback report.
# TODO Move this to a global fixture
description = new_compute_rate
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': description}
})
enterprise.assign()
logger.info('Assigning CUSTOM Compute rate')
assign_obj.assign()
logger.info('Assigning CUSTOM {} rate'.format(assign_type))

yield

# Resetting the Chargeback rate assignment
for klass in (cb.ComputeAssign, cb.StorageAssign):
enterprise = klass(
for assign_type in ("Compute", "Storage"):
assign_obj = appliance.collections.assignments.instantiate(
assign_type=assign_type,
assign_to="The Enterprise",
selections={
'Enterprise': {'Rate': '<Nothing>'}
})
enterprise.assign()
assign_obj.assign()
logger.info('Re-setting {} rate to <Nothing>'.format(assign_type))


def verify_records_rollups_table(appliance, provider):
Expand Down
Loading