Skip to content
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
5 changes: 5 additions & 0 deletions lib/inc/internal/sources/lparstat_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace whereami { namespace sources {
*/
struct lparstat_data
{
/**
* Default empty constructor
*/
lparstat_data(): partition_name(""), partition_number(0), wpar_key(0), wpar_configured_id(0) { }

/**
* The partition name
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/src/sources/lparstat_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace whereami { namespace sources {

parse_oslevel_output(oslevel_result.output);

return true;
return version_.first > 0;
}

void lparstat::parse_oslevel_output(std::string const& oslevel_output)
Expand Down Expand Up @@ -156,4 +156,4 @@ namespace whereami { namespace sources {
});
}

}}
}} // whereami::sources
39 changes: 32 additions & 7 deletions lib/tests/detectors/lpar_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,40 @@ using namespace whereami::testing::lparstat;
using namespace std;

SCENARIO("Using the LPAR detector") {
WHEN("Running inside a LPAR") {
lparstat_fixture lparstat_source {"5.3.0.0", "output/lparstat/lpar.txt"};
WHEN("Running on AIX") {
WHEN("Running inside an LPAR") {
lparstat_fixture lparstat_source {"5.3.0.0", "output/lparstat/lpar.txt"};
auto res = lpar(lparstat_source);
THEN("The result is valid") {
REQUIRE(res.valid());
}
THEN("The result has the expected metadata") {
REQUIRE(res.get<string>("partition_name") == "aix-71-agent3");
REQUIRE(res.get<int>("partition_number") == 16);
}
}
WHEN("`oslevel` suggests AIX but lparstat output is unusable for some reason") {
lparstat_fixture lparstat_source {"7.1.0.0", "output/lparstat/kvm_power8.txt"};
auto res = lpar(lparstat_source);
THEN("The result is not valid") {
REQUIRE_FALSE(res.valid());
}
THEN("The data is still correctly initialized") {
REQUIRE(res.get<string>("partition_name").empty());
REQUIRE(res.get<int>("partition_number") == 0);
}
}
}

WHEN("Running outside of AIX") {
lparstat_fixture lparstat_source {"oslevel: command not found", "output/lparstat/kvm_power8.txt"};
auto res = lpar(lparstat_source);
THEN("the result is valid") {
REQUIRE(res.valid());
THEN("The result is not valid") {
REQUIRE_FALSE(res.valid());
}
THEN("the result has the expected metadata") {
REQUIRE(res.get<string>("partition_name") == "aix-71-agent3");
REQUIRE(res.get<int>("partition_number") == 16);
THEN("The data is still correctly initialized") {
REQUIRE(res.get<string>("partition_name").empty());
REQUIRE(res.get<int>("partition_number") == 0);
}
}
}
39 changes: 32 additions & 7 deletions lib/tests/detectors/wpar_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,40 @@ using namespace whereami::testing::lparstat;
using namespace std;

SCENARIO("Using the WPAR detector") {
WHEN("Running inside a WPAR") {
lparstat_fixture lparstat_source {"7.1.0.0", "output/lparstat/wpar.txt"};
WHEN("Running on AIX") {
WHEN("Running inside a WPAR") {
lparstat_fixture lparstat_source {"7.1.0.0", "output/lparstat/wpar.txt"};
auto res = wpar(lparstat_source);
THEN("the result is valid") {
REQUIRE(res.valid());
}
THEN("the result has the expected metadata") {
REQUIRE(res.get<int>("key") == 1);
REQUIRE(res.get<int>("configured_id") == 1);
}
}
WHEN("Not running inside a WPAR") {
lparstat_fixture lparstat_source {"7.1.0.0", "output/lparstat/lpar.txt"};
auto res = wpar(lparstat_source);
THEN("The result is not valid") {
REQUIRE_FALSE(res.valid());
}
THEN("The data is still correctly initialized") {
REQUIRE(res.get<int>("key") == 0);
REQUIRE(res.get<int>("configured_id") == 0);
}
}
}

WHEN("Running outside of AIX") {
lparstat_fixture lparstat_source {"oslevel: command not found", "output/lparstat/kvm_power8.txt"};
auto res = wpar(lparstat_source);
THEN("the result is valid") {
REQUIRE(res.valid());
THEN("The result is not valid") {
REQUIRE_FALSE(res.valid());
}
THEN("the result has the expected metadata") {
REQUIRE(res.get<int>("key") == 1);
REQUIRE(res.get<int>("configured_id") == 1);
THEN("The data is still correctly initialized") {
REQUIRE(res.get<int>("key") == 0);
REQUIRE(res.get<int>("configured_id") == 0);
}
}
}
2 changes: 1 addition & 1 deletion lib/tests/fixtures/lparstat_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace whereami { namespace testing { namespace lparstat {
*/
bool collect_aix_version_from_oslevel() override {
parse_oslevel_output(version_string_);
return true;
return this->version_.first > 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/tests/fixtures/output/lparstat/kvm_power8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lparstat: is not supported on the Power KVM pSeries Guest platform
43 changes: 31 additions & 12 deletions lib/tests/sources/lparstat_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,39 @@ using namespace whereami::sources;
using namespace whereami::testing::lparstat;

SCENARIO("Using the lparstat data source") {
WHEN("Running on AIX") {
WHEN("LPAR information is available") {
WHEN("WPAR information is available") {
THEN("LPAR and WPAR fields are filled") {
lparstat_fixture lparstat_source {"7.1.0.0", "output/lparstat/wpar.txt"};
REQUIRE(lparstat_source.partition_number() == 16);
REQUIRE(lparstat_source.partition_name() == "aix-71-agent3");
REQUIRE(lparstat_source.wpar_key() == 1);
REQUIRE(lparstat_source.wpar_configured_id() == 1);
}
}

WHEN("WPAR information is not available") {
lparstat_fixture lparstat_source {"5.3.0.0", "output/lparstat/lpar.txt"};
REQUIRE(lparstat_source.partition_number() == 16);
REQUIRE(lparstat_source.partition_name() == "aix-71-agent3");
REQUIRE(lparstat_source.wpar_key() == 0);
REQUIRE(lparstat_source.wpar_configured_id() == 0);
WHEN("WPAR INFORMATION is not available") {
THEN("LPAR fields are filled and WPAR fields are empty") {
lparstat_fixture lparstat_source {"5.3.0.0", "output/lparstat/lpar.txt"};
REQUIRE(lparstat_source.partition_number() == 16);
REQUIRE(lparstat_source.partition_name() == "aix-71-agent3");
REQUIRE(lparstat_source.wpar_key() == 0);
REQUIRE(lparstat_source.wpar_configured_id() == 0);
}
}
}
}

WHEN("WPAR information is available") {
lparstat_fixture lparstat_source {"7.1.0.0", "output/lparstat/wpar.txt"};
REQUIRE(lparstat_source.partition_number() == 16);
REQUIRE(lparstat_source.partition_name() == "aix-71-agent3");
REQUIRE(lparstat_source.wpar_key() == 1);
REQUIRE(lparstat_source.wpar_configured_id() == 1);
WHEN("Running outside of AIX") {
WHEN("An lparstat executable is available but this is not an AIX machine") {
THEN("the source does not attempt to collect any data and empty values are correctly initialized") {
lparstat_fixture lparstat_source {"0.0", "output/lparstat/kvm_power8.txt"};
REQUIRE(lparstat_source.partition_number() == 0);
REQUIRE(lparstat_source.partition_name().empty());
REQUIRE(lparstat_source.wpar_key() == 0);
REQUIRE(lparstat_source.wpar_configured_id() == 0);
}
}
}
}
42 changes: 36 additions & 6 deletions locales/whereami.pot
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,28 @@ msgid "{1}: file could not be read."
msgstr ""

#. debug
#: lib/src/sources/cgroup_source.cc
msgid "File {!} could not be read"
#: lib/src/detectors/zone_detector.cc
msgid "zonename executable not found"
msgstr ""

#. debug
#: lib/src/sources/dmi_source.cc
msgid " not found."
#: lib/src/detectors/zone_detector.cc
msgid "Error while running zonename ({1})"
msgstr ""

#. debug
#: lib/src/sources/dmi_source.cc
msgid "Using dmidecode to query DMI information."
#: lib/src/detectors/zone_detector.cc
msgid "zoneadm executable not found"
msgstr ""

#. debug
#: lib/src/detectors/zone_detector.cc
msgid "Error while running `zoneadm list -p` ({1})"
msgstr ""

#. debug
#: lib/src/sources/cgroup_source.cc
msgid "File {!} could not be read"
msgstr ""

#. debug
Expand All @@ -48,11 +58,31 @@ msgstr ""
msgid "Error while running dmidecode ({1})"
msgstr ""

#. debug
#: lib/src/sources/dmi_source.cc
msgid " not found."
msgstr ""

#. debug
#: lib/src/sources/dmi_source.cc
msgid "{1}: {2}."
msgstr ""

#. debug
#: lib/src/sources/lparstat_source.cc
msgid "oslevel executable not found"
msgstr ""

#. debug
#: lib/src/sources/lparstat_source.cc
msgid "lparstat executable not found"
msgstr ""

#. debug
#: lib/src/sources/lparstat_source.cc
msgid "Error while running lparstat ({1})"
msgstr ""

#. debug
#: lib/src/whereami.cc
msgid "whereami version is {1}"
Expand Down