Browse Source

NSX|P: Consume nsxlib folderization patch

Change-Id: I24e2099b8c13c61218ca3c7582961a8620cfca28
changes/22/628322/5
Anna Khmelnitsky 3 years ago
committed by Adit Sarfaty
parent
commit
d1bf1f324e
  1. 5
      devstack/tools/nsxp_cleanup.py
  2. 5
      vmware_nsx/plugins/nsx_p/plugin.py
  3. 3
      vmware_nsx/plugins/nsx_v3/utils.py
  4. 63
      vmware_nsx/tests/unit/nsx_p/test_plugin.py

5
devstack/tools/nsxp_cleanup.py

@ -22,7 +22,8 @@ from neutron.db.models import securitygroup
from neutron.db.models import segment # noqa
from neutron.db import models_v2
from vmware_nsxlib import v3
from vmware_nsxlib.policy import policy
from vmware_nsxlib.v3 import config
from vmware_nsxlib.v3 import exceptions
@ -71,7 +72,7 @@ class NSXClient(object):
# allow admin user to delete entities created
# under openstack principal identity
allow_overwrite_header=True)
self.nsxpolicy = v3.NsxPolicyLib(nsxlib_config)
self.nsxpolicy = policy.NsxPolicyLib(nsxlib_config)
def get_nsx_os_domains(self):
domains = self.get_os_resources(self.nsxpolicy.domain.list())

5
vmware_nsx/plugins/nsx_p/plugin.py

@ -63,11 +63,12 @@ from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
from vmware_nsxlib.v3 import exceptions as nsx_lib_exc
from vmware_nsxlib.v3 import nsx_constants as nsxlib_consts
from vmware_nsxlib.v3 import policy_constants
from vmware_nsxlib.v3 import policy_defs
from vmware_nsxlib.v3 import security
from vmware_nsxlib.v3 import utils as nsxlib_utils
from vmware_nsxlib.v3.policy import constants as policy_constants
from vmware_nsxlib.v3.policy import core_defs as policy_defs
LOG = log.getLogger(__name__)
NSX_P_SECURITY_GROUP_TAG = 'os-security-group'
NSX_P_GLOBAL_DOMAIN_ID = policy_constants.DEFAULT_DOMAIN

3
vmware_nsx/plugins/nsx_v3/utils.py

@ -38,6 +38,7 @@ from vmware_nsxlib.v3 import config
from vmware_nsxlib.v3 import core_resources
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
from vmware_nsxlib.v3 import nsx_constants
from vmware_nsxlib.v3 import policy
NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin'
OS_NEUTRON_ID_SCOPE = 'os-neutron-id'
@ -196,7 +197,7 @@ def get_nsxpolicy_wrapper(nsx_username=None, nsx_password=None,
plugin_tag=NSX_NEUTRON_PLUGIN,
plugin_ver=n_version.version_info.release_string(),
allow_passthrough=cfg.CONF.nsx_p.allow_passthrough)
return v3.NsxPolicyLib(nsxlib_config)
return policy.NsxPolicyLib(nsxlib_config)
def get_orphaned_dhcp_servers(context, plugin, nsxlib, dhcp_profile_uuid=None):

63
vmware_nsx/tests/unit/nsx_p/test_plugin.py

