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

Commit 601268d

Browse files
author
Matous Mojzis
committed
Added invalid cidr/ip tests for floating_ip_add and subnet_add
1 parent 9ce2cc7 commit 601268d

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed

cfme/networks/floating_ips.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import attr
22
from navmazing import NavigateToAttribute
3+
from navmazing import NavigateToSibling
34

45
from cfme.common import Taggable
56
from cfme.exceptions import ItemNotFound
67
from cfme.modeling.base import BaseCollection
78
from cfme.modeling.base import BaseEntity
89
from cfme.modeling.base import parent_of_type
10+
from cfme.networks.views import FloatingIpAddView
911
from cfme.networks.views import FloatingIpDetailsView
1012
from cfme.networks.views import FloatingIpView
1113
from cfme.utils.appliance.implementations.ui import CFMENavigateStep
1214
from cfme.utils.appliance.implementations.ui import navigate_to
1315
from cfme.utils.appliance.implementations.ui import navigator
16+
from cfme.utils.wait import wait_for
1417

1518

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

59+
def create(self, tenant, provider, network_manager, network_name,
60+
floating_ip_address=None, fixed_ip_address=None, network_port_id=None):
61+
"""Create subnet
62+
63+
Args:
64+
tenant: (str) name of the tenant to place FIP to
65+
provider: crud object of Openstack cloud provider
66+
network_manager: (str) name of network manager
67+
network_name: (str) name of the network to create FIP under
68+
floating_ip_address: (str) Floating Address(Name) of FIP, for example: 192.168.12.2/24
69+
fixed_ip_address: (str) Fixed Address(Name) of FIP, for example: 192.168.12.2/24
70+
network_port_id: (str) Id of network port to associate FIP with
71+
72+
Returns: instance of cfme.networks.floating_ips.FloatingIp
73+
"""
74+
view = navigate_to(self, 'Add')
75+
view.fill({'network_manager': network_manager,
76+
'network': network_name,
77+
'network_port_id': network_port_id,
78+
'floating_ip_address': floating_ip_address,
79+
'fixed_ip_address': fixed_ip_address,
80+
'cloud_tenant': tenant})
81+
view.add.click()
82+
view.flash.assert_success_message(f'Floating IP "{floating_ip_address}" created')
83+
floating_ip = self.instantiate(floating_ip_address, provider, network_name)
84+
# Refresh provider's relationships to have new FIP displayed
85+
wait_for(provider.is_refreshed, func_kwargs=dict(refresh_delta=10), timeout=600)
86+
wait_for(lambda: floating_ip.exists, timeout=100, fail_func=floating_ip.browser.refresh)
87+
return floating_ip
88+
5689

5790
@navigator.register(FloatingIpCollection, 'All')
5891
class All(CFMENavigateStep):
@@ -78,3 +111,12 @@ def step(self, *args, **kwargs):
78111
surf_pages=True).click()
79112
except Exception:
80113
raise ItemNotFound('Floating IP not found on the page')
114+
115+
116+
@navigator.register(FloatingIpCollection, 'Add')
117+
class AddFloatingIP(CFMENavigateStep):
118+
VIEW = FloatingIpAddView
119+
prerequisite = NavigateToSibling('All')
120+
121+
def step(self, *args, **kwargs):
122+
self.prerequisite_view.toolbar.configuration.item_select('Add a new Floating IP')

cfme/networks/views.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,13 @@ class SubnetAddView(BaseLoggedInPage):
641641
gateway = TextInput(name='gateway_ip')
642642
add = Button('Add')
643643

644-
is_displayed = displayed_not_implemented
644+
@property
645+
def is_displayed(self):
646+
return (
647+
self.logged_in_as_current_user and
648+
self.navigation.currently_selected == ['Networks', 'Subnets'] and
649+
self.title.text == 'Add New Subnet'
650+
)
645651

646652

647653
class SubnetEditView(BaseLoggedInPage):
@@ -852,13 +858,15 @@ def is_displayed(self):
852858

853859
class FloatingIpToolBar(View):
854860
""" Represents floating ips toolbar and its controls """
861+
configuration = Dropdown(text='Configuration')
855862
policy = Dropdown(text='Policy')
856863
download = Dropdown(text='Download')
857864
view_selector = View.nested(ItemsToolBarViewSelector)
858865

859866

