torture: test FSRVP server state V0->1 upgrades fsrvp_srv_v3_v0_tdb_upgrade
authorDavid Disseldorp <ddiss@samba.org>
Wed, 25 Mar 2015 14:39:32 +0000 (15:39 +0100)
committerDavid Disseldorp <ddiss@samba.org>
Thu, 26 Mar 2015 14:50:34 +0000 (15:50 +0100)
For each FSRVP server state test, store the state in both current and V0
formats. Call the common retrieval function for both databases, and
confirm that the transparent version update data is consistent.

Signed-off-by: David Disseldorp <ddiss@samba.org>
source4/torture/local/fsrvp_state.c

index 8a947414e23826d11c08054695fe5291bc7bf55d..92796d76ea39301fa6f1d80371ae1ba1217628f1 100644 (file)
@@ -283,40 +283,67 @@ err_ctx_free:
 static bool test_fsrvp_state_empty(struct torture_context *tctx)
 {
        NTSTATUS status;
+       int i;
        struct fss_global fss_global;
        struct stat sbuf;
        char db_dir[] = "fsrvp_torture_XXXXXX";
        char *db_path = talloc_asprintf(NULL, "%s/%s",
                                        mkdtemp(db_dir), FSS_DB_NAME);
+       char *db_path_v0 = talloc_asprintf(NULL, "%s/%s",
+                                          db_dir, "srv_fss_v0.tdb");
 
        memset(&fss_global, 0, sizeof(fss_global));
        fss_global.mem_ctx = talloc_new(NULL);
-       fss_global.db_path = db_path;
 
        status = fss_state_store(fss_global.mem_ctx, fss_global.sc_sets,
-                                fss_global.sc_sets_count, fss_global.db_path);
+                                fss_global.sc_sets_count, db_path);
        torture_assert_ntstatus_ok(tctx, status,
                                   "failed to store empty fss state");
 
-       torture_assert_int_equal(tctx, stat(fss_global.db_path, &sbuf), 0,
+       status = fss_state_store_v0(fss_global.mem_ctx, fss_global.sc_sets,
+                                   fss_global.sc_sets_count,
+                                   db_path_v0);
+       torture_assert_ntstatus_ok(tctx, status,
+                                  "failed to store empty V0 fss state");
+
+       torture_assert_int_equal(tctx, stat(db_path, &sbuf), 0,
                        "failed to stat fss state tdb");
+       torture_assert_int_equal(tctx, stat(db_path_v0, &sbuf), 0,
+                       "failed to stat V0 fss state tdb");
        talloc_free(fss_global.mem_ctx);
 
        memset(&fss_global, 0, sizeof(fss_global));
        fss_global.mem_ctx = talloc_new(NULL);
-       fss_global.db_path = db_path;
 
        status = fss_state_retrieve(fss_global.mem_ctx, &fss_global.sc_sets,
                                    &fss_global.sc_sets_count,
-                                   fss_global.db_path);
+                                   db_path);
        torture_assert_ntstatus_ok(tctx, status,
                                   "failed to retrieve empty fss state");
        torture_assert_int_equal(tctx, fss_global.sc_sets_count, 0,
                                 "sc_sets_count set when it should be zero");
+
+       /* read old tdb twice, first triggers upgrade, second verifies */
+       for (i = 0; i < 2; i++) {
+               talloc_free(fss_global.mem_ctx);
+               memset(&fss_global, 0, sizeof(fss_global));
+               fss_global.mem_ctx = talloc_new(NULL);
+               /* retrieve and force upgrade of V0 database */
+               status = fss_state_retrieve(fss_global.mem_ctx, &fss_global.sc_sets,
+                                           &fss_global.sc_sets_count,
+                                           db_path_v0);
+               torture_assert_ntstatus_ok(tctx, status,
+                                          "failed to retrieve empty V0 fss state");
+               torture_assert_int_equal(tctx, fss_global.sc_sets_count, 0,
+                                        "V0 sc_sets_count set when it should be zero");
+       }
+
        talloc_free(fss_global.mem_ctx);
        unlink(db_path);
+       unlink(db_path_v0);
        rmdir(db_dir);
        talloc_free(db_path);
+       talloc_free(db_path_v0);
 
        return true;
 }
@@ -525,6 +552,7 @@ static bool test_fsrvp_state_single(struct torture_context *tctx)
 {
        NTSTATUS status;
        bool ok;
+       int i;
        struct fss_global fss_gs;
        struct fss_global fss_gr;
        struct fss_sc_set *sc_set;
@@ -533,10 +561,11 @@ static bool test_fsrvp_state_single(struct torture_context *tctx)
        char db_dir[] = "fsrvp_torture_XXXXXX";
        char *db_path = talloc_asprintf(NULL, "%s/%s",
                                        mkdtemp(db_dir), FSS_DB_NAME);
+       char *db_path_v0 = talloc_asprintf(NULL, "%s/%s",
+                                          db_dir, "srv_fss_v0.tdb");
 
        memset(&fss_gs, 0, sizeof(fss_gs));
        fss_gs.mem_ctx = talloc_new(NULL);
-       fss_gs.db_path = db_path;
 
        ok = test_fsrvp_state_sc_set(tctx, fss_gs.mem_ctx, &sc_set);
        torture_assert(tctx, ok, "failed to create sc set");
@@ -557,16 +586,20 @@ static bool test_fsrvp_state_single(struct torture_context *tctx)
        sc->smaps_count++;
 
        status = fss_state_store(fss_gs.mem_ctx, fss_gs.sc_sets,
-                                fss_gs.sc_sets_count, fss_gs.db_path);
+                                fss_gs.sc_sets_count, db_path);
        torture_assert_ntstatus_ok(tctx, status,
                                   "failed to store fss state");
 
