Ejemplo n.º 1
0
    def setUp(self):
        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        mock_api = mock.patch(NSXAPI_NAME, autospec=True)
        # Avoid runs of the synchronizer looping call
        # These unit tests will excplicitly invoke synchronization
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        self.mock_api = mock_api.start()
        patch_sync.start()
        self.mock_api.return_value.login.return_value = "the_cookie"
        # Emulate tests against NSX 3.x
        self.mock_api.return_value.get_version.return_value = (
            version.Version("3.1"))

        self.mock_api.return_value.request.side_effect = self.fc.fake_request
        self.fake_cluster = cluster.NSXCluster(name='fake-cluster',
                                               nsx_controllers=['1.1.1.1:999'],
                                               default_tz_uuid=_uuid(),
                                               nsx_user='******',
                                               nsx_password='******')
        self.fake_cluster.api_client = client.NsxApiClient(
            ('1.1.1.1', '999', True),
            self.fake_cluster.nsx_user,
            self.fake_cluster.nsx_password,
            request_timeout=self.fake_cluster.req_timeout,
            http_timeout=self.fake_cluster.http_timeout,
            retries=self.fake_cluster.retries,
            redirects=self.fake_cluster.redirects)
        # Instantiate Neutron plugin
        # and setup needed config variables
        args = [
            '--config-file',
            get_fake_conf('neutron.conf.test'), '--config-file',
            get_fake_conf('nsx.ini.test')
        ]
        config.parse(args=args)
        cfg.CONF.set_override('allow_overlapping_ips', True)
        self._plugin = plugin.NsxPlugin()
        # Mock neutron manager plugin load functions to speed up tests
        mock_nm_get_plugin = mock.patch('neutron.manager.NeutronManager.'
                                        'get_plugin')
        mock_nm_get_service_plugins = mock.patch(
            'neutron.manager.NeutronManager.get_service_plugins')
        self.mock_nm_get_plugin = mock_nm_get_plugin.start()
        self.mock_nm_get_plugin.return_value = self._plugin
        mock_nm_get_service_plugins.start()
        super(SyncTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(mock_api.stop)
        self.addCleanup(mock_nm_get_plugin.stop)
        self.addCleanup(mock_nm_get_service_plugins.stop)
Ejemplo n.º 2
0
    def setUp(self):
        self.adminContext = context.get_admin_context()
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]
        cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
        # Save the original RESOURCE_ATTRIBUTE_MAP
        self.saved_attr_map = {}
        for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
            self.saved_attr_map[resource] = attrs.copy()
        ext_mgr = MacLearningExtensionManager()
        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx.start()
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        # Emulate tests against NSX 2.x
        instance.return_value.get_nvp_version.return_value = NVPVersion("3.0")
        instance.return_value.request.side_effect = self.fc.fake_request
        cfg.CONF.set_override('metadata_mode', None, 'NSX')
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nsx.stop)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.restore_resource_attribute_map)
        self.addCleanup(cfg.CONF.reset)
        super(MacLearningDBTestCase, self).setUp(plugin=PLUGIN_NAME,
                                                 ext_mgr=ext_mgr)
Ejemplo n.º 3
0
    def setUp(self):
        self.adminContext = context.get_admin_context()
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]
        cfg.CONF.set_override('api_extensions_path', NSXEXT_PATH)
        # Save the original RESOURCE_ATTRIBUTE_MAP
        self.saved_attr_map = {}
        for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
            self.saved_attr_map[resource] = attrs.copy()
        ext_mgr = MacLearningExtensionManager()
        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx.start()
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        # Emulate tests against NSX 2.x
        instance.return_value.get_nvp_version.return_value = NVPVersion("3.0")
        instance.return_value.request.side_effect = self.fc.fake_request
        cfg.CONF.set_override('metadata_mode', None, 'NSX')
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nsx.stop)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.restore_resource_attribute_map)
        self.addCleanup(cfg.CONF.reset)
        super(MacLearningDBTestCase, self).setUp(plugin=PLUGIN_NAME,
                                                 ext_mgr=ext_mgr)
