1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// -*- 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) 2020 Red Hat
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "gtest/gtest.h"
#include "include/cephfs/libcephfs.h"
#include "common/ceph_context.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
class MonConfig : public ::testing::Test
{
protected:
struct ceph_mount_info *ca;
void SetUp() override {
ASSERT_EQ(0, ceph_create(&ca, NULL));
ASSERT_EQ(0, ceph_conf_read_file(ca, NULL));
ASSERT_EQ(0, ceph_conf_parse_env(ca, NULL));
}
void TearDown() override {
ceph_shutdown(ca);
}
// Helper to remove/unset all possible mon information from ConfigProxy
void clear_mon_config(CephContext *cct) {
auto& conf = cct->_conf;
// Clear safe_to_start_threads, allowing updates to config values
conf._clear_safe_to_start_threads();
ASSERT_EQ(0, conf.set_val("monmap", "", nullptr));
ASSERT_EQ(0, conf.set_val("mon_host", "", nullptr));
ASSERT_EQ(0, conf.set_val("mon_dns_srv_name", "", nullptr));
conf.set_safe_to_start_threads();
}
// Helper to test basic operation on a mount
void use_mount(struct ceph_mount_info *mnt, string name_prefix) {
char name[20];
snprintf(name, sizeof(name), "%s.%d", name_prefix.c_str(), getpid());
int fd = ceph_open(mnt, name, O_CREAT|O_RDWR, 0644);
ASSERT_LE(0, fd);
ceph_close(mnt, fd);
}
};
TEST_F(MonConfig, MonAddrsMissing) {
CephContext *cct;
// Test mount failure when there is no known mon config source
cct = ceph_get_mount_context(ca);
ASSERT_NE(nullptr, cct);
clear_mon_config(cct);
ASSERT_EQ(-ENOENT, ceph_mount(ca, NULL));
}
TEST_F(MonConfig, MonAddrsInConfigProxy) {
// Test a successful mount with default mon config source in ConfigProxy
ASSERT_EQ(0, ceph_mount(ca, NULL));
use_mount(ca, "foo");
}
TEST_F(MonConfig, MonAddrsInCct) {
struct ceph_mount_info *cb;
CephContext *cct;
// Perform mount to bootstrap mon addrs in CephContext
ASSERT_EQ(0, ceph_mount(ca, NULL));
// Reuse bootstrapped CephContext, clearing ConfigProxy mon addr sources
cct = ceph_get_mount_context(ca);
ASSERT_NE(nullptr, cct);
clear_mon_config(cct);
ASSERT_EQ(0, ceph_create_with_context(&cb, cct));
// Test a successful mount with only mon values in CephContext
ASSERT_EQ(0, ceph_mount(cb, NULL));
use_mount(ca, "bar");
use_mount(cb, "bar");
ceph_shutdown(cb);
}
|