860867
class FloatingIpDetailsToolBar(View):
861868
""" Represents toolbar of summary of port """
869+
configuration = Dropdown(text='Configuration')
862870
policy = Dropdown(text='Policy')
863871
download = Button(title='Print or export summary')
864872

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

922930

931+
class FloatingIpAddView(BaseLoggedInPage):
932+
""" Represents Add view of floating IP """
933+
title = Text('//div[@id="main-content"]//h1')
934+
network_manager = Select(name='ems_id')
935+
network = Select(name='cloud_network_id')
936+
cloud_tenant = Select(name='cloud_tenant_id')
937+
floating_ip_address = TextInput(name='address')
938+
fixed_ip_address = TextInput(name='fixed_ip_address')
939+
network_port_id = TextInput(name='network_port_ems_ref')
940+
add = Button('Add')
941+
cancel = Button('Cancel')
942+
943+
@property
944+
def is_displayed(self):
945+
return (
946+
self.logged_in_as_current_user and
947+
self.navigation.currently_selected == ['Networks', 'Floating IPs'] and
948+
self.title.text == 'Add New Floating IP'
949+
)
950+
951+
923952
class OneProviderFloatingIpView(BaseLoggedInPage):
924953
""" Represents Floating Ip all for specific Network provider """
925954

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
from cfme import test_requirements
4+
from cfme.cloud.provider.openstack import OpenStackProvider
5+
from cfme.networks.views import FloatingIpView
6+
7+
pytestmark = [
8+
test_requirements.sdn,
9+
pytest.mark.usefixtures('setup_provider'),
10+
pytest.mark.provider([OpenStackProvider], scope="module")
11+
]
12+
13+
14+
@pytest.fixture()
15+
def network_manager(appliance, provider):
16+
network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all()
17+
yield network_manager
18+
19+
20+
@pytest.mark.meta(automates=[1652501])
21+
def test_network_ip_address_invalid_address(appliance, provider, network_manager, setup_provider):
22+
"""
23+
Bugzilla: 1652501
24+
Polarion:
25+
assignee: mmojzis
26+
casecomponent: Cloud
27+
caseimportance: medium
28+
initialEstimate: 1/10h
29+
"""
30+
subnets_collection = appliance.collections.network_floating_ips
31+
invalid_address = 'test'
32+
33+
with pytest.raises(AssertionError):
34+
subnets_collection.create(network_manager=network_manager.name,
35+
network_name=provider.data['public_network'],
36+
tenant=provider.data['tenant'], provider=provider,
37+
floating_ip_address=invalid_address)
38+
39+
view = subnets_collection.create_view(FloatingIpView)
40+
view.flash.assert_message(
41+
f"Unable to create Floating IP \"{invalid_address}\": Invalid input for floating_ip_address"
42+
f". Reason: \'{invalid_address}\' is not a valid IP address.")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
from cfme import test_requirements
4+
from cfme.cloud.provider.openstack import OpenStackProvider
5+
from cfme.networks.views import SubnetView
6+
7+
pytestmark = [
8+
test_requirements.sdn,
9+
pytest.mark.usefixtures('setup_provider'),
10+
pytest.mark.provider([OpenStackProvider], scope="module")
11+
]
12+
13+
14+
@pytest.fixture()
15+
def network_manager(appliance, provider):
16+
network_manager, = appliance.collections.network_providers.filter({"provider": provider}).all()
17+
yield network_manager
18+
19+
20+
@pytest.mark.meta(automates=[1652515])
21+
def test_network_subnet_invalid_cidr(appliance, provider, network_manager, setup_provider):
22+
"""
23+
Bugzilla: 1652515
24+
Polarion:
25+
assignee: mmojzis
26+
casecomponent: Cloud
27+
caseimportance: medium
28+
initialEstimate: 1/10h
29+
"""
30+
subnets_collection = appliance.collections.network_subnets
31+
invalid_cidr = 'test'
32+
33+
with pytest.raises(AssertionError):
34+
subnets_collection.create(network_manager=network_manager.name,
35+
network_name=provider.data['public_network'],
36+
tenant=provider.data['tenant'], cidr=invalid_cidr,
37+
name='test_subnet', provider=provider)
38+
39+
view = subnets_collection.create_view(SubnetView)
40+
view.flash.assert_message(
41+
f"Unable to create Cloud Subnet: Invalid input for cidr. Reason: '{invalid_cidr}' is not a"
42+
" valid IP subnet.")

0 commit comments

Comments
 (0)