ofc_opts = [
cfg.StrOpt('host', default='127.0.0.1',
help=_("Host to connect to")),
+ cfg.StrOpt('path_prefix', default='',
+ help=_("Base URL of OFC REST API. "
+ "It is prepended to each API request.")),
cfg.StrOpt('port', default='8888',
help=_("Port to connect to")),
cfg.StrOpt('driver', default='trema',
import mock
from oslo.config import cfg
+from neutron.plugins.nec.common import config
from neutron.plugins.nec.common import exceptions as nexc
from neutron.plugins.nec.common import ofc_client
from neutron.tests import base
class OFCClientTest(base.BaseTestCase):
- def _test_do_request(self, status, resbody, data, exctype=None,
- exc_checks=None):
+ def _test_do_request(self, status, resbody, expected_data, exctype=None,
+ exc_checks=None, path_prefix=None):
res = mock.Mock()
res.status = status
res.read.return_value = resbody
with mock.patch.object(ofc_client.OFCClient, 'get_connection',
return_value=conn):
client = ofc_client.OFCClient()
-
+ path = '/somewhere'
+ realpath = path_prefix + path if path_prefix else path
if exctype:
e = self.assertRaises(exctype, client.do_request,
- 'GET', '/somewhere', body={})
- self.assertEqual(data, str(e))
+ 'GET', path, body={})
+ self.assertEqual(expected_data, str(e))
if exc_checks:
for k, v in exc_checks.items():
self.assertEqual(v, getattr(e, k))
else:
- response = client.do_request('GET', '/somewhere', body={})
- self.assertEqual(response, data)
+ response = client.do_request('GET', path, body={})
+ self.assertEqual(response, expected_data)
headers = {"Content-Type": "application/json"}
expected = [
- mock.call.request('GET', '/somewhere', '{}', headers),
+ mock.call.request('GET', realpath, '{}', headers),
mock.call.getresponse(),
]
conn.assert_has_calls(expected)
for status in [201, 202, 204]:
self._test_do_request(status, None, None)
+ def test_do_request_with_path_prefix(self):
+ config.CONF.set_override('path_prefix', '/dummy', group='OFC')
+ self._test_do_request(200, json.dumps([1, 2, 3]), [1, 2, 3],
+ path_prefix='/dummy')
+
def test_do_request_returns_404(self):
resbody = ''
errmsg = _("The specified OFC resource (/somewhere) is not found.")