]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/osd/TestOSDScrub.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / osd / TestOSDScrub.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
7 *
8 * Author: Loic Dachary <loic@dachary.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library Public License for more details.
19 *
20 */
21
22 #include <stdio.h>
23 #include <signal.h>
24 #include <gtest/gtest.h>
25 #include "osd/OSD.h"
26 #include "os/ObjectStore.h"
27 #include "mon/MonClient.h"
28 #include "common/ceph_argparse.h"
29 #include "msg/Messenger.h"
30
31 class TestOSDScrub: public OSD {
32
33 public:
34 TestOSDScrub(CephContext *cct_,
35 ObjectStore *store_,
36 int id,
37 Messenger *internal,
38 Messenger *external,
39 Messenger *hb_front_client,
40 Messenger *hb_back_client,
41 Messenger *hb_front_server,
42 Messenger *hb_back_server,
43 Messenger *osdc_messenger,
44 MonClient *mc, const std::string &dev, const std::string &jdev) :
45 OSD(cct_, store_, id, internal, external, hb_front_client, hb_back_client, hb_front_server, hb_back_server, osdc_messenger, mc, dev, jdev)
46 {
47 }
48
49 bool scrub_time_permit(utime_t now) {
50 return OSD::scrub_time_permit(now);
51 }
52 };
53
54 TEST(TestOSDScrub, scrub_time_permit) {
55 ObjectStore *store = ObjectStore::create(g_ceph_context,
56 g_conf->osd_objectstore,
57 g_conf->osd_data,
58 g_conf->osd_journal);
59 std::string cluster_msgr_type = g_conf->ms_cluster_type.empty() ? g_conf->get_val<std::string>("ms_type") : g_conf->ms_cluster_type;
60 Messenger *ms = Messenger::create(g_ceph_context, cluster_msgr_type,
61 entity_name_t::OSD(0), "make_checker",
62 getpid(), 0);
63 ms->set_cluster_protocol(CEPH_OSD_PROTOCOL);
64 ms->set_default_policy(Messenger::Policy::stateless_server(0));
65 ms->bind(g_conf->public_addr);
66 MonClient mc(g_ceph_context);
67 mc.build_initial_monmap();
68 TestOSDScrub* osd = new TestOSDScrub(g_ceph_context, store, 0, ms, ms, ms, ms, ms, ms, ms, &mc, "", "");
69
70 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "0");
71 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "24");
72 g_ceph_context->_conf->apply_changes(NULL);
73 tm tm;
74 strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm);
75 utime_t now = utime_t(mktime(&tm), 0);
76 bool ret = osd->scrub_time_permit(now);
77 ASSERT_TRUE(ret);
78
79 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "24");
80 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "0");
81 g_ceph_context->_conf->apply_changes(NULL);
82 strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm);
83 now = utime_t(mktime(&tm), 0);
84 ret = osd->scrub_time_permit(now);
85 ASSERT_FALSE(ret);
86
87 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "0");
88 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "0");
89 g_ceph_context->_conf->apply_changes(NULL);
90 strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm);
91 now = utime_t(mktime(&tm), 0);
92 ret = osd->scrub_time_permit(now);
93 ASSERT_TRUE(ret);
94
95 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "20");
96 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07");
97 g_ceph_context->_conf->apply_changes(NULL);
98 strptime("2015-01-16 01:05:13", "%Y-%m-%d %H:%M:%S", &tm);
99 now = utime_t(mktime(&tm), 0);
100 ret = osd->scrub_time_permit(now);
101 ASSERT_TRUE(ret);
102
103 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "20");
104 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07");
105 g_ceph_context->_conf->apply_changes(NULL);
106 strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm);
107 now = utime_t(mktime(&tm), 0);
108 ret = osd->scrub_time_permit(now);
109 ASSERT_TRUE(ret);
110
111 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "20");
112 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07");
113 g_ceph_context->_conf->apply_changes(NULL);
114 strptime("2015-01-16 08:05:13", "%Y-%m-%d %H:%M:%S", &tm);
115 now = utime_t(mktime(&tm), 0);
116 ret = osd->scrub_time_permit(now);
117 ASSERT_FALSE(ret);
118
119 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "01");
120 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07");
121 g_ceph_context->_conf->apply_changes(NULL);
122 strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm);
123 now = utime_t(mktime(&tm), 0);
124 ret = osd->scrub_time_permit(now);
125 ASSERT_FALSE(ret);
126
127 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "01");
128 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07");
129 g_ceph_context->_conf->apply_changes(NULL);
130 strptime("2015-01-16 00:05:13", "%Y-%m-%d %H:%M:%S", &tm);
131 now = utime_t(mktime(&tm), 0);
132 ret = osd->scrub_time_permit(now);
133 ASSERT_FALSE(ret);
134
135 g_ceph_context->_conf->set_val("osd_scrub_begin_hour", "01");
136 g_ceph_context->_conf->set_val("osd_scrub_end_hour", "07");
137 g_ceph_context->_conf->apply_changes(NULL);
138 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
139 now = utime_t(mktime(&tm), 0);
140 ret = osd->scrub_time_permit(now);
141 ASSERT_TRUE(ret);
142
143 }
144
145 // Local Variables:
146 // compile-command: "cd ../.. ; make unittest_osdscrub ; ./unittest_osdscrub --log-to-stderr=true --debug-osd=20 # --gtest_filter=*.* "
147 // End: