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