def _do_test_cluster_ls(self): nfs_mod = Module('nfs', '', '') cluster = NFSCluster(nfs_mod) rc, out, err = cluster.list_nfs_cluster() assert rc == 0 assert out == self.cluster_id
def _do_test_cluster_info(self): nfs_mod = Module('nfs', '', '') cluster = NFSCluster(nfs_mod) rc, out, err = cluster.show_nfs_cluster_info(self.cluster_id) assert rc == 0 assert json.loads(out) == {"foo": {"virtual_ip": None, "backend": []}}
def test_export_validate(self, block): cluster_id = 'foo' blocks = GaneshaConfParser(block).parse() export = Export.from_export_block(blocks[0], cluster_id) nfs_mod = Module('nfs', '', '') with mock.patch('nfs.export_utils.check_fs', return_value=True): export.validate(nfs_mod)
def _do_test_config_dict(self, cluster: str, expected_exports: Dict[int, List[str]]) -> None: nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) export = [e for e in conf.exports['foo'] if e.export_id == 1][0] ex_dict = export.to_dict() assert ex_dict == { 'access_type': 'RW', 'clients': [{ 'access_type': None, 'addresses': ['192.168.0.10', '192.168.1.0/8'], 'squash': 'None' }, { 'access_type': 'RO', 'addresses': ['192.168.0.0/16'], 'squash': 'All' }], 'cluster_id': 'foo', 'export_id': 1, 'fsal': { 'fs_name': 'a', 'name': 'CEPH', 'user_id': 'ganesha' }, 'path': '/', 'protocols': [4], 'pseudo': '/cephfs_a/', 'security_label': True, 'squash': 'no_root_squash', 'transports': [] } export = [e for e in conf.exports['foo'] if e.export_id == 2][0] ex_dict = export.to_dict() assert ex_dict == { 'access_type': 'RW', 'clients': [], 'cluster_id': 'foo', 'export_id': 2, 'fsal': { 'name': 'RGW', 'access_key_id': 'the_access_key', 'secret_access_key': 'the_secret_key', 'user_id': 'nfs.foo.bucket' }, 'path': '/', 'protocols': [3, 4], 'pseudo': '/rgw', 'security_label': True, 'squash': 'AllAnonymous', 'transports': ['TCP', 'UDP'] }
def _do_test_ganesha_conf(self) -> None: nfs_mod = Module('nfs', '', '') ganesha_conf = ExportMgr(nfs_mod) exports = ganesha_conf.exports[self.cluster_id] assert len(exports) == 2 self._validate_export_1([e for e in exports if e.export_id == 1][0]) self._validate_export_2([e for e in exports if e.export_id == 2][0])
def _do_test_remove_export(self, cluster_id: str, expected_exports: Dict[int, List[str]]) -> None: nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) assert len(conf.exports[cluster_id]) == 2 assert conf.delete_export(cluster_id=cluster_id, pseudo_path="/rgw") == (0, "Successfully deleted export", "") exports = conf.exports[cluster_id] assert len(exports) == 1 assert exports[0].export_id == 1
def _do_test_remove_export(self) -> None: nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) assert len(conf.exports[self.cluster_id]) == 2 assert conf.delete_export( cluster_id=self.cluster_id, pseudo_path="/rgw") == (0, "Successfully deleted export", "") exports = conf.exports[self.cluster_id] assert len(exports) == 1 assert exports[0].export_id == 1
def _do_test_ganesha_conf(self, cluster: str, expected_exports: Dict[int, List[str]]) -> None: nfs_mod = Module('nfs', '', '') ganesha_conf = ExportMgr(nfs_mod) exports = ganesha_conf.exports['foo'] assert len(exports) == 2 #assert 1 in exports #assert 2 in exports self._validate_export_1([e for e in exports if e.export_id == 1][0]) self._validate_export_2([e for e in exports if e.export_id == 2][0])
def _do_test_create_export_cephfs(self): nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) exports = conf.list_exports(cluster_id=self.cluster_id) ls = json.loads(exports[1]) assert len(ls) == 2 r = conf.create_export( fsal_type='cephfs', cluster_id=self.cluster_id, fs_name='myfs', path='/', pseudo_path='/cephfs2', read_only=False, squash='root', addr=["192.168.1.0/8"], ) assert r[0] == 0 exports = conf.list_exports(cluster_id=self.cluster_id) ls = json.loads(exports[1]) assert len(ls) == 3 export = conf._fetch_export('foo', '/cephfs2') assert export.export_id assert export.path == "/" assert export.pseudo == "/cephfs2" assert export.access_type == "none" assert export.squash == "none" assert export.protocols == [4] assert export.transports == ["TCP"] assert export.fsal.name == "CEPH" assert export.fsal.user_id == "nfs.foo.3" assert export.fsal.cephx_key == "thekeyforclientabc" assert len(export.clients) == 1 assert export.clients[0].squash == 'root' assert export.clients[0].access_type == 'rw' assert export.clients[0].addresses == ["192.168.1.0/8"] assert export.cluster_id == self.cluster_id
def _do_test_create_export_rgw(self, cluster_id, expected_exports): nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) exports = conf.list_exports(cluster_id=cluster_id) ls = json.loads(exports[1]) assert len(ls) == 2 r = conf.create_export( fsal_type='rgw', cluster_id=cluster_id, bucket='bucket', pseudo_path='/mybucket', read_only=False, squash='root', addr=["192.168.0.0/16"] ) assert r[0] == 0 exports = conf.list_exports(cluster_id=cluster_id) ls = json.loads(exports[1]) assert len(ls) == 3 export = conf._fetch_export('foo', '/mybucket') assert export.export_id assert export.path == "bucket" assert export.pseudo == "/mybucket" assert export.access_type == "none" assert export.squash == "none" assert export.protocols == [4] assert export.transports == ["TCP"] assert export.fsal.name == "RGW" assert export.fsal.user_id == "nfs.foo.bucket" assert export.fsal.access_key_id == "the_access_key" assert export.fsal.secret_access_key == "the_secret_key" assert len(export.clients) == 1 assert export.clients[0].squash == 'root' assert export.clients[0].access_type == 'rw' assert export.clients[0].addresses == ["192.168.0.0/16"] assert export.cluster_id == cluster_id
def _do_test_cluster_config(self): nfs_mod = Module('nfs', '', '') cluster = NFSCluster(nfs_mod) rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id) assert rc == 0 assert out == "" rc, out, err = cluster.set_nfs_cluster_config(self.cluster_id, '# foo\n') assert rc == 0 rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id) assert rc == 0 assert out == "# foo\n" rc, out, err = cluster.reset_nfs_cluster_config(self.cluster_id) assert rc == 0 rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id) assert rc == 0 assert out == ""
def _do_test_update_export_with_list(self): nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) r = conf.apply_export( self.cluster_id, json.dumps([ { 'path': 'bucket', 'pseudo': '/rgw/bucket', 'cluster_id': self.cluster_id, 'access_type': 'RW', 'squash': 'root', 'security_label': False, 'protocols': [4], 'transports': ['TCP'], 'clients': [{ 'addresses': ["192.168.0.0/16"], 'access_type': None, 'squash': None }], 'fsal': { 'name': 'RGW', 'user_id': 'nfs.foo.bucket', 'access_key_id': 'the_access_key', 'secret_access_key': 'the_secret_key', } }, { 'path': 'bucket2', 'pseudo': '/rgw/bucket2', 'cluster_id': self.cluster_id, 'access_type': 'RO', 'squash': 'root', 'security_label': False, 'protocols': [4], 'transports': ['TCP'], 'clients': [{ 'addresses': ["192.168.0.0/16"], 'access_type': None, 'squash': None }], 'fsal': { 'name': 'RGW', 'user_id': 'nfs.foo.bucket2', 'access_key_id': 'the_access_key', 'secret_access_key': 'the_secret_key', } }, ])) assert r[0] == 0 export = conf._fetch_export('foo', '/rgw/bucket') assert export.export_id == 3 assert export.path == "bucket" assert export.pseudo == "/rgw/bucket" assert export.access_type == "RW" assert export.squash == "root" assert export.protocols == [4] assert export.transports == ["TCP"] assert export.fsal.name == "RGW" assert export.fsal.access_key_id == "the_access_key" assert export.fsal.secret_access_key == "the_secret_key" assert len(export.clients) == 1 assert export.clients[0].squash is None assert export.clients[0].access_type is None assert export.cluster_id == self.cluster_id export = conf._fetch_export('foo', '/rgw/bucket2') assert export.export_id == 4 assert export.path == "bucket2" assert export.pseudo == "/rgw/bucket2" assert export.access_type == "RO" assert export.squash == "root" assert export.protocols == [4] assert export.transports == ["TCP"] assert export.fsal.name == "RGW" assert export.fsal.access_key_id == "the_access_key" assert export.fsal.secret_access_key == "the_secret_key" assert len(export.clients) == 1 assert export.clients[0].squash is None assert export.clients[0].access_type is None assert export.cluster_id == self.cluster_id
def _do_test_update_export_with_ganesha_conf(self): nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) r = conf.apply_export(self.cluster_id, self.export_3) assert r[0] == 0
def _do_test_update_export(self): nfs_mod = Module('nfs', '', '') conf = ExportMgr(nfs_mod) r = conf.apply_export( self.cluster_id, json.dumps({ 'export_id': 2, 'path': 'bucket', 'pseudo': '/rgw/bucket', 'cluster_id': self.cluster_id, 'access_type': 'RW', 'squash': 'all_squash', 'security_label': False, 'protocols': [4, 3], 'transports': ['TCP', 'UDP'], 'clients': [{ 'addresses': ["192.168.0.0/16"], 'access_type': None, 'squash': None }], 'fsal': { 'name': 'RGW', 'user_id': 'nfs.foo.bucket', 'access_key_id': 'the_access_key', 'secret_access_key': 'the_secret_key', } })) assert r[0] == 0 export = conf._fetch_export('foo', '/rgw/bucket') assert export.export_id == 2 assert export.path == "bucket" assert export.pseudo == "/rgw/bucket" assert export.access_type == "RW" assert export.squash == "all_squash" assert export.protocols == [4, 3] assert export.transports == ["TCP", "UDP"] assert export.fsal.name == "RGW" assert export.fsal.access_key_id == "the_access_key" assert export.fsal.secret_access_key == "the_secret_key" assert len(export.clients) == 1 assert export.clients[0].squash is None assert export.clients[0].access_type is None assert export.cluster_id == self.cluster_id # do it again, with changes r = conf.apply_export( self.cluster_id, json.dumps({ 'export_id': 2, 'path': 'newbucket', 'pseudo': '/rgw/bucket', 'cluster_id': self.cluster_id, 'access_type': 'RO', 'squash': 'root', 'security_label': False, 'protocols': [4], 'transports': ['TCP'], 'clients': [{ 'addresses': ["192.168.10.0/16"], 'access_type': None, 'squash': None }], 'fsal': { 'name': 'RGW', 'user_id': 'nfs.foo.newbucket', 'access_key_id': 'the_access_key', 'secret_access_key': 'the_secret_key', } })) assert r[0] == 0 export = conf._fetch_export('foo', '/rgw/bucket') assert export.export_id == 2 assert export.path == "newbucket" assert export.pseudo == "/rgw/bucket" assert export.access_type == "RO" assert export.squash == "root" assert export.protocols == [4] assert export.transports == ["TCP"] assert export.fsal.name == "RGW" assert export.fsal.access_key_id == "the_access_key" assert export.fsal.secret_access_key == "the_secret_key" assert len(export.clients) == 1 assert export.clients[0].squash is None assert export.clients[0].access_type is None assert export.cluster_id == self.cluster_id # again, but without export_id r = conf.apply_export( self.cluster_id, json.dumps({ 'path': 'newestbucket', 'pseudo': '/rgw/bucket', 'cluster_id': self.cluster_id, 'access_type': 'RW', 'squash': 'root', 'security_label': False, 'protocols': [4], 'transports': ['TCP'], 'clients': [{ 'addresses': ["192.168.10.0/16"], 'access_type': None, 'squash': None }], 'fsal': { 'name': 'RGW', 'user_id': 'nfs.foo.newestbucket', 'access_key_id': 'the_access_key', 'secret_access_key': 'the_secret_key', } })) assert r[0] == 0 export = conf._fetch_export(self.cluster_id, '/rgw/bucket') assert export.export_id == 2 assert export.path == "newestbucket" assert export.pseudo == "/rgw/bucket" assert export.access_type == "RW" assert export.squash == "root" assert export.protocols == [4] assert export.transports == ["TCP"] assert export.fsal.name == "RGW" assert export.fsal.access_key_id == "the_access_key" assert export.fsal.secret_access_key == "the_secret_key" assert len(export.clients) == 1 assert export.clients[0].squash is None assert export.clients[0].access_type is None assert export.cluster_id == self.cluster_id