Skip to content

Commit

Permalink
Add basic UT for flow based drop logging
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Flynn <tom.flynn@gmail.com>
  • Loading branch information
tomflynn committed Sep 13, 2020
1 parent 5f1897e commit 5a3cb7f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
12 changes: 6 additions & 6 deletions agent-ovs/lib/FSPacketDropLogConfigSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ FSPacketDropLogConfigSource::FSPacketDropLogConfigSource(ExtraConfigManager* man
listener.addWatch(serviceDir, *this);
}

static bool isPacketDropLogConfig(fs::path filePath) {
static bool isPacketDropLogConfig(const fs::path& filePath) {
string fstr = filePath.filename().string();
return (boost::algorithm::ends_with(fstr, ".droplogcfg") &&
!boost::algorithm::starts_with(fstr, "."));
}

static bool isPacketDropFlowConfig(fs::path filePath) {
static bool isPacketDropFlowConfig(const fs::path& filePath) {
string fstr = filePath.filename().string();
return (boost::algorithm::ends_with(fstr, ".dropflowcfg") &&
!boost::algorithm::starts_with(fstr, "."));
}

static inline bool validateIpAddress(const boost::optional<string> ipAddress,
static inline bool validateIpAddress(const boost::optional<string>& ipAddress,
optional<boost::asio::ip::address> &_targetAddress,bool require_v4, const string &inputField) {
address targetAddress;
boost::system::error_code ec;
Expand All @@ -79,7 +79,7 @@ static inline bool validateIpAddress(const boost::optional<string> ipAddress,
return true;
}

static inline bool validateMacAddress(const boost::optional<string> macAddress,
static inline bool validateMacAddress(const boost::optional<string>& macAddress,
optional<opflex::modb::MAC> &_targetMacAddress, const string &inputField) {
opflex::modb::MAC targetMacAddress;
if(!macAddress) {
Expand Down Expand Up @@ -111,7 +111,7 @@ void FSPacketDropLogConfigSource::updated(const fs::path& filePath) {
(filePath.string() != dropCfg.filePath)) {
return;
}
string pathStr = filePath.string();
const string& pathStr = filePath.string();
std::string dropLogMode;
read_json(pathStr, properties);
static const std::string DROP_LOG_ENABLE("drop-log-enable");
Expand Down Expand Up @@ -221,7 +221,7 @@ void FSPacketDropLogConfigSource::deleted(const fs::path& filePath) {
<< " at " << filePath;
} else if(isPacketDropFlowConfig(filePath)) {

DropFlowMap::iterator it = dropFlowMap.find(pathStr);
auto it = dropFlowMap.find(pathStr);
if(it != dropFlowMap.end()) {
opflex::modb::URI uri = opflex::modb::URIBuilder()
.addElement("ObserverDropFlowConfigUniverse")
Expand Down
4 changes: 0 additions & 4 deletions agent-ovs/lib/FSWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
#include <sys/eventfd.h>
#endif
#include <poll.h>
#include <cerrno>
#include <unistd.h>
#include <arpa/inet.h>

#include <boost/algorithm/string/predicate.hpp>

#include <opflex/modb/URIBuilder.h>

Expand Down
30 changes: 29 additions & 1 deletion agent-ovs/lib/test/ExtraConfigManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <opflexagent/FSRDConfigSource.h>
#include <opflexagent/FSPacketDropLogConfigSource.h>
#include <opflexagent/logging.h>

#include <opflexagent/test/BaseFixture.h>

Expand Down Expand Up @@ -96,5 +95,34 @@ BOOST_FIXTURE_TEST_CASE( droplogconfigsource, FSConfigFixture ) {
WAIT_FOR(!(DropLogConfig::resolve(agent.getFramework(), uri)), 500);
watcher.stop();
}

BOOST_FIXTURE_TEST_CASE( dropflowconfigsource, FSConfigFixture ) {
using modelgbp::observer::DropFlowConfig;
fs::path path(temp / "a.dropflowcfg");
fs::ofstream os(path);
os << "{"
<< "\"uuid\":\"83f18f0b-80f7-46e2-b06c-4d9487b0c793\""
<< "}" << std::endl;
os.close();
FSWatcher watcher;
opflex::modb::URI uri =
opflex::modb::URIBuilder().addElement("PolicyUniverse")
.addElement("ObserverDropLogConfig").build();
FSPacketDropLogConfigSource source(&agent.getExtraConfigManager(), watcher,
temp.string(), uri);
watcher.start();

opflex::modb::URI flowUri = opflex::modb::URIBuilder()
.addElement("ObserverDropFlowConfigUniverse")
.addElement("ObserverDropFlowConfig")
.addElement("83f18f0b-80f7-46e2-b06c-4d9487b0c793").build();

WAIT_FOR(DropFlowConfig::resolve(agent.getFramework(), flowUri), 500);

fs::remove(path);
WAIT_FOR(!(DropFlowConfig::resolve(agent.getFramework(), flowUri)), 500);
watcher.stop();
}

BOOST_AUTO_TEST_SUITE_END()
}

0 comments on commit 5a3cb7f

Please sign in to comment.