]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
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)
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.
24 #include <gtest/gtest.h>
26 #include "os/ObjectStore.h"
27 #include "mon/MonClient.h"
28 #include "common/ceph_argparse.h"
29 #include "msg/Messenger.h"
31 class TestOSDScrub
: public OSD
{
34 TestOSDScrub(CephContext
*cct_
,
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
)
49 bool scrub_time_permit(utime_t now
) {
50 return OSD::scrub_time_permit(now
);
54 TEST(TestOSDScrub
, scrub_time_permit
) {
55 ObjectStore
*store
= ObjectStore::create(g_ceph_context
,
56 g_conf
->osd_objectstore
,
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",
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
, "", "");
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
146 // compile-command: "cd ../.. ; make unittest_osdscrub ; ./unittest_osdscrub --log-to-stderr=true --debug-osd=20 # --gtest_filter=*.* "