Skip to content

Commit

Permalink
[fix] Fixed network topology graph stuck at loading #353
Browse files Browse the repository at this point in the history
- Bumped openwisp-network-topology~=1.1.1
- Added websocket routes for network topology

Closes #353
  • Loading branch information
pandafy authored and nemesifier committed Nov 27, 2024
1 parent d5e4201 commit 9bf0f2e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
16 changes: 14 additions & 2 deletions images/common/openwisp/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from openwisp.utils import env_bool

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "openwisp.settings")
django_asgi_app = get_asgi_application()

from openwisp_controller.routing import get_routes # noqa: E402
from openwisp_controller.routing import ( # noqa: E402
get_routes as get_controller_routes,
)

routes = get_controller_routes()

if env_bool(os.environ.get('USE_OPENWISP_TOPOLOGY')):
from openwisp_network_topology.routing import ( # noqa: E402
websocket_urlpatterns as network_topology_routes,
)

routes.extend(network_topology_routes)

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(get_routes()))
AuthMiddlewareStack(URLRouter(routes))
),
}
)
2 changes: 0 additions & 2 deletions images/common/openwisp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@

# OpenWISP Modules's configurations
OPENWISP_FIRMWARE_UPGRADER_MAX_FILE_SIZE = MAX_REQUEST_SIZE
# TODO: Remove when https://github.com/openwisp/docker-openwisp/issues/156 is fixed
OPENWISP_NETWORK_TOPOLOGY_API_AUTH_REQUIRED = False
DJANGO_X509_DEFAULT_CERT_VALIDITY = int(os.environ['DJANGO_X509_DEFAULT_CERT_VALIDITY'])
DJANGO_X509_DEFAULT_CA_VALIDITY = int(os.environ['DJANGO_X509_DEFAULT_CA_VALIDITY'])
SOCIALACCOUNT_PROVIDERS = {
Expand Down
2 changes: 1 addition & 1 deletion images/openwisp_base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN pip install --no-cache-dir --user --upgrade ${OPENWISP_MONITORING_SOURCE}
ARG OPENWISP_FIRMWARE_SOURCE=openwisp-firmware-upgrader~=1.1.0
# hadolint ignore=DL3013
RUN pip install --no-cache-dir --user --upgrade ${OPENWISP_FIRMWARE_SOURCE}
ARG OPENWISP_TOPOLOGY_SOURCE=openwisp-network-topology~=1.1.0
ARG OPENWISP_TOPOLOGY_SOURCE=openwisp-network-topology~=1.1.1
# hadolint ignore=DL3013
RUN pip install --no-cache-dir --user --upgrade ${OPENWISP_TOPOLOGY_SOURCE}
ARG OPENWISP_RADIUS_SOURCE=openwisp-radius~=1.1.0
Expand Down
2 changes: 2 additions & 0 deletions images/openwisp_websocket/module_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
'openwisp_notifications',
# openwisp-ipam
'openwisp_ipam',
# openwisp-network-topology
'openwisp_network_topology',
'openwisp_utils.admin_theme',
# admin
'django.contrib.admin',
Expand Down
40 changes: 40 additions & 0 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,46 @@ def test_topology_graph(self):
label = 'automated-selenium-test-02'
self.login()
self.create_network_topology(label)
self.get_resource(label, path, select_field='field-label')
# Click on "Visualize topology graph" button
try:
WebDriverWait(self.base_driver, 2).until(
EC.presence_of_element_located((By.CSS_SELECTOR, 'input.visualizelink'))
)
except TimeoutException:
self.fail('Topology visualize button not found.')
else:
self.base_driver.find_element(
By.CSS_SELECTOR, 'input.visualizelink'
).click()
# Click on sidebar handle
try:
WebDriverWait(self.base_driver, 2).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, 'button.sideBarHandle')
)
)
except TimeoutException:
self.fail('Topology visualize button not found.')
else:
self.base_driver.find_element(
By.CSS_SELECTOR, 'button.sideBarHandle'
).click()
# Verify topology label
try:
WebDriverWait(self.base_driver, 2).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, '.njg-valueLabel'))
)
except TimeoutException:
self.fail('Topology visualize button not found.')
else:
self.assertEqual(
self.base_driver.find_element(
By.CSS_SELECTOR, '.njg-valueLabel'
).text.lower(),
label,
)
self.assertEqual(len(self.console_error_check()), 0)
self.action_on_resource(label, path, 'delete_selected')
self.assertNotIn('<li>Nodes: ', self.base_driver.page_source)
self.action_on_resource(label, path, 'update_selected')
Expand Down

0 comments on commit 9bf0f2e

Please sign in to comment.