]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-objectstore-tool: Add dry-run checking to ops missing it
authorDavid Zafman <dzafman@redhat.com>
Fri, 6 Nov 2015 03:06:17 +0000 (19:06 -0800)
committerDavid Zafman <dzafman@redhat.com>
Thu, 25 Feb 2016 20:50:27 +0000 (12:50 -0800)
Update test to check most operations

Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit e89f0e1c5e8a378809bec7c705ea2c23235d4b28)

Conflicts:
src/tools/ceph_objectstore_tool.cc (trivial)

src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index 4c230f057a0955e6fa9b7345680afc3b8d23bab0..61b0f57b79dcf5683355d2edd6925499e09aec79 100755 (executable)
@@ -446,6 +446,13 @@ def set_osd_weight(CFSD_PREFIX, osd_ids, osd_path, weight):
                stderr=subprocess.DEVNULL,
                shell=True)
     assert(ret == 0)
+
+    # Minimum test of --dry-run by using it, but not checking anything
+    cmd = CFSD_PREFIX + "--op set-osdmap --file {osdmap_file} --epoch {epoch} --force --dry-run"
+    cmd = cmd.format(osd=osd_path, osdmap_file=osdmap_file.name, epoch=epoch)
+    ret = call(cmd, stdout=subprocess.DEVNULL, shell=True)
+    assert(ret == 0)
+
     # osdmaptool increases the epoch of the changed osdmap, so we need to force the tool
     # to use use a different epoch than the one in osdmap
     cmd = CFSD_PREFIX + "--op set-osdmap --file {osdmap_file} --epoch {epoch} --force"
@@ -525,6 +532,10 @@ def test_get_set_inc_osdmap(CFSD_PREFIX, osd_path):
     cmd = CFSD_PREFIX + "--op set-inc-osdmap --force --epoch {epoch} --file {file}"
     ret = call(cmd.format(osd=osd_path, epoch=epoch, file=file_e2.name), shell=True)
     if ret: return 1
+    # Use dry-run to set back to e1 which shouldn't happen
+    cmd = CFSD_PREFIX + "--op set-inc-osdmap --dry-run --epoch {epoch} --file {file}"
+    ret = call(cmd.format(osd=osd_path, epoch=epoch, file=file_e1_backup.name), shell=True)
+    if ret: return 1
     # read from e1
     file_e1_read = tempfile.NamedTemporaryFile(delete=False)
     cmd = CFSD_PREFIX + "--op get-inc-osdmap --epoch {epoch} --file {file}"
@@ -1132,6 +1143,14 @@ def main(argv):
                         cmd = ("echo -n foobar | " + CFSD_PREFIX + " --pgid {pg} '{json}' set-attr {key}").format(osd=osd, pg=pg, json=JSON, key=attrkey)
                         logging.debug(cmd)
                         ret = call(cmd, shell=True)
+                        if ret != 0:
+                            logging.error("Bad exit status {ret} from set-attr".format(ret=ret))
+                            ERRORS += 1
+                            continue
+                        # Test set-attr with dry-run
+                        cmd = ("echo -n dryrunbroken | " + CFSD_PREFIX + "--dry-run '{json}' set-attr {key}").format(osd=osd, pg=pg, json=JSON, key=attrkey)
+                        logging.debug(cmd)
+                        ret = call(cmd, shell=True, stdout=nullfd)
                         if ret != 0:
                             logging.error("Bad exit status {ret} from set-attr".format(ret=ret))
                             ERRORS += 1
@@ -1152,6 +1171,14 @@ def main(argv):
                         cmd = (CFSD_PREFIX + "'{json}' rm-attr {key}").format(osd=osd, pg=pg, json=JSON, key=attrkey)
                         logging.debug(cmd)
                         ret = call(cmd, shell=True)
+                        if ret != 0:
+                            logging.error("Bad exit status {ret} from rm-attr".format(ret=ret))
+                            ERRORS += 1
+                            continue
+                        # Check rm-attr with dry-run
+                        cmd = (CFSD_PREFIX + "--dry-run '{json}' rm-attr {key}").format(osd=osd, pg=pg, json=JSON, key=attrkey)
+                        logging.debug(cmd)
+                        ret = call(cmd, shell=True, stdout=nullfd)
                         if ret != 0:
                             logging.error("Bad exit status {ret} from rm-attr".format(ret=ret))
                             ERRORS += 1
@@ -1199,6 +1226,14 @@ def main(argv):
                         logging.error("Check of set-omaphdr failed because we got {val}".format(val=getval))
                         ERRORS += 1
                         continue
+                    # Test dry-run with set-omaphdr
+                    cmd = ("echo -n dryrunbroken | " + CFSD_PREFIX + "--dry-run '{json}' set-omaphdr").format(osd=osd, pg=pg, json=JSON)
+                    logging.debug(cmd)
+                    ret = call(cmd, shell=True, stdout=nullfd)
+                    if ret != 0:
+                        logging.error("Bad exit status {ret} from set-omaphdr".format(ret=ret))
+                        ERRORS += 1
+                        continue
                     # Put back value
                     cmd = ("echo -n {val} | " + CFSD_PREFIX + "'{json}' set-omaphdr").format(osd=osd, pg=pg, json=JSON, val=hdr)
                     logging.debug(cmd)
@@ -1220,6 +1255,14 @@ def main(argv):
                         cmd = ("echo -n foobar | " + CFSD_PREFIX + " --pgid {pg} '{json}' set-omap {key}").format(osd=osd, pg=pg, json=JSON, key=omapkey)
                         logging.debug(cmd)
                         ret = call(cmd, shell=True)
