|
1 | 1 | import argparse |
2 | 2 | import logging |
| 3 | +import shutil |
| 4 | +import subprocess |
3 | 5 | import unittest |
| 6 | +import os |
4 | 7 |
|
5 | 8 | from utils import ( |
6 | 9 | Size, |
@@ -57,107 +60,132 @@ def log_dl(when): |
57 | 60 | with allocated_files( |
58 | 61 | (args.path / f"test{n:02d}.dat", 1 * Size.GIB) for n in range(1, 4) |
59 | 62 | ) as bf: |
60 | | - ####################################################################### |
61 | | - preTest("create zpool backed by single file") |
62 | | - with zpool_create(ctx, "test01", paths_to_unc(bf[:1])): |
63 | | - log_dl("after test01 pool create") |
64 | | - |
65 | | - ####################################################################### |
66 | | - preTest("create zpool backed by two files") |
67 | | - with zpool_create(ctx, "test02", paths_to_unc(bf[:2])): |
68 | | - log_dl("after test02 pool create") |
69 | | - |
70 | | - ####################################################################### |
71 | | - preTest("create zpool backed by three files") |
72 | | - with zpool_create(ctx, "test03", paths_to_unc(bf)): |
73 | | - log_dl("after test03 pool create") |
74 | | - |
75 | | - ####################################################################### |
76 | | - preTest("create mirror zpool backed by two files") |
77 | | - with zpool_create(ctx, "test04", ["mirror", *paths_to_unc(bf[:2])]): |
78 | | - log_dl("after test04 pool create") |
79 | | - |
80 | | - ####################################################################### |
81 | | - preTest("create mirror zpool backed by three files") |
82 | | - with zpool_create(ctx, "test05", ["mirror", *paths_to_unc(bf)]): |
83 | | - log_dl("after test05 pool create") |
84 | | - |
85 | | - ####################################################################### |
86 | | - preTest("create raidz zpool backed by three files") |
87 | | - with zpool_create(ctx, "test06", ["raidz", *paths_to_unc(bf)]): |
88 | | - log_dl("after test06 pool create") |
| 63 | + # ####################################################################### |
| 64 | + # preTest("create zpool backed by single file") |
| 65 | + # with zpool_create(ctx, "test01", paths_to_unc(bf[:1])): |
| 66 | + # log_dl("after test01 pool create") |
| 67 | + |
| 68 | + # ####################################################################### |
| 69 | + # preTest("create zpool backed by two files") |
| 70 | + # with zpool_create(ctx, "test02", paths_to_unc(bf[:2])): |
| 71 | + # log_dl("after test02 pool create") |
| 72 | + |
| 73 | + # ####################################################################### |
| 74 | + # preTest("create zpool backed by three files") |
| 75 | + # with zpool_create(ctx, "test03", paths_to_unc(bf)): |
| 76 | + # log_dl("after test03 pool create") |
| 77 | + |
| 78 | + # ####################################################################### |
| 79 | + # preTest("create mirror zpool backed by two files") |
| 80 | + # with zpool_create(ctx, "test04", ["mirror", *paths_to_unc(bf[:2])]): |
| 81 | + # log_dl("after test04 pool create") |
| 82 | + |
| 83 | + # ####################################################################### |
| 84 | + # preTest("create mirror zpool backed by three files") |
| 85 | + # with zpool_create(ctx, "test05", ["mirror", *paths_to_unc(bf)]): |
| 86 | + # log_dl("after test05 pool create") |
| 87 | + |
| 88 | + # ####################################################################### |
| 89 | + # preTest("create raidz zpool backed by three files") |
| 90 | + # with zpool_create(ctx, "test06", ["raidz", *paths_to_unc(bf)]): |
| 91 | + # log_dl("after test06 pool create") |
| 92 | + |
| 93 | + # ####################################################################### |
| 94 | + # preTest("create raidz1 zpool backed by three files") |
| 95 | + # with zpool_create(ctx, "test07", ["raidz1", *paths_to_unc(bf)]): |
| 96 | + # log_dl("after test07 pool create") |
89 | 97 |
|
90 | 98 | ####################################################################### |
91 | | - preTest("create raidz1 zpool backed by three files") |
92 | | - with zpool_create(ctx, "test07", ["raidz1", *paths_to_unc(bf)]): |
93 | | - log_dl("after test07 pool create") |
94 | | - |
95 | | - ####################################################################### |
96 | | - preTest("snapshot no hang") |
97 | | - with zpool_create(ctx, "testsn01", paths_to_unc(bf[:1])) as pool: |
98 | | - log_dl("after testsn01 pool create") |
99 | | - |
100 | | - allocate_file(pool.mount_path / "test01.file", 1 * Size.KIB) |
101 | | - run_cmd(ctx.ZFS, ["snapshot", "testsn01@friday"]) |
102 | | - allocate_file(pool.mount_path / "test02.file", 1 * Size.KIB) |
103 | | - run_cmd(ctx.ZPOOL, ["export", "testsn01"]) |
104 | | - pool.destroy = False # already exported |
105 | | - |
106 | | - ####################################################################### |
107 | | - preTest("snapshot hang") |
108 | | - with zpool_create(ctx, "testsn02", paths_to_unc(bf[:1])) as pool: |
109 | | - log_dl("after testsn02 pool create") |
110 | | - |
111 | | - allocate_file(pool.mount_path / "test01.file", 1 * Size.KIB) |
112 | | - run_cmd(ctx.ZFS, ["snapshot", "testsn02@friday"]) |
113 | | - allocate_file(pool.mount_path / "test02.file", 1 * Size.KIB) |
114 | | - run_cmd(ctx.ZFS, ["mount", "testsn02@friday"]) |
115 | | - run_cmd(ctx.ZPOOL, ["export", "testsn02"]) |
116 | | - pool.destroy = False # already exported |
117 | | - |
118 | | - ####################################################################### |
119 | | - preTest("regex for key file") |
120 | | - with random_key(args.path / "key01.key", 32) as key01: |
121 | | - key01uri = "file://" + str(path_to_unc(key01)).replace("\\", "/") |
122 | | - |
123 | | - with zpool_create( |
124 | | - ctx, |
125 | | - "tank", |
126 | | - paths_to_unc(bf[:1]), |
127 | | - zfs_options={ |
128 | | - "encryption": "aes-256-ccm", |
129 | | - "keylocation": key01uri, |
130 | | - "keyformat": "raw", |
131 | | - }, |
132 | | - ): |
133 | | - log_dl("after tank pool create") |
134 | | - |
135 | | - run_cmd(ctx.ZFS, ["get", "keylocation", "tank"]) |
136 | | - run_cmd(ctx.ZPOOL, ["export", "tank"]) |
137 | | - |
138 | | - log_dl("before pool import") |
139 | | - |
140 | | - run_cmd( |
141 | | - ctx.ZPOOL, |
142 | | - [ |
143 | | - "import", |
144 | | - "-d", |
145 | | - bf[0].parent.as_posix(), |
146 | | - "-f", |
147 | | - "-l", |
148 | | - "tank", |
149 | | - ], |
150 | | - ) |
151 | | - |
152 | | - log_dl("after pool import") |
153 | | - |
154 | | - ####################################################################### |
155 | | - preTest("run out of drive letters") |
156 | | - for i in range(1, 26): |
157 | | - with zpool_create(ctx, f"tank{i}", paths_to_unc(bf[:1])) as pool: |
158 | | - log_dl(f"after tank{i} pool create") |
159 | | - |
160 | | - allocate_file(pool.mount_path / "test01.file", 1 * Size.KIB) |
| 99 | + preTest("rclone and export") |
| 100 | + if shutil.which("rclone"): |
| 101 | + with zpool_create(ctx, "test08", paths_to_unc(bf[:1])) as pool: |
| 102 | + log_dl("after test08 pool create") |
| 103 | + |
| 104 | + try: |
| 105 | + subprocess.run( |
| 106 | + [ |
| 107 | + "rclone", |
| 108 | + "sync", |
| 109 | + os.environ["WINDIR"], |
| 110 | + # bf[1], |
| 111 | + pool.mount_path / "copy.bin", |
| 112 | + ], |
| 113 | + timeout=15, |
| 114 | + ) |
| 115 | + except subprocess.TimeoutExpired: |
| 116 | + pass |
| 117 | + |
| 118 | + run_cmd(ctx.ZPOOL, ["export", "test08"]) |
| 119 | + pool.destroy = False # already exported |
| 120 | + else: |
| 121 | + logger.warning("skipped because rclone is not in path") |
| 122 | + |
| 123 | + # ####################################################################### |
| 124 | + # preTest("snapshot no hang") |
| 125 | + # with zpool_create(ctx, "testsn01", paths_to_unc(bf[:1])) as pool: |
| 126 | + # log_dl("after testsn01 pool create") |
| 127 | + |
| 128 | + # allocate_file(pool.mount_path / "test01.file", 1 * Size.KIB) |
| 129 | + # run_cmd(ctx.ZFS, ["snapshot", "testsn01@friday"]) |
| 130 | + # allocate_file(pool.mount_path / "test02.file", 1 * Size.KIB) |
| 131 | + # run_cmd(ctx.ZPOOL, ["export", "testsn01"]) |
| 132 | + # pool.destroy = False # already exported |
| 133 | + |
| 134 | + # ####################################################################### |
| 135 | + # preTest("snapshot hang") |
| 136 | + # with zpool_create(ctx, "testsn02", paths_to_unc(bf[:1])) as pool: |
| 137 | + # log_dl("after testsn02 pool create") |
| 138 | + |
| 139 | + # allocate_file(pool.mount_path / "test01.file", 1 * Size.KIB) |
| 140 | + # run_cmd(ctx.ZFS, ["snapshot", "testsn02@friday"]) |
| 141 | + # allocate_file(pool.mount_path / "test02.file", 1 * Size.KIB) |
| 142 | + # run_cmd(ctx.ZFS, ["mount", "testsn02@friday"]) |
| 143 | + # run_cmd(ctx.ZPOOL, ["export", "testsn02"]) |
| 144 | + # pool.destroy = False # already exported |
| 145 | + |
| 146 | + # ####################################################################### |
| 147 | + # preTest("regex for key file") |
| 148 | + # with random_key(args.path / "key01.key", 32) as key01: |
| 149 | + # key01uri = "file://" + str(path_to_unc(key01)).replace("\\", "/") |
| 150 | + |
| 151 | + # with zpool_create( |
| 152 | + # ctx, |
| 153 | + # "tank", |
| 154 | + # paths_to_unc(bf[:1]), |
| 155 | + # zfs_options={ |
| 156 | + # "encryption": "aes-256-ccm", |
| 157 | + # "keylocation": key01uri, |
| 158 | + # "keyformat": "raw", |
| 159 | + # }, |
| 160 | + # ): |
| 161 | + # log_dl("after tank pool create") |
| 162 | + |
| 163 | + # run_cmd(ctx.ZFS, ["get", "keylocation", "tank"]) |
| 164 | + # run_cmd(ctx.ZPOOL, ["export", "tank"]) |
| 165 | + |
| 166 | + # log_dl("before pool import") |
| 167 | + |
| 168 | + # run_cmd( |
| 169 | + # ctx.ZPOOL, |
| 170 | + # [ |
| 171 | + # "import", |
| 172 | + # "-d", |
| 173 | + # bf[0].parent.as_posix(), |
| 174 | + # "-f", |
| 175 | + # "-l", |
| 176 | + # "tank", |
| 177 | + # ], |
| 178 | + # ) |
| 179 | + |
| 180 | + # log_dl("after pool import") |
| 181 | + |
| 182 | + # ####################################################################### |
| 183 | + # preTest("run out of drive letters") |
| 184 | + # for i in range(1, 26): |
| 185 | + # with zpool_create(ctx, f"tank{i}", paths_to_unc(bf[:1])) as pool: |
| 186 | + # log_dl(f"after tank{i} pool create") |
| 187 | + |
| 188 | + # allocate_file(pool.mount_path / "test01.file", 1 * Size.KIB) |
161 | 189 |
|
162 | 190 |
|
163 | 191 | if __name__ == "__main__": |
|
0 commit comments