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

Commit

Permalink
Added invalid cidr/ip tests for floating_ip_add and subnet_add
Browse files Browse the repository at this point in the history
  • Loading branch information
Matous Mojzis committed Apr 7, 2020
1 parent 9ce2cc7 commit 601268d
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 1 deletion.
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')
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()
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):
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.")

0 comments on commit 601268d

Please sign in to comment.