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

[1LP][WIPTEST]Added invalid cidr/ip tests for floating_ip_add and subnet_add #10033

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions cfme/networks/floating_ips.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import attr
from navmazing import NavigateToAttribute
from navmazing import NavigateToSibling

from cfme.common import Taggable
from cfme.exceptions import ItemNotFound
from cfme.modeling.base import BaseCollection
from cfme.modeling.base import BaseEntity
from cfme.modeling.base import parent_of_type
from cfme.networks.views import FloatingIpAddView
from cfme.networks.views import FloatingIpDetailsView
from cfme.networks.views import FloatingIpView
from cfme.utils.appliance.implementations.ui import CFMENavigateStep
from cfme.utils.appliance.implementations.ui import navigate_to
from cfme.utils.appliance.implementations.ui import navigator
from cfme.utils.wait import wait_for


@attr.s
Expand Down Expand Up @@ -53,6 +56,36 @@ def all(self):
floating_ips.append(self.instantiate(address=ip.data['address']))
return floating_ips

def create(self, tenant, provider, network_manager, network_name,
floating_ip_address=None, fixed_ip_address=None, network_port_id=None):
"""Create subnet

Args:
tenant: (str) name of the tenant to place FIP to
provider: crud object of Openstack cloud provider
network_manager: (str) name of network manager
network_name: (str) name of the network to create FIP under
floating_ip_address: (str) Floating Address(Name) of FIP, for example: 192.168.12.2/24
fixed_ip_address: (str) Fixed Address(Name) of FIP, for example: 192.168.12.2/24
network_port_id: (str) Id of network port to associate FIP with

Returns: instance of cfme.networks.floating_ips.FloatingIp
"""
view = navigate_to(self, 'Add')
view.fill({'network_manager': network_manager,
'network': network_name,
'network_port_id': network_port_id,
'floating_ip_address': floating_ip_address,
'fixed_ip_address': fixed_ip_address,
'cloud_tenant': tenant})
view.add.click()
view.flash.assert_success_message(f'Floating IP "{floating_ip_address}" created')
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to assert_no error() here instead and have the actual flash message asserted in a test.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed @jawatts, @mmojzis can you cover this flash assertion with a positive CRUD test case? Looks like only negative test cases are included in this PR.

floating_ip = self.instantiate(floating_ip_address, provider, network_name)
# Refresh provider's relationships to have new FIP displayed
wait_for(provider.is_refreshed, func_kwargs=dict(refresh_delta=10), timeout=600)
wait_for(lambda: floating_ip.exists, timeout=100, fail_func=floating_ip.browser.refresh)
return floating_ip


@navigator.register(FloatingIpCollection, 'All')
class All(CFMENavigateStep):
Expand All @@ -78,3 +111,12 @@ def step(self, *args, **kwargs):
surf_pages=True).click()
except Exception:
raise ItemNotFound('Floating IP not found on the page')


@navigator.register(FloatingIpCollection, 'Add')
class AddFloatingIP(CFMENavigateStep):
VIEW = FloatingIpAddView
prerequisite = NavigateToSibling('All')

def step(self, *args, **kwargs):
self.prerequisite_view.toolbar.configuration.item_select('Add a new Floating IP')
31 changes: 30 additions & 1 deletion cfme/networks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,13 @@ class SubnetAddView(BaseLoggedInPage):
gateway = TextInput(name='gateway_ip')
add = Button('Add')

is_displayed = displayed_not_implemented
@property
def is_displayed(self):
return (
self.logged_in_as_current_user and
self.navigation.currently_selected == ['Networks', 'Subnets'] and
self.title.text == 'Add New Subnet'
)


class SubnetEditView(BaseLoggedInPage):
Expand Down Expand Up @@ -852,13 +858,15 @@ def is_displayed(self):

class FloatingIpToolBar(View):
""" Represents floating ips toolbar and its controls """
configuration = Dropdown(text='Configuration')
policy = Dropdown(text='Policy')
download = Dropdown(text='Download')
view_selector = View.nested(ItemsToolBarViewSelector)


class FloatingIpDetailsToolBar(View):
""" Represents toolbar of summary of port """
configuration = Dropdown(text='Configuration')
policy = Dropdown(text='Policy')
download = Button(title='Print or export summary')

Expand Down Expand Up @@ -920,6 +928,27 @@ def is_displayed(self):
self.entities.title.text == '{} (Summary)'.format(self.context['object'].address))


