|
7 | 7 | # ip addresses). |
8 | 8 |
|
9 | 9 | import testhelper |
| 10 | +from testhelper import SMBClient |
10 | 11 | import os |
11 | 12 | import pytest |
12 | 13 | import typing |
13 | | -from pathlib import Path |
14 | | - |
15 | 14 |
|
16 | 15 | test_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
17 | 16 | test_info_file = os.getenv("TEST_INFO_FILE") |
18 | 17 | test_info = testhelper.read_yaml(test_info_file) |
19 | 18 |
|
20 | 19 |
|
21 | | -def file_content_check(f: typing.IO, comp_str: str) -> bool: |
22 | | - read_data = f.read() |
23 | | - return read_data == comp_str |
24 | | - |
25 | | - |
26 | | -def consistency_check(mount_point: Path, ipaddr: str, share_name: str) -> None: |
| 20 | +def consistency_check(hostname: str, share_name: str) -> None: |
27 | 21 | mount_params = testhelper.get_mount_parameters(test_info, share_name) |
28 | | - mount_params["host"] = ipaddr |
29 | | - try: |
30 | | - test_file = testhelper.get_tmp_file(mount_point) |
31 | | - test_file_resp = test_file.with_suffix(".resp") |
32 | | - test_file_remote = "test-" + ipaddr + "." + share_name |
33 | | - with open(test_file, "w") as f: |
34 | | - f.write(test_string) |
35 | | - put_cmds = "put %s %s" % (test_file, test_file_remote) |
36 | | - (ret, output) = testhelper.smbclient(mount_params, put_cmds) |
37 | | - assert ret == 0, "Failed to copy file to server" |
38 | | - |
39 | | - # The file read cycle |
40 | | - get_cmds = "get %s %s; rm %s" % ( |
41 | | - test_file_remote, |
42 | | - test_file_resp, |
43 | | - test_file_remote, |
44 | | - ) |
45 | | - (ret, output) = testhelper.smbclient(mount_params, get_cmds) |
46 | | - assert ret == 0, "Failed to copy file from server" |
47 | | - with open(test_file_resp, "r") as f: |
48 | | - assert file_content_check( |
49 | | - f, test_string |
50 | | - ), "File content does not match" |
51 | | - finally: |
52 | | - if test_file.exists(): |
53 | | - test_file.unlink() |
54 | | - if test_file_resp.exists(): |
55 | | - test_file_resp.unlink() |
56 | | - |
57 | | - |
58 | | -def generate_consistency_check( |
59 | | - test_info_file: dict, |
60 | | -) -> typing.List[typing.Tuple[str, str]]: |
61 | | - if not test_info_file: |
62 | | - return [] |
| 22 | + test_filename = "/test_consistency" |
| 23 | + |
| 24 | + # file write cycle |
| 25 | + scon = SMBClient( |
| 26 | + hostname, |
| 27 | + share_name, |
| 28 | + mount_params["username"], |
| 29 | + mount_params["password"], |
| 30 | + ) |
| 31 | + scon.simple_write(test_filename, test_string) |
| 32 | + del scon |
| 33 | + |
| 34 | + # file read cycle |
| 35 | + scon = SMBClient( |
| 36 | + hostname, |
| 37 | + share_name, |
| 38 | + mount_params["username"], |
| 39 | + mount_params["password"], |
| 40 | + ) |
| 41 | + retstr = scon.simple_read(test_filename) |
| 42 | + scon.unlink(test_filename) |
| 43 | + del scon |
| 44 | + |
| 45 | + assert retstr == test_string, "File content does not match" |
| 46 | + |
| 47 | + |
| 48 | +def generate_consistency_check() -> typing.List[typing.Tuple[str, str]]: |
63 | 49 | arr = [] |
64 | | - for share in testhelper.get_exported_shares(test_info): |
65 | | - s = testhelper.get_share(test_info, share) |
66 | | - arr.append((s["server"], s["name"])) |
| 50 | + for sharename in testhelper.get_exported_shares(test_info): |
| 51 | + share = testhelper.get_share(test_info, sharename) |
| 52 | + arr.append((share["server"], share["name"])) |
67 | 53 | return arr |
68 | 54 |
|
69 | 55 |
|
70 | | -@pytest.mark.parametrize( |
71 | | - "ipaddr,share_name", generate_consistency_check(test_info) |
72 | | -) |
73 | | -def test_consistency(ipaddr: str, share_name: str) -> None: |
74 | | - tmp_root = testhelper.get_tmp_root() |
75 | | - mount_point = testhelper.get_tmp_mount_point(tmp_root) |
76 | | - consistency_check(mount_point, ipaddr, share_name) |
77 | | - os.rmdir(mount_point) |
78 | | - os.rmdir(tmp_root) |
| 56 | +@pytest.mark.parametrize("hostname,share_name", generate_consistency_check()) |
| 57 | +def test_consistency(hostname: str, share_name: str) -> None: |
| 58 | + consistency_check(hostname, share_name) |
0 commit comments