Avoid version API call for policy lib
Policy API does not expose version yet In addition, this solves client cert generation issue (no backend connection is yet available when certificate generation flow is invoked, so get_version will fail on init) Change-Id: Ibb1ea9b64bb92f3cae488db41da6bec849ce042e
This commit is contained in:
parent
05bea2e6ee
commit
bf31413c73
@ -92,10 +92,6 @@ def _mock_nsxlib():
|
|||||||
"NsxLibTransportZone.get_id_by_name_or_id"),
|
"NsxLibTransportZone.get_id_by_name_or_id"),
|
||||||
side_effect=_return_id_key).start()
|
side_effect=_return_id_key).start()
|
||||||
|
|
||||||
mock.patch(
|
|
||||||
"vmware_nsxlib.v3.NsxLib.get_version",
|
|
||||||
return_value='1.1.0').start()
|
|
||||||
|
|
||||||
|
|
||||||
def get_default_nsxlib_config():
|
def get_default_nsxlib_config():
|
||||||
return config.NsxLibConfig(
|
return config.NsxLibConfig(
|
||||||
|
@ -29,8 +29,6 @@ class NsxPolicyLibTestCase(unittest.TestCase):
|
|||||||
def setUp(self, *args, **kwargs):
|
def setUp(self, *args, **kwargs):
|
||||||
super(NsxPolicyLibTestCase, self).setUp()
|
super(NsxPolicyLibTestCase, self).setUp()
|
||||||
|
|
||||||
mock.patch.object(v3.NsxPolicyLib, "get_version",
|
|
||||||
return_value='2.0.0').start()
|
|
||||||
nsxlib_config = nsxlib_testcase.get_default_nsxlib_config()
|
nsxlib_config = nsxlib_testcase.get_default_nsxlib_config()
|
||||||
self.policy_lib = v3.NsxPolicyLib(nsxlib_config)
|
self.policy_lib = v3.NsxPolicyLib(nsxlib_config)
|
||||||
self.policy_api = self.policy_lib.policy_api
|
self.policy_api = self.policy_lib.policy_api
|
||||||
|
@ -59,7 +59,7 @@ class NsxLibBase(object):
|
|||||||
|
|
||||||
super(NsxLibBase, self).__init__()
|
super(NsxLibBase, self).__init__()
|
||||||
|
|
||||||
self.nsx_version = self.get_version()
|
self.nsx_version = None
|
||||||
|
|
||||||
def set_config(self, nsxlib_config):
|
def set_config(self, nsxlib_config):
|
||||||
"""Set config user provided and extend it according to application"""
|
"""Set config user provided and extend it according to application"""
|
||||||
@ -79,11 +79,6 @@ class NsxLibBase(object):
|
|||||||
def init_api(self):
|
def init_api(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_version(self):
|
|
||||||
node = self.client.get("node")
|
|
||||||
version = node.get('node_version')
|
|
||||||
return version
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def feature_supported(self, feature):
|
def feature_supported(self, feature):
|
||||||
pass
|
pass
|
||||||
@ -190,8 +185,16 @@ class NsxLib(NsxLibBase):
|
|||||||
def keepalive_section(self):
|
def keepalive_section(self):
|
||||||
return 'transport-zones'
|
return 'transport-zones'
|
||||||
|
|
||||||
|
def get_version(self):
|
||||||
|
if self.nsx_version:
|
||||||
|
return self.nsx_version
|
||||||
|
|
||||||
|
node = self.client.get("node")
|
||||||
|
self.nsx_version = node.get('node_version')
|
||||||
|
return self.nsx_version
|
||||||
|
|
||||||
def feature_supported(self, feature):
|
def feature_supported(self, feature):
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
if (version.LooseVersion(self.get_version()) >=
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_2_0_0)):
|
version.LooseVersion(nsx_constants.NSX_VERSION_2_0_0)):
|
||||||
# Features available since 2.0
|
# Features available since 2.0
|
||||||
if (feature == nsx_constants.FEATURE_EXCLUDE_PORT_BY_TAG or
|
if (feature == nsx_constants.FEATURE_EXCLUDE_PORT_BY_TAG or
|
||||||
@ -199,7 +202,7 @@ class NsxLib(NsxLibBase):
|
|||||||
feature == nsx_constants.FEATURE_LOAD_BALANCER):
|
feature == nsx_constants.FEATURE_LOAD_BALANCER):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
if (version.LooseVersion(self.get_version()) >=
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_1_1_0)):
|
version.LooseVersion(nsx_constants.NSX_VERSION_1_1_0)):
|
||||||
# Features available since 1.1
|
# Features available since 1.1
|
||||||
if (feature == nsx_constants.FEATURE_MAC_LEARNING or
|
if (feature == nsx_constants.FEATURE_MAC_LEARNING or
|
||||||
@ -234,13 +237,7 @@ class NsxPolicyLib(NsxLibBase):
|
|||||||
return 'infra'
|
return 'infra'
|
||||||
|
|
||||||
def feature_supported(self, feature):
|
def feature_supported(self, feature):
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
return (feature == nsx_constants.FEATURE_NSX_POLICY)
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_2_0_0)):
|
|
||||||
# NSX policy is available since 2.0
|
|
||||||
if feature == nsx_constants.FEATURE_NSX_POLICY:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client_url_prefix(self):
|
def client_url_prefix(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user