]>
Commit | Line | Data |
---|---|---|
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> | |
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, | |
11fdf7f2 TL |
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; | |
7c673cae FG |
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)); | |
11fdf7f2 | 65 | ms->bind(g_conf()->public_addr); |
7c673cae FG |
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 | ||
11fdf7f2 TL |
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(nullptr); | |
7c673cae | 73 | tm tm; |
9f95a23c | 74 | tm.tm_isdst = -1; |
7c673cae FG |
75 | strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); |
76 | utime_t now = utime_t(mktime(&tm), 0); | |
77 | bool ret = osd->scrub_time_permit(now); | |
78 | ASSERT_TRUE(ret); | |
79 | ||
11fdf7f2 TL |
80 | g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "24"); |
81 | g_ceph_context->_conf.set_val("osd_scrub_end_hour", "0"); | |
82 | g_ceph_context->_conf.apply_changes(nullptr); | |
7c673cae FG |
83 | strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); |
84 | now = utime_t(mktime(&tm), 0); | |
85 | ret = osd->scrub_time_permit(now); | |
86 | ASSERT_FALSE(ret); | |
87 | ||
11fdf7f2 TL |
88 | g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "0"); |
89 | g_ceph_context->_conf.set_val("osd_scrub_end_hour", "0"); | |
90 | g_ceph_context->_conf.apply_changes(nullptr); | |
7c673cae FG |
91 | strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm); |
92 | now = utime_t(mktime(&tm), 0); | |
93 | ret = osd->scrub_time_permit(now); | |
94 | ASSERT_TRUE(ret); | |
95 | ||
11fdf7f2 TL |
96 | g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "20"); |
97 | g_ceph_context->_conf.set_val("osd_scrub_end_hour", "07"); | |
98 | g_ceph_context->_conf.apply_changes(nullptr); | |
7c673cae FG |
99 | strptime("2015-01-16 01:05:13", "%Y-%m-%d %H:%M:%S", &tm); |
100 | now = utime_t(mktime(&tm), 0); | |
101 | 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 20: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 08: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_FALSE(ret); | |
119 | ||
11fdf7f2 TL |
120 | g_ceph_context->_conf.set_val("osd_scrub_begin_hour", "01"); |
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 20: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 00: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 04: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_TRUE(ret); | |
143 | ||
144 | } | |
145 | ||
146 | // Local Variables: | |
147 | // compile-command: "cd ../.. ; make unittest_osdscrub ; ./unittest_osdscrub --log-to-stderr=true --debug-osd=20 # --gtest_filter=*.* " | |
148 | // End: |