mirror of
https://github.com/ceph/ceph
synced 2025-03-31 07:53:23 +00:00
common/hostname: use NODE_NAME environment variable insetad, if set
This is set by rook to the physical node. Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
0acb5cb454
commit
e583f80086
@ -18,6 +18,12 @@
|
||||
|
||||
std::string ceph_get_hostname()
|
||||
{
|
||||
// are we in a container? if so we would prefer the *real* hostname.
|
||||
const char *node_name = getenv("NODE_NAME");
|
||||
if (node_name) {
|
||||
return node_name;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
gethostname(buf, 1024);
|
||||
return std::string(buf);
|
||||
|
@ -44,12 +44,24 @@ std::string exec(const char* cmd) {
|
||||
|
||||
TEST(Hostname, full) {
|
||||
std::string hn = ceph_get_hostname();
|
||||
ASSERT_EQ(hn, exec("hostname")) ;
|
||||
|
||||
|
||||
if (const char *nn = getenv("NODE_NAME")) {
|
||||
// we are in a container
|
||||
std::cout << "we are in a container on " << nn << ", reporting " << hn
|
||||
<< std::endl;
|
||||
ASSERT_EQ(hn, nn);
|
||||
} else {
|
||||
ASSERT_EQ(hn, exec("hostname")) ;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Hostname, short) {
|
||||
std::string shn = ceph_get_short_hostname();
|
||||
ASSERT_EQ(shn, exec("hostname -s")) ;
|
||||
if (const char *nn = getenv("NODE_NAME")) {
|
||||
// we are in a container
|
||||
std::cout << "we are in a container on " << nn << ", reporting short " << shn
|
||||
<< ", skipping test because env var may or may not be short form"
|
||||
<< std::endl;
|
||||
} else {
|
||||
ASSERT_EQ(shn, exec("hostname -s")) ;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user