Coverage for manila/tests/api/v2/test_security_services.py: 100%
40 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2018 SAP SE
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
15from unittest import mock
17import datetime
18import ddt
20from manila.api.v2 import security_service
21from manila.common import constants
22from manila import context
23from manila import test
24from manila.tests.api import fakes
27def stub_security_service(self, version, id):
28 ss_dict = dict(
29 id=id,
30 name='security_service_%s' % str(id),
31 type=constants.SECURITY_SERVICES_ALLOWED_TYPES[0],
32 description='Fake Security Service Desc',
33 dns_ip='1.1.1.1',
34 server='fake-server',
35 domain='fake-domain',
36 user='fake-user',
37 password='fake-password',
38 status=constants.STATUS_NEW,
39 share_networks=[],
40 created_at=datetime.datetime(2017, 8, 24, 1, 1, 1, 1),
41 updated_at=datetime.datetime(2017, 8, 24, 1, 1, 1, 1),
42 project_id='fake-project'
43 )
44 if self.is_microversion_ge(version, '2.44'):
45 ss_dict['ou'] = 'fake-ou'
46 if self.is_microversion_ge(version, '2.76'):
47 ss_dict['default_ad_site'] = 'fake-default_ad_site'
49 return ss_dict
52@ddt.ddt
53class SecurityServicesAPITest(test.TestCase):
54 @ddt.data(
55 ('2.0'),
56 ('2.43'),
57 ('2.44'),
58 ('2.76'),
59 )
60 def test_index(self, version):
61 ss = [
62 stub_security_service(self, version, 1),
63 stub_security_service(self, version, 2),
64 ]
65 ctxt = context.RequestContext('admin', 'fake', True)
66 request = fakes.HTTPRequest.blank('/security-services?all_tenants=1',
67 version=version)
68 request.headers['X-Openstack-Manila-Api-Version'] = version
69 request.environ['manila.context'] = ctxt
70 self.mock_object(security_service.db, 'security_service_get_all',
71 mock.Mock(return_value=ss))
72 self.mock_object(security_service.db,
73 'share_network_get_all_by_security_service',
74 mock.Mock(return_value=[]))
76 ss_controller = security_service.SecurityServiceController()
78 result = ss_controller.detail(request)
80 self.assertIsInstance(result, dict)
81 self.assertEqual(['security_services'], list(result.keys()))
82 self.assertIsInstance(result['security_services'], list)
83 self.assertEqual(2, len(result['security_services']))
84 self.assertIn(ss[0], result['security_services'])
86 ss_keys = list(result['security_services'][0].keys())
87 if self.is_microversion_ge(version, '2.44'):
88 self.assertIn('ou', ss_keys)
89 else:
90 self.assertNotIn('ou', ss_keys)
92 if self.is_microversion_ge(version, '2.76'):
93 self.assertIn('default_ad_site', ss_keys)
94 else:
95 self.assertNotIn('default_ad_site', ss_keys)