diff options
Diffstat (limited to 'src/pybind/mgr/rook/rook-client-python/rook_client/tests')
4 files changed, 93 insertions, 0 deletions
diff --git a/src/pybind/mgr/rook/rook-client-python/rook_client/tests/__init__.py b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/__init__.py diff --git a/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_README.py b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_README.py new file mode 100644 index 000000000..50d6c41b4 --- /dev/null +++ b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_README.py @@ -0,0 +1,28 @@ +def objectstore(api_name, name, namespace, instances): + from rook_client.ceph import cephobjectstore as cos + rook_os = cos.CephObjectStore( + apiVersion=api_name, + metadata=dict( + name=name, + namespace=namespace + ), + spec=cos.Spec( + metadataPool=cos.MetadataPool( + failureDomain='host', + replicated=cos.Replicated( + size=1 + ) + ), + dataPool=cos.DataPool( + failureDomain='osd', + replicated=cos.Replicated( + size=1 + ) + ), + gateway=cos.Gateway( + port=80, + instances=instances + ) + ) + ) + return rook_os.to_json() diff --git a/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_examples.py b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_examples.py new file mode 100644 index 000000000..5367844ec --- /dev/null +++ b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_examples.py @@ -0,0 +1,52 @@ +from os.path import expanduser, dirname, realpath + +import yaml +import pytest + +import rook_client +from rook_client.cassandra.cluster import Cluster as CassandraCluster +from rook_client.ceph.cephcluster import CephCluster +from rook_client.ceph.cephfilesystem import CephFilesystem +from rook_client.ceph.cephnfs import CephNFS +from rook_client.ceph.cephobjectstore import CephObjectStore +from rook_client.ceph.cephblockpool import CephBlockPool + + +def _load_example(crd_base, what): + with open(expanduser('{crd_base}/{what}').format(crd_base=crd_base, what=what)) as f: + return f.read() + + +@pytest.mark.parametrize( + "strict,cls,filename", + [ + (True, CephCluster, "ceph/cluster-external.yaml"), + (True, CephCluster, "ceph/cluster-on-pvc.yaml"), + (True, CephCluster, "ceph/cluster.yaml"), + (True, CephFilesystem, "ceph/filesystem-ec.yaml"), + (True, CephFilesystem, "ceph/filesystem-test.yaml"), + (True, CephFilesystem, "ceph/filesystem.yaml"), + (True, CephObjectStore, "ceph/object-ec.yaml"), + (True, CephObjectStore, "ceph/object-openshift.yaml"), + (True, CephObjectStore, "ceph/object-test.yaml"), + (True, CephObjectStore, "ceph/object.yaml"), + (True, CephNFS, "ceph/nfs.yaml"), + (True, CephBlockPool, "ceph/pool.yaml"), + (True, CephBlockPool, "ceph/pool-ec.yaml"), + (True, CephBlockPool, "ceph/pool-test.yaml"), + + # schema invalid: + # (False, CassandraCluster, "cassandra/cluster.yaml"), + ], +) +def test_exact_match(strict, cls, filename, crd_base): + crds = yaml.safe_load_all(_load_example(crd_base, filename)) + rook_client.STRICT = strict + [crd] = [e for e in crds if e.get('kind', '') == cls.__name__] + + c = cls.from_json(crd) + assert crd == c.to_json() + + + + diff --git a/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_properties.py b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_properties.py new file mode 100644 index 000000000..0d580e43f --- /dev/null +++ b/src/pybind/mgr/rook/rook-client-python/rook_client/tests/test_properties.py @@ -0,0 +1,13 @@ +from copy import deepcopy + +import pytest + +from rook_client.ceph import cephcluster as cc + + +def test_omit(): + cv = cc.CephVersion() + with pytest.raises(AttributeError): + cv.allowUnsupported + + assert not hasattr(cv, 'allowUnsupported') |