From e85197c63019f95c1133dc55176ad23cd3b6e31b Mon Sep 17 00:00:00 2001 From: Xinze Chi Date: Fri, 16 Jan 2015 08:31:16 +0000 Subject: [PATCH] test: add test for osd scrub Signed-off-by: Xinze Chi --- src/test/Makefile.am | 8 ++ src/test/osd/TestOSDScrub.cc | 157 +++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 src/test/osd/TestOSDScrub.cc diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 03ba231b66483..0ab77cfb01e39 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -416,6 +416,14 @@ if LINUX unittest_pglog_LDADD += -ldl endif # LINUX +unittest_osdscrub_SOURCES = test/osd/TestOSDScrub.cc +unittest_osdscrub_CXXFLAGS = $(UNITTEST_CXXFLAGS) +unittest_osdscrub_LDADD = $(LIBOSD) $(UNITTEST_LDADD) $(CEPH_GLOBAL) +check_PROGRAMS += unittest_osdscrub +if LINUX +unittest_osdscrub_LDADD += -ldl +endif # LINUX + unittest_ecbackend_SOURCES = test/osd/TestECBackend.cc unittest_ecbackend_CXXFLAGS = $(UNITTEST_CXXFLAGS) unittest_ecbackend_LDADD = $(LIBOSD) $(UNITTEST_LDADD) $(CEPH_GLOBAL) diff --git a/src/test/osd/TestOSDScrub.cc b/src/test/osd/TestOSDScrub.cc new file mode 100644 index 0000000000000..a5da6dc6c9866 --- /dev/null +++ b/src/test/osd/TestOSDScrub.cc @@ -0,0 +1,157 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2013 Cloudwatt + * + * Author: Loic Dachary + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library Public License for more details. + * + */ + +#include +#include +#include "osd/OSD.h" +#include "os/ObjectStore.h" +#include "mon/MonClient.h" +#include "common/ceph_argparse.h" +#include "global/global_init.h" +#include +#include "msg/Messenger.h" + +class TestOSDScrub: public OSD { + +public: + TestOSDScrub(CephContext *cct_, + ObjectStore *store_, + int id, + Messenger *internal, + Messenger *external, + Messenger *hb_client, + Messenger *hb_front_server, + Messenger *hb_back_server, + Messenger *osdc_messenger, + MonClient *mc, const std::string &dev, const std::string &jdev) : + OSD(cct_, store_, id, internal, external, hb_client, hb_front_server, hb_back_server, osdc_messenger, mc, dev, jdev) + { + } + + bool scrub_time_permit(utime_t now) { + return OSD::scrub_time_permit(now); + } +}; + +TEST(TestOSDScrub, scrub_time_permit) { + ObjectStore *store = ObjectStore::create(g_ceph_context, + g_conf->osd_objectstore, + g_conf->osd_data, + g_conf->osd_journal); + Messenger *ms = Messenger::create(g_ceph_context, g_conf->ms_type, + entity_name_t::OSD(0), "make_checker", + getpid()); + ms->set_cluster_protocol(CEPH_OSD_PROTOCOL); + ms->set_default_policy(Messenger::Policy::stateless_server(0, 0)); + ms->bind(g_conf->public_addr); + MonClient mc(g_ceph_context); + mc.build_initial_monmap(); + TestOSDScrub* osd = new TestOSDScrub(g_ceph_context, store, 0, ms, ms, ms, ms, ms, ms, &mc, "", ""); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "0"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "24"); + g_ceph_context->_conf->apply_changes(NULL); + tm tm; + strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); + utime_t now = utime_t(mktime(&tm), 0); + bool ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "24"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "0"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_FALSE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "0"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "0"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "20"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 01:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "20"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "20"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 08:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_FALSE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "01"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_FALSE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "01"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 00:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_FALSE(ret); + + g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "01"); + g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07"); + g_ceph_context->_conf->apply_changes(NULL); + strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm); + now = utime_t(mktime(&tm), 0); + ret = osd->scrub_time_permit(now); + ASSERT_TRUE(ret); + +} + +int main(int argc, char **argv) { + vector args; + argv_to_vec(argc, (const char **)argv, args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +// Local Variables: +// compile-command: "cd ../.. ; make unittest_osdscrub ; ./unittest_osdscrub --log-to-stderr=true --debug-osd=20 # --gtest_filter=*.* " +// End: -- 2.39.5