]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/osd/TestOSDScrub.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / osd / TestOSDScrub.cc
CommitLineData
7c673cae
FG
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>
f67539c2 25#include "common/async/context_pool.h"
7c673cae
FG
26#include "osd/OSD.h"
27#include "os/ObjectStore.h"
28#include "mon/MonClient.h"
29#include "common/ceph_argparse.h"
30#include "msg/Messenger.h"
31
32class TestOSDScrub: public OSD {
33
34public:
35 TestOSDScrub(CephContext *cct_,
20effc67 36 std::unique_ptr<ObjectStore> store_,
7c673cae
FG
37 int id,
38 Messenger *internal,
39 Messenger *external,
40 Messenger *hb_front_client,
41 Messenger *hb_back_client,
42 Messenger *hb_front_server,
43 Messenger *hb_back_server,
44 Messenger *osdc_messenger,
f67539c2
TL
45 MonClient *mc, const std::string &dev, const std::string &jdev,
46 ceph::async::io_context_pool& ictx) :
20effc67
TL
47 OSD(cct_, std::move(store_), id, internal, external,
48 hb_front_client, hb_back_client,
49 hb_front_server, hb_back_server,
50 osdc_messenger, mc, dev, jdev, ictx)
7c673cae
FG
51 {
52 }
53
54 bool scrub_time_permit(utime_t now) {
20effc67 55 return service.get_scrub_services().scrub_time_permit(now);
7c673cae
FG
56 }
57};
58
59TEST(TestOSDScrub, scrub_time_permit) {
f67539c2 60 ceph::async::io_context_pool icp(1);
20effc67 61 std::unique_ptr<ObjectStore> store = ObjectStore::create(g_ceph_context,
11fdf7f2
TL
62 g_conf()->osd_objectstore,
63 g_conf()->osd_data,
64 g_conf()->osd_journal);
65 std::string cluster_msgr_type = g_conf()->ms_cluster_type.empty() ? g_conf().get_val<std::string>("ms_type") : g_conf()->ms_cluster_type;
7c673cae
FG
66 Messenger *ms = Messenger::create(g_ceph_context, cluster_msgr_type,
67 entity_name_t::OSD(0), "make_checker",
f67539c2 68 getpid());
7c673cae
FG
69 ms->set_cluster_protocol(CEPH_OSD_PROTOCOL);
70 ms->set_default_policy(Messenger::Policy::stateless_server(0));
11fdf7f2 71 ms->bind(g_conf()->public_addr);
f67539c2 72 MonClient mc(g_ceph_context, icp);
7c673cae 73 mc.build_initial_monmap();
20effc67 74 TestOSDScrub* osd = new TestOSDScrub(g_ceph_context, std::move(store), 0, ms, ms, ms, ms, ms, ms, ms, &mc, "", "", icp);
7c673cae 75
f67539c2
TL
76 // These are now invalid
77 int err = g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "24");
78 ASSERT_TRUE(err < 0);
79 //GTEST_LOG_(INFO) << " osd_scrub_begin_hour = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_begin_hour");
80
81 err = g_ceph_context->_conf.set_val("osd_scrub_end_hour", "24");
82 ASSERT_TRUE(err < 0);
83 //GTEST_LOG_(INFO) << " osd_scrub_end_hour = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_end_hour");
84
85 err = g_ceph_context->_conf.set_val("osd_scrub_begin_week_day", "7");
86 ASSERT_TRUE(err < 0);
87 //GTEST_LOG_(INFO) << " osd_scrub_begin_week_day = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_begin_week_day");
88
89 err = g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "7");
90 ASSERT_TRUE(err < 0);
91 //GTEST_LOG_(INFO) << " osd_scrub_end_week_day = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_end_week_day");
92
93 // Test all day
11fdf7f2 94 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "0");
f67539c2 95 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "0");
11fdf7f2 96 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae 97 tm tm;
9f95a23c 98 tm.tm_isdst = -1;
7c673cae
FG
99 strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm);
100 utime_t now = utime_t(mktime(&tm), 0);
101 bool ret = osd->scrub_time_permit(now);
102 ASSERT_TRUE(ret);
103
11fdf7f2
TL
104 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "20");
105 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07");
106 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae
FG
107 strptime("2015-01-16 01:05:13", "%Y-%m-%d %H:%M:%S", &tm);
108 now = utime_t(mktime(&tm), 0);
109 ret = osd->scrub_time_permit(now);
110 ASSERT_TRUE(ret);
111
11fdf7f2
TL
112 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "20");
113 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07");
114 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae
FG
115 strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm);
116 now = utime_t(mktime(&tm), 0);
117 ret = osd->scrub_time_permit(now);
118 ASSERT_TRUE(ret);
119
11fdf7f2
TL
120 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "20");
121 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07");
122 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae
FG
123 strptime("2015-01-16 08:05:13", "%Y-%m-%d %H:%M:%S", &tm);
124 now = utime_t(mktime(&tm), 0);
125 ret = osd->scrub_time_permit(now);
126 ASSERT_FALSE(ret);
127
11fdf7f2
TL
128 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "01");
129 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07");
130 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae
FG
131 strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm);
132 now = utime_t(mktime(&tm), 0);
133 ret = osd->scrub_time_permit(now);
134 ASSERT_FALSE(ret);
135
11fdf7f2
TL
136 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "01");
137 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07");
138 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae
FG
139 strptime("2015-01-16 00:05:13", "%Y-%m-%d %H:%M:%S", &tm);
140 now = utime_t(mktime(&tm), 0);
141 ret = osd->scrub_time_permit(now);
142 ASSERT_FALSE(ret);
143
11fdf7f2
TL
144 g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "01");
145 g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07");
146 g_ceph_context->_conf.apply_changes(nullptr);
7c673cae
FG
147 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
148 now = utime_t(mktime(&tm), 0);
149 ret = osd->scrub_time_permit(now);
150 ASSERT_TRUE(ret);
151
f67539c2
TL
152 // Sun = 0, Mon = 1, Tue = 2, Wed = 3, Thu = 4m, Fri = 5, Sat = 6
153 // Jan 16, 2015 is a Friday (5)
154 // every day
155 g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "0"); // inclusive
156 g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "0"); // not inclusive
157 g_ceph_context->_conf.apply_changes(nullptr);
158 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
159 now = utime_t(mktime(&tm), 0);
160 ret = osd->scrub_time_permit(now);
161 ASSERT_TRUE(ret);
162
163 // test Sun - Thu
164 g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "0"); // inclusive
165 g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "5"); // not inclusive
166 g_ceph_context->_conf.apply_changes(nullptr);
167 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
168 now = utime_t(mktime(&tm), 0);
169 ret = osd->scrub_time_permit(now);
170 ASSERT_FALSE(ret);
171
172 // test Fri - Sat
173 g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "5"); // inclusive
174 g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "0"); // not inclusive
175 g_ceph_context->_conf.apply_changes(nullptr);
176 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
177 now = utime_t(mktime(&tm), 0);
178 ret = osd->scrub_time_permit(now);
179 ASSERT_TRUE(ret);
180
181 // Jan 14, 2015 is a Wednesday (3)
182 // test Tue - Fri
183 g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "2"); // inclusive
184 g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "6"); // not inclusive
185 g_ceph_context->_conf.apply_changes(nullptr);
186 strptime("2015-01-14 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
187 now = utime_t(mktime(&tm), 0);
188 ret = osd->scrub_time_permit(now);
189 ASSERT_TRUE(ret);
190
191 // Test Sat - Sun
192 g_ceph_context->_conf.set_val("osd_scrub_begin_week day", "6"); // inclusive
193 g_ceph_context->_conf.set_val("osd_scrub_end_week_day", "1"); // not inclusive
194 g_ceph_context->_conf.apply_changes(nullptr);
195 strptime("2015-01-14 04:05:13", "%Y-%m-%d %H:%M:%S", &tm);
196 now = utime_t(mktime(&tm), 0);
197 ret = osd->scrub_time_permit(now);
198 ASSERT_FALSE(ret);
7c673cae
FG
199}
200
201// Local Variables:
202// compile-command: "cd ../.. ; make unittest_osdscrub ; ./unittest_osdscrub --log-to-stderr=true --debug-osd=20 # --gtest_filter=*.* "
203// End: