cbef154e4d2189b11d312710f510ce1654faa6cf
[openstack-build/neutron-build.git] / neutron / tests / unit / plugins / ml2 / drivers / openvswitch / mech_driver / test_mech_openvswitch.py
1 # Copyright (c) 2013 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15
16 from oslo_config import cfg
17
18 from neutron.common import constants
19 from neutron.extensions import portbindings
20 from neutron.plugins.ml2.drivers.openvswitch.mech_driver \
21     import mech_openvswitch
22 from neutron.tests.unit.plugins.ml2 import _test_mech_agent as base
23
24
25 class OpenvswitchMechanismBaseTestCase(base.AgentMechanismBaseTestCase):
26     VIF_TYPE = portbindings.VIF_TYPE_OVS
27     VIF_DETAILS = {portbindings.CAP_PORT_FILTER: True,
28                    portbindings.OVS_HYBRID_PLUG: True}
29     AGENT_TYPE = constants.AGENT_TYPE_OVS
30
31     GOOD_MAPPINGS = {'fake_physical_network': 'fake_bridge'}
32     GOOD_TUNNEL_TYPES = ['gre', 'vxlan']
33     GOOD_CONFIGS = {'bridge_mappings': GOOD_MAPPINGS,
34                     'tunnel_types': GOOD_TUNNEL_TYPES}
35
36     BAD_MAPPINGS = {'wrong_physical_network': 'wrong_bridge'}
37     BAD_TUNNEL_TYPES = ['bad_tunnel_type']
38     BAD_CONFIGS = {'bridge_mappings': BAD_MAPPINGS,
39                    'tunnel_types': BAD_TUNNEL_TYPES}
40
41     AGENTS = [{'alive': True,
42                'configurations': GOOD_CONFIGS,
43                'host': 'host'}]
44     AGENTS_DEAD = [{'alive': False,
45                     'configurations': GOOD_CONFIGS,
46                     'host': 'dead_host'}]
47     AGENTS_BAD = [{'alive': False,
48                    'configurations': GOOD_CONFIGS,
49                    'host': 'bad_host_1'},
50                   {'alive': True,
51                    'configurations': BAD_CONFIGS,
52                    'host': 'bad_host_2'}]
53
54     def setUp(self):
55         super(OpenvswitchMechanismBaseTestCase, self).setUp()
56         self.driver = mech_openvswitch.OpenvswitchMechanismDriver()
57         self.driver.initialize()
58
59
60 class OpenvswitchMechanismSGDisabledBaseTestCase(
61     OpenvswitchMechanismBaseTestCase):
62     VIF_DETAILS = {portbindings.CAP_PORT_FILTER: False,
63                    portbindings.OVS_HYBRID_PLUG: False}
64
65     def setUp(self):
66         cfg.CONF.set_override('enable_security_group',
67                               False,
68                               group='SECURITYGROUP')
69         super(OpenvswitchMechanismSGDisabledBaseTestCase, self).setUp()
70
71
72 class OpenvswitchMechanismGenericTestCase(OpenvswitchMechanismBaseTestCase,
73                                           base.AgentMechanismGenericTestCase):
74     pass
75
76
77 class OpenvswitchMechanismLocalTestCase(OpenvswitchMechanismBaseTestCase,
78                                         base.AgentMechanismLocalTestCase):
79     pass
80
81
82 class OpenvswitchMechanismFlatTestCase(OpenvswitchMechanismBaseTestCase,
83                                        base.AgentMechanismFlatTestCase):
84     pass
85
86
87 class OpenvswitchMechanismVlanTestCase(OpenvswitchMechanismBaseTestCase,
88                                        base.AgentMechanismVlanTestCase):
89     pass
90
91
92 class OpenvswitchMechanismGreTestCase(OpenvswitchMechanismBaseTestCase,
93                                       base.AgentMechanismGreTestCase):
94     pass
95
96
97 class OpenvswitchMechanismSGDisabledLocalTestCase(
98     OpenvswitchMechanismSGDisabledBaseTestCase,
99     base.AgentMechanismLocalTestCase):
100     pass