Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / tests / unit / plugins / ml2 / drivers / mechanism_logger.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_log import log
17
18 from neutron._i18n import _
19 from neutron.plugins.ml2 import driver_api as api
20
21 LOG = log.getLogger(__name__)
22
23
24 class LoggerMechanismDriver(api.MechanismDriver):
25     """Mechanism driver that logs all calls and parameters made.
26
27     Generally used for testing and debugging.
28     """
29
30     def initialize(self):
31         pass
32
33     def _log_network_call(self, method_name, context):
34         LOG.info(_("%(method)s called with network settings %(current)s "
35                    "(original settings %(original)s) and "
36                    "network segments %(segments)s"),
37                  {'method': method_name,
38                   'current': context.current,
39                   'original': context.original,
40                   'segments': context.network_segments})
41
42     def create_network_precommit(self, context):
43         self._log_network_call("create_network_precommit", context)
44
45     def create_network_postcommit(self, context):
46         self._log_network_call("create_network_postcommit", context)
47
48     def update_network_precommit(self, context):
49         self._log_network_call("update_network_precommit", context)
50
51     def update_network_postcommit(self, context):
52         self._log_network_call("update_network_postcommit", context)
53
54     def delete_network_precommit(self, context):
55         self._log_network_call("delete_network_precommit", context)
56
57     def delete_network_postcommit(self, context):
58         self._log_network_call("delete_network_postcommit", context)
59
60     def _log_subnet_call(self, method_name, context):
61         LOG.info(_("%(method)s called with subnet settings %(current)s "
62                    "(original settings %(original)s)"),
63                  {'method': method_name,
64                   'current': context.current,
65                   'original': context.original})
66
67     def create_subnet_precommit(self, context):
68         self._log_subnet_call("create_subnet_precommit", context)
69
70     def create_subnet_postcommit(self, context):
71         self._log_subnet_call("create_subnet_postcommit", context)
72
73     def update_subnet_precommit(self, context):
74         self._log_subnet_call("update_subnet_precommit", context)
75
76     def update_subnet_postcommit(self, context):
77         self._log_subnet_call("update_subnet_postcommit", context)
78
79     def delete_subnet_precommit(self, context):
80         self._log_subnet_call("delete_subnet_precommit", context)
81
82     def delete_subnet_postcommit(self, context):
83         self._log_subnet_call("delete_subnet_postcommit", context)
84
85     def _log_port_call(self, method_name, context):
86         network_context = context.network
87         LOG.info(_("%(method)s called with port settings %(current)s "
88                    "(original settings %(original)s) "
89                    "host %(host)s "
90                    "(original host %(original_host)s) "
91                    "vif type %(vif_type)s "
92                    "(original vif type %(original_vif_type)s) "
93                    "vif details %(vif_details)s "
94                    "(original vif details %(original_vif_details)s) "
95                    "binding levels %(levels)s "
96                    "(original binding levels %(original_levels)s) "
97                    "on network %(network)s "
98                    "with segments to bind %(segments_to_bind)s"),
99                  {'method': method_name,
100                   'current': context.current,
101                   'original': context.original,
102                   'host': context.host,
103                   'original_host': context.original_host,
104                   'vif_type': context.vif_type,
105                   'original_vif_type': context.original_vif_type,
106                   'vif_details': context.vif_details,
107                   'original_vif_details': context.original_vif_details,
108                   'levels': context.binding_levels,
109                   'original_levels': context.original_binding_levels,
110                   'network': network_context.current,
111                   'segments_to_bind': context.segments_to_bind})
112
113     def create_port_precommit(self, context):
114         self._log_port_call("create_port_precommit", context)
115
116     def create_port_postcommit(self, context):
117         self._log_port_call("create_port_postcommit", context)
118
119     def update_port_precommit(self, context):
120         self._log_port_call("update_port_precommit", context)
121
122     def update_port_postcommit(self, context):
123         self._log_port_call("update_port_postcommit", context)
124
125     def delete_port_precommit(self, context):
126         self._log_port_call("delete_port_precommit", context)
127
128     def delete_port_postcommit(self, context):
129         self._log_port_call("delete_port_postcommit", context)
130
131     def bind_port(self, context):
132         self._log_port_call("bind_port", context)