class FloatingIpAddView(BaseLoggedInPage):
""" Represents Add view of floating IP """
title = Text('//div[@id="main-content"]//h1')
network_manager = Select(name='ems_id')
network = Select(name='cloud_network_id')
cloud_tenant = Select(name='cloud_tenant_id')
floating_ip_address = TextInput(name='address')
fixed_ip_address = TextInput(name='fixed_ip_address')
network_port_id = TextInput(name='network_port_ems_ref')
add = Button('Add')
cancel = Button('Cancel')

@property
def is_displayed(self):
return (
self.logged_in_as_current_user and
self.navigation.currently_selected == ['Networks', 'Floating IPs'] and
self.title.text == 'Add New Floating IP'
)


class OneProviderFloatingIpView(BaseLoggedInPage):
""" Represents Floating Ip all for specific Network provider """

Expand Down
42 changes: 42 additions & 0 deletions cfme/tests/networks/test_sdn_addresses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from cfme import test_requirements
from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.networks.views import FloatingIpView

pytestmark = [
test_requirements.sdn,
pytest.mark.usefixtures('setup_provider'),
pytest.mark.provider([OpenStackProvider], scope="module")
]


@pytest.fixture()
def network_manager(appliance, provider):
network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all()
Copy link
Member

Choose a reason for hiding this comment

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

Can you wrap this potential ValueError in a pytest.skip call, so it doesn't start throwing errors when there's more/less than 1 element in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yield network_manager


@pytest.mark.meta(automates=[1652501])
def test_network_ip_address_invalid_address(appliance, provider, network_manager, setup_provider):
"""
Bugzilla: 1652501
Polarion:
assignee: mmojzis
casecomponent: Cloud
caseimportance: medium
initialEstimate: 1/10h
"""
subnets_collection = appliance.collections.network_floating_ips
invalid_address = 'test'

with pytest.raises(AssertionError):
subnets_collection.create(network_manager=network_manager.name,
network_name=provider.data['public_network'],
tenant=provider.data['tenant'], provider=provider,
floating_ip_address=invalid_address)

view = subnets_collection.create_view(FloatingIpView)
view.flash.assert_message(
f"Unable to create Floating IP \"{invalid_address}\": Invalid input for floating_ip_address"
f". Reason: \'{invalid_address}\' is not a valid IP address.")
42 changes: 42 additions & 0 deletions cfme/tests/networks/test_sdn_subnets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from cfme import test_requirements
from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.networks.views import SubnetView

pytestmark = [
test_requirements.sdn,
pytest.mark.usefixtures('setup_provider'),
pytest.mark.provider([OpenStackProvider], scope="module")
]


@pytest.fixture()
def network_manager(appliance, provider):
Copy link
Contributor

@jarovo jarovo Apr 2, 2020

Choose a reason for hiding this comment

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

This method does the same as the one in the other file, so I am frowning on picking the first network_manager here as well.

But I think also having this a fixture doesn't provide enough (any) benefits yet it just creates some potential problems in future because it is a code dup. It is fixture for effectively a one-liner. I am sure one-liners dups are not considered a problem most of the times.

I will ask other reviewers what they think about fixtures like this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in the future when they add another providers with network managers the fixture makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

@JaryN valid concern for sure.

I wouldn't consider this a blocker to merging this PR, but warrants some future enhancement.

This could be a globally available fixture (cfme/fixtures/), or even a subcollection of the parent cloud provider.

network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all()
yield network_manager


@pytest.mark.meta(automates=[1652515])
def test_network_subnet_invalid_cidr(appliance, provider, network_manager, setup_provider):
"""
Bugzilla: 1652515
Polarion:
assignee: mmojzis
casecomponent: Cloud
caseimportance: medium
initialEstimate: 1/10h
"""
subnets_collection = appliance.collections.network_subnets
invalid_cidr = 'test'

with pytest.raises(AssertionError):
subnets_collection.create(network_manager=network_manager.name,
network_name=provider.data['public_network'],
tenant=provider.data['tenant'], cidr=invalid_cidr,
name='test_subnet', provider=provider)

view = subnets_collection.create_view(SubnetView)
view.flash.assert_message(
f"Unable to create Cloud Subnet: Invalid input for cidr. Reason: '{invalid_cidr}' is not a"
" valid IP subnet.")