Ejemplo n.º 4
0
    def setUp(self):
        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        mock_api = mock.patch(NSXAPI_NAME, autospec=True)
        # Avoid runs of the synchronizer looping call
        # These unit tests will excplicitly invoke synchronization
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        self.mock_api = mock_api.start()
        patch_sync.start()
        self.mock_api.return_value.login.return_value = "the_cookie"
        # Emulate tests against NSX 3.x
        self.mock_api.return_value.get_version.return_value = (
            version.Version("3.1"))

        self.mock_api.return_value.request.side_effect = self.fc.fake_request
        self.fake_cluster = cluster.NSXCluster(
            name='fake-cluster', nsx_controllers=['1.1.1.1:999'],
            default_tz_uuid=_uuid(), nsx_user='******', nsx_password='******')
        self.fake_cluster.api_client = client.NsxApiClient(
            ('1.1.1.1', '999', True),
            self.fake_cluster.nsx_user, self.fake_cluster.nsx_password,
            request_timeout=self.fake_cluster.req_timeout,
            http_timeout=self.fake_cluster.http_timeout,
            retries=self.fake_cluster.retries,
            redirects=self.fake_cluster.redirects)
        # Instantiate Neutron plugin
        # and setup needed config variables
        args = ['--config-file', get_fake_conf('neutron.conf.test'),
                '--config-file', get_fake_conf('nsx.ini.test')]
        config.parse(args=args)
        cfg.CONF.set_override('allow_overlapping_ips', True)
        self._plugin = plugin.NsxPlugin()
        # Mock neutron manager plugin load functions to speed up tests
        mock_nm_get_plugin = mock.patch('neutron.manager.NeutronManager.'
                                        'get_plugin')
        mock_nm_get_service_plugins = mock.patch(
            'neutron.manager.NeutronManager.get_service_plugins')
        self.mock_nm_get_plugin = mock_nm_get_plugin.start()
        self.mock_nm_get_plugin.return_value = self._plugin
        mock_nm_get_service_plugins.start()
        super(SyncTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(mock_api.stop)
        self.addCleanup(mock_nm_get_plugin.stop)
        self.addCleanup(mock_nm_get_service_plugins.stop)
Ejemplo n.º 5
0
    def setUp(self):
        test_lib.test_config["config_files"] = [vmware.get_fake_conf("nsx.ini.test")]
        # mock nsx api client
        self.fc = fake.FakeClient(vmware.STUBS_PATH)
        self.mock_nsx = mock.patch(vmware.NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx.start()
        instance.return_value.login.return_value = "the_cookie"
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, "_start_loopingcall")
        patch_sync.start()

        instance.return_value.request.side_effect = self.fc.fake_request
        super(SecurityGroupsTestCase, self).setUp(vmware.PLUGIN_NAME)
Ejemplo n.º 6
0
    def setUp(self):
        test_lib.test_config['config_files'] = [get_fake_conf('nsx.ini.test')]
        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx.start()
        instance.return_value.login.return_value = "the_cookie"
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        instance.return_value.request.side_effect = self.fc.fake_request
        super(PortSecurityTestCase, self).setUp(PLUGIN_NAME)
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nsx.stop)
        self.addCleanup(patch_sync.stop)
Ejemplo n.º 7
0
    def setUp(self):
        test_lib.test_config['config_files'] = [get_fake_conf('nsx.ini.test')]
        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsx = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx.start()
        instance.return_value.login.return_value = "the_cookie"
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        instance.return_value.request.side_effect = self.fc.fake_request
        super(PortSecurityTestCase, self).setUp(PLUGIN_NAME)
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nsx.stop)
        self.addCleanup(patch_sync.stop)
Ejemplo n.º 8
0
    def setUp(self):
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]

        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsx_api = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx_api.start()
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        # Emulate tests against NSX 2.x
        instance.return_value.get_version.return_value = "2.999"
        instance.return_value.request.side_effect = self.fc.fake_request
        super(DhcpAgentNotifierTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.mock_nsx_api.stop)
