Skip to content

Commit 88a4e4d

Browse files
Ashutosh Grewalfacebook-github-bot
authored andcommitted
Enhance AgentVoqSwitchWithMultipleDsfNodesTest tests to work in multi-switch mode
Summary: Hw_agent_tests use fb303 counters to do the tests. In mono mode, this is simply a call to wedge-agent binary. However, tests don't work in multi mode, since these counters are not available in the sw-agent. For multi-switch mode, get the the client to hwAgent cached in SwSwitch for the hwAgent, and call getRegexCounters on it. Reviewed By: msomasundaran Differential Revision: D74614472 Privacy Context Container: L1125642 fbshipit-source-id: 39b199cbde1fc2153213562fbc5a41234836d33d
1 parent d3a7b04 commit 88a4e4d

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

fboss/agent/test/AgentEnsemble.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,30 @@ std::map<std::string, int64_t> AgentEnsemble::getFb303CountersByRegex(
731731
return counters;
732732
}
733733

734+
/**
735+
* Retrieves the value of a specific fb303 counter for a given switch.
736+
*
737+
* @details
738+
* Works in both mono-switch and multi-switch environments.
739+
*
740+
* @param key The name of the counter to retrieve.
741+
* @param switchID The ID of the switch for which to retrieve the counter.
742+
*
743+
* @return The value of the specified counter.
744+
*/
745+
int64_t AgentEnsemble::getFb303Counter(
746+
const std::string& key,
747+
const SwitchID& switchID) {
748+
int64_t counter{0};
749+
#ifndef IS_OSS
750+
auto client = getSw()->getHwSwitchThriftClientTable()->getClient(switchID);
751+
apache::thrift::Client<facebook::thrift::Monitor> monitoringClient{
752+
client->getChannelShared()};
753+
counter = monitoringClient.sync_getCounter(key);
754+
#endif
755+
return counter;
756+
}
757+
734758
/**
735759
* Retrieves the value of the first counter that matches a given regex pattern
736760
* for a specific port.

fboss/agent/test/AgentEnsemble.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,30 @@ class AgentEnsemble : public TestEnsembleIf {
322322
const std::string& regex);
323323

324324
/**
325-
* Retrieves the value of the first counter that matches a given regex pattern
326-
* for a specific port.
325+
* Retrieves the value of a specific fb303 counter for a given switch.
326+
*
327+
* @details
328+
* Works in both mono-switch and multi-switch environments.
329+
*
330+
* @param key The name of the counter to retrieve.
331+
* @param switchID The ID of the switch for which to retrieve the counter.
332+
*
333+
* @return The value of the specified counter.
334+
*/
335+
int64_t getFb303Counter(const std::string& key, const SwitchID& switchID);
336+
337+
/**
338+
* Retrieves the value of the first counter that matches a given regex
339+
* pattern for a specific port.
327340
*
328341
* @details
329342
* Works in both mono-switch and multi-switch environments.
330343
*
331344
* @param portId The ID of the port for which to retrieve the counter.
332345
* @param regex The regex pattern to match against counter names.
333346
*
334-
* @return The value of the first matching counter if one exists, otherwise
335-
* nullopt.
347+
* @return The value of the first matching counter if one exists,
348+
* otherwise nullopt.
336349
*/
337350
std::optional<int64_t> getFb303CounterIfExists(
338351
const PortID& portId,

fboss/agent/test/agent_hw_tests/AgentVoqSwitchWithMultipleDsfNodesTests.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ TEST_F(AgentVoqSwitchWithMultipleDsfNodesTest, remoteSystemPort) {
8888
// keeping remote switch id passed below in sync with it
8989
int numCores =
9090
checkSameAndGetAsic(getAgentEnsemble()->getL3Asics())->getNumCores();
91-
auto getStats = [] {
91+
auto getStats = [this] {
92+
auto switchID = *getSw()->getHwAsicTable()->getSwitchIDs().begin();
9293
return std::make_tuple(
93-
fbData->getCounter(kSystemPortsFree), fbData->getCounter(kVoqsFree));
94+
getAgentEnsemble()->getFb303Counter(
95+
std::string(kSystemPortsFree), switchID),
96+
getAgentEnsemble()->getFb303Counter(
97+
std::string(kVoqsFree), switchID));
9498
};
9599
auto [beforeSysPortsFree, beforeVoqsFree] = getStats();
96100
applyNewState([&](const std::shared_ptr<SwitchState>& in) {

0 commit comments

Comments
 (0)