Ejemplo n.º 1
0
    def setUp(self):
        # mock nvp api client
        self.fc = fake_nvpapiclient.FakeClient(STUBS_PATH)
        mock_nvpapi = mock.patch(NVPAPI_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_nvpapi = mock_nvpapi.start()
        patch_sync.start()
        self.mock_nvpapi.return_value.login.return_value = "the_cookie"
        # Emulate tests against NVP 3.x
        self.mock_nvpapi.return_value.get_nvp_version.return_value = (
            NvpApiClient.NVPVersion("3.1"))

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        self.mock_nvpapi.return_value.request.side_effect = _fake_request
        self.fake_cluster = nsx_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 = NvpApiClient.NVPApiHelper(
            ('1.1.1.1', '999', True), self.fake_cluster.nsx_user,
            self.fake_cluster.nsx_password, self.fake_cluster.req_timeout,
            self.fake_cluster.http_timeout, self.fake_cluster.retries,
            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 = NeutronPlugin.NvpPluginV2()
        # 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(NvpSyncTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(mock_nvpapi.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('nvp.ini.full.test')]
        test_config['plugin_name_v2'] = PLUGIN_NAME
        cfg.CONF.set_override('api_extensions_path', NVPEXT_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()
        test_config['extension_manager'] = ext_mgr
        # mock nvp api client
        self.fc = fake_nvpapiclient.FakeClient(STUBS_PATH)
        self.mock_nvpapi = mock.patch(NVPAPI_NAME, autospec=True)
        instance = self.mock_nvpapi.start()

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        # Emulate tests against NVP 2.x
        instance.return_value.get_nvp_version.return_value = NVPVersion("3.0")
        instance.return_value.request.side_effect = _fake_request
        cfg.CONF.set_override('metadata_mode', None, 'NVP')
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nvpapi.stop)
        self.addCleanup(self.restore_resource_attribute_map)
        self.addCleanup(cfg.CONF.reset)
        super(MacLearningDBTestCase, self).setUp()
Ejemplo n.º 3
0
    def setUp(self):
        self.adminContext = context.get_admin_context()
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]
        test_config['plugin_name_v2'] = PLUGIN_NAME
        cfg.CONF.set_override('api_extensions_path', NVPEXT_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()
        test_config['extension_manager'] = ext_mgr
        # mock nvp api client
        self.fc = fake_nvpapiclient.FakeClient(STUBS_PATH)
        self.mock_nvpapi = mock.patch(NVPAPI_NAME, autospec=True)
        instance = self.mock_nvpapi.start()
        # Avoid runs of the synchronizer looping call
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        patch_sync.start()

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        # Emulate tests against NVP 2.x
        instance.return_value.get_nvp_version.return_value = NVPVersion("3.0")
        instance.return_value.request.side_effect = _fake_request
        cfg.CONF.set_override('metadata_mode', None, 'NSX')
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nvpapi.stop)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.restore_resource_attribute_map)
        self.addCleanup(cfg.CONF.reset)
        super(MacLearningDBTestCase, self).setUp()
Ejemplo n.º 4
0
    def setUp(self):
        # mock nvp api client
        self.fc = fake_nvpapiclient.FakeClient(STUBS_PATH)
        mock_nvpapi = mock.patch(NVPAPI_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_nvpapi = mock_nvpapi.start()
        patch_sync.start()
        self.mock_nvpapi.return_value.login.return_value = "the_cookie"
        # Emulate tests against NVP 3.x
        self.mock_nvpapi.return_value.get_nvp_version.return_value = (
            NvpApiClient.NVPVersion("3.1"))

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        self.mock_nvpapi.return_value.request.side_effect = _fake_request
        self.fake_cluster = nvp_cluster.NVPCluster(
            name='fake-cluster', nvp_controllers=['1.1.1.1:999'],
            default_tz_uuid=_uuid(), nvp_user='******', nvp_password='******')
        self.fake_cluster.api_client = NvpApiClient.NVPApiHelper(
            ('1.1.1.1', '999', True),
            self.fake_cluster.nvp_user, self.fake_cluster.nvp_password,
            self.fake_cluster.req_timeout, self.fake_cluster.http_timeout,
            self.fake_cluster.retries, 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('nvp.ini.test')]
        config.parse(args=args)
        cfg.CONF.set_override('allow_overlapping_ips', True)
        self._plugin = NeutronPlugin.NvpPluginV2()
        # 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(NvpSyncTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(mock_nvpapi.stop)
        self.addCleanup(mock_nm_get_plugin.stop)
        self.addCleanup(mock_nm_get_service_plugins.stop)
Ejemplo n.º 5
0
    def setUp(self):
        test_config['plugin_name_v2'] = PLUGIN_NAME
        test_config['config_files'] = [get_fake_conf('nvp.ini.full.test')]

        # mock nvp api client
        self.fc = fake_nvpapiclient.FakeClient(STUBS_PATH)
        self.mock_nvpapi = mock.patch(NVPAPI_NAME, autospec=True)
        instance = self.mock_nvpapi.start()

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        # Emulate tests against NVP 2.x
        instance.return_value.get_nvp_version.return_value = "2.999"
        instance.return_value.request.side_effect = _fake_request
        super(NVPDhcpAgentNotifierTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nvpapi.stop)
Ejemplo n.º 6
0
    def setUp(self):
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]

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

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        # Emulate tests against NVP 2.x
        instance.return_value.get_nvp_version.return_value = "2.999"
        instance.return_value.request.side_effect = _fake_request
        super(NVPDhcpAgentNotifierTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.mock_nvpapi.stop)
        self.addCleanup(cfg.CONF.reset)
