Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ign -> gz Environment Variable Migration : gz-transport #318

Merged
merged 2 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ release will remove the deprecated code.
### Deprecated

1. The `ignition` namespace is deprecated and will be removed in future versions. Use `gz` instead.

1. Header files under `ignition/...` are deprecated and will be removed in future versions.
Use `gz/...` instead.
1. The following `IGN_` prefixed environment variables are deprecated and will be removed in future versions.
Use the `GZ_` prefixed versions instead!
1. `IGN_TRANSPORT_USERNAME` -> `GZ_TRANSPORT_USERNAME`

1. `IGN_TRANSPORT_PASSWORD` -> `GZ_TRANSPORT_PASSWORD`
1. `IGN_PARTITION` -> `GZ_PARTITION`
1. `IGN_IP` -> `GZ_IP`
1. `IGN_TRANSPORT_TOPIC_STATISTICS` -> `GZ_TRANSPORT_TOPIC_STATISTICS`
1. `IGN_DISCOVERY_MSG_PORT` -> `GZ_DISCOVERY_MSG_PORT`
1. `IGN_DISCOVERY_MULTICAST_IP` -> `GZ_DISCOVERY_MULTICAST_IP`
1. `IGN_DISCOVERY_SRV_PORT` -> `GZ_DISCOVERY_SRV_PORT`
1. `IGN_RELAY` -> `GZ_RELAY`
1. `IGN_TRANSPORT_LOG_SQL_PATH` -> `GZ_TRANSPORT_LOG_SQL_PATH`
1. `IGN_TRANSPORT_RCVHWM` -> `GZ_TRANSPORT_RCVHWM`
1. `IGN_TRANSPORT_SNDHWM` -> `GZ_TRANSPORT_SNDHWM`
1. `IGN_VERBOSE` -> `GZ_VERBOSE`

1. `IGN_TRANSPORT_LOG_SQL_PATH` is deprecated and will be removed in future versions.
Use `GZ_TRANSPORT_LOG_SQL_PATH` instead.

## Gazebo Transport 9.X to 10.X

