#define NETWORK_H
#include <asiolink/io_address.h>
+#include <asiolink/io_error.h>
#include <cc/cfg_to_element.h>
#include <cc/data.h>
#include <cc/element_value.h>
/// @return siaddr value
util::Optional<asiolink::IOAddress>
getSiaddr(const Inheritance& inheritance = Inheritance::ALL) const {
- return (getProperty<Network4>(&Network4::getSiaddr, siaddr_,
- inheritance, "next-server"));
+ // Temporary fix for global next-server being the empty string.
+ try {
+ return (getProperty<Network4>(&Network4::getSiaddr, siaddr_,
+ inheritance, "next-server"));
+ } catch (asiolink::IOError) {
+ return (siaddr_);
+ }
}
/// @brief Sets server hostname for the network.
EXPECT_EQ("global_iface", net_child->getIface().get());
}
+// Test that getSiaddr() never fails.
+TEST_F(NetworkTest, getSiaddrNeverFail) {
+ TestNetworkPtr net_child(new TestNetwork4());
+
+ // Set the next-server textual address to the empty string.
+ // Note that IOAddress("") throws IOError.
+ globals_->set("next-server", Element::create(""));
+
+ net_child->setFetchGlobalsFn(getFetchGlobalsFn());
+
+ // Get an IPv4 view of the test network.
+ auto net4_child = boost::dynamic_pointer_cast<Network4>(net_child);
+ EXPECT_NO_THROW(net4_child->getSiaddr());
+}
+
}