记一次因无意新增配置了service_plugins值firewall_v2,在自己开发的plugin中却无法获取到fwaas的plugin实例
上图的net_topo是自己写的plugin,firewall_v2为防火墙
问题
希望在net_topo中去使用firewall,然后进行防火墙规则、防火墙策略、防火墙组的创建,那么在调用防火墙plugin去创建防火墙前需要获得它的plugin实例,可问题就是我获取的值是为None
class NetTopoPlugin(ext_nettopo.NetTopoPluginBase):
supported_extension_aliases = ["net-topo"] # need get_alias()
# __native_pagination_support = True
# __native_sorting_support = True
# __filter_validation_support = True
path_prefix = const.API_PREFIX
def __init__(self):`
super(NetTopoPlugin, self).__init__()
self.tenant_id =None
self.plugin = directory.get_plugin()
self.l3_plugin = directory.get_plugin(plugin_constants.L3)
self.fw_plugin = directory.get_plugin(plugin_constants.FIREWALL_V2)
LOG.info("NetTopoPlugin started"
self.fw_plugin >> None
解决:
思路:
再看下self.l3_plugin的是否也是None ,但并不是None,包括self.plugin是有值的
但唯独self.fw_plugin没有值, 难道配置文件配错了neutron没有加载firewall,也不是,因为我通过命令去验证了防火墙所有功能,一切是ok的。
先还是看下 directory.get_plugin(plugin_constants.FIREWALL_V2) 为什么为None
于是pdb如下
加载了的有l3、core还就是没有firewall,所以获取不到firwall的plugin
这时候我就怀疑了neutron还真没加载firewall,就尝试着跟着neutron加载service plugin的代码去pdb调试跟踪下,看能不能找着点什么,
从上图来看neutron要加载的plugin是有firewallv2,但为什么我在自己开发的net_topo中却获取不到firewall plugin 呢,
看到了这一串值后,我沉思了,why。。。,盯看了一会儿,此时终于灵光一现,发现net_topo是在firewall_v2前面,再联想到之前脑子里模糊的知道 service_plugins配置时要注意顺序,但不知道其真意。
ca,ca,ca,原来注意顺序就是这意思 ,neutron会按着你配置service_plugins值去顺序加载plugin, net_topo在firewall_v2之前,此时想在net_topo中去使用firewall_v2当然获取不到firewall_v2 ,因为还并未加载firewall_v2
所以只需要简单将firewall_v2值,放在net_topo前即可解决
总结:
如果需要使用某一plugin,那么此plugin首先要让neutron去加载,其次要注意顺序,如A中需要使用B ,那么B就得先于A让neutron加载