Newer
Older
################################################################################
# Copyright 2018-2020, Barcelona Supercomputing Center (BSC), Spain #
# Copyright 2015-2020, Johannes Gutenberg Universitaet Mainz, Germany #
# #
# This software was partially supported by the #
# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). #
# #
# This software was partially supported by the #
# ADA-FS project under the SPPEXA project funded by the DFG. #
# #
# SPDX-License-Identifier: MIT #
################################################################################
import harness
from pathlib import Path
import errno
import stat
import os
import ctypes
import sh
import sys
import pytest
from harness.logger import logger
nonexisting = "nonexisting"
#@pytest.mark.xfail(reason="invalid errno returned on success")
def test_mkdir(gkfs_daemon, gkfs_client):
"""Create a new directory in the FS's root"""
topdir = gkfs_daemon.mountdir / "top"
longer = Path(topdir.parent, topdir.name + "_plus")
dir_a = topdir / "dir_a"
dir_b = topdir / "dir_b"
file_a = topdir / "file_a"
subdir_a = dir_a / "subdir_a"
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# create topdir
ret = gkfs_client.mkdir(
topdir,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
# test stat on existing dir
ret = gkfs_client.stat(topdir)
assert ret.retval == 0
assert stat.S_ISDIR(ret.statbuf.st_mode)
# open topdir
ret = gkfs_client.open(topdir, os.O_DIRECTORY)
assert ret.retval != -1
# read and write should be impossible on directories
ret = gkfs_client.read(topdir, 1)
assert ret.buf is None
assert ret.retval == -1
assert ret.errno == errno.EISDIR
# buf = bytes('42', sys.stdout.encoding)
# print(buf.hex())
buf = b'42'
ret = gkfs_client.write(topdir, buf, 1)
assert ret.retval == -1
assert ret.errno == errno.EISDIR
# read top directory that is empty
ret = gkfs_client.opendir(topdir)
assert ret.dirp is not None
ret = gkfs_client.readdir(topdir)
# XXX: This might change in the future if we add '.' and '..'
assert len(ret.dirents) == 0
# close directory
# TODO: disabled for now because we have no way to keep DIR* alive
# between gkfs.io executions
# ret = gkfs_client.opendir(XXX)
# populate top directory
for d in [dir_a, dir_b]:
ret = gkfs_client.mkdir(
d,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
os.O_CREAT,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval != -1
ret = gkfs_client.readdir(gkfs_daemon.mountdir)
# XXX: This might change in the future if we add '.' and '..'
assert len(ret.dirents) == 1
assert ret.dirents[0].d_name == 'top'
assert ret.dirents[0].d_type == 4 # DT_DIR
expected = [
( dir_a.name, 4 ), # DT_DIR
( dir_b.name, 4 ),
( file_a.name, 8 ) # DT_REG
]
ret = gkfs_client.readdir(topdir)
assert len(ret.dirents) == len(expected)
for d,e in zip(ret.dirents, expected):
assert d.d_name == e[0]
assert d.d_type == e[1]
# remove file using rmdir should produce an error
ret = gkfs_client.rmdir(file_a)
assert ret.retval == -1
assert ret.errno == errno.ENOTDIR
# create a directory with the same prefix as topdir but longer name
ret = gkfs_client.mkdir(
longer,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
expected = [
( topdir.name, 4 ), # DT_DIR
( longer.name, 4 ), # DT_DIR
]
ret = gkfs_client.readdir(gkfs_daemon.mountdir)
assert len(ret.dirents) == len(expected)
for d,e in zip(ret.dirents, expected):
assert d.d_name == e[0]
assert d.d_type == e[1]
# create 2nd level subdir and check it's not included in readdir()
ret = gkfs_client.mkdir(
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
assert ret.retval == 0
expected = [
( topdir.name, 4 ), # DT_DIR
( longer.name, 4 ), # DT_DIR
]
ret = gkfs_client.readdir(gkfs_daemon.mountdir)
assert len(ret.dirents) == len(expected)
for d,e in zip(ret.dirents, expected):
assert d.d_name == e[0]
assert d.d_type == e[1]
expected = [
( subdir_a.name, 4 ), # DT_DIR
]
ret = gkfs_client.readdir(dir_a)
assert len(ret.dirents) == len(expected)
for d,e in zip(ret.dirents, expected):
assert d.d_name == e[0]
assert d.d_type == e[1]
return
Ramon Nou
committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def test_extended(gkfs_daemon, gkfs_shell, gkfs_client):
topdir = gkfs_daemon.mountdir / "test_extended"
longer = Path(topdir.parent, topdir.name + "_plus")
dir_a = topdir / "dir_a"
dir_b = topdir / "dir_b"
file_a = topdir / "file_a"
subdir_a = dir_a / "subdir_a"
# create topdir
ret = gkfs_client.mkdir(
topdir,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
ret = gkfs_client.mkdir(
dir_a,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
ret = gkfs_client.mkdir(
dir_b,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
ret = gkfs_client.mkdir(
subdir_a,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval == 0
ret = gkfs_client.open(file_a,
os.O_CREAT,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
assert ret.retval != -1
buf = b'42'
ret = gkfs_client.write(file_a, buf, 1)
assert ret.retval == 1
cmd = gkfs_shell.sfind(
topdir,
f'-M {gkfs_daemon.mountdir}',
'-S 1',
'-name "*_k*"'
)
assert cmd.exit_code == 0
assert cmd.stdout.decode() == "MATCHED 0/4\n"
Ramon Nou
committed
@pytest.mark.skip(reason="invalid errno returned on success")
@pytest.mark.parametrize("directory_path",
[ nonexisting ])
def test_opendir(gkfs_daemon, gkfs_client, directory_path):
ret = gkfs_client.opendir(gkfs_daemon.mountdir / directory_path)
assert ret.dirp is None
assert ret.errno == errno.ENOENT
# def test_stat(gkfs_daemon):
# pass
# def test_rmdir(gkfs_daemon):
# pass
# def test_closedir(gkfs_daemon):
# pass