diff --git a/openstack_dashboard/test/selenium/integration/test_networks.py b/openstack_dashboard/test/selenium/integration/test_networks.py index 0ec2302f7d..1c0d50c7d0 100644 --- a/openstack_dashboard/test/selenium/integration/test_networks.py +++ b/openstack_dashboard/test/selenium/integration/test_networks.py @@ -43,6 +43,18 @@ def clear_network_demo(network_name, openstack_demo): ) +@pytest.fixture +def new_subnet_demo(subnet_name, new_network_demo, openstack_demo): + subnet = openstack_demo.network.create_subnet( + name=subnet_name, + network_id=new_network_demo.id, + ip_version=4, + cidr="10.11.0.0/16", + ) + yield subnet + openstack_demo.delete_subnet(subnet) + + # required_state: True/False (marked/unmarked) def ensure_checkbox(required_state, element): current_state = element.is_selected() diff --git a/openstack_dashboard/test/selenium/integration/test_routers.py b/openstack_dashboard/test/selenium/integration/test_routers.py index a0fbf307f8..4cdf6ba2af 100644 --- a/openstack_dashboard/test/selenium/integration/test_routers.py +++ b/openstack_dashboard/test/selenium/integration/test_routers.py @@ -12,9 +12,16 @@ from oslo_utils import uuidutils import pytest +import test_networks from openstack_dashboard.test.selenium import widgets +# Imported fixtures +subnet_name = test_networks.subnet_name +network_name = test_networks.network_name +new_subnet_demo = test_networks.new_subnet_demo +new_network_demo = test_networks.new_network_demo + @pytest.fixture def router_name(): @@ -51,6 +58,26 @@ def clear_router_demo(router_name, openstack_demo): openstack_demo.delete_router(router_name) +@pytest.fixture +def clear_interface_from_router_demo(new_router_demo, new_subnet_demo, + openstack_demo): + yield None + openstack_demo.network.remove_interface_from_router( + router=new_router_demo.id, + subnet_id=new_subnet_demo.id, + ) + + +@pytest.fixture +def new_interface(new_router_demo, new_network_demo, new_subnet_demo, + openstack_demo): + interface = openstack_demo.network.add_interface_to_router( + router=new_router_demo.id, + subnet_id=new_subnet_demo.id, + ) + yield interface + + def test_create_router_demo(login, driver, router_name, openstack_demo, config, clear_router_demo): login('user') @@ -136,3 +163,73 @@ def test_delete_router_admin(login, driver, router_name, openstack_admin, messages = widgets.get_and_dismiss_messages(driver) assert f"Success: Deleted Router: {router_name}" in messages assert openstack_admin.network.find_router(router_name) is None + + +def test_router_add_interface_demo(login, driver, router_name, openstack_demo, + new_router_demo, new_network_demo, + clear_interface_from_router_demo, + new_subnet_demo, config): + fixed_ip_test = "10.11.1.33" + + login('user') + url = '/'.join(( + config.dashboard.dashboard_url, + 'project', + 'routers', + )) + driver.get(url) + rows = driver.find_elements_by_css_selector( + f"table#routers tr[data-display='{router_name}']" + ) + assert len(rows) == 1 + rows[0].find_element_by_link_text(router_name).click() + driver.find_element_by_link_text("Interfaces").click() + driver.find_element_by_id("interfaces__action_create").click() + add_interface_form = driver.find_element_by_css_selector( + ".modal-dialog form") + widgets.select_from_dropdown( + add_interface_form, f"{new_network_demo.name}: {new_subnet_demo.cidr} " + f"({new_subnet_demo.name})") + add_interface_form.find_element_by_id( + "id_ip_address").send_keys(fixed_ip_test) + add_interface_form.find_element_by_css_selector(".btn-primary").click() + messages = widgets.get_and_dismiss_messages(driver) + assert f"Success: Interface added {fixed_ip_test}" in messages + + is_interface_added_sdk = False + all_ports = openstack_demo.network.get("/ports").json()['ports'] + for port in all_ports: + for fixed_ip in port['fixed_ips']: + if fixed_ip['ip_address'] == fixed_ip_test: + if port['device_id'] == new_router_demo.id: + is_interface_added_sdk = True + assert is_interface_added_sdk + + +def test_router_delete_interface_demo(login, driver, router_name, + openstack_demo, new_interface, config): + login('user') + url = '/'.join(( + config.dashboard.dashboard_url, + 'project', + 'routers', + )) + driver.get(url) + rows = driver.find_elements_by_css_selector( + f"table#routers tr[data-display='{router_name}']" + ) + assert len(rows) == 1 + rows[0].find_element_by_link_text(router_name).click() + driver.find_element_by_link_text("Interfaces").click() + port_id = new_interface['port_id'] + extracted_port_name = f"({port_id[:13]})" + rows = driver.find_elements_by_css_selector( + f"table#interfaces tr[data-display='{extracted_port_name}']" + ) + assert len(rows) == 1 + rows[0].find_element_by_css_selector("td.actions_column").click() + widgets.confirm_modal(driver) + messages = widgets.get_and_dismiss_messages(driver) + assert f"Success: Deleted Interface: {extracted_port_name}" in messages + assert(openstack_demo.network.find_port( + new_interface['port_id']) is None)