From 601268d3c76b734ffad16d12f4ae5e77c7a6fc3e Mon Sep 17 00:00:00 2001 From: Matous Mojzis Date: Wed, 1 Apr 2020 19:14:28 +0200 Subject: [PATCH] Added invalid cidr/ip tests for floating_ip_add and subnet_add --- cfme/networks/floating_ips.py | 42 +++++++++++++++++++++++ cfme/networks/views.py | 31 ++++++++++++++++- cfme/tests/networks/test_sdn_addresses.py | 42 +++++++++++++++++++++++ cfme/tests/networks/test_sdn_subnets.py | 42 +++++++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 cfme/tests/networks/test_sdn_addresses.py create mode 100644 cfme/tests/networks/test_sdn_subnets.py diff --git a/cfme/networks/floating_ips.py b/cfme/networks/floating_ips.py index 1c57119273..9a4d808a9c 100644 --- a/cfme/networks/floating_ips.py +++ b/cfme/networks/floating_ips.py @@ -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 @@ -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): @@ -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') diff --git a/cfme/networks/views.py b/cfme/networks/views.py index 803544394a..1dfa195038 100644 --- a/cfme/networks/views.py +++ b/cfme/networks/views.py @@ -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): @@ -852,6 +858,7 @@ 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) @@ -859,6 +866,7 @@ class FloatingIpToolBar(View): class FloatingIpDetailsToolBar(View): """ Represents toolbar of summary of port """ + configuration = Dropdown(text='Configuration') policy = Dropdown(text='Policy') download = Button(title='Print or export summary') @@ -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 """ diff --git a/cfme/tests/networks/test_sdn_addresses.py b/cfme/tests/networks/test_sdn_addresses.py new file mode 100644 index 0000000000..9208385d77 --- /dev/null +++ b/cfme/tests/networks/test_sdn_addresses.py @@ -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.") diff --git a/cfme/tests/networks/test_sdn_subnets.py b/cfme/tests/networks/test_sdn_subnets.py new file mode 100644 index 0000000000..22c0bb7fc8 --- /dev/null +++ b/cfme/tests/networks/test_sdn_subnets.py @@ -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.")