Debian Codegraph @

neutron_taas/tests/unit/extensions/test_tap_mirror.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import copy
14 from unittest import mock
15 from webob import exc
16
17 from oslo_utils import uuidutils
18
19 from neutron.api import extensions
20 from neutron.conf import common as conf_common
21 from neutron.tests.unit.api.v2 import test_base as test_api_v2
22 from neutron.tests.unit.extensions import base as test_extensions_base
23
24 from neutron_lib.api.definitions import tap_mirror as tap_mirror_api
25
26 from neutron_taas import extensions as taas_extensions
27
28
29 TAP_MIRROR_PATH = 'taas/tap_mirrors'
30
31
32 class TapMirrorExtensionTestCase(test_extensions_base.ExtensionTestCase):
33
34 def setUp(self):
35 conf_common.register_core_common_config_opts()
36 extensions.append_api_extensions_path(taas_extensions.__path__)
37 super().setUp()
38 plural_mappings = {'tap_mirror': 'tap_mirrors'}
39 self.setup_extension(
40 '%s.%s' % (taas_extensions.tap_mirror.TapMirrorBase.__module__,
41 taas_extensions.tap_mirror.TapMirrorBase.__name__),
42 tap_mirror_api.ALIAS,
43 taas_extensions.tap_mirror.Tap_mirror,
44 'taas',
45 plural_mappings=plural_mappings,
46 translate_resource_name=False)
47 self.instance = self.plugin.return_value
48
49 def test_create_tap_mirror(self):
50 project_id = uuidutils.generate_uuid()
51 tap_mirror_data = {
52 'project_id': project_id,
53 'tenant_id': project_id,
54 'name': 'MyMirror',
55 'description': 'This is my Tap Mirror',
56 'port_id': uuidutils.generate_uuid(),
57 'directions': {"IN": 101},
58 'remote_ip': '10.99.8.3',
59 'mirror_type': 'gre',
60 }
61 data = {'tap_mirror': tap_mirror_data}
62 expected_ret_val = copy.copy(tap_mirror_data)
63 expected_ret_val.update({'id': uuidutils.generate_uuid()})
64 self.instance.create_tap_mirror.return_value = expected_ret_val
65
66 res = self.api.post(test_api_v2._get_path(TAP_MIRROR_PATH,
67 fmt=self.fmt),
68 self.serialize(data),
69 content_type='application/%s' % self.fmt)
70 self.instance.create_tap_mirror.assert_called_with(
71 mock.ANY,
72 tap_mirror=data)
73 self.assertEqual(exc.HTTPCreated.code, res.status_int)
74 res = self.deserialize(res)
75 self.assertIn('tap_mirror', res)
76 self.assertEqual(expected_ret_val, res['tap_mirror'])
77
78 def test_delete_tap_mirror(self):
79 self._test_entity_delete('tap_mirror')