@ -51,7 +51,8 @@ from vmware_nsx.tests import unit as vmware
from vmware_nsx.tests.unit.common_plugin import common_v3
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
from vmware_nsxlib.v3 import nsx_constants
from vmware_nsxlib.v3 import policy_constants
from vmware_nsxlib.v3.policy import constants as policy_constants
PLUGIN_NAME = 'vmware_nsx.plugin.NsxPolicyPlugin'
NSX_OVERLAY_TZ_NAME = 'OVERLAY_TZ'
@ -90,7 +91,7 @@ class NsxPPluginTestCaseMixin(
resource_list_result = {'results': [{'id': 'test',
'display_name': 'test'}]}
mock.patch(
"vmware_nsxlib.v3.NsxPolicyLib.get_version",
"vmware_nsxlib.v3.policy.NsxPolicyLib.get_version",
return_value=nsx_constants.NSX_VERSION_2_4_0).start()
mock.patch(
"vmware_nsxlib.v3.client.RESTClient.get").start()
@ -101,20 +102,20 @@ class NsxPPluginTestCaseMixin(
"vmware_nsxlib.v3.client.RESTClient.patch").start()
mock.patch(
"vmware_nsxlib.v3.client.RESTClient.delete").start()
mock.patch("vmware_nsxlib.v3.policy_resources."
mock.patch("vmware_nsxlib.v3.policy.core_resources."
"NsxPolicyCommunicationMapApi._get_last_seq_num",
return_value=-1).start()
mock.patch("vmware_nsxlib.v3.policy_resources."
mock.patch("vmware_nsxlib.v3.policy.core_resources."
"NsxPolicyResourceBase._wait_until_realized",
return_value={'state': policy_constants.STATE_REALIZED}
).start()
mock.patch("vmware_nsxlib.v3.policy_resources."
mock.patch("vmware_nsxlib.v3.policy.core_resources."
"NsxPolicyTier1Api.update_transport_zone").start()
mock.patch("vmware_nsxlib.v3.policy_resources."
mock.patch("vmware_nsxlib.v3.policy.core_resources."
"NsxPolicySegmentApi.get_realized_logical_switch_id",
return_value=LOGICAL_SWITCH_ID
).start()
mock.patch("vmware_nsxlib.v3.policy_resources."
mock.patch("vmware_nsxlib.v3.policy.core_resources."
"NsxPolicySegmentApi.get_realized_id",
return_value=LOGICAL_SWITCH_ID
).start()
@ -195,12 +196,12 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
def test_create_provider_flat_network(self):
providernet_args = {pnet.NETWORK_TYPE: 'flat'}
with mock.patch('vmware_nsxlib.v3.policy_resources.'
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.create_or_overwrite',
side_effect=_return_id_key) as nsx_create, \
mock.patch('vmware_nsxlib.v3.policy_resources.NsxPolicySegmentApi.'
'delete') as nsx_delete, \
mock.patch('vmware_nsxlib.v3.policy_resources.'
mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.delete') as nsx_delete, \
mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicyTransportZoneApi.get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN), \
self.network(name='flat_net',
@ -221,7 +222,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
providernet_args = {pnet.NETWORK_TYPE: 'flat',
pnet.PHYSICAL_NETWORK: physical_network}
with mock.patch(
'vmware_nsxlib.v3.policy_resources.NsxPolicyTransportZoneApi.'
'vmware_nsxlib.v3.policy.core_resources.NsxPolicyTransportZoneApi.'
'get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN), \
self.network(name='flat_net',
@ -234,7 +235,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
providernet_args = {pnet.NETWORK_TYPE: 'flat',
pnet.SEGMENTATION_ID: 11}
with mock.patch(
'vmware_nsxlib.v3.policy_resources.NsxPolicyTransportZoneApi.'
'vmware_nsxlib.v3.policy.core_resources.NsxPolicyTransportZoneApi.'
'get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN):
result = self._create_network(fmt='json', name='bad_flat_net',
@ -248,11 +249,11 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
def test_create_provider_geneve_network(self):
providernet_args = {pnet.NETWORK_TYPE: 'geneve'}
with mock.patch('vmware_nsxlib.v3.policy_resources.'
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.create_or_overwrite',
side_effect=_return_id_key) as nsx_create, \
mock.patch('vmware_nsxlib.v3.policy_resources.NsxPolicySegmentApi.'
'delete') as nsx_delete, \
mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.delete') as nsx_delete, \
self.network(name='geneve_net',
providernet_args=providernet_args,
arg_list=(pnet.NETWORK_TYPE, )) as net:
@ -271,7 +272,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
providernet_args = {pnet.NETWORK_TYPE: 'geneve',
pnet.PHYSICAL_NETWORK: physical_network}
with mock.patch(
'vmware_nsxlib.v3.policy_resources.NsxPolicyTransportZoneApi.'
'vmware_nsxlib.v3.policy.core_resources.NsxPolicyTransportZoneApi.'
'get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_OVERLAY),\
self.network(name='geneve_net',
@ -283,7 +284,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
providernet_args = {pnet.NETWORK_TYPE: 'geneve',
pnet.SEGMENTATION_ID: 11}
with mock.patch(
'vmware_nsxlib.v3.policy_resources.NsxPolicyTransportZoneApi.'
'vmware_nsxlib.v3.policy.core_resources.NsxPolicyTransportZoneApi.'
'get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_OVERLAY):
result = self._create_network(fmt='json', name='bad_geneve_net',
@ -298,12 +299,12 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
def test_create_provider_vlan_network(self):
providernet_args = {pnet.NETWORK_TYPE: 'vlan',
pnet.SEGMENTATION_ID: 11}
with mock.patch('vmware_nsxlib.v3.policy_resources.'
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.create_or_overwrite',
side_effect=_return_id_key) as nsx_create, \
mock.patch('vmware_nsxlib.v3.policy_resources.NsxPolicySegmentApi.'
'delete') as nsx_delete, \
mock.patch('vmware_nsxlib.v3.policy_resources.'
mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.delete') as nsx_delete, \
mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicyTransportZoneApi.get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN), \
self.network(name='vlan_net',
@ -326,11 +327,11 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
pnet.PHYSICAL_NETWORK: physical_network}
with mock.patch(
'vmware_nsxlib.v3.policy_resources.NsxPolicySegmentApi.'
'vmware_nsxlib.v3.policy.core_resources.NsxPolicySegmentApi.'
'create_or_overwrite',
side_effect=nsxlib_exc.ResourceNotFound) as nsx_create, \
mock.patch('vmware_nsxlib.v3.policy_resources.NsxPolicySegmentApi.'
'delete') as nsx_delete, \
mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.delete') as nsx_delete, \
self.network(name='nsx_net',
providernet_args=providernet_args,
arg_list=(pnet.NETWORK_TYPE,
@ -352,7 +353,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
providernet_args = {pnet.NETWORK_TYPE: 'nsx-net',
pnet.PHYSICAL_NETWORK: physical_network}
with mock.patch(
"vmware_nsxlib.v3.policy_resources.NsxPolicySegmentApi.get",
"vmware_nsxlib.v3.policy.core_resources.NsxPolicySegmentApi.get",
side_effect=nsxlib_exc.ResourceNotFound):
result = self._create_network(fmt='json', name='bad_nsx_net',
admin_state_up=True,
@ -365,7 +366,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
def test_create_transparent_vlan_network(self):
providernet_args = {vlan_apidef.VLANTRANSPARENT: True}
with mock.patch('vmware_nsxlib.v3.policy_resources.'
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicyTransportZoneApi.get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_OVERLAY), \
self.network(name='vt_net',
@ -376,7 +377,7 @@ class NsxPTestNetworks(test_db_base_plugin_v2.TestNetworksV2,
def test_create_provider_vlan_network_with_transparent(self):
providernet_args = {pnet.NETWORK_TYPE: 'vlan',
vlan_apidef.VLANTRANSPARENT: True}
with mock.patch('vmware_nsxlib.v3.policy_resources.'
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicyTransportZoneApi.get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN):
result = self._create_network(fmt='json', name='badvlan_net',
@ -858,8 +859,8 @@ class NsxPTestSecurityGroup(common_v3.FixExternalNetBaseTest,
if vlan_id:
providernet_args[pnet.SEGMENTATION_ID] = vlan_id
mock_tt = mock.patch('vmware_nsxlib.v3'
'.policy_resources.NsxPolicyTransportZoneApi'
mock_tt = mock.patch('vmware_nsxlib.v3.policy'
'.core_resources.NsxPolicyTransportZoneApi'
'.get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN)
mock_tt.start()
@ -870,7 +871,7 @@ class NsxPTestSecurityGroup(common_v3.FixExternalNetBaseTest,
pnet.SEGMENTATION_ID))
def _test_create_port_vnic_direct(self, vlan_id):
with mock.patch('vmware_nsxlib.v3.policy_resources.'
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicyTransportZoneApi.get_transport_type',
return_value=nsx_constants.TRANSPORT_TYPE_VLAN),\
self._test_create_direct_network(vlan_id=vlan_id) as network:

Loading…
Cancel
Save