Skip to content

Commit

Permalink
Merge pull request #208 from cnweaver/missing-crossbar
Browse files Browse the repository at this point in the history
Deal gracefully with crossbar not being found
  • Loading branch information
BrianJKoopman authored Aug 16, 2021
2 parents edccf36 + acb012f commit 24bc78a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ There are also several Python package dependencies, which are listed in the

.. _requirements.txt: requirements.txt

Additionally ``crossbar`` is a required dependency which is not automatically
installed. It can be installed with pip or run via Docker.

Installation
------------
Clone this repository and install using pip::
Expand Down
5 changes: 4 additions & 1 deletion docs/user/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ Python Dependencies
All python dependencies for OCS are listed in (and automatically installed via)
the ``requirements.txt`` file. Some of the dependencies are:

* `crossbar.io`_ - An implementation of a WAMP router.
* `Autobahn`_ - Provides open-source implementations of WAMP.
* `twisted`_ - Used with Autobahn for networking.

Other Dependencies
``````````````````

* `crossbar.io`_ - An implementation of a WAMP router.
* Docker_ - Containerization software used for deploying several SO written
packages.
* `Docker Compose`_ - CLI tool for running multi-container Docker
applications.

Crossbar may be installed via pip if it will be used without Docker; if it
will be used with Docker it does not need to be separately installed.

Operating System
````````````````
Deploying in Docker makes OCS almost OS independent. If running components
Expand Down
5 changes: 5 additions & 0 deletions ocs/site_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import argparse
import collections
import deprecation
import errno


class SiteConfig:
Expand Down Expand Up @@ -134,6 +135,10 @@ def from_dict(cls, data, parent=None):
self = cls()
self.parent = parent
self.binary = data.get('bin', shutil.which('crossbar'))
if self.binary is None:
raise RuntimeError("Unable to locate crossbar binary")
if not os.path.exists(self.binary):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), self.binary)
self.cbdir = data.get('config-dir')
if self.cbdir is None:
self.cbdir_args = []
Expand Down
18 changes: 16 additions & 2 deletions tests/test_site_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

import pytest
from ocs.site_config import get_control_client
from ocs.site_config import get_control_client, CrossbarConfig


class TestGetControlClient:
Expand Down Expand Up @@ -44,3 +44,17 @@ def test_none_client_type_wo_wamp_http_site(self):

with pytest.raises(ValueError):
get_control_client('test', site=mock_site, client_type=None)

def test_missing_crossbar(self):
crossbar_found = MagicMock(return_value="someplace/bin/crossbar")
with patch("shutil.which", crossbar_found), \
patch("os.path.exists", MagicMock(return_value=True)):
config = CrossbarConfig.from_dict({})
assert config.binary == "someplace/bin/crossbar"

crossbar_not_found = MagicMock(return_value=None)
with patch("shutil.which", crossbar_not_found), pytest.raises(RuntimeError):
config = CrossbarConfig.from_dict({})

with pytest.raises(FileNotFoundError):
config = CrossbarConfig.from_dict({"bin": "not/a/valid/path/to/crossbar"})

0 comments on commit 24bc78a

Please sign in to comment.