Ejemplo n.º 9
0
    def setUp(self):
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]

        # mock api client
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsx_api = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsx_api.start()
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        # Emulate tests against NSX 2.x
        instance.return_value.get_version.return_value = "2.999"
        instance.return_value.request.side_effect = self.fc.fake_request
        super(DhcpAgentNotifierTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.mock_nsx_api.stop)
Ejemplo n.º 10
0
    def setUp(self, plugin=vmware.PLUGIN_NAME, ext_mgr=None, service_plugins=None):
        test_lib.test_config["config_files"] = [vmware.get_fake_conf("nsx.ini.test")]
        # mock api client
        self.fc = fake.FakeClient(vmware.STUBS_PATH)
        self.mock_nsx = mock.patch(vmware.NSXAPI_NAME, autospec=True)
        self.mock_instance = self.mock_nsx.start()
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, "_start_loopingcall")
        patch_sync.start()

        # Emulate tests against NSX 2.x
        self.mock_instance.return_value.get_version.return_value = version_module.Version("2.9")
        self.mock_instance.return_value.request.side_effect = self.fc.fake_request
        super(NsxPluginV2TestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr)
        # Newly created port's status is always 'DOWN' till NSX wires them.
        self.port_create_status = constants.PORT_STATUS_DOWN
        cfg.CONF.set_override("metadata_mode", None, "NSX")
        self.addCleanup(self.fc.reset_all)
Ejemplo n.º 11
0
from neutron import context
from neutron.db.firewall import firewall_db
from neutron.openstack.common import uuidutils
from neutron.plugins.vmware.vshield.common import exceptions as vcns_exc
from neutron.plugins.vmware.vshield import vcns_driver
from neutron.tests.unit.db.firewall import test_db_firewall
from neutron.tests.unit import vmware
from neutron.tests.unit.vmware.vshield import fake_vcns


_uuid = uuidutils.generate_uuid

VSE_ID = 'edge-1'
ROUTER_ID = '42f95450-5cc9-44e4-a744-1320e592a9d5'

VCNS_CONFIG_FILE = vmware.get_fake_conf("vcns.ini.test")


class VcnsDriverTestCase(test_db_firewall.FirewallPluginDbTestCase,
                         firewall_db.Firewall_db_mixin):

    def vcns_firewall_patch(self):
        instance = self.mock_vcns.start()
        instance.return_value.update_firewall.side_effect = (
            self.fc2.update_firewall)
        instance.return_value.delete_firewall.side_effect = (
            self.fc2.delete_firewall)
        instance.return_value.update_firewall_rule.side_effect = (
            self.fc2.update_firewall_rule)
        instance.return_value.delete_firewall_rule.side_effect = (
            self.fc2.delete_firewall_rule)
Ejemplo n.º 12
0
import mock
from oslo.config import cfg

from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.vmware.api_client import client
from neutron.plugins.vmware.api_client import version
from neutron.plugins.vmware.common import config  # noqa
from neutron.plugins.vmware.common import exceptions
from neutron.plugins.vmware.common import sync
from neutron.plugins.vmware import nsx_cluster
from neutron.plugins.vmware.nsxlib import lsn as lsnlib
from neutron.tests import base
from neutron.tests.unit import vmware

BASE_CONF_PATH = vmware.get_fake_conf('neutron.conf.test')
NSX_INI_PATH = vmware.get_fake_conf('nsx.ini.basic.test')
NSX_INI_FULL_PATH = vmware.get_fake_conf('nsx.ini.full.test')
NSX_INI_AGENTLESS_PATH = vmware.get_fake_conf('nsx.ini.agentless.test')
NSX_INI_COMBINED_PATH = vmware.get_fake_conf('nsx.ini.combined.test')
NVP_INI_DEPR_PATH = vmware.get_fake_conf('nvp.ini.full.test')


