int cstat_load_data_from_disk(struct cstat **clist, struct conf **globalcs, struct conf **cconfs) { if(!globalcs) return -1; return cstat_get_client_names(clist, get_string(globalcs[OPT_CLIENTCONFDIR])) || cstat_reload_from_client_confs(clist, globalcs, cconfs)<0 || reload_from_clientdir(clist)<0; }
END_TEST static struct cstat *test_cstat_remove_setup(struct conf ***globalcs, const char *cnames[]) { struct cstat *clist=NULL; clean(); fail_unless((*globalcs=confs_alloc())!=NULL); fail_unless(!confs_init(*globalcs)); build_file(GLOBAL_CONF, MIN_SERVER_CONF); fail_unless(!conf_load_global_only(GLOBAL_CONF, *globalcs)); build_clientconfdir_files(cnames); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames); return clist; }
END_TEST START_TEST(test_cstat_get_client_names) { struct cstat *clist=NULL; const char *cnames[] = {"cli1", "cli2", "cli3", NULL}; const char *cnames_add[] = {"cli0", "cli1", "cli2", "cli2a", "cli3", "cli4", NULL}; const char *cnames_rm[] = {"cli2", NULL}; const char *tmp_files[] = {".abc", "xyz~", NULL }; clean(); build_clientconfdir_files(cnames); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames); // Call again with the same clientconfdir files. clean(); build_clientconfdir_files(cnames); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames); // Call again with extra clientconfdir files. clean(); build_clientconfdir_files(cnames_add); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames_add); // Call again with fewer clientconfdir files. // The list will not be shorter. clean(); build_clientconfdir_files(cnames_rm); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames_add); // Temporary files should be missed. clean(); build_clientconfdir_files(tmp_files); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames_add); // Cause an error. clean(); fail_unless(cstat_get_client_names(&clist, CLIENTCONFDIR)==-1); cstat_list_free(&clist); clean(); alloc_check(); }
END_TEST START_TEST(test_cstat_add_out_of_order) { struct cstat *clist=NULL; struct conf **globalcs; const char *cnames31204[] = {"cli3", "cli1", "cli2", "cli0", "cli4", NULL}; const char *cnames01234[] = {"cli0", "cli1", "cli2", "cli3", "cli4", NULL}; clean(); fail_unless((globalcs=confs_alloc())!=NULL); fail_unless(!confs_init(globalcs)); build_file(GLOBAL_CONF, MIN_SERVER_CONF); fail_unless(!conf_load_global_only(GLOBAL_CONF, globalcs)); build_clientconfdir_files(cnames31204); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames01234); test_cstat_remove_teardown(&globalcs, &clist); }
static void do_test_json_send_clients_with_backup(const char *path, struct sd *sd, int s, const char *specific_client) { struct asfd *asfd; struct cstat *c=NULL; struct cstat *clist=NULL; const char *cnames[] = {"cli1", "cli2", "cli3", NULL}; fail_unless(recursive_delete(CLIENTCONFDIR)==0); build_clientconfdir_files(cnames, NULL); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames); for(c=clist; c; c=c->next) { c->permitted=1; c->protocol=PROTO_1; fail_unless((c->sdirs=setup_sdirs(c->protocol, c->name))!=NULL); build_storage_dirs((struct sdirs *)c->sdirs, sd, s); fail_unless(!cstat_set_backup_list(c)); fail_unless(c->bu!=NULL); // Hack the cntr timestamps so that they are always the same. c->cntr->ent[(uint8_t)CMD_TIMESTAMP]->count=200; c->cntr->ent[(uint8_t)CMD_TIMESTAMP_END]->count=400; } asfd=asfd_setup(path); c=NULL; if(specific_client) fail_unless((c=cstat_get_by_name(clist, specific_client))!=NULL); fail_unless(!json_send(asfd, clist, c, NULL, NULL, NULL, 0/*cache*/)); cstat_list_free_sdirs(clist); cstat_list_free(&clist); fail_unless(!recursive_delete(SDIRS)); tear_down(&asfd); }