From 8be6ef7f22c4d191176972bcbc9518003e4f3c0d Mon Sep 17 00:00:00 2001 From: mnadeem92 Date: Tue, 22 Jan 2019 13:27:52 +0530 Subject: [PATCH] Adding Collection of Assignments Co-authored-by: Reuben Varghese " --- cfme/intelligence/chargeback/assignments.py | 61 +++++++++---------- cfme/tests/containers/test_chargeback.py | 17 +++--- .../test_chargeback_long_term_rates.py | 20 +++--- .../chargeback/test_resource_allocation.py | 24 ++++---- .../test_validate_chargeback_report.py | 40 ++++++------ .../test_chargeback_assignments.py | 27 +++++--- cfme/tests/ssui/test_ssui_dashboard.py | 20 +++--- entry_points.txt | 1 + 8 files changed, 113 insertions(+), 97 deletions(-) diff --git a/cfme/intelligence/chargeback/assignments.py b/cfme/intelligence/chargeback/assignments.py index 94d62ed450..596bf50fa4 100644 --- a/cfme/intelligence/chargeback/assignments.py +++ b/cfme/intelligence/chargeback/assignments.py @@ -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 @@ -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" ) @@ -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 ] ) @@ -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. @@ -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') @@ -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 @@ -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) diff --git a/cfme/tests/containers/test_chargeback.py b/cfme/tests/containers/test_chargeback.py index 11924603f2..03f4ee4eea 100644 --- a/cfme/tests/containers/test_chargeback.py +++ b/cfme/tests/containers/test_chargeback.py @@ -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 @@ -124,7 +124,7 @@ 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 @@ -132,7 +132,8 @@ def assign_custom_compute_rate(obj_type, chargeback_rate, provider): :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={ @@ -140,7 +141,8 @@ def assign_custom_compute_rate(obj_type, chargeback_rate, provider): }) 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} @@ -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="").assign() + appliance.collections.assignments.instantiate(assign_type="Compute", + assign_to="").assign() @pytest.fixture(scope='module') diff --git a/cfme/tests/intelligence/chargeback/test_chargeback_long_term_rates.py b/cfme/tests/intelligence/chargeback/test_chargeback_long_term_rates.py index b21732df6e..0911192ed0 100644 --- a/cfme/tests/intelligence/chargeback/test_chargeback_long_term_rates.py +++ b/cfme/tests/intelligence/chargeback/test_chargeback_long_term_rates.py @@ -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 @@ -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': ''} }) - enterprise.assign() + assign_obj.assign() + logger.info('Re-setting {} rate to '.format(assign_type)) def verify_records_rollups_table(appliance, provider): diff --git a/cfme/tests/intelligence/chargeback/test_resource_allocation.py b/cfme/tests/intelligence/chargeback/test_resource_allocation.py index 492b049e46..918c6bd0b3 100644 --- a/cfme/tests/intelligence/chargeback/test_resource_allocation.py +++ b/cfme/tests/intelligence/chargeback/test_resource_allocation.py @@ -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 @@ -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': ''} }) - enterprise.assign() + assign_obj.assign() + logger.info('Re-setting {} rate to '.format(assign_type)) def verify_vm_uptime(appliance, provider): @@ -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') diff --git a/cfme/tests/intelligence/reports/test_validate_chargeback_report.py b/cfme/tests/intelligence/reports/test_validate_chargeback_report.py index 94af17a5d8..bfd2f2f169 100644 --- a/cfme/tests/intelligence/reports/test_validate_chargeback_report.py +++ b/cfme/tests/intelligence/reports/test_validate_chargeback_report.py @@ -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 @@ -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': ''} }) - enterprise.assign() + assign_obj.assign() + logger.info('Re-setting {} rate to '.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': ''} }) - enterprise.assign() + assign_obj.assign() + logger.info('Re-setting {} rate to '.format(assign_type)) def verify_records_rollups_table(appliance, provider): diff --git a/cfme/tests/intelligence/test_chargeback_assignments.py b/cfme/tests/intelligence/test_chargeback_assignments.py index 1aac935fdb..01705e8901 100644 --- a/cfme/tests/intelligence/test_chargeback_assignments.py +++ b/cfme/tests/intelligence/test_chargeback_assignments.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import cfme.intelligence.chargeback.assignments as cb import pytest import random @@ -20,13 +19,15 @@ def test_assign_compute_enterprise(appliance, virtualcenter_provider): assignee: None initialEstimate: None """ - view = navigate_to(appliance.server, 'Chargeback') + view = navigate_to(appliance.server, 'Chargeback', wait_for_view=30) - enterprise = cb.ComputeAssign( + enterprise = appliance.collections.assignments.instantiate( + assign_type="Compute", assign_to="The Enterprise", selections={ 'Enterprise': {'Rate': 'Default'} - }) + } + ) enterprise.assign() # Assert that the selection made is listed on the UI @@ -44,7 +45,8 @@ def test_assign_compute_provider(appliance, virtualcenter_provider): """ view = navigate_to(appliance.server, 'Chargeback') - compute_provider = cb.ComputeAssign( + compute_provider = appliance.collections.assignments.instantiate( + assign_type="Compute", assign_to='Selected Providers', selections={ virtualcenter_provider.name: {'Rate': 'Default'} @@ -70,7 +72,8 @@ def test_assign_compute_cluster(appliance, virtualcenter_provider): cluster_name = "{}/{}".format(virtualcenter_provider.name, random.choice(virtualcenter_provider.data["clusters"])) - cluster = cb.ComputeAssign( + cluster = appliance.collections.assignments.instantiate( + assign_type="Compute", assign_to='Selected Cluster / Deployment Roles', selections={ cluster_name: {'Rate': 'Default'} @@ -94,7 +97,8 @@ def test_assign_compute_taggedvm(appliance, virtualcenter_provider): """ view = navigate_to(appliance.server, 'Chargeback') - tagged_vm = cb.ComputeAssign( + tagged_vm = appliance.collections.assignments.instantiate( + assign_type="Compute", assign_to="Tagged VMs and Instances", tag_category="Location", selections={ @@ -119,7 +123,8 @@ def test_assign_storage_enterprise(appliance, virtualcenter_provider): """ view = navigate_to(appliance.server, 'Chargeback') - enterprise = cb.StorageAssign( + enterprise = appliance.collections.assignments.instantiate( + assign_type="Storage", assign_to="The Enterprise", selections={ 'Enterprise': {'Rate': 'Default'} @@ -143,7 +148,8 @@ def test_assign_storage_datastores(appliance, virtualcenter_provider): datastore = random.choice(virtualcenter_provider.data["datastores"])["name"] - sel_datastore = cb.StorageAssign( + sel_datastore = appliance.collections.assignments.instantiate( + assign_type="Storage", assign_to="Selected Datastores", selections={ datastore: {'Rate': 'Default'} @@ -166,7 +172,8 @@ def test_assign_storage_tagged_datastores(appliance, virtualcenter_provider): """ view = navigate_to(appliance.server, 'Chargeback') - tagged_datastore = cb.StorageAssign( + tagged_datastore = appliance.collections.assignments.instantiate( + assign_type="Storage", assign_to="Tagged Datastores", tag_category="Location", selections={ diff --git a/cfme/tests/ssui/test_ssui_dashboard.py b/cfme/tests/ssui/test_ssui_dashboard.py index 2a55cad6cc..74a3fdde3a 100644 --- a/cfme/tests/ssui/test_ssui_dashboard.py +++ b/cfme/tests/ssui/test_ssui_dashboard.py @@ -4,7 +4,6 @@ import fauxfactory import pytest -import cfme.intelligence.chargeback.assignments as cb import cfme.intelligence.chargeback.rates as rates from cfme.infrastructure.provider import InfraProvider from cfme.infrastructure.provider.scvmm import SCVMMProvider @@ -52,26 +51,29 @@ def new_compute_rate(enable_candu): @pytest.fixture(scope="module") -def assign_chargeback_rate(new_compute_rate): +def assign_chargeback_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 - 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': new_compute_rate} }) - enterprise.assign() - logger.info('Assigning CUSTOM Compute and Storage rates') + 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': ''} }) - enterprise.assign() + assign_obj.assign() + logger.info('Re-setting {} rate to '.format(assign_type)) def verify_vm_uptime(appliance, provider, vmname): diff --git a/entry_points.txt b/entry_points.txt index 8f0d380427..6a9f346821 100644 --- a/entry_points.txt +++ b/entry_points.txt @@ -18,6 +18,7 @@ ansible_tower_job_templates = cfme.ansible_tower.explorer:AnsibleTowerJobTemplat ansible_tower_jobs = cfme.ansible_tower.jobs:TowerJobsCollection ansible_tower_providers = cfme.ansible_tower.explorer:AnsibleTowerProvidersCollection ansible_tower_systems = cfme.ansible_tower.explorer:AnsibleTowerSystemsCollection +assignments = cfme.intelligence.chargeback.assignments:AssignsCollection balancers = cfme.networks.balancer:BalancerCollection block_managers = cfme.storage.manager:BlockManagerCollection bottlenecks = cfme.optimize.bottlenecks:BottlenecksCollection