class NSXClusterTest(base.BaseTestCase):

    cluster_opts = {'default_tz_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'nsx_user': '******',
                    'nsx_password': '******',
                    'req_timeout': 45,
Ejemplo n.º 13
0
from neutron.plugins.vmware.vshield import vcns_driver
from neutron.services.loadbalancer import constants as lb_constants
from neutron.tests.unit.db.loadbalancer import test_db_loadbalancer
from neutron.tests.unit.vmware import get_fake_conf
from neutron.tests.unit.vmware import VCNS_NAME
from neutron.tests.unit.vmware.vshield import fake_vcns

_uuid = uuidutils.generate_uuid

VSE_ID = 'edge-1'
POOL_MAP_INFO = {
    'pool_id': None,
    'edge_id': VSE_ID,
    'pool_vseid': 'pool-1'}

VCNS_CONFIG_FILE = get_fake_conf("vcns.ini.test")


class VcnsDriverTestCase(test_db_loadbalancer.LoadBalancerPluginDbTestCase):

    def vcns_loadbalancer_patch(self):
        instance = self.mock_vcns.start()
        instance.return_value.create_vip.side_effect = (
            self.fc2.create_vip)
        instance.return_value.get_vip.side_effect = (
            self.fc2.get_vip)
        instance.return_value.update_vip.side_effect = (
            self.fc2.update_vip)
        instance.return_value.delete_vip.side_effect = (
            self.fc2.delete_vip)
        instance.return_value.create_pool.side_effect = (
Ejemplo n.º 14
0
from eventlet import greenthread
import mock

from neutron.common import config as n_config
from neutron.plugins.vmware.vshield.common import constants as vcns_const
from neutron.plugins.vmware.vshield.common.constants import RouterStatus
from neutron.plugins.vmware.vshield.tasks.constants import TaskState
from neutron.plugins.vmware.vshield.tasks.constants import TaskStatus
from neutron.plugins.vmware.vshield.tasks import tasks as ts
from neutron.plugins.vmware.vshield import vcns_driver
from neutron.tests import base
from neutron.tests.unit.vmware import get_fake_conf
from neutron.tests.unit.vmware import VCNS_NAME
from neutron.tests.unit.vmware.vshield import fake_vcns

VCNS_CONFIG_FILE = get_fake_conf("vcns.ini.test")

ts.TaskManager.set_default_interval(100)


class VcnsDriverTaskManagerTestCase(base.BaseTestCase):
    def setUp(self):
        super(VcnsDriverTaskManagerTestCase, self).setUp()
        self.manager = ts.TaskManager()
        self.manager.start(100)

    def tearDown(self):
        self.manager.stop()
        # Task manager should not leave running threads around
        # if _thread is None it means it was killed in stop()
        self.assertIsNone(self.manager._thread)
Ejemplo n.º 15
0
from neutron.common import config as q_config
from neutron.manager import NeutronManager
from neutron.openstack.common import uuidutils
from neutron.plugins.vmware.api_client import client
from neutron.plugins.vmware.api_client import version
from neutron.plugins.vmware.common import config  # noqa
from neutron.plugins.vmware.common import exceptions
from neutron.plugins.vmware.common import sync
from neutron.plugins.vmware import nsx_cluster
from neutron.plugins.vmware.nsxlib import lsn as lsnlib
from neutron.tests import base
from neutron.tests.unit.vmware import get_fake_conf
from neutron.tests.unit.vmware import PLUGIN_NAME

BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
NSX_INI_PATH = get_fake_conf('nsx.ini.basic.test')
NSX_INI_FULL_PATH = get_fake_conf('nsx.ini.full.test')
NSX_INI_AGENTLESS_PATH = get_fake_conf('nsx.ini.agentless.test')
NVP_INI_DEPR_PATH = get_fake_conf('nvp.ini.full.test')


class NSXClusterTest(base.BaseTestCase):

    cluster_opts = {'default_tz_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'nsx_user': '******',
                    'nsx_password': '******',
                    'req_timeout': 45,
                    'http_timeout': 25,
Ejemplo n.º 16
0
import mock
from oslo.config import cfg

from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.vmware.api_client import client
from neutron.plugins.vmware.api_client import version
from neutron.plugins.vmware.common import config  # noqa
from neutron.plugins.vmware.common import exceptions
from neutron.plugins.vmware.common import sync
from neutron.plugins.vmware import nsx_cluster
from neutron.plugins.vmware.nsxlib import lsn as lsnlib
from neutron.tests import base
from neutron.tests.unit import vmware

BASE_CONF_PATH = vmware.get_fake_conf('neutron.conf.test')
NSX_INI_PATH = vmware.get_fake_conf('nsx.ini.basic.test')
NSX_INI_FULL_PATH = vmware.get_fake_conf('nsx.ini.full.test')
NSX_INI_AGENTLESS_PATH = vmware.get_fake_conf('nsx.ini.agentless.test')
NSX_INI_COMBINED_PATH = vmware.get_fake_conf('nsx.ini.combined.test')
NVP_INI_DEPR_PATH = vmware.get_fake_conf('nvp.ini.full.test')


class NSXClusterTest(base.BaseTestCase):

    cluster_opts = {
        'default_tz_uuid': uuidutils.generate_uuid(),
        'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
        'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
        'nsx_user': '******',
        'nsx_password': '******',
Ejemplo n.º 17
0
from neutron.common import config as q_config
from neutron.manager import NeutronManager
from neutron.openstack.common import uuidutils
from neutron.plugins.vmware.api_client import client
from neutron.plugins.vmware.api_client import version
from neutron.plugins.vmware.common import config  # noqa
from neutron.plugins.vmware.common import exceptions
from neutron.plugins.vmware.common import sync
from neutron.plugins.vmware import nsx_cluster
from neutron.plugins.vmware.nsxlib import lsn as lsnlib
from neutron.tests import base
from neutron.tests.unit.vmware import get_fake_conf
from neutron.tests.unit.vmware import PLUGIN_NAME

BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
NSX_INI_PATH = get_fake_conf('nsx.ini.basic.test')
NSX_INI_FULL_PATH = get_fake_conf('nsx.ini.full.test')
NSX_INI_AGENTLESS_PATH = get_fake_conf('nsx.ini.agentless.test')
NVP_INI_DEPR_PATH = get_fake_conf('nvp.ini.full.test')


class NSXClusterTest(base.BaseTestCase):

    cluster_opts = {'default_tz_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'nsx_user': '******',
                    'nsx_password': '******',
                    'req_timeout': 45,
                    'http_timeout': 25,
Ejemplo n.º 18
0
import mock
from oslo.config import cfg

from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.vmware.api_client import client
from neutron.plugins.vmware.api_client import version
from neutron.plugins.vmware.common import config  # noqa
from neutron.plugins.vmware.common import exceptions
from neutron.plugins.vmware.common import sync
from neutron.plugins.vmware import nsx_cluster
from neutron.plugins.vmware.nsxlib import lsn as lsnlib
from neutron.tests import base
from neutron.tests.unit import vmware

BASE_CONF_PATH = vmware.get_fake_conf("neutron.conf.test")
NSX_INI_PATH = vmware.get_fake_conf("nsx.ini.basic.test")
NSX_INI_FULL_PATH = vmware.get_fake_conf("nsx.ini.full.test")
NSX_INI_AGENTLESS_PATH = vmware.get_fake_conf("nsx.ini.agentless.test")
NVP_INI_DEPR_PATH = vmware.get_fake_conf("nvp.ini.full.test")


class NSXClusterTest(base.BaseTestCase):

    cluster_opts = {
        "default_tz_uuid": uuidutils.generate_uuid(),
        "default_l2_gw_service_uuid": uuidutils.generate_uuid(),
        "default_l2_gw_service_uuid": uuidutils.generate_uuid(),
        "nsx_user": "******",
        "nsx_password": "******",
        "req_timeout": 45,