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;
}
{
NTSTATUS status;
bool ok;
+ int i;
struct fss_global fss_gs;
struct fss_global fss_gr;
struct fss_sc_set *sc_set;
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");
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");
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;
}
{
NTSTATUS status;
bool ok;
+ int i;
struct fss_global fss_gs;
struct fss_global fss_gr;
struct fss_sc_set *sc_set_a;
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");
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");
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;
}