]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_rgw_client.py
1 # -*- coding: utf-8 -*-
2 # pylint: disable=too-many-public-methods
3 from unittest
import TestCase
4 from unittest
.mock
import Mock
, patch
6 from ..exceptions
import DashboardException
7 from ..services
.rgw_client
import NoCredentialsException
, \
8 NoRgwDaemonsException
, RgwClient
, _parse_frontend_config
9 from ..settings
import Settings
10 from . import KVStoreMockMixin
, RgwStub
# pylint: disable=no-name-in-module
13 @patch('dashboard.services.rgw_client.RgwClient._get_user_id', Mock(
14 return_value
='dummy_admin'))
15 class RgwClientTest(TestCase
, KVStoreMockMixin
):
19 self
.CONFIG_KEY_DICT
.update({
20 'RGW_API_ACCESS_KEY': 'klausmustermann',
21 'RGW_API_SECRET_KEY': 'supergeheim',
24 def test_ssl_verify(self
):
25 Settings
.RGW_API_SSL_VERIFY
= True
26 instance
= RgwClient
.admin_instance()
27 self
.assertTrue(instance
.session
.verify
)
29 def test_no_ssl_verify(self
):
30 Settings
.RGW_API_SSL_VERIFY
= False
31 instance
= RgwClient
.admin_instance()
32 self
.assertFalse(instance
.session
.verify
)
34 def test_no_daemons(self
):
35 RgwStub
.get_mgr_no_services()
36 with self
.assertRaises(NoRgwDaemonsException
) as cm
:
37 RgwClient
.admin_instance()
38 self
.assertIn('No RGW service is running.', str(cm
.exception
))
40 def test_no_credentials(self
):
41 self
.CONFIG_KEY_DICT
.update({
42 'RGW_API_ACCESS_KEY': '',
43 'RGW_API_SECRET_KEY': '',
45 with self
.assertRaises(NoCredentialsException
) as cm
:
46 RgwClient
.admin_instance()
47 self
.assertIn('No RGW credentials found', str(cm
.exception
))
49 def test_default_daemon_wrong_settings(self
):
50 self
.CONFIG_KEY_DICT
.update({
51 'RGW_API_HOST': '172.20.0.2',
52 'RGW_API_PORT': '7990',
54 with self
.assertRaises(DashboardException
) as cm
:
55 RgwClient
.admin_instance()
56 self
.assertIn('No RGW daemon found with user-defined host:', str(cm
.exception
))
58 @patch.object(RgwClient
, '_get_daemon_zone_info')
59 def test_get_placement_targets_from_zone(self
, zone_info
):
60 zone_info
.return_value
= {
61 'id': 'a0df30ea-4b5b-4830-b143-2bedf684663d',
64 'key': 'default-placement',
66 'index_pool': 'default.rgw.buckets.index',
69 'data_pool': 'default.rgw.buckets.data'
77 instance
= RgwClient
.admin_instance()
79 'zonegroup': 'zonegroup1',
80 'placement_targets': [
82 'name': 'default-placement',
83 'data_pool': 'default.rgw.buckets.data'
87 self
.assertEqual(expected_result
, instance
.get_placement_targets())
89 @patch.object(RgwClient
, '_get_realms_info')
90 def test_get_realms(self
, realms_info
):
91 realms_info
.side_effect
= [
93 'default_info': '51de8373-bc24-4f74-a9b7-8e9ef4cb71f7',
101 instance
= RgwClient
.admin_instance()
103 self
.assertEqual(['realm1', 'realm2'], instance
.get_realms())
104 self
.assertEqual([], instance
.get_realms())
107 class RgwClientHelperTest(TestCase
):
108 def test_parse_frontend_config_1(self
):
109 self
.assertEqual(_parse_frontend_config('beast port=8000'), (8000, False))
111 def test_parse_frontend_config_2(self
):
112 self
.assertEqual(_parse_frontend_config('beast port=80 port=8000'), (80, False))
114 def test_parse_frontend_config_3(self
):
115 self
.assertEqual(_parse_frontend_config('beast ssl_port=443 port=8000'), (443, True))
117 def test_parse_frontend_config_4(self
):
118 self
.assertEqual(_parse_frontend_config('beast endpoint=192.168.0.100:8000'), (8000, False))
120 def test_parse_frontend_config_5(self
):
121 self
.assertEqual(_parse_frontend_config('beast endpoint=[::1]'), (80, False))
123 def test_parse_frontend_config_6(self
):
124 self
.assertEqual(_parse_frontend_config(
125 'beast ssl_endpoint=192.168.0.100:8443'), (8443, True))
127 def test_parse_frontend_config_7(self
):
128 self
.assertEqual(_parse_frontend_config('beast ssl_endpoint=192.168.0.100'), (443, True))
130 def test_parse_frontend_config_8(self
):
131 self
.assertEqual(_parse_frontend_config(
132 'beast ssl_endpoint=[::1]:8443 endpoint=192.0.2.3:80'), (8443, True))
134 def test_parse_frontend_config_9(self
):
135 self
.assertEqual(_parse_frontend_config(
136 'beast port=8080 endpoint=192.0.2.3:80'), (8080, False))
138 def test_parse_frontend_config_10(self
):
139 self
.assertEqual(_parse_frontend_config(
140 'beast ssl_endpoint=192.0.2.3:8443 port=8080'), (8443, True))
142 def test_parse_frontend_config_11(self
):
143 self
.assertEqual(_parse_frontend_config('civetweb port=8000s'), (8000, True))
145 def test_parse_frontend_config_12(self
):
146 self
.assertEqual(_parse_frontend_config('civetweb port=443s port=8000'), (443, True))
148 def test_parse_frontend_config_13(self
):
149 self
.assertEqual(_parse_frontend_config('civetweb port=192.0.2.3:80'), (80, False))
151 def test_parse_frontend_config_14(self
):
152 self
.assertEqual(_parse_frontend_config('civetweb port=172.5.2.51:8080s'), (8080, True))
154 def test_parse_frontend_config_15(self
):
155 self
.assertEqual(_parse_frontend_config('civetweb port=[::]:8080'), (8080, False))
157 def test_parse_frontend_config_16(self
):
158 self
.assertEqual(_parse_frontend_config('civetweb port=ip6-localhost:80s'), (80, True))
160 def test_parse_frontend_config_17(self
):
161 self
.assertEqual(_parse_frontend_config('civetweb port=[2001:0db8::1234]:80'), (80, False))
163 def test_parse_frontend_config_18(self
):
164 self
.assertEqual(_parse_frontend_config('civetweb port=[::1]:8443s'), (8443, True))
166 def test_parse_frontend_config_19(self
):
167 self
.assertEqual(_parse_frontend_config('civetweb port=127.0.0.1:8443s+8000'), (8443, True))
169 def test_parse_frontend_config_20(self
):
170 self
.assertEqual(_parse_frontend_config('civetweb port=127.0.0.1:8080+443s'), (8080, False))
172 def test_parse_frontend_config_21(self
):
173 with self
.assertRaises(LookupError) as ctx
:
174 _parse_frontend_config('civetweb port=xyz')
175 self
.assertEqual(str(ctx
.exception
),
176 'Failed to determine RGW port from "civetweb port=xyz"')
178 def test_parse_frontend_config_22(self
):
179 with self
.assertRaises(LookupError) as ctx
:
180 _parse_frontend_config('civetweb')
181 self
.assertEqual(str(ctx
.exception
), 'Failed to determine RGW port from "civetweb"')
183 def test_parse_frontend_config_23(self
):
184 with self
.assertRaises(LookupError) as ctx
:
185 _parse_frontend_config('mongoose port=8080')
186 self
.assertEqual(str(ctx
.exception
),
187 'Failed to determine RGW port from "mongoose port=8080"')