]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/mgr/dashboard/test_ganesha.py
1 # -*- coding: utf-8 -*-
2 # pylint: disable=too-many-public-methods
4 from __future__
import absolute_import
8 from .helper
import DashboardTestCase
, JObj
, JLeaf
, JList
11 class GaneshaTest(DashboardTestCase
):
13 AUTH_ROLES
= ['pool-manager', 'ganesha-manager']
16 def create_pool(cls
, name
, pg_num
, pool_type
, application
='rbd'):
20 'pool_type': pool_type
,
21 'application_metadata': [application
]
23 if pool_type
== 'erasure':
24 data
['flags'] = ['ec_overwrites']
25 cls
._task
_post
("/api/pool", data
)
29 super(GaneshaTest
, cls
).setUpClass()
30 cls
.create_pool('ganesha', 3, 'replicated')
31 cls
._rados
_cmd
(['-p', 'ganesha', '-N', 'ganesha1', 'create', 'conf-node1'])
32 cls
._rados
_cmd
(['-p', 'ganesha', '-N', 'ganesha1', 'create', 'conf-node2'])
33 cls
._rados
_cmd
(['-p', 'ganesha', '-N', 'ganesha1', 'create', 'conf-node3'])
34 cls
._rados
_cmd
(['-p', 'ganesha', '-N', 'ganesha2', 'create', 'conf-node1'])
35 cls
._rados
_cmd
(['-p', 'ganesha', '-N', 'ganesha2', 'create', 'conf-node2'])
36 cls
._rados
_cmd
(['-p', 'ganesha', '-N', 'ganesha2', 'create', 'conf-node3'])
37 cls
._ceph
_cmd
(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2'])
40 cls
._radosgw
_admin
_cmd
([
41 'user', 'create', '--uid', 'admin', '--display-name', 'admin',
42 '--system', '--access-key', 'admin', '--secret', 'admin'
44 cls
._ceph
_cmd
(['dashboard', 'set-rgw-api-secret-key', 'admin'])
45 cls
._ceph
_cmd
(['dashboard', 'set-rgw-api-access-key', 'admin'])
48 def tearDownClass(cls
):
49 super(GaneshaTest
, cls
).tearDownClass()
50 cls
._radosgw
_admin
_cmd
(['user', 'rm', '--uid', 'admin', '--purge-data'])
51 cls
._ceph
_cmd
(['osd', 'pool', 'delete', 'ganesha', 'ganesha', '--yes-i-really-really-mean-it'])
53 @DashboardTestCase.RunAs('test', 'test', [{'rbd-image': ['create', 'update', 'delete']}])
54 def test_read_access_permissions(self
):
55 self
._get
('/api/nfs-ganesha/export')
56 self
.assertStatus(403)
58 def test_list_daemons(self
):
59 daemons
= self
._get
("/api/nfs-ganesha/daemon")
60 self
.assertEqual(len(daemons
), 6)
61 daemons
= [(d
['daemon_id'], d
['cluster_id']) for d
in daemons
]
62 self
.assertIn(('node1', 'cluster1'), daemons
)
63 self
.assertIn(('node2', 'cluster1'), daemons
)
64 self
.assertIn(('node3', 'cluster1'), daemons
)
65 self
.assertIn(('node1', 'cluster2'), daemons
)
66 self
.assertIn(('node2', 'cluster2'), daemons
)
67 self
.assertIn(('node3', 'cluster2'), daemons
)
70 def create_export(cls
, path
, cluster_id
, daemons
, fsal
, sec_label_xattr
=None):
72 fsal
= {"name": "CEPH", "user_id":"admin", "fs_name": None, "sec_label_xattr": sec_label_xattr
}
73 pseudo
= "/cephfs{}".format(path
)
75 fsal
= {"name": "RGW", "rgw_user_id": "admin"}
76 pseudo
= "/rgw/{}".format(path
if path
[0] != '/' else "")
80 "cluster_id": cluster_id
,
81 "daemons": ["node1", "node3"],
85 "squash": "no_root_squash",
86 "security_label": sec_label_xattr
is not None,
88 "transports": ["TCP"],
90 "addresses":["10.0.0.0/8"],
95 return cls
._task
_post
('/api/nfs-ganesha/export', ex_json
)
98 super(GaneshaTest
, self
).tearDown()
99 exports
= self
._get
("/api/nfs-ganesha/export")
100 if self
._resp
.status_code
!= 200:
102 self
.assertIsInstance(exports
, list)
104 self
._task
_delete
("/api/nfs-ganesha/export/{}/{}"
105 .format(exp
['cluster_id'], exp
['export_id']))
107 def test_create_export(self
):
108 exports
= self
._get
("/api/nfs-ganesha/export")
109 self
.assertEqual(len(exports
), 0)
111 data
= self
.create_export("/foo", 'cluster1', ['node1', 'node2'], 'CEPH', "security.selinux")
113 exports
= self
._get
("/api/nfs-ganesha/export")
114 self
.assertEqual(len(exports
), 1)
115 self
.assertDictEqual(exports
[0], data
)
118 def test_update_export(self
):
119 export
= self
.test_create_export()
120 export
['access_type'] = 'RO'
121 export
['daemons'] = ['node1', 'node3']
122 export
['security_label'] = True
123 data
= self
._task
_put
('/api/nfs-ganesha/export/{}/{}'
124 .format(export
['cluster_id'], export
['export_id']),
126 exports
= self
._get
("/api/nfs-ganesha/export")
127 self
.assertEqual(len(exports
), 1)
128 self
.assertDictEqual(exports
[0], data
)
129 self
.assertEqual(exports
[0]['daemons'], ['node1', 'node3'])
130 self
.assertEqual(exports
[0]['security_label'], True)
132 def test_delete_export(self
):
133 export
= self
.test_create_export()
134 self
._task
_delete
("/api/nfs-ganesha/export/{}/{}"
135 .format(export
['cluster_id'], export
['export_id']))
136 self
.assertStatus(204)
138 def test_get_export(self
):
139 exports
= self
._get
("/api/nfs-ganesha/export")
140 self
.assertEqual(len(exports
), 0)
142 data1
= self
.create_export("/foo", 'cluster2', ['node1', 'node2'], 'CEPH')
143 data2
= self
.create_export("mybucket", 'cluster2', ['node2', 'node3'], 'RGW')
145 export1
= self
._get
("/api/nfs-ganesha/export/cluster2/1")
146 self
.assertDictEqual(export1
, data1
)
148 export2
= self
._get
("/api/nfs-ganesha/export/cluster2/2")
149 self
.assertDictEqual(export2
, data2
)
151 def test_invalid_status(self
):
152 self
._ceph
_cmd
(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', ''])
154 data
= self
._get
('/api/nfs-ganesha/status')
155 self
.assertStatus(200)
156 self
.assertIn('available', data
)
157 self
.assertIn('message', data
)
158 self
.assertFalse(data
['available'])
159 self
.assertIn('Ganesha config location is not configured. Please set the GANESHA_RADOS_POOL_NAMESPACE setting.',
162 self
._ceph
_cmd
(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2'])
164 def test_valid_status(self
):
165 data
= self
._get
('/api/nfs-ganesha/status')
166 self
.assertStatus(200)
167 self
.assertIn('available', data
)
168 self
.assertIn('message', data
)
169 self
.assertTrue(data
['available'])