summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRatan Gupta <ratagupt@in.ibm.com>2017-11-22 15:44:42 +0530
committerRatan Gupta <ratagupt@in.ibm.com>2018-03-15 00:20:22 +0530
commitc27170ab2747f7854a06c4dc533c2ad3c88dd758 (patch)
tree11a39f5aac4bd26903746195541e18e96b74335c /test
parentd475cd63286ec7b3f74c3959cabaa292b6648265 (diff)
downloadphosphor-networkd-c27170ab2747f7854a06c4dc533c2ad3c88dd758.tar.gz
phosphor-networkd-c27170ab2747f7854a06c4dc533c2ad3c88dd758.zip
Reduce journal logs
Presently the code was creating the elog during reading of the values from the config parser which creates the journal log internally("Internal error Occured") Apart from creating elog,Code also logs into the journal more descriptive message saying which section and key was not found. The code which catches the exception that also logs into the journal. In the changed approach instead of throwing exception we are returning the return code as not finding a section or key in the network config file is not an error. Change-Id: Ib89a3af6541fdf93fb5fa9a8e583d6c6ed88da79 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_config_parser.cpp40
-rw-r--r--test/test_ethernet_interface.cpp8
-rw-r--r--test/test_vlan_interface.cpp22
3 files changed, 34 insertions, 36 deletions
diff --git a/test/test_config_parser.cpp b/test/test_config_parser.cpp
index a07390b..1c902d2 100644
--- a/test/test_config_parser.cpp
+++ b/test/test_config_parser.cpp
@@ -46,17 +46,20 @@ class TestConfigParser : public testing::Test
TEST_F(TestConfigParser, ReadConfigDataFromFile)
{
- auto values = parser.getValues("Network", "DHCP");
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+
+ std::tie(rc, values) = parser.getValues("Network", "DHCP");
std::string expectedValue = "true";
bool found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("DHCP", "ClientIdentifier");
+ std::tie(rc, values) = parser.getValues("DHCP", "ClientIdentifier");
expectedValue = "mac";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("Match", "Name");
+ std::tie(rc, values) = parser.getValues("Match", "Name");
expectedValue = "eth0";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
@@ -64,35 +67,20 @@ TEST_F(TestConfigParser, ReadConfigDataFromFile)
TEST_F(TestConfigParser, SectionNotExist)
{
- using namespace sdbusplus::xyz::openbmc_project::Common::Error;
- bool caughtException = false;
- try
- {
- parser.getValues("abc", "ipaddress");
- }
- catch (const std::exception& e)
- {
- caughtException = true;
- }
- EXPECT_EQ(true, caughtException);
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+ std::tie(rc, values) = parser.getValues("abc", "ipaddress");
+ EXPECT_EQ(config::ReturnCode::SECTION_NOT_FOUND, rc);
}
TEST_F(TestConfigParser, KeyNotFound)
{
- using namespace sdbusplus::xyz::openbmc_project::Common::Error;
- bool caughtException = false;
- try
- {
- parser.getValues("Network", "abc");
- }
- catch (const std::exception& e)
- {
- caughtException = true;
- }
- EXPECT_EQ(true, caughtException);
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+ std::tie(rc, values) = parser.getValues("Network", "abc");
+ EXPECT_EQ(config::ReturnCode::KEY_NOT_FOUND, rc);
remove("/tmp/eth0.network");
}
}//namespace network
}//namespace phosphor
-
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index 27fbb67..2181006 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -197,7 +197,9 @@ TEST_F(TestEthernetInterface, addNameServers)
fs::path filePath = confDir;
filePath /= "00-bmc-test0.network";
config::Parser parser(filePath.string());
- auto values = parser.getValues("Network", "DNS");
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+ std::tie(rc, values) = parser.getValues("Network", "DNS");
EXPECT_EQ(servers , values);
validateResolvFile(values);
@@ -210,7 +212,9 @@ TEST_F(TestEthernetInterface, addNTPServers)
fs::path filePath = confDir;
filePath /= "00-bmc-test0.network";
config::Parser parser(filePath.string());
- auto values = parser.getValues("Network", "NTP");
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+ std::tie(rc, values) = parser.getValues("Network", "NTP");
EXPECT_EQ(servers , values);
}
diff --git a/test/test_vlan_interface.cpp b/test/test_vlan_interface.cpp
index 9711a1a..00384f1 100644
--- a/test/test_vlan_interface.cpp
+++ b/test/test_vlan_interface.cpp
@@ -123,17 +123,20 @@ TEST_F(TestVlanInterface, createVLAN)
filePath /= "test0.50.netdev";
config::Parser parser(filePath.string());
- auto values = parser.getValues("NetDev", "Name");
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+
+ std::tie(rc, values) = parser.getValues("NetDev", "Name");
std::string expectedValue = "test0.50";
bool found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("NetDev", "Kind");
+ std::tie(rc, values) = parser.getValues("NetDev", "Kind");
expectedValue = "vlan";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("VLAN", "Id");
+ std::tie(rc, values) = parser.getValues("VLAN", "Id");
expectedValue = "50";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
@@ -163,17 +166,20 @@ TEST_F(TestVlanInterface, createMultipleVLAN)
fs::path filePath = confDir;
filePath /= "test0.50.netdev";
config::Parser parser(filePath.string());
- auto values = parser.getValues("NetDev", "Name");
+ config::ReturnCode rc = config::ReturnCode::SUCCESS;
+ config::ValueList values;
+
+ std::tie(rc, values) = parser.getValues("NetDev", "Name");
std::string expectedValue = "test0.50";
bool found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("NetDev", "Kind");
+ std::tie(rc, values) = parser.getValues("NetDev", "Kind");
expectedValue = "vlan";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("VLAN", "Id");
+ std::tie(rc, values) = parser.getValues("VLAN", "Id");
expectedValue = "50";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
@@ -181,12 +187,12 @@ TEST_F(TestVlanInterface, createMultipleVLAN)
filePath = confDir;
filePath /= "test0.60.netdev";
parser.setFile(filePath.string());
- values = parser.getValues("NetDev", "Name");
+ std::tie(rc, values) = parser.getValues("NetDev", "Name");
expectedValue = "test0.60";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
- values = parser.getValues("VLAN", "Id");
+ std::tie(rc, values) = parser.getValues("VLAN", "Id");
expectedValue = "60";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
OpenPOWER on IntegriCloud