Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.
Merged
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
29 changes: 22 additions & 7 deletions cfme/infrastructure/virtual_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from cfme.common import BaseLoggedInPage
from cfme.common import ComparableMixin
from cfme.common import CompareView
from cfme.common import TimelinesView
from cfme.common.provider_views import TemplatesCompareView
from cfme.common.vm import Template
Expand All @@ -49,6 +50,7 @@
from cfme.exceptions import DestinationNotFound
from cfme.exceptions import displayed_not_implemented
from cfme.exceptions import ItemNotFound
from cfme.exceptions import ToolbarOptionGreyedOrUnavailable
from cfme.services.requests import RequestsView
from cfme.utils.appliance.implementations.ui import CFMENavigateStep
from cfme.utils.appliance.implementations.ui import navigate_to
Expand Down Expand Up @@ -491,7 +493,7 @@ class InfraVmSnapshotAddView(InfraVmView):


class InfraVmGenealogyToolbar(View):
"""The toolbar on the genalogy page"""
"""The toolbar on the genealogy page"""
history = Dropdown(title='History')
reload = Button(title='Refresh this page')
edit_tags = Button(title='Edit Tags for this VM')
Expand All @@ -512,6 +514,16 @@ def is_displayed(self):
return self.in_infra_vms and self.title.text == expected_title


class InfraVmCompareView(CompareView):
@property
def is_displayed(self):
title = "Compare VM or Template"
return (self.title.text == title and
self.navigation.currently_selected == ['Compute',
'Infrastructure', 'Virtual Machines']
)


class VMDisk(
namedtuple('VMDisk', ['filename', 'size', 'size_unit', 'type', 'mode'])):
"""Represents a single VM disk
Expand Down Expand Up @@ -1404,27 +1416,30 @@ def compare(self, *objects, **kwargs):
attributes: `all`, `different` or `same`. Default: `all`.
mode: `exists` or `details`. Default: `exists`."""
sections = kwargs.get('sections')
attributes = kwargs.get('attributes', 'all').lower()
mode = kwargs.get('mode', 'exists').lower()
assert len(objects) >= 2, 'You must specify at least two objects'
objects = [o.name if isinstance(o, (InfraVm, InfraTemplate)) else o for o in objects]
view = self.navigate()
for obj in objects:
if not isinstance(obj, list):
path = find_path(view.tree, obj)
view.tree.check_node(*path)
if view.toolbar.compare.disabled:
raise ToolbarOptionGreyedOrUnavailable("The compare button is greyed out or disabled")
view.toolbar.compare.click()
view.flash.assert_no_errors()
compare_view = self.obj.create_view(InfraVmCompareView, wait=20)
compare_view.flash.assert_no_error()
# COMPARE PAGE
compare_view = self.obj.create_view('Compare')

if sections is not None:
list(map(lambda path: compare_view.tree.check_node(*path), sections))
compare_view.apply.click()
compare_view.flash.assert_no_errors()
# Set requested attributes sets
getattr(compare_view.toolbar, self.attr_mapping[attributes]).click()
getattr(compare_view.toolbar, "all_attributes").click()
# Set the requested mode
getattr(compare_view.toolbar, self.mode_mapping[mode]).click()
getattr(compare_view.toolbar, "exists_mode").click()

return compare_view

@property
def tree(self):
Expand Down
72 changes: 37 additions & 35 deletions cfme/tests/cloud_infra_common/test_genealogy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import fauxfactory
import pytest
from wait_for import wait_for

from cfme import test_requirements
from cfme.cloud.provider import CloudProvider
from cfme.common.provider import BaseProvider
from cfme.containers.provider.openshift import OpenshiftProvider
from cfme.exceptions import ToolbarOptionGreyedOrUnavailable
from cfme.infrastructure.provider.rhevm import RHEVMProvider
from cfme.infrastructure.provider.scvmm import SCVMMProvider
from cfme.infrastructure.provider.virtualcenter import VMwareProvider
from cfme.markers.env_markers.provider import providers
from cfme.utils.appliance.implementations.ui import navigate_to
from cfme.utils.generators import random_vm_name
from cfme.utils.log import logger
from cfme.utils.providers import ProviderFilter

Expand All @@ -22,6 +27,29 @@
scope='module'),
test_requirements.genealogy
]


@pytest.fixture
def create_vm_with_clone(request, create_vm, provider, appliance):
"""Fixture to provision a VM and clone it"""
first_name = fauxfactory.gen_alphanumeric()
last_name = fauxfactory.gen_alphanumeric()
email = "{first_name}.{last_name}@test.com"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want to use f-sting here. Other thought fauxfactory.gen_email()

provision_type = 'VMware'

vm_name = random_vm_name(context=None, max_length=15)

create_vm.clone_vm(email, first_name, last_name, vm_name, provision_type)
vm2 = appliance.collections.infra_vms.instantiate(vm_name, provider)
wait_for(lambda: vm2.exists, timeout=120)

@request.addfinalizer
def _cleanup():
vm2.cleanup_on_provider()
provider.refresh_provider_relationships()

return create_vm, vm2

# uncollected above in pytest_generate_tests
@pytest.mark.parametrize("from_edit", [True, False], ids=["via_edit", "via_summary"])
@pytest.mark.uncollectif(lambda provider, from_edit:
Expand Down Expand Up @@ -72,11 +100,11 @@ def test_vm_genealogy_detected(
f"{small_template.name} is not in {create_vm.name}'s ancestors"


@pytest.mark.manual
@pytest.mark.provider([VMwareProvider])
@pytest.mark.tier(1)
def test_compare_button_enabled():
def test_genealogy_comparison(create_vm_with_clone, soft_assert):
"""
Test that compare button is enabled
Test that compare button is enabled and the compare page is loaded when 2 VM's are compared

Polarion:
assignee: spusater
Expand All @@ -97,36 +125,10 @@ def test_compare_button_enabled():
Bugzilla:
1694712
"""
pass


@pytest.mark.manual
@pytest.mark.tier(2)
def test_cloud_infra_genealogy():
"""
Edit infra vm and cloud instance
When editing cloud instance, genealogy should be present on the edit
page.
When you have two providers - one infra and one cloud - added, there
should be no cloud vms displayed when setting genealogy for infra vm
and vice-versa.

Polarion:
assignee: spusater
casecomponent: Infra
caseimportance: medium
initialEstimate: 1/6h
setup: Have a cloud instance and an infra vm
testSteps:
1. Navigate to instance/vm details, choose Genealogy
2. Verify that for cloud instance no infra vms are displayed
3. Verify that for infra vm no cloud instances are displayed
expectedResults:
1. Genealogy displayed
2. No infra vms displayed
3. No cloud instances displayed
Bugzilla:
1399141
1399144
"""
pass
try:
compare_view = create_vm_with_clone[0].genealogy.compare(*create_vm_with_clone)
assert compare_view.is_displayed
except ToolbarOptionGreyedOrUnavailable:
Copy link
Member

Choose a reason for hiding this comment

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

🎉

logger.exception("The compare button is disabled or unavailable")
pytest.fail("The compare button is disabled or unavailable")