File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed
networking_generic_switch Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 1515import abc
1616
1717from neutron_lib .utils .helpers import parse_mappings
18+ from oslo_concurrency import lockutils
1819from oslo_log import log as logging
1920from oslo_utils import strutils
2021import stevedore
2122
23+ from networking_generic_switch import config as gsw_conf
2224from networking_generic_switch import exceptions as gsw_exc
2325
2426GENERIC_SWITCH_NAMESPACE = 'generic_switch.devices'
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
6480def device_manager (device_cfg , device_name = "" ):
6581 device_type = device_cfg .get ('device_type' , '' )
Original file line number Diff line number Diff line change 2222from neutron_lib .plugins .ml2 import api
2323from oslo_log import log as logging
2424
25- from networking_generic_switch import config as gsw_conf
2625from networking_generic_switch import devices
2726from networking_generic_switch .devices import utils as device_utils
2827from 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 :
Original file line number Diff line number Diff line change 2121from neutron_lib .callbacks import resources
2222from neutron_lib .plugins import directory
2323
24+ from networking_generic_switch import devices
2425from networking_generic_switch .devices import utils as device_utils
2526from networking_generic_switch import exceptions
2627from networking_generic_switch import generic_switch_mech as gsm
3233class 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' }
You can’t perform that action at this time.
0 commit comments