Expand Down
2 changes: 1 addition & 1 deletion include/gz/transport/CIface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
/// \brief Create a transport node.
/// \param[in] _partition Optional name of the partition to use.
/// Use nullptr to use the default value, which is specified via the
/// IGN_PARTITION environment variable.
/// GZ_PARTITION environment variable.
/// \return A pointer to a new transport node. Do not manually delete this
/// pointer, instead use ignTransportNodeDestroy.
IgnTransportNode GZ_TRANSPORT_VISIBLE *ignTransportNodeCreate(
Expand Down
48 changes: 39 additions & 9 deletions include/gz/transport/Discovery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,18 @@ namespace gz
exit(false),
enabled(false)
{
std::string ignIp;
if (env("IGN_IP", ignIp) && !ignIp.empty())
this->hostInterfaces = {ignIp};
std::string gzIp;
if (env("GZ_IP", gzIp) && !gzIp.empty())
{
this->hostInterfaces = {gzIp};
}
// TODO(CH3): Deprecated. Remove on tock.
else if (env("IGN_IP", gzIp) && !gzIp.empty())
{
std::cerr << "IGN_IP is deprecated and will be removed! "
<< "Use GZ_IP instead!" << std::endl;
this->hostInterfaces = {gzIp};
}
else
{
// Get the list of network interfaces in this host.
Expand Down Expand Up @@ -232,10 +241,17 @@ namespace gz
this->mcastAddr.sin_port = htons(static_cast<u_short>(this->port));

std::vector<std::string> relays;
std::string ignRelay = "";
if (env("IGN_RELAY", ignRelay) && !ignRelay.empty())
std::string gzRelay = "";
if (env("GZ_RELAY", gzRelay) && !gzRelay.empty())
{
relays = transport::split(ignRelay, ':');
relays = transport::split(gzRelay, ':');
}
// TODO(CH3): Deprecated. Remove on tock.
else if (env("IGN_RELAY", gzRelay) && !gzRelay.empty())
{
std::cout << "IGN_RELAY is deprecated and will be removed! "
<< "Use GZ_RELAY instead!" << std::endl;
relays = transport::split(gzRelay, ':');
}

// Register all unicast relays.
Expand Down Expand Up @@ -1279,9 +1295,23 @@ namespace gz
/// \return The discovery version.
private: uint8_t Version() const
{
static std::string ignStats;
static int topicStats =
(env("IGN_TRANSPORT_TOPIC_STATISTICS", ignStats) && ignStats == "1");
static std::string gzStats;
static int topicStats;

if (env("GZ_TRANSPORT_TOPIC_STATISTICS", gzStats) && !gzStats.empty())
{
topicStats = (gzStats == "1");
}
// TODO(CH3): Deprecated. Remove on tock.
else if (env("IGN_TRANSPORT_TOPIC_STATISTICS", gzStats)
&& !gzStats.empty())
{
std::cout << "IGN_TRANSPORT_TOPIC_STATISTICS is deprecated! "
<< "Use GZ_TRANSPORT_TOPIC_STATISTICS instead!"
<< std::endl;
topicStats = (gzStats == "1");
}

return this->kWireVersion + (topicStats * 100);
}

Expand Down
2 changes: 1 addition & 1 deletion include/gz/transport/NodeOptions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace gz
/// \param[in] _partition The partition's name.
/// The default partition value is created using a combination of your
/// hostname, followed by ':' and your username. E.g.: "bb9:caguero" .
/// It's also possible to use the environment variable IGN_PARTITION for
/// It's also possible to use the environment variable GZ_PARTITION for
/// setting a partition name.
/// \return True when operation succeed or false if the partition name was
/// invalid.
Expand Down
5 changes: 4 additions & 1 deletion log/test/integration/playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,10 @@ int main(int argc, char **argv)
partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("IGN_PARTITION", partition.c_str(), 1);
setenv("GZ_PARTITION", partition.c_str(), 1);

setenv("GZ_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);

// TODO(CH3): Deprecated. Remove this on tick-tock.
setenv("IGN_TRANSPORT_LOG_SQL_PATH",
Expand Down
5 changes: 4 additions & 1 deletion log/test/integration/recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ int main(int argc, char **argv)
partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("IGN_PARTITION", partition.c_str(), 1);
setenv("GZ_PARTITION", partition.c_str(), 1);

setenv("GZ_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);

// TODO(CH3): Deprecated. Remove this on tick-tock.
setenv("IGN_TRANSPORT_LOG_SQL_PATH",
Expand Down
4 changes: 2 additions & 2 deletions log/test/integration/topicChirp_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char **argv)
{
// Argument list:
// [0]: Name of current process
// [1]: Partition name (used for setting the IGN_PARTITION env variable)
// [1]: Partition name (used for setting the GZ_PARTITION env variable)
// [2]: Number of times that the topics should chirp
// [3]-[N]: A name for each topic that should chirp

Expand All @@ -90,7 +90,7 @@ int main(int argc, char **argv)
return -2;
}

setenv("IGN_PARTITION", argv[1], 1);
setenv("GZ_PARTITION", argv[1], 1);

const int chirps = atoi(argv[2]);

Expand Down
2 changes: 1 addition & 1 deletion src/CIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int main(int argc, char **argv)
std::string partition = testing::getRandomNumber();

// Set the partition name for this process.
setenv("IGN_PARTITION", partition.c_str(), 1);
setenv("GZ_PARTITION", partition.c_str(), 1);

// Enable verbose mode.
// setenv("IGN_VERBOSE", "1", 1);
Expand Down
24 changes: 12 additions & 12 deletions src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,23 @@ TEST(DiscoveryTest, TestActivity)
}

//////////////////////////////////////////////////
/// \brief Check that a wrong IGN_IP value makes HostAddr() to return 127.0.0.1
TEST(DiscoveryTest, WrongIgnIp)
/// \brief Check that a wrong GZ_IP value makes HostAddr() to return 127.0.0.1
TEST(DiscoveryTest, WrongGzIp)
{
// Save the current value of IGN_IP environment variable.
std::string ignIp;
env("IGN_IP", ignIp);
// Save the current value of GZ_IP environment variable.
std::string gzIp;
env("GZ_IP", gzIp);

// Incorrect value for IGN_IP
setenv("IGN_IP", "127.0.0.0", 1);
// Incorrect value for GZ_IP
setenv("GZ_IP", "127.0.0.0", 1);

transport::Discovery<MessagePublisher> discovery1(pUuid1, g_ip, g_msgPort);
EXPECT_EQ(discovery1.HostAddr(), "127.0.0.1");

// Unset IGN_IP.
unsetenv("IGN_IP");
// Unset GZ_IP.
unsetenv("GZ_IP");

// Restore IGN_IP.
if (!ignIp.empty())
setenv("IGN_IP", ignIp.c_str(), 1);
// Restore GZ_IP.
if (!gzIp.empty())
setenv("GZ_IP", gzIp.c_str(), 1);
}
15 changes: 12 additions & 3 deletions src/NetUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ inline namespace GZ_TRANSPORT_VERSION_NAMESPACE
std::string determineHost()
{
// First, did the user set IGN_IP?
std::string ignIp;
if (env("IGN_IP", ignIp) && !ignIp.empty())
return ignIp;
std::string gzIp;
if (env("GZ_IP", gzIp) && !gzIp.empty())
{
return gzIp;
}
// TODO(CH3): Deprecated. Remove on tock.
else if (env("IGN_IP", gzIp) && !gzIp.empty())
{
std::cout << "IGN_IP is deprecated and will be removed! "
<< "Use GZ_IP instead!" << std::endl;
return gzIp;
}

// Second, try the preferred local and public IP address.
std::string hostIP;
Expand Down
17 changes: 13 additions & 4 deletions src/NodeOptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ using namespace transport;
NodeOptions::NodeOptions()
: dataPtr(new NodeOptionsPrivate())
{
// Check if the environment variable IGN_PARTITION is present.
std::string ignPartition;
if (env("IGN_PARTITION", ignPartition))
this->SetPartition(ignPartition);
// Check if the environment variable GZ_PARTITION is present.
std::string gzPartition;
if (env("GZ_PARTITION", gzPartition))
{
this->SetPartition(gzPartition);
}
// TODO(CH3): Deprecated. Remove on tock.
else if (env("IGN_PARTITION", gzPartition))
{
std::cout << "IGN_PARTITION is deprecated and will be removed! "
<< "Use GZ_PARTITION instead!" << std::endl;
this->SetPartition(gzPartition);
}
}

//////////////////////////////////////////////////
Expand Down
10 changes: 5 additions & 5 deletions src/NodeOptions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
using namespace gz;

//////////////////////////////////////////////////
/// \brief Check that IGN_PARTITION is set.
/// \brief Check that is set.
TEST(NodeOptionsTest, ignPartition)
{
// Set IGN_PARTITION
// Set GZ_PARTITION
std::string aPartition = "customPartition";
setenv("IGN_PARTITION", aPartition.c_str(), 1);
setenv("GZ_PARTITION", aPartition.c_str(), 1);

transport::NodeOptions opts;
EXPECT_EQ(opts.Partition(), aPartition);

// A partition set by the user should overwrite IGN_PARTITION.
// A partition set by the user should overwrite GZ_PARTITION.
std::string userPartition = "userPartition";
opts.SetPartition(userPartition);
EXPECT_EQ(opts.Partition(), userPartition);
Expand All @@ -53,7 +53,7 @@ TEST(NodeOptionsTest, ignPartition)
TEST(NodeOptionsTest, accessors)
{
// Check the default values.
unsetenv("IGN_PARTITION");
unsetenv("GZ_PARTITION");
transport::NodeOptions opts;
EXPECT_TRUE(opts.NameSpace().empty());
auto defaultPartition = transport::hostname() + ":" + transport::username();
Expand Down
Loading