Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / tests / unit / plugins / ml2 / drivers / mech_fake_agent.py
1 # Copyright (C) 2014,2015 VA Linux Systems Japan K.K.
2 # Copyright (C) 2014 Fumihiko Kakuma <kakuma at valinux co jp>
3 # Copyright (C) 2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
4 # All Rights Reserved.
5 #
6 # Based on openvswitch mechanism driver.
7 #
8 # Copyright (c) 2013 OpenStack Foundation
9 # All Rights Reserved.
10 #
11 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
12 #    not use this file except in compliance with the License. You may obtain
13 #    a copy of the License at
14 #
15 #         http://www.apache.org/licenses/LICENSE-2.0
16 #
17 #    Unless required by applicable law or agreed to in writing, software
18 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20 #    License for the specific language governing permissions and limitations
21 #    under the License.
22
23 from neutron.agent import securitygroups_rpc
24 from neutron.common import constants
25 from neutron.extensions import portbindings
26 from neutron.plugins.common import constants as p_constants
27 from neutron.plugins.ml2.drivers import mech_agent
28
29
30 class FakeAgentMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
31     """ML2 mechanism driver for testing.
32
33     This is a ML2 mechanism driver used by UTs in test_l2population.
34     This driver implements minimum requirements for L2pop mech driver.
35     As there are some agent-based mechanism drivers and OVS agent
36     mech driver is not the only one to support L2pop, it is useful to
37     test L2pop with multiple drivers like this to check the minimum
38     requirements.
39
40     NOTE(yamamoto): This is a modified copy of ofagent mechanism driver as
41     of writing this.  There's no need to keep this synced with the "real"
42     ofagent mechansim driver or its agent.
43     """
44
45     def __init__(self):
46         sg_enabled = securitygroups_rpc.is_firewall_enabled()
47         vif_details = {portbindings.CAP_PORT_FILTER: sg_enabled,
48                        portbindings.OVS_HYBRID_PLUG: sg_enabled}
49         super(FakeAgentMechanismDriver, self).__init__(
50             # NOTE(yamamoto): l2pop driver has a hardcoded list of
51             # supported agent types.
52             constants.AGENT_TYPE_OFA,
53             portbindings.VIF_TYPE_OVS,
54             vif_details)
55
56     def get_allowed_network_types(self, agent):
57         return (agent['configurations'].get('tunnel_types', []) +
58                 [p_constants.TYPE_LOCAL, p_constants.TYPE_FLAT,
59                  p_constants.TYPE_VLAN])
60
61     def get_mappings(self, agent):
62         return dict(agent['configurations'].get('interface_mappings', {}))