Merge "Adding API for checking features availabilty"

This commit is contained in:
Jenkins 2017-05-25 22:54:09 +00:00 committed by Gerrit Code Review
commit a4d4667768
4 changed files with 72 additions and 0 deletions

View File

@ -29,6 +29,8 @@ 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

View File

@ -16,6 +16,7 @@
from neutron_lib import exceptions as n_exc
from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase
from vmware_nsxlib.v3 import nsx_constants
from vmware_nsxlib.v3 import utils
@ -236,3 +237,25 @@ class TestNsxV3Utils(nsxlib_testcase.NsxClientTestCase):
cookie_name='ABC', cookie_fallback=True,
bogus='bogus')
self.assertEqual(resp, expected)
class NsxFeaturesTestCase(nsxlib_testcase.NsxLibTestCase):
def test_v2_features(self, current_version='2.0.0'):
self.nsxlib.nsx_version = current_version
self.assertTrue(self.nsxlib.feature_supported(
nsx_constants.FEATURE_ROUTER_FIREWALL))
self.assertTrue(self.nsxlib.feature_supported(
nsx_constants.FEATURE_EXCLUDE_PORT_BY_TAG))
def test_v2_features_plus(self):
self.test_v2_features(current_version='2.0.1')
def test_v2_features_minus(self):
self.nsxlib.nsx_version = '1.9.9'
self.assertFalse(self.nsxlib.feature_supported(
nsx_constants.FEATURE_ROUTER_FIREWALL))
self.assertFalse(self.nsxlib.feature_supported(
nsx_constants.FEATURE_EXCLUDE_PORT_BY_TAG))
self.assertTrue(self.nsxlib.feature_supported(
nsx_constants.FEATURE_MAC_LEARNING))

View File

@ -16,6 +16,7 @@
import abc
import six
from distutils import version
from oslo_log import log
from vmware_nsxlib._i18n import _
@ -25,6 +26,7 @@ from vmware_nsxlib.v3 import core_resources
from vmware_nsxlib.v3 import exceptions
from vmware_nsxlib.v3 import load_balancer
from vmware_nsxlib.v3 import native_dhcp
from vmware_nsxlib.v3 import nsx_constants
from vmware_nsxlib.v3 import policy_defs
from vmware_nsxlib.v3 import policy_resources
from vmware_nsxlib.v3 import resources
@ -56,6 +58,8 @@ class NsxLibBase(object):
super(NsxLibBase, self).__init__()
self.nsx_version = self.get_version()
def set_config(self, nsxlib_config):
"""Set config user provided and extend it according to application"""
self.nsxlib_config = nsxlib_config
@ -74,6 +78,10 @@ class NsxLibBase(object):
version = node.get('node_version')
return version
@abc.abstractmethod
def feature_supported(self, feature):
pass
def build_v3_api_version_tag(self):
return self.general_apis.build_v3_api_version_tag()
@ -176,6 +184,24 @@ class NsxLib(NsxLibBase):
def keepalive_section(self):
return 'transport-zones'
def feature_supported(self, feature):
if (version.LooseVersion(self.nsx_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
feature == nsx_constants.FEATURE_ROUTER_FIREWALL or
feature == nsx_constants.FEATURE_LOAD_BALANCER):
return True
if (version.LooseVersion(self.nsx_version) >=
version.LooseVersion(nsx_constants.NSX_VERSION_1_1_0)):
# Features available since 1.1
if (feature == nsx_constants.FEATURE_MAC_LEARNING or
feature == nsx_constants.FEATURE_DYNAMIC_CRITERIA):
return True
return False
class NsxPolicyLib(NsxLibBase):
@ -196,3 +222,12 @@ class NsxPolicyLib(NsxLibBase):
@property
def keepalive_section(self):
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

View File

@ -114,3 +114,15 @@ ERR_CODE_IPAM_IP_NOT_IN_POOL = 5110
ERR_CODE_IPAM_RANGE_MODIFY = 5602
ERR_CODE_IPAM_RANGE_DELETE = 5015
ERR_CODE_IPAM_RANGE_SHRUNK = 5016
# backend versions
NSX_VERSION_1_1_0 = '1.1.0'
NSX_VERSION_2_0_0 = '2.0.0'
# Features available depending on the backend version
FEATURE_MAC_LEARNING = 'MAC Learning'
FEATURE_DYNAMIC_CRITERIA = 'Dynamic criteria'
FEATURE_EXCLUDE_PORT_BY_TAG = 'Exclude Port by Tag'
FEATURE_ROUTER_FIREWALL = 'Router Firewall'
FEATURE_LOAD_BALANCER = 'Load Balancer'
FEATURE_NSX_POLICY = 'NSX Policy'