+                        if ret != 0:
+                            logging.error("Bad exit status {ret} from set-omap".format(ret=ret))
+                            ERRORS += 1
+                            continue
+                        # Check set-omap with dry-run
+                        cmd = ("echo -n dryrunbroken | " + CFSD_PREFIX + "--dry-run --pgid {pg} '{json}' set-omap {key}").format(osd=osd, pg=pg, json=JSON, key=omapkey)
+                        logging.debug(cmd)
+                        ret = call(cmd, shell=True, stdout=nullfd)
                         if ret != 0:
                             logging.error("Bad exit status {ret} from set-omap".format(ret=ret))
                             ERRORS += 1
@@ -1240,6 +1283,13 @@ def main(argv):
                         cmd = (CFSD_PREFIX + "'{json}' rm-omap {key}").format(osd=osd, pg=pg, json=JSON, key=omapkey)
                         logging.debug(cmd)
                         ret = call(cmd, shell=True)
+                        if ret != 0:
+                            logging.error("Bad exit status {ret} from rm-omap".format(ret=ret))
+                            ERRORS += 1
+                        # Check rm-omap with dry-run
+                        cmd = (CFSD_PREFIX + "--dry-run '{json}' rm-omap {key}").format(osd=osd, pg=pg, json=JSON, key=omapkey)
+                        logging.debug(cmd)
+                        ret = call(cmd, shell=True, stdout=nullfd)
                         if ret != 0:
                             logging.error("Bad exit status {ret} from rm-omap".format(ret=ret))
                             ERRORS += 1
index 35e4f59b2e27aa9a2a2b348d008f99200b45b54a..a6d885a57062a794ecb3b5887f68b6e91691e3e0 100644 (file)
@@ -1136,6 +1136,8 @@ int set_inc_osdmap(ObjectStore *store, epoch_t e, bufferlist& bl, bool force) {
     }
     cout << "Creating a new epoch." << std::endl;
   }
+  if (dry_run)
+    return 0;
   ObjectStore::Transaction t;
   t.write(META_COLL, inc_oid, 0, bl.length(), bl);
   t.truncate(META_COLL, inc_oid, bl.length());
@@ -1180,6 +1182,8 @@ int set_osdmap(ObjectStore *store, epoch_t e, bufferlist& bl, bool force) {
     }
     cout << "Creating a new epoch." << std::endl;
   }
+  if (dry_run)
+    return 0;
   ObjectStore::Transaction t;
   t.write(META_COLL, full_oid, 0, bl.length(), bl);
   t.truncate(META_COLL, full_oid, bl.length());
@@ -2487,6 +2491,9 @@ int do_set_attr(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key,
   if (ret < 0)
     return ret;
 
+  if (dry_run)
+    return 0;
+
   t->touch(coll, ghobj);
 
   t->setattr(coll, ghobj, key,  bl);
@@ -2503,6 +2510,9 @@ int do_rm_attr(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key)
   if (debug)
     cerr << "Rmattr " << ghobj << std::endl;
 
+  if (dry_run)
+    return 0;
+
   t->rmattr(coll, ghobj, key);
 
   store->apply_transaction(*t);
@@ -2556,6 +2566,9 @@ int do_set_omap(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key,
 
   attrset.insert(pair<string, bufferlist>(key, valbl));
 
+  if (dry_run)
+    return 0;
+
   t->touch(coll, ghobj);
 
   t->omap_setkeys(coll, ghobj, attrset);
@@ -2575,6 +2588,9 @@ int do_rm_omap(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key)
   if (debug)
     cerr << "Rm_omap " << ghobj << std::endl;
 
+  if (dry_run)
+    return 0;
+
   t->omap_rmkeys(coll, ghobj, keys);
 
   store->apply_transaction(*t);
@@ -2614,6 +2630,9 @@ int do_set_omaphdr(ObjectStore *store, coll_t coll, ghobject_t &ghobj, int fd)
   if (ret)
     return ret;
 
+  if (dry_run)
+    return 0;
+
   t->touch(coll, ghobj);
 
   t->omap_setheader(coll, ghobj, hdrbl);
@@ -2958,6 +2977,9 @@ int remove_clone(ObjectStore *store, coll_t coll, ghobject_t &ghobj, snapid_t cl
   ret = remove_from(snapset.clone_size, "clone_size", cloneid, force);
   if (ret) return ret;
 
+  if (dry_run)
+    return 0;
+
   bufferlist bl;
   ::encode(snapset, bl);
   ObjectStore::Transaction t;
@@ -4048,6 +4070,10 @@ int main(int argc, char **argv)
       cout << "Remove past-intervals " << past_intervals << std::endl;
 
       past_intervals.clear();
+      if (dry_run) {
+        ret = 0;
+        goto out;
+      }
       ret = write_info(*t, map_epoch, info, past_intervals);
 
       if (ret == 0) {
@@ -4075,11 +4101,13 @@ int main(int argc, char **argv)
       info.history.last_epoch_clean = superblock.current_epoch;
       past_intervals.clear();
 
-      ret = write_info(*t, map_epoch, info, past_intervals);
-      if (ret == 0) {
+      if (!dry_run) {
+       ret = write_info(*t, map_epoch, info, past_intervals);
+       if (ret != 0)
+         goto out;
        fs->apply_transaction(*t);
-       cout << "Marking complete succeeded" << std::endl;
       }
+      cout << "Marking complete succeeded" << std::endl;
     } else {
       assert(!"Should have already checked for valid --op");
     }