From: Radosław Korzeniewski Date: Mon, 22 Mar 2021 13:25:10 +0000 (+0100) Subject: metaplugin: Update and extend regression tests. X-Git-Tag: Release-11.3.2~654 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31474afb3ed8328a46a45e503bff1635a5e379b9;p=thirdparty%2Fbacula.git metaplugin: Update and extend regression tests. --- diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp index 38c87d2af..b91219f86 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp @@ -307,7 +307,11 @@ int32_t PTCOMM::recvbackend_header(bpContext *ctx, char cmd) f_eod = f_error = f_fatal = true; return -1; } - DMSG(ctx, DDEBUG, "RECV: %c\n", header.status); + + // some packet commands require data + header.length[6] = 0; /* end of string */ + + DMSG2(ctx, DDEBUG, "RECV: %c %s\n", header.status, header.length); /* check for protocol status */ if (header.status == 'F'){ @@ -322,9 +326,6 @@ int32_t PTCOMM::recvbackend_header(bpContext *ctx, char cmd) return 0; } - // other packet commands require data - header.length[6] = 0; /* end of string */ - // convert packet length from ASCII to binary int32_t msglen = atoi(header.length); @@ -575,7 +576,9 @@ int32_t PTCOMM::sendbackend(bpContext *ctx, char cmd, POOLMEM *buf, int32_t len) header = &myheader; #endif header->status = cmd; - DMSG2(ctx, DDEBUG, "SENT: %c %s\n", header->status, buf ? buf : ""); + char bindata[17]; + transcript_bin_data_to_display(bindata, buf, len); + DMSG2(ctx, DDEBUG, "SENT: %c %s\n", header->status, bindata); if (bsnprintf(header->length, sizeof(PTHEADER), "%06i", len) != 6){ /* problem rendering packet header */ DMSG0(ctx, DERROR, "Problem rendering packet header for command.\n"); @@ -594,8 +597,7 @@ int32_t PTCOMM::sendbackend(bpContext *ctx, char cmd, POOLMEM *buf, int32_t len) status = write(wfd, buf, len); } #endif - if (status < 0) - { + if (status < 0){ // error DMSG0(ctx, DERROR, "PTCOMM cannot write packet to backend.\n"); JMSG0(ctx, is_fatal() ? M_FATAL : M_ERROR, "PTCOMM cannot write packet to backend.\n"); diff --git a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c index 769d226e7..e4b5ca1be 100644 --- a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c +++ b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c @@ -145,6 +145,29 @@ int read_plugin(char * buf) return len; } +void read_plugin_data_stream() +{ + int len = read_plugin(buf); + if (len == 0){ + /* empty file to restore */ + LOG("#> Empty data."); + return; + } + bool loopgo = true; + int fsize = len; + while (loopgo){ + len = read_plugin(buf); + fsize += len; + if (len > 0){ + LOG("#> data stream saved."); + continue; + } else { + loopgo = false; + snprintf(buflog, 4096, "#> data END = %i", fsize); + } + } +} + /** * @brief Sends/writes the data to plugin with assembling the raw packet. * @@ -434,7 +457,7 @@ void perform_backup() { snprintf(buf, BIGBUFLEN, "FNAME:%s/office/%d/document.docx\n", PLUGINPREFIX, mypid); write_plugin('C', buf); - write_plugin('C', "STAT:D 10240 100 100 040755 1\n"); + write_plugin('C', "STAT:F 10240 100 100 040755 1\n"); write_plugin('C', "TSTAMP:1504271937 1504271937 1504271937\n"); write_plugin('C', "METADATA_STREAM\n"); @@ -613,8 +636,7 @@ void perform_restore(){ int fsize; bool loopgo = true; - if (regress_error_restore_stderr) - { + if (regress_error_restore_stderr) { // test some stderror handling errno = EACCES; perror("I've got some unsuspected error which I'd like to display on stderr (COMM_STDERR)"); @@ -622,15 +644,15 @@ void perform_restore(){ /* Restore Loop (5) */ LOG("#> Restore Loop."); - while (true){ + while (true) { read_plugin(buf); /* check if FINISH job */ - if (strcmp(buf, "FINISH\n") == 0){ + if (strcmp(buf, "FINISH\n") == 0) { LOG("#> finish files."); break; } /* check for ACL command */ - if (strcmp(buf, "ACL\n") == 0){ + if (strcmp(buf, "ACL\n") == 0) { while (read_plugin(buf) > 0); LOG("#> ACL data saved."); write_plugin('I', "TEST5R - acl data saved."); @@ -638,9 +660,8 @@ void perform_restore(){ continue; } - /* check for XATTR command */ - if (strcmp(buf, "XATTR\n") == 0){ + if (strcmp(buf, "XATTR\n") == 0) { while (read_plugin(buf) > 0); LOG("#> XATTR data saved."); write_plugin('I', "TEST5R - xattr data saved."); @@ -648,7 +669,7 @@ void perform_restore(){ continue; } /* check if FNAME then follow file parameters */ - if (strncmp(buf, "FNAME:", 6) == 0){ + if (strncmp(buf, "FNAME:", 6) == 0) { /* we read here a file parameters */ while (read_plugin(buf) > 0); /* signal OK */ @@ -661,6 +682,16 @@ void perform_restore(){ #endif continue; } + + /* check for METADATA stream */ + if (strncmp(buf, "METADATA_STREAM", 15) == 0){ + // handle metadata + read_plugin_data_stream(); + /* signal OK */ + write_plugin('C', "OK\n"); + continue; + } + /* check if DATA command, so read the data packets */ if (strcmp(buf, "DATA\n") == 0){ len = read_plugin(buf); diff --git a/regress/scripts/metaplugin-protocol-tests.sh b/regress/scripts/metaplugin-protocol-tests.sh index 5b823256b..37b81094b 100755 --- a/regress/scripts/metaplugin-protocol-tests.sh +++ b/regress/scripts/metaplugin-protocol-tests.sh @@ -165,7 +165,7 @@ cat <${cwd}/tmp/bconcmds @# @output /dev/null messages -@$out ${cwd}/tmp/log4.out +@$out ${cwd}/tmp/rlog1.out setdebug level=500 client=$CLIENT trace=1 restore fileset=$FilesetBackup1 where=${cwd}/tmp select all storage=File done yes @@ -178,10 +178,31 @@ END_OF_DATA run_bconsole +# restore with metadata +cat <${cwd}/tmp/bconcmds +@# +@# Restore +@# +@output /dev/null +messages +@$out ${cwd}/tmp/rlog2.out +setdebug level=500 client=$CLIENT trace=1 +restore fileset=$FilesetBackup5 where=${cwd}/tmp select all storage=File done +yes +wait +messages +llist job=RestoreFiles +@output +quit +END_OF_DATA + +run_bconsole + # and finally test listing mode TEST=1 for ppath in / containers containers/bucket1 containers/bucket2 do + cat <${cwd}/tmp/bconcmds @# @# Listing @@ -283,11 +304,19 @@ then dstat=1 fi -RET=$(grep "jobstatus:" ${cwd}/tmp/log4.out | awk '{print $2}') -REND=$(grep -w -c "TESTEND" ${cwd}/tmp/log4.out) +RET=$(grep "jobstatus:" ${cwd}/tmp/rlog1.out | awk '{print $2}') +REND=$(grep -w -c "TESTEND" ${cwd}/tmp/rlog1.out) +if [ "x$RET" != "xT" ] || [ "$REND" -ne 1 ] +then + echo "rlog1" "$RET" "$REND" + rstat=1 +fi + +RET=$(grep "jobstatus:" ${cwd}/tmp/rlog2.out | tail -1 | awk '{print $2}') +REND=$(grep -w -c "TESTEND" ${cwd}/tmp/rlog2.out) if [ "x$RET" != "xT" ] || [ "$REND" -ne 1 ] then - echo "log4" "$RET" "$REND" + echo "rlog2" "$RET" "$REND" rstat=1 fi