1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
import json
from unittest.mock import Mock
from dashboard.controllers.smb import SMBCluster, SMBShare
from .. import mgr
from ..tests import ControllerTestCase
class SMBClusterTest(ControllerTestCase):
_endpoint = '/api/smb/cluster'
_clusters = {
"resources": [{
"resource_type": "ceph.smb.cluster",
"cluster_id": "clusterADTest",
"auth_mode": "active-directory",
"intent": "present",
"domain_settings": {
"realm": "DOMAIN1.SINK.TEST",
"join_sources": [
{
"source_type": "resource",
"ref": "join1-admin"
}]
},
"custom_dns": [
"192.168.76.204"
],
"placement": {
"count": 1
}
},
{
"resource_type": "ceph.smb.cluster",
"cluster_id": "clusterUserTest",
"auth_mode": "user",
"intent": "present",
"user_group_settings": [
{
"source_type": "resource",
"ref": "ug1"
}
]
}]
}
@classmethod
def setup_server(cls):
cls.setup_controllers([SMBCluster])
def test_list_one_cluster(self):
mgr.remote = Mock(return_value=self._clusters['resources'][0])
self._get(self._endpoint)
self.assertStatus(200)
self.assertJsonBody([self._clusters['resources'][0]])
def test_list_multiple_clusters(self):
mgr.remote = Mock(return_value=self._clusters)
self._get(self._endpoint)
self.assertStatus(200)
self.assertJsonBody(self._clusters['resources'])
def test_get_cluster(self):
mgr.remote = Mock(return_value=self._clusters['resources'][0])
cluster_id = self._clusters['resources'][0]['cluster_id']
self._get(f'{self._endpoint}/{cluster_id}')
self.assertStatus(200)
self.assertJsonBody(self._clusters['resources'][0])
mgr.remote.assert_called_once_with('smb', 'show', [f'ceph.smb.cluster.{cluster_id}'])
def test_create_ad(self):
mock_simplified = Mock()
mock_simplified.to_simplified.return_value = json.dumps(self._clusters['resources'][0])
mgr.remote = Mock(return_value=mock_simplified)
_cluster_data = """
{ "cluster_resource": {
"resource_type": "ceph.smb.cluster",
"cluster_id": "clusterADTest",
"auth_mode": "active-directory",
"domain_settings": {
"realm": "DOMAIN1.SINK.TEST",
"join_sources": [
{
"source_type": "resource",
"ref": "join1-admin"
}
]
}
}
}
"""
self._post(self._endpoint, _cluster_data)
self.assertStatus(201)
self.assertInJsonBody(json.dumps(self._clusters['resources'][0]))
def test_create_user(self):
mock_simplified = Mock()
mock_simplified.to_simplified.return_value = json.dumps(self._clusters['resources'][1])
mgr.remote = Mock(return_value=mock_simplified)
_cluster_data = """
{ "cluster_resource": {
"resource_type": "ceph.smb.cluster",
"cluster_id": "clusterUser123Test",
"auth_mode": "user",
"user_group_settings": [
{
"source_type": "resource",
"ref": "ug1"
}
]
}
}
"""
self._post(self._endpoint, _cluster_data)
self.assertStatus(201)
self.assertInJsonBody(json.dumps(self._clusters['resources'][1]))
class SMBShareTest(ControllerTestCase):
_endpoint = '/api/smb/share'
_shares = [{
"resource_type": "ceph.smb.share",
"cluster_id": "clusterUserTest",
"share_id": "share1",
"intent": "present",
"name": "share1name",
"readonly": "false",
"browseable": "true",
"cephfs": {
"volume": "fs1",
"path": "/",
"provider": "samba-vfs"
}
},
{
"resource_type": "ceph.smb.share",
"cluster_id": "clusterADTest",
"share_id": "share2",
"intent": "present",
"name": "share2name",
"readonly": "false",
"browseable": "true",
"cephfs": {
"volume": "fs2",
"path": "/",
"provider": "samba-vfs"
}
}
]
@classmethod
def setup_server(cls):
cls.setup_controllers([SMBShare])
def test_list_all(self):
mgr.remote = Mock(return_value=self._shares)
self._get(self._endpoint)
self.assertStatus(200)
self.assertJsonBody(self._shares)
def test_list_from_cluster(self):
mgr.remote = Mock(return_value=self._shares[0])
self._get(self._endpoint)
self.assertStatus(200)
self.assertJsonBody(self._shares[0])
def test_delete(self):
_res = {
"resource": {
"resource_type": "ceph.smb.share",
"cluster_id": "smbCluster1",
"share_id": "share1",
"intent": "removed"
},
"state": "removed",
"success": "true"
}
_res_simplified = {
"resource_type": "ceph.smb.share",
"cluster_id": "smbCluster1",
"share_id": "share1",
"intent": "removed"
}
mgr.remote = Mock(return_value=Mock(return_value=_res))
mgr.remote.return_value.one.return_value.to_simplified = Mock(return_value=_res_simplified)
self._delete(f'{self._endpoint}/smbCluster1/share1')
self.assertStatus(204)
mgr.remote.assert_called_once_with('smb', 'apply_resources', json.dumps(_res_simplified))
|