ceph/qa/tasks/mgr/dashboard/test_rbd.py
zouaiguo 4840e899f1 [mgr/dashboard] add image id to rbd info instead of block_name_prefix
when create images use data_pool parameter, such as:
rbd create -p pool1 -s 1G --data-pool pool2  image1

then get image info from mgr use request http://192.7.7.36:7000/rbd_pool_data/pool1
we got the response:
[{"parent_name": "", "parent_pool": 18446744073709551615, "name": "image1", "num_objs": 256, "block_name_prefix": "rbd_data.14.f561643c986", "obj_size": 4194304, "features": 189, "features_name": "fast-diff, layering, exclusive-lock, deep-flatten, object-map, data-pool", "order": 22, "size": 1073741824}]

notice:
since block_name_prefix is deprecated,
from block_name_prefix we can not get image id(the real id is ''f561643c9869')
we need add image id to rbd info instead block_name_prefix

Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rados
>>> import rbd
>>> RADOS_NAME = 'client.admin'
>>> cluster_name="ceph"
>>> cluster_handle = rados.Rados(name=RADOS_NAME, clustername=cluster_name, conffile='')
>>> cluster_handle.connect()
>>> ioctx = cluster_handle.open_ioctx("pool1")
>>> image_inst = rbd.Image(ioctx, "image1")
>>> image_inst.stat()
{'parent_name': '', 'parent_pool': 18446744073709551615L, 'num_objs': 256L, 'block_name_prefix': u'rbd_data.14.f561643c986', 'obj_size': 4194304L, 'order': 22, 'size': 1073741824L}
>>> image_inst.id()
u'f561643c9869'

after fix:

[root@tfg36 site-packages]# curl http://192.7.7.36:7000/rbd_pool_data/pool1
[{"parent_name": "", "parent_pool": 18446744073709551615, "name": "image1", "num_objs": 256, "block_name_prefix": "rbd_data.14.f561643c986", "obj_size": 4194304, "features": 189, "id": "f561643c9869", "features_name": "fast-diff, layering, exclusive-lock, deep-flatten, object-map, data-pool", "order": 22, "size": 1073741824}]

Signed-off-by: zouaiguo <zou.aiguo@zte.com.cn>
2018-03-28 10:14:42 +08:00

125 lines
4.6 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import absolute_import
import unittest
from .helper import DashboardTestCase, authenticate
class RbdTest(DashboardTestCase):
@classmethod
def setUpClass(cls):
super(RbdTest, cls).setUpClass()
cls._ceph_cmd(['osd', 'pool', 'create', 'rbd', '100', '100'])
cls._ceph_cmd(['osd', 'pool', 'application', 'enable', 'rbd', 'rbd'])
cls._rbd_cmd(['create', '--size=1G', 'img1'])
cls._rbd_cmd(['create', '--size=2G', 'img2'])
osd_metadata = cls.ceph_cluster.mon_manager.get_osd_metadata()
cls.bluestore_support = True
for osd in osd_metadata:
if osd['osd_objectstore'] != 'bluestore':
cls.bluestore_support = False
break
@classmethod
def tearDownClass(cls):
super(RbdTest, cls).tearDownClass()
cls._ceph_cmd(['osd', 'pool', 'delete', 'rbd', 'rbd', '--yes-i-really-really-mean-it'])
@authenticate
def test_list(self):
data = self._get('/api/rbd/rbd')
self.assertStatus(200)
img1 = data['value'][0]
self.assertEqual(img1['name'], 'img1')
self.assertEqual(img1['size'], 1073741824)
self.assertEqual(img1['num_objs'], 256)
self.assertEqual(img1['obj_size'], 4194304)
self.assertEqual(img1['features_name'],
['deep-flatten', 'exclusive-lock', 'fast-diff', 'layering', 'object-map'])
self.assertIn('id', img1)
img2 = data['value'][1]
self.assertEqual(img2['name'], 'img2')
self.assertEqual(img2['size'], 2147483648)
self.assertEqual(img2['num_objs'], 512)
self.assertEqual(img2['obj_size'], 4194304)
self.assertEqual(img2['features_name'],
['deep-flatten', 'exclusive-lock', 'fast-diff', 'layering', 'object-map'])
self.assertIn('id', img2)
@authenticate
def test_create(self):
rbd_name = 'test_rbd'
data = {'pool_name': 'rbd',
'name': rbd_name,
'size': 10240}
self._post('/api/rbd', data)
self.assertStatus(201)
self.assertJsonBody({"success": True})
# TODO: change to GET the specific RBD instead of the list as soon as it is available?
get_res = self._get('/api/rbd/rbd')
self.assertStatus(200)
for rbd in get_res['value']:
if rbd['name'] == rbd_name:
self.assertEqual(rbd['size'], 10240)
self.assertEqual(rbd['num_objs'], 1)
self.assertEqual(rbd['obj_size'], 4194304)
self.assertEqual(rbd['features_name'],
['deep-flatten', 'exclusive-lock', 'fast-diff', 'layering',
'object-map'])
break
@authenticate
def test_create_rbd_in_data_pool(self):
if not self.bluestore_support:
self.skipTest('requires bluestore cluster')
self._ceph_cmd(['osd', 'pool', 'create', 'data_pool', '12', '12', 'erasure'])
self._ceph_cmd(['osd', 'pool', 'application', 'enable', 'data_pool', 'rbd'])
self._ceph_cmd(['osd', 'pool', 'set', 'data_pool', 'allow_ec_overwrites', 'true'])
rbd_name = 'test_rbd_in_data_pool'
data = {'pool_name': 'rbd',
'name': rbd_name,
'size': 10240,
'data_pool': 'data_pool'}
self._post('/api/rbd', data)
self.assertStatus(201)
self.assertJsonBody({"success": True})
# TODO: possibly change to GET the specific RBD (see above)
get_res = self._get('/api/rbd/rbd')
self.assertStatus(200)
for rbd in get_res['value']:
if rbd['name'] == rbd_name:
self.assertEqual(rbd['size'], 10240)
self.assertEqual(rbd['num_objs'], 1)
self.assertEqual(rbd['obj_size'], 4194304)
self.assertEqual(rbd['features_name'],
['data-pool', 'deep-flatten', 'exclusive-lock', 'fast-diff',
'layering', 'object-map'])
break
self._ceph_cmd(['osd', 'pool', 'delete', 'data_pool', 'data_pool',
'--yes-i-really-really-mean-it'])
@authenticate
def test_create_rbd_twice(self):
data = {'pool_name': 'rbd',
'name': 'test_rbd_twice',
'size': 10240}
self._post('/api/rbd', data)
self._post('/api/rbd', data)
self.assertStatus(400)
self.assertJsonBody({"success": False, "errno": 17,
"detail": "[errno 17] error creating image"})