]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
metaplugin: Update and extend regression tests.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Mon, 22 Mar 2021 13:25:10 +0000 (14:25 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
bacula/src/plugins/fd/pluginlib/ptcomm.cpp
bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c
regress/scripts/metaplugin-protocol-tests.sh

index 38c87d2afe7d5e3195539cf832895bdd3eec4549..b91219f869d9f265b917bca4d049d070ba87c832 100644 (file)
@@ -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");
index 769d226e71cfc2a527beb70212e7374bb5f673d6..e4b5ca1bed311517e4b7a358b308a81a7abee500 100644 (file)
@@ -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);
index 5b823256baeead9b52c3f0142d1005697e4df25d..37b81094ba283059ac06f6c1ab5bec19484c0b8c 100755 (executable)
@@ -165,7 +165,7 @@ cat <<END_OF_DATA >${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 <<END_OF_DATA >${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 <<END_OF_DATA >${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