Skip to content

Commit 4cc3090

Browse files
committed
Store driver objects in a global dict
When security group support is added, device objects need to be shared between the existing mechanism driver and also a service plugin. This change invokes drivers and stores them in a single global DEVICES dict. Change-Id: I5cd5880cded950cd5f3cfff6c77750f44e92618e Related-Bug: #2110760
1 parent 0b9d710 commit 4cc3090

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

networking_generic_switch/devices/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
import abc
1616

1717
from neutron_lib.utils.helpers import parse_mappings
18+
from oslo_concurrency import lockutils
1819
from oslo_log import log as logging
1920
from oslo_utils import strutils
2021
import stevedore
2122

23+
from networking_generic_switch import config as gsw_conf
2224
from networking_generic_switch import exceptions as gsw_exc
2325

2426
GENERIC_SWITCH_NAMESPACE = 'generic_switch.devices'
@@ -60,6 +62,20 @@
6062
{'name': 'ngs_allowed_ports'},
6163
]
6264

65+
EM_SEMAPHORE = 'ngs_device_manager'
66+
DEVICES = {}
67+
68+
69+
@lockutils.synchronized(EM_SEMAPHORE)
70+
def get_devices():
71+
global DEVICES
72+
gsw_devices = gsw_conf.get_devices()
73+
for device_name, device_cfg in gsw_devices.items():
74+
if device_name in DEVICES:
75+
continue
76+
DEVICES[device_name] = device_manager(device_cfg, device_name)
77+
return DEVICES
78+
6379

6480
def device_manager(device_cfg, device_name=""):
6581
device_type = device_cfg.get('device_type', '')

networking_generic_switch/generic_switch_mech.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from neutron_lib.plugins.ml2 import api
2323
from oslo_log import log as logging
2424

25-
from networking_generic_switch import config as gsw_conf
2625
from networking_generic_switch import devices
2726
from networking_generic_switch.devices import utils as device_utils
2827
from networking_generic_switch import exceptions as ngs_exc
@@ -51,11 +50,7 @@ def initialize(self):
5150
self.vif_details = {portbindings.VIF_DETAILS_CONNECTIVITY:
5251
portbindings.CONNECTIVITY_L2}
5352

54-
gsw_devices = gsw_conf.get_devices()
55-
self.switches = {}
56-
for switch_info, device_cfg in gsw_devices.items():
57-
switch = devices.device_manager(device_cfg, switch_info)
58-
self.switches[switch_info] = switch
53+
self.switches = devices.get_devices()
5954

6055
LOG.info('Devices %s have been loaded', self.switches.keys())
6156
if not self.switches:

networking_generic_switch/tests/unit/test_generic_switch_mech.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from neutron_lib.callbacks import resources
2222
from neutron_lib.plugins import directory
2323

24+
from networking_generic_switch import devices
2425
from networking_generic_switch.devices import utils as device_utils
2526
from networking_generic_switch import exceptions
2627
from networking_generic_switch import generic_switch_mech as gsm
@@ -32,6 +33,7 @@
3233
class TestGenericSwitchDriver(unittest.TestCase):
3334
def setUp(self):
3435
super(TestGenericSwitchDriver, self).setUp()
36+
devices.DEVICES.clear()
3537
self.switch_mock = mock.Mock()
3638
self.switch_mock.config = {'device_type': 'bar', 'spam': 'ham',
3739
'ip': 'ip'}

0 commit comments

Comments
 (0)