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"),
|
||||
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():
|
||||
return config.NsxLibConfig(
|
||||
|
@ -29,8 +29,6 @@ class NsxPolicyLibTestCase(unittest.TestCase):
|
||||
def setUp(self, *args, **kwargs):
|
||||
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()
|
||||
self.policy_lib = v3.NsxPolicyLib(nsxlib_config)
|
||||
self.policy_api = self.policy_lib.policy_api
|
||||
|
@ -59,7 +59,7 @@ class NsxLibBase(object):
|
||||
|
||||
super(NsxLibBase, self).__init__()
|
||||
|
||||
self.nsx_version = self.get_version()
|
||||
self.nsx_version = None
|
||||
|
||||
def set_config(self, nsxlib_config):
|
||||
"""Set config user provided and extend it according to application"""
|
||||
@ -79,11 +79,6 @@ class NsxLibBase(object):
|
||||
def init_api(self):
|
||||
pass
|
||||
|
||||
def get_version(self):
|
||||
node = self.client.get("node")
|
||||
version = node.get('node_version')
|
||||
return version
|
||||
|
||||
@abc.abstractmethod
|
||||
def feature_supported(self, feature):
|
||||
pass
|
||||
@ -190,8 +185,16 @@ class NsxLib(NsxLibBase):
|
||||
def keepalive_section(self):
|
||||
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):
|
||||
if (version.LooseVersion(self.nsx_version) >=
|
||||
if (version.LooseVersion(self.get_version()) >=
|
||||
version.LooseVersion(nsx_constants.NSX_VERSION_2_0_0)):
|
||||
# Features available since 2.0
|
||||
if (feature == nsx_constants.FEATURE_EXCLUDE_PORT_BY_TAG or
|
||||
@ -199,7 +202,7 @@ class NsxLib(NsxLibBase):
|
||||
feature == nsx_constants.FEATURE_LOAD_BALANCER):
|
||||
return True
|
||||
|
||||
if (version.LooseVersion(self.nsx_version) >=
|
||||
if (version.LooseVersion(self.get_version()) >=
|
||||
version.LooseVersion(nsx_constants.NSX_VERSION_1_1_0)):
|
||||
# Features available since 1.1
|
||||
if (feature == nsx_constants.FEATURE_MAC_LEARNING or
|
||||
@ -234,13 +237,7 @@ class NsxPolicyLib(NsxLibBase):
|
||||
return 'infra'
|
||||
|
||||
def feature_supported(self, feature):
|
||||
if (version.LooseVersion(self.nsx_version) >=
|
||||
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
|
||||
return (feature == nsx_constants.FEATURE_NSX_POLICY)
|
||||
|
||||
@property
|
||||
def client_url_prefix(self):
|
||||
|
Loading…
Reference in New Issue
Block a user