Commit c856173a authored by Paal Kvamme's avatar Paal Kvamme
Browse files

In the Python wrapper when cloning a file on the cloud the iocontext is needed.

parent a2c225c6
Pipeline #59753 passed with stages
in 8 minutes and 33 seconds
......@@ -1439,15 +1439,33 @@ ZgyWriter_clone(ZgyClass* self, PyObject* args, PyObject* keywds)
NULL))
return NULL;
static const auto iscloud = [](const char* fn) {
return fn && strncmp(fn, "sd://", 5) == 0;
};
const bool has_iocontext = PyMapping_HasKeyString(keywds, "iocontext");
const bool out_sdcontext = has_iocontext && iscloud(filename_str);
const bool tpl_sdcontext = has_iocontext && iscloud(template_str);
std::shared_ptr<IOContext> iocontext;
try {
if (out_sdcontext || tpl_sdcontext)
iocontext = ZgyCommon_getIOContext(self, "sd://", iocontext_obj);
}
catch (...) {
return _raise_ex();
}
ZgyWriterArgs writer_args;
try {
auto parent = IZgyReader::open(std::string(template_str));
auto parent = IZgyReader::open(std::string(template_str),
tpl_sdcontext ? iocontext.get() : nullptr);
writer_args.metafrom(parent);
}
catch (...) {
return _raise_ex();
}
writer_args.filename(std::string(filename_str));
if (out_sdcontext)
writer_args.iocontext(iocontext.get());
if (datamin < datamax)
writer_args.datarange(datamin, datamax);
if (datatype_obj) {
......
......@@ -2928,6 +2928,22 @@ def testCloudConsolidateOverlap(filename, *, verbose = False):
assert trace.calls[0].nbytes == 0x13458 + 0x127d8
assert trace.calls[0].padded == 2*1024*1024
def testCloudClone(outfilename, templatename):
"""
Test: Clone works also on the cloud.
"""
size = (112, 64, 176)
ctxt = SDCredentials()
with newzgy.ZgyWriter(templatename, iocontext=ctxt, size=size) as writer:
assert(writer.size == size)
writer.close()
with newzgy.ZgyWriter(outfilename, iocontext=ctxt, templatename=templatename) as writer:
assert(writer.size == size)
writer.close()
with newzgy.ZgyReader(outfilename, iocontext = ctxt) as reader:
assert(reader.size == size)
reader.close()
def Main():
np.seterr(all='raise')
......@@ -3140,6 +3156,23 @@ def SDMain():
with TimeMe("ConsolidateOverlap"):
testCloudConsolidateOverlap(fn.name)
with CloudFileAutoDelete("clone_me_1.zgy", SDCredentials()) as outfn, \
CloudFileAutoDelete("clone_me_2.zgy", SDCredentials()) as tplfn, \
TimeMe("CloudCloneCC"):
testCloudClone(outfn.name, tplfn.name)
with CloudFileAutoDelete("clone_me_3.zgy", SDCredentials()) as outfn, \
LocalFileAutoDelete("clone_me_4.zgy") as tplfn, \
TimeMe("CloudCloneCL"):
testCloudClone(outfn.name, tplfn.name)
with LocalFileAutoDelete("clone_me_5.zgy") as outfn, \
CloudFileAutoDelete("clone_me_6.zgy", SDCredentials()) as tplfn, \
TimeMe("CloudCloneLC"):
testCloudClone(outfn.name, tplfn.name)
with LocalFileAutoDelete("clone_me_7.zgy") as outfn, \
LocalFileAutoDelete("clone_me_8.zgy") as tplfn, \
TimeMe("CloudCloneLL"):
testCloudClone(outfn.name, tplfn.name)
if __name__ == "__main__":
print("Running test_black.py with ad-hoc timers.")
if len(sys.argv) <= 1 or "local" in sys.argv[1:]:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment