]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/mgr/dashboard/test_rbd_mirroring.py
39e5f895f11085271b22a7d1f1dcf9db007ef8b9
1 # -*- coding: utf-8 -*-
2 # pylint: disable=too-many-public-methods
4 from __future__
import absolute_import
6 from .helper
import DashboardTestCase
9 class RbdMirroringTest(DashboardTestCase
):
10 AUTH_ROLES
= ['pool-manager', 'block-manager']
13 def create_pool(cls
, name
, application
='rbd'):
17 'pool_type': 'replicated',
18 'application_metadata': [application
]
20 cls
._task
_post
("/api/pool", data
)
23 def get_pool(cls
, pool
):
24 data
= cls
._get
('/api/block/mirroring/pool/{}'.format(pool
))
25 if isinstance(data
, dict):
30 def update_pool(cls
, pool
, mirror_mode
):
31 data
= {'mirror_mode': mirror_mode
}
32 return cls
._task
_put
('/api/block/mirroring/pool/{}'.format(pool
),
36 def list_peers(cls
, pool
):
37 data
= cls
._get
('/api/block/mirroring/pool/{}/peer'.format(pool
))
38 if isinstance(data
, list):
43 def get_peer(cls
, pool
, peer_uuid
):
44 data
= cls
._get
('/api/block/mirroring/pool/{}/peer/{}'.format(pool
, peer_uuid
))
45 if isinstance(data
, dict):
50 def create_peer(cls
, pool
, cluster_name
, client_id
, **kwargs
):
51 data
= {'cluster_name': cluster_name
, 'client_id': client_id
}
53 return cls
._task
_post
('/api/block/mirroring/pool/{}/peer'.format(pool
),
57 def update_peer(cls
, pool
, peer_uuid
, **kwargs
):
58 return cls
._task
_put
('/api/block/mirroring/pool/{}/peer/{}'.format(pool
, peer_uuid
),
62 def delete_peer(cls
, pool
, peer_uuid
):
63 return cls
._task
_delete
('/api/block/mirroring/pool/{}/peer/{}'.format(pool
, peer_uuid
))
67 super(RbdMirroringTest
, cls
).setUpClass()
68 cls
.create_pool('rbd')
71 def tearDownClass(cls
):
72 super(RbdMirroringTest
, cls
).tearDownClass()
73 cls
._ceph
_cmd
(['osd', 'pool', 'delete', 'rbd', 'rbd', '--yes-i-really-really-mean-it'])
75 @DashboardTestCase.RunAs('test', 'test', [{'rbd-mirroring': ['create', 'update', 'delete']}])
76 def test_read_access_permissions(self
):
78 self
.assertStatus(403)
79 self
.list_peers('rbd')
80 self
.assertStatus(403)
81 self
.get_peer('rbd', '123')
82 self
.assertStatus(403)
84 @DashboardTestCase.RunAs('test', 'test', [{'rbd-mirroring': ['read', 'update', 'delete']}])
85 def test_create_access_permissions(self
):
86 self
.create_peer('rbd', 'remote', 'id')
87 self
.assertStatus(403)
89 @DashboardTestCase.RunAs('test', 'test', [{'rbd-mirroring': ['read', 'create', 'delete']}])
90 def test_update_access_permissions(self
):
91 self
.update_peer('rbd', '123')
92 self
.assertStatus(403)
94 @DashboardTestCase.RunAs('test', 'test', [{'rbd-mirroring': ['read', 'create', 'update']}])
95 def test_delete_access_permissions(self
):
96 self
.delete_peer('rbd', '123')
97 self
.assertStatus(403)
99 def test_mirror_mode(self
):
100 self
.update_pool('rbd', 'disabled')
101 mode
= self
.get_pool('rbd').get('mirror_mode')
102 self
.assertEqual(mode
, 'disabled')
104 self
.update_pool('rbd', 'image')
105 mode
= self
.get_pool('rbd').get('mirror_mode')
106 self
.assertEqual(mode
, 'image')
108 self
.update_pool('rbd', 'pool')
109 mode
= self
.get_pool('rbd').get('mirror_mode')
110 self
.assertEqual(mode
, 'pool')
112 self
.update_pool('rbd', 'disabled')
113 mode
= self
.get_pool('rbd').get('mirror_mode')
114 self
.assertEqual(mode
, 'disabled')
116 def test_set_invalid_mirror_mode(self
):
117 self
.update_pool('rbd', 'invalid')
118 self
.assertStatus(400)
120 def test_set_same_mirror_mode(self
):
121 self
.update_pool('rbd', 'disabled')
122 self
.update_pool('rbd', 'disabled')
123 self
.assertStatus(200)
126 self
.update_pool('rbd', 'image')
127 self
.assertStatus(200)
129 peers
= self
.list_peers('rbd')
130 self
.assertStatus(200)
131 self
.assertEqual([], peers
)
133 uuid
= self
.create_peer('rbd', 'remote', 'admin')['uuid']
134 self
.assertStatus(201)
136 peers
= self
.list_peers('rbd')
137 self
.assertStatus(200)
138 self
.assertEqual([uuid
], peers
)
142 'cluster_name': 'remote',
143 'site_name': 'remote',
144 'client_id': 'admin',
147 'direction': 'rx-tx',
150 peer
= self
.get_peer('rbd', uuid
)
151 self
.assertEqual(expected_peer
, peer
)
153 self
.update_peer('rbd', uuid
, mon_host
='1.2.3.4')
154 self
.assertStatus(200)
156 expected_peer
['mon_host'] = '1.2.3.4'
157 peer
= self
.get_peer('rbd', uuid
)
158 self
.assertEqual(expected_peer
, peer
)
160 self
.delete_peer('rbd', uuid
)
161 self
.assertStatus(204)
163 self
.update_pool('rbd', 'disabled')
164 self
.assertStatus(200)
166 def test_disable_mirror_with_peers(self
):
167 self
.update_pool('rbd', 'image')
168 self
.assertStatus(200)
170 uuid
= self
.create_peer('rbd', 'remote', 'admin')['uuid']
171 self
.assertStatus(201)
173 self
.update_pool('rbd', 'disabled')
174 self
.assertStatus(400)
176 self
.delete_peer('rbd', uuid
)
177 self
.assertStatus(204)
179 self
.update_pool('rbd', 'disabled')
180 self
.assertStatus(200)
182 def test_site_name(self
):
183 expected_site_name
= {'site_name': 'site-a'}
184 self
._task
_put
('/api/block/mirroring/site_name', expected_site_name
)
185 self
.assertStatus(200)
187 site_name
= self
._get
('/api/block/mirroring/site_name')
188 self
.assertStatus(200)
189 self
.assertEqual(expected_site_name
, site_name
)
191 def test_bootstrap(self
):
192 self
.update_pool('rbd', 'image')
193 token_data
= self
._task
_post
('/api/block/mirroring/pool/rbd/bootstrap/token', {})
194 self
.assertStatus(200)
197 'token': token_data
['token'],
198 'direction': 'invalid'}
199 self
._task
_post
('/api/block/mirroring/pool/rbd/bootstrap/peer', import_data
)
200 self
.assertStatus(400)
202 # cannot import "youself" as peer
203 import_data
['direction'] = 'rx'
204 self
._task
_post
('/api/block/mirroring/pool/rbd/bootstrap/peer', import_data
)
205 self
.assertStatus(400)