|
| 1 | +import testhelper |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | + |
| 5 | +def test_read_yaml1(): |
| 6 | + testinfo = testhelper.read_yaml("test-info1.yml") |
| 7 | + |
| 8 | + export1 = testinfo["shares"]["export1"] |
| 9 | + assert export1["server"] == "hostname1" |
| 10 | + assert export1["path"] == "/mnt/share/export1-cephfs-vfs" |
| 11 | + assert export1["backend"]["name"] == "cephfs.vfs" |
| 12 | + assert "user1" not in export1["users"] |
| 13 | + assert "test2" in export1["users"] |
| 14 | + assert export1["users"]["test2"] == "x" |
| 15 | + |
| 16 | + export2 = testinfo["shares"]["export2"] |
| 17 | + assert export2["server"] == "server_name" |
| 18 | + assert "path" not in export2 |
| 19 | + assert export2["backend"]["name"] == "glusterfs" |
| 20 | + assert "test2" not in export2["users"] |
| 21 | + assert "user2" in export2["users"] |
| 22 | + assert export2["users"]["user2"] == "user2password" |
| 23 | + |
| 24 | + |
| 25 | +def test_read_yaml2(): |
| 26 | + testinfo = testhelper.read_yaml("test-info2.yml") |
| 27 | + |
| 28 | + export = testinfo["shares"]["gluster-vol"] |
| 29 | + assert export["server"] == "192.168.123.10" |
| 30 | + assert "path" not in export |
| 31 | + assert export["backend"]["name"] == "glusterfs" |
| 32 | + assert "user1" not in export["users"] |
| 33 | + assert "test1" in export["users"] |
| 34 | + assert export["users"]["test1"] == "x" |
| 35 | + |
| 36 | + |
| 37 | +def test_get_share(): |
| 38 | + testinfo = testhelper.read_yaml("test-info1.yml") |
| 39 | + export2 = testhelper.get_share(testinfo, "export2") |
| 40 | + assert export2["server"] == "server_name" |
| 41 | + assert "path" not in export2 |
| 42 | + assert export2["backend"]["name"] == "glusterfs" |
| 43 | + assert "test2" not in export2["users"] |
| 44 | + assert "user2" in export2["users"] |
| 45 | + assert export2["users"]["user2"] == "user2password" |
| 46 | + |
| 47 | + |
| 48 | +def test_list_premounted(): |
| 49 | + testinfo = testhelper.read_yaml("test-info1.yml") |
| 50 | + premounted = testhelper.get_premounted_shares(testinfo) |
| 51 | + assert len(premounted) == 1 |
| 52 | + assert Path("/mnt/share/export1-cephfs-vfs") in premounted |
| 53 | + |
| 54 | + |
| 55 | +def test_generate_exported_shares(): |
| 56 | + testinfo = testhelper.read_yaml("test-info1.yml") |
| 57 | + arr = [] |
| 58 | + for sharename in testhelper.get_exported_shares(testinfo): |
| 59 | + share = testhelper.get_share(testinfo, sharename) |
| 60 | + arr.append((share["server"], share["name"])) |
| 61 | + assert len(arr) == 1 |
| 62 | + assert ("server_name", "export2") in arr |
0 commit comments