1
# Copyright 2014 OpenStack Foundation.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
18
from neutron.tests import base
19
from oslo_config import cfg
21
from neutron_fwaas.services.firewall.agents import firewall_service
23
FWAAS_NOP_DEVICE = ('neutron_fwaas.tests.unit.services.firewall.agents.'
24
'test_firewall_agent_api.NoopFwaasDriver')
27
class TestFirewallDeviceDriverLoading(base.BaseTestCase):
30
super(TestFirewallDeviceDriverLoading, self).setUp()
31
self.service = firewall_service.FirewallService(mock.Mock())
33
def test_loading_firewall_device_driver(self):
34
"""Get the sole device driver for FWaaS."""
35
cfg.CONF.set_override('driver',
38
driver = self.service.load_device_drivers()
39
self.assertIsNotNone(driver)
40
self.assertIn(driver.__class__.__name__, FWAAS_NOP_DEVICE)
42
def test_fail_no_such_firewall_device_driver(self):
43
"""Failure test of import error for FWaaS device driver."""
44
cfg.CONF.set_override('driver',
47
self.assertRaises(ImportError,
48
self.service.load_device_drivers)
50
def test_fail_firewall_no_device_driver_specified(self):
51
"""Failure test when no FWaaS device driver is specified.
53
This is a configuration error, as the user must specify a device
54
driver, when enabling the firewall service (and there is no default
55
configuration set. We'll simulate that by using an empty string.
57
cfg.CONF.set_override('driver',
60
self.assertRaises(ValueError,
61
self.service.load_device_drivers)