Ejemplo n.º 7
0
    def setUp(self):
        test_config['config_files'] = [get_fake_conf('nsx.ini.full.test')]

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

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        # Emulate tests against NVP 2.x
        instance.return_value.get_nvp_version.return_value = "2.999"
        instance.return_value.request.side_effect = _fake_request
        super(NVPDhcpAgentNotifierTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(self.mock_nvpapi.stop)
        self.addCleanup(cfg.CONF.reset)
Ejemplo n.º 8
0
import testtools

import mock
from oslo.config import cfg

from neutron.common import config as q_config
from neutron.manager import NeutronManager
from neutron.openstack.common import uuidutils
from neutron.plugins.nicira.common import config  # noqa
from neutron.plugins.nicira.common import exceptions
from neutron.plugins.nicira.common import sync
from neutron.plugins.nicira import nvp_cluster
from neutron.tests.unit.nicira import get_fake_conf
from neutron.tests.unit.nicira import PLUGIN_NAME

BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
NVP_BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
NVP_INI_PATH = get_fake_conf('nvp.ini.basic.test')
NVP_INI_FULL_PATH = get_fake_conf('nvp.ini.full.test')
NVP_INI_DEPR_PATH = get_fake_conf('nvp.ini.grizzly.test')
NVP_INI_AGENTLESS_PATH = get_fake_conf('nvp.ini.agentless.test')


class NVPClusterTest(testtools.TestCase):

    cluster_opts = {'default_tz_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
                    'nvp_cluster_uuid': uuidutils.generate_uuid(),
                    'nvp_user': '******',
                    'nvp_password': '******',
Ejemplo n.º 9
0
from neutron.db.firewall import firewall_db
from neutron.openstack.common import uuidutils
from neutron.plugins.nicira.vshield.common import exceptions as vcns_exc
from neutron.plugins.nicira.vshield import vcns_driver
from neutron.tests.unit.db.firewall import test_db_firewall
from neutron.tests.unit.nicira import get_fake_conf
from neutron.tests.unit.nicira import VCNS_NAME
from neutron.tests.unit.nicira.vshield import fake_vcns


_uuid = uuidutils.generate_uuid

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

VCNS_CONFIG_FILE = 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.º 10
0
import mock

from neutron.common import config as n_config
from neutron.plugins.nicira.vshield.common import (
    constants as vcns_const)
from neutron.plugins.nicira.vshield.common.constants import RouterStatus
from neutron.plugins.nicira.vshield.tasks.constants import TaskState
from neutron.plugins.nicira.vshield.tasks.constants import TaskStatus
from neutron.plugins.nicira.vshield.tasks import tasks as ts
from neutron.plugins.nicira.vshield import vcns_driver
from neutron.tests import base
from neutron.tests.unit.nicira import get_fake_conf
from neutron.tests.unit.nicira import VCNS_NAME
from neutron.tests.unit.nicira.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()
        super(VcnsDriverTaskManagerTestCase, self).tearDown()
Ejemplo n.º 11
0
import fixtures
import testtools

from oslo.config import cfg

from neutron.common import config as q_config
from neutron.manager import NeutronManager
from neutron.openstack.common import uuidutils
from neutron.plugins.nicira.common import config  # noqa
from neutron.plugins.nicira.common import exceptions
from neutron.plugins.nicira import nvp_cluster
from neutron.tests.unit.nicira import get_fake_conf
from neutron.tests.unit.nicira import PLUGIN_NAME

BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
NVP_BASE_CONF_PATH = get_fake_conf('neutron.conf.test')
NVP_INI_PATH = get_fake_conf('nvp.ini.basic.test')
NVP_INI_FULL_PATH = get_fake_conf('nvp.ini.full.test')
NVP_INI_DEPR_PATH = get_fake_conf('nvp.ini.grizzly.test')
NVP_INI_AGENTLESS_PATH = get_fake_conf('nvp.ini.agentless.test')


class NVPClusterTest(testtools.TestCase):

    cluster_opts = {
        'default_tz_uuid': uuidutils.generate_uuid(),
        'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
        'default_l2_gw_service_uuid': uuidutils.generate_uuid(),
        'nvp_cluster_uuid': uuidutils.generate_uuid(),
        'nvp_user': '******',