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

[WIP] Tests for grouping cluster candu graphs by tags #8677

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
75 changes: 59 additions & 16 deletions cfme/tests/candu/test_graph_groupbytag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from cfme import test_requirements
from cfme.common.candu_views import UtilizationZoomView
from cfme.infrastructure.provider import InfraProvider
from cfme.tests.candu import compare_data_with_unit
from cfme.utils.appliance.implementations.ui import navigate_to

Expand All @@ -12,40 +13,61 @@
test_requirements.c_and_u
]

HOST_GRAPHS = ['host_cpu',
'host_memory',
'host_disk',
'host_network',
'host_cpu_state']
GRAPHS = ['cpu',
'memory',
'disk',
'network',
'cpu_state']

INTERVAL = ['Hourly', 'Daily']

GROUP_BY = ['VM Location']

CANDU_VM = 'cu-24x7'

ENTITY = ['host', 'cluster']


@pytest.fixture(scope='function')
def host(temp_appliance_extended_db):
def entity_object(temp_appliance_extended_db, entity):
vm = temp_appliance_extended_db.rest_api.collections.vms.get(name=CANDU_VM)

vm_host = vm.host.name
return temp_appliance_extended_db.collections.hosts.instantiate(name=vm_host)
provider = temp_appliance_extended_db.rest_api.collections.providers.get(id=vm.ems_id)
provider_object = temp_appliance_extended_db.collections.infra_providers.instantiate(
InfraProvider, name=provider.name)
vm_object = temp_appliance_extended_db.collections.infra_vms.instantiate(
CANDU_VM, provider_object)
if entity == 'host':
return vm_object.host
elif entity == 'cluster':
return vm_object.cluster
"""
if entity == 'host':
vm_host = vm.host.name
return temp_appliance_extended_db.collections.hosts.instantiate(name=vm_host)
elif entity == 'cluster':
provider = temp_appliance_extended_db.rest_api.collections.providers.get(id=vm.ems_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required:
we have property for getting custer for specific vm

Copy link
Contributor

@jawatts jawatts Apr 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nachandr when we were looking at this the other day, we were using the entity object that was returned by the rest api. What @digitronik is suggesting here is to actually use the vm and cluster collections (this will use the GUI).

`In[17]: vm = appliance.collections.infra_vms.instantiate(name='cu-24x7', provider=vmwaretest)
In[18]: vm
Out[18]: InfraVm(name='cu-24x7', provider=VMwareProvider(endpoints={'default': <cfme.infrastructure.provider.virtualcenter.VirtualCenterEndpoint object at 0x7fdff3065650>}, name='vSphere 6.5 (nested)', key='vsphere65-nested', zone='default', start_ip='10.8.196.40', end_ip='10.8.196.40', provider_data=None), template_name=None)
In[19]: vm.cluster
Out[19]: Cluster(name=u'Cluster', provider=VMwareProvider(endpoints={'default': <cfme.infrastructure.provider.virtualcenter.VirtualCenterEndpoint object at 0x7fdff3065650>}, name='vSphere 6.5 (nested)', key='vsphere65-nested', zone='default', start_ip='10.8.196.40', end_ip='10.8.196.40', provider_data=None))

Nikhil and I did chat offline and this is slower with our current implementation. I think both ways work here.

provider_object = temp_appliance_extended_db.collections.infra_providers.instantiate(
InfraProvider, name=provider.name)
vm_object = temp_appliance_extended_db.collections.infra_vms.instantiate(
CANDU_VM, provider_object)
return vm_object.cluster
"""


@pytest.mark.parametrize('gp_by', GROUP_BY, ids=['vm_tag'])
@pytest.mark.parametrize('interval', INTERVAL)
@pytest.mark.parametrize('graph_type', HOST_GRAPHS)
def test_tagwise(candu_db_restore, interval, graph_type, gp_by, host):
@pytest.mark.parametrize('graph_type', GRAPHS)
@pytest.mark.parametrize('entity', ENTITY)
def test_tagwise(candu_db_restore, interval, graph_type, gp_by, entity, entity_object):
"""Tests for grouping host graphs by VM tag for hourly and Daily intervals

prerequisites:
* DB from an appliance on which C&U is enabled
* DB should have C&U data collection enabled for Tag category
* DB should have a VM tagged with proper tag category
* DB should have a VM and VM/host tagged with proper tag category

Steps:
* Navigate to Host Utilization Page
* Navigate to Host/Cluster Utilization Page
* Select interval(Hourly or Daily)
* Select group by option with VM tag
* Check graph displayed or not
Expand All @@ -61,21 +83,42 @@ def test_tagwise(candu_db_restore, interval, graph_type, gp_by, host):
initialEstimate: 1/4h
casecomponent: CandU
"""
view = navigate_to(host, 'candu')
if entity == 'host':
view = navigate_to(entity_object, 'candu')
elif entity == 'cluster':
view = navigate_to(entity_object, 'Utilization')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaaaaahhh this was my bad :). I think we need to use same name. TODO: need PR for this.

data = {'interval': interval, 'group_by': gp_by}
view.options.fill(data)

entity_graph = '{}_{}'.format(entity, graph_type)

# Check graph displayed or not
try:
graph = getattr(view.interval_type, graph_type)
if entity == 'host':
graph = getattr(view.interval_type, entity_graph)
elif entity == 'cluster':
graph = getattr(view, entity_graph)
except AttributeError:
pytest.fail('{} graph was not displayed'.format(graph_type))
pytest.fail('{} graph was not displayed'.format(entity_graph))
assert graph.is_displayed

# zoom in button not available with normal graph except Host and VM.
# We have to use vm or host average graph for zoom in operation.
if entity == 'cluster':
graph_zoom = ["cluster_host", "cluster_vm"]
enity_avg_graph = '{}_vm_host_avg'.format(entity_graph)
# entity_graph = entity + '_' + graph_type
avg_graph = entity_graph if entity_graph in graph_zoom else enity_avg_graph
try:
avg_graph = getattr(view, avg_graph)
except AttributeError:
pytest.fail('{} graph was not displayed'.format(entity_graph))

graph.zoom_in()
view = view.browser.create_view(UtilizationZoomView)

# check for chart and tag London available or not in legend list.
# wait, some time graph take time to load
view.flush_widget_cache()
assert view.chart.is_displayed
legends = view.chart.all_legends
Expand Down