+       status = fss_state_store_v0(fss_gs.mem_ctx, fss_gs.sc_sets,
+                                   fss_gs.sc_sets_count, db_path_v0);
+       torture_assert_ntstatus_ok(tctx, status,
+                                  "failed to store V0 fss state");
+
        memset(&fss_gr, 0, sizeof(fss_gr));
        fss_gr.mem_ctx = talloc_new(NULL);
-       fss_gr.db_path = db_path;
 
        status = fss_state_retrieve(fss_gr.mem_ctx, &fss_gr.sc_sets,
-                                   &fss_gr.sc_sets_count, fss_gr.db_path);
+                                   &fss_gr.sc_sets_count, db_path);
        torture_assert_ntstatus_ok(tctx, status,
                                   "failed to retrieve fss state");
 
@@ -574,11 +607,29 @@ static bool test_fsrvp_state_single(struct torture_context *tctx)
        torture_assert(tctx, ok,
                       "stored and retrieved state comparison failed");
 
+       /* read old tdb twice, first triggers upgrade, second verifies */
+       for (i = 0; i < 2; i++) {
+               talloc_free(fss_gr.mem_ctx);
+               memset(&fss_gr, 0, sizeof(fss_gr));
+               fss_gr.mem_ctx = talloc_new(NULL);
+               /* retrieve and force upgrade of V0 database */
+               status = fss_state_retrieve(fss_gr.mem_ctx, &fss_gr.sc_sets,
+                                           &fss_gr.sc_sets_count, db_path_v0);
+               torture_assert_ntstatus_ok(tctx, status,
+                                          "failed to retrieve V0 fss state");
+
+               ok = test_fsrvp_state_compare(tctx, &fss_gs, &fss_gr);
+               torture_assert(tctx, ok,
+                              "stored and upgraded state comparison failed");
+       }
+
        talloc_free(fss_gs.mem_ctx);
        talloc_free(fss_gr.mem_ctx);
        unlink(db_path);
+       unlink(db_path_v0);
        rmdir(db_dir);
        talloc_free(db_path);
+       talloc_free(db_path_v0);
 
        return true;
 }
@@ -600,6 +651,7 @@ static bool test_fsrvp_state_multi(struct torture_context *tctx)
 {
        NTSTATUS status;
        bool ok;
+       int i;
        struct fss_global fss_gs;
        struct fss_global fss_gr;
        struct fss_sc_set *sc_set_a;
@@ -612,10 +664,11 @@ static bool test_fsrvp_state_multi(struct torture_context *tctx)
        char db_dir[] = "fsrvp_torture_XXXXXX";
        char *db_path = talloc_asprintf(NULL, "%s/%s",
                                        mkdtemp(db_dir), FSS_DB_NAME);
+       char *db_path_v0 = talloc_asprintf(NULL, "%s/%s",
+                                          db_dir, "srv_fss_v0.tdb");
 
        memset(&fss_gs, 0, sizeof(fss_gs));
        fss_gs.mem_ctx = talloc_new(NULL);
-       fss_gs.db_path = db_path;
 
        ok = test_fsrvp_state_sc_set(tctx, fss_gs.mem_ctx, &sc_set_a);
        torture_assert(tctx, ok, "failed to create sc set");
@@ -662,15 +715,19 @@ static bool test_fsrvp_state_multi(struct torture_context *tctx)
        sc_ab->smaps_count++;
 
        status = fss_state_store(fss_gs.mem_ctx, fss_gs.sc_sets,
-                                fss_gs.sc_sets_count, fss_gs.db_path);
+                                fss_gs.sc_sets_count, db_path);
        torture_assert_ntstatus_ok(tctx, status,
                                   "failed to store fss state");
 
+       status = fss_state_store_v0(fss_gs.mem_ctx, fss_gs.sc_sets,
+                                   fss_gs.sc_sets_count, db_path_v0);
+       torture_assert_ntstatus_ok(tctx, status,
+                                  "failed to store V0 fss state");
+
        memset(&fss_gr, 0, sizeof(fss_gr));
        fss_gr.mem_ctx = talloc_new(NULL);
-       fss_gr.db_path = db_path;
        status = fss_state_retrieve(fss_gr.mem_ctx, &fss_gr.sc_sets,
-                                   &fss_gr.sc_sets_count, fss_gr.db_path);
+                                   &fss_gr.sc_sets_count, db_path);
        torture_assert_ntstatus_ok(tctx, status,
                                   "failed to retrieve fss state");
 
@@ -678,11 +735,29 @@ static bool test_fsrvp_state_multi(struct torture_context *tctx)
        torture_assert(tctx, ok,
                       "stored and retrieved state comparison failed");
 
+       /* read old tdb twice, first triggers upgrade, second verifies */
+       for (i = 0; i < 2; i++) {
+               talloc_free(fss_gr.mem_ctx);
+               memset(&fss_gr, 0, sizeof(fss_gr));
+               fss_gr.mem_ctx = talloc_new(NULL);
+               /* retrieve and force upgrade of V0 database */
+               status = fss_state_retrieve(fss_gr.mem_ctx, &fss_gr.sc_sets,
+                                           &fss_gr.sc_sets_count, db_path_v0);
+               torture_assert_ntstatus_ok(tctx, status,
+                                          "failed to retrieve V0 fss state");
+
+               ok = test_fsrvp_state_compare(tctx, &fss_gs, &fss_gr);
+               torture_assert(tctx, ok,
+                              "stored and upgraded state comparison failed");
+       }
+
        talloc_free(fss_gs.mem_ctx);
        talloc_free(fss_gr.mem_ctx);
        unlink(db_path);
+       unlink(db_path_v0);
        rmdir(db_dir);
        talloc_free(db_path);
+       talloc_free(db_path_v0);
 
        return true;
 }