Skip to content

Commit

Permalink
Merge branch 'master' into dynamic-buffer-calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenxs authored Nov 24, 2020
2 parents e37a6fb + a2c82ff commit 3458442
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 4 deletions.
11 changes: 11 additions & 0 deletions common/dbconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ class DBConnector : public RedisContext

int64_t del(const std::string &key);

#ifdef SWIG
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatiblity
// TODO: remove this function after applications use the function name `delete`
%pythoncode %{
def _del(self, *args, **kwargs):
return self.delete(*args, **kwargs)
%}
#endif

bool exists(const std::string &key);

int64_t hdel(const std::string &key, const std::string &field);
Expand Down
2 changes: 1 addition & 1 deletion common/dbinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::vector<std::string> DBInterface::keys(const std::string& dbName, const char
auto keys = m_redisClient.at(dbName).keys(pattern);
if (keys.empty())
{
std::string message = "DB '{" + dbName + "}' is empty!";
std::string message = "DB '{" + dbName + "}' is empty with pattern '" + pattern + "'!";
SWSS_LOG_WARN("%s", message.c_str());
throw UnavailableDataError(message, "hset");
}
Expand Down
8 changes: 7 additions & 1 deletion common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void err_exit(const char *fn, int ln, int e, const char *fmt, ...)
err_exit(__FUNCTION__, __LINE__, e, (fmt), ##args); \
}

#ifdef __GNUC__
# define ATTRIBUTE_NORTEURN __attribute__ ((noreturn))
#else
# define ATTRIBUTE_NORTEURN
#endif

class Logger
{
Expand Down Expand Up @@ -130,7 +135,8 @@ class Logger

static void swssPrioNotify(const std::string &component, const std::string &prioStr);
static void swssOutputNotify(const std::string &component, const std::string &outputStr);
[[ noreturn ]] void settingThread();

ATTRIBUTE_NORTEURN void settingThread();

LogSettingChangeObservers m_settingChangeObservers;
std::map<std::string, std::string> m_currentPrios;
Expand Down
11 changes: 11 additions & 0 deletions common/producerstatetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ class ProducerStateTable : public TableBase, public TableName_KeySet
const std::string &op = DEL_COMMAND,
const std::string &prefix = EMPTY_PREFIX);

#ifdef SWIG
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatiblity
// TODO: remove this function after applications use the function name `delete`
%pythoncode %{
def _del(self, *args, **kwargs):
return self.delete(*args, **kwargs)
%}
#endif

void flush();

int64_t count();
Expand Down
11 changes: 11 additions & 0 deletions common/producertable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class ProducerTable : public TableBase, public TableName_KeyValueOpQueues
const std::string &op = DEL_COMMAND,
const std::string &prefix = EMPTY_PREFIX);

#ifdef SWIG
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatiblity
// TODO: remove this function after applications use the function name `delete`
%pythoncode %{
def _del(self, *args, **kwargs):
return self.delete(*args, **kwargs)
%}
#endif

void flush();

private:
Expand Down
6 changes: 4 additions & 2 deletions common/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace swss {
#define APP_FDB_TABLE_NAME "FDB_TABLE"
#define APP_PFC_WD_TABLE_NAME "PFC_WD_TABLE"
#define APP_SWITCH_TABLE_NAME "SWITCH_TABLE"

#define APP_COPP_TABLE_NAME "COPP_TABLE"
#define APP_VRF_TABLE_NAME "VRF_TABLE"
#define APP_VNET_TABLE_NAME "VNET_TABLE"
Expand Down Expand Up @@ -78,7 +78,7 @@ namespace swss {
#define APP_HW_MUX_CABLE_TABLE_NAME "HW_MUX_CABLE_TABLE"
#define APP_MUX_CABLE_COMMAND_TABLE_NAME "MUX_CABLE_COMMAND_TABLE"
#define APP_MUX_CABLE_RESPONSE_TABLE_NAME "MUX_CABLE_RESPONSE_TABLE"

#define APP_SYSTEM_PORT_TABLE_NAME "SYSTEM_PORT_TABLE"

#define APP_MACSEC_PORT_TABLE_NAME "MACSEC_PORT_TABLE"
Expand All @@ -94,6 +94,8 @@ namespace swss {
#define APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME "BUFFER_PORT_INGRESS_PROFILE_LIST_TABLE"
#define APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME "BUFFER_PORT_EGRESS_PROFILE_LIST_TABLE"

#define APP_NEIGH_RESOLVE_TABLE_NAME "NEIGH_RESOLVE_TABLE"

/***** TO BE REMOVED *****/

#define APP_TC_TO_QUEUE_MAP_TABLE_NAME "TC_TO_QUEUE_MAP_TABLE"
Expand Down
12 changes: 12 additions & 0 deletions common/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ class Table : public TableBase, public TableEntryEnumerable {
virtual void del(const std::string &key,
const std::string &op = "",
const std::string &prefix = EMPTY_PREFIX);

#ifdef SWIG
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatiblity
// TODO: remove this function after applications use the function name `delete`
%pythoncode %{
def _del(self, *args, **kwargs):
return self.delete(*args, **kwargs)
%}
#endif

virtual void hdel(const std::string &key,
const std::string &field,
const std::string &op = "",
Expand Down
17 changes: 17 additions & 0 deletions pyext/swsscommon.i
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%module swsscommon

%rename(delete) del;

%{
#include "schema.h"
#include "dbconnector.h"
Expand All @@ -21,6 +23,7 @@
#include "notificationconsumer.h"
#include "notificationproducer.h"
#include "warm_restart.h"
#include "logger.h"
%}

%include <std_string.i>
Expand All @@ -29,6 +32,19 @@
%include <std_map.i>
%include <typemaps.i>
%include <stdint.i>
%include <exception.i>

%exception {
try
{
$action
}
SWIG_CATCH_STDEXCEPT // catch std::exception derivatives
catch (...)
{
SWIG_exception(SWIG_UnknownError, "unknown exception");
}
}

%template(FieldValuePair) std::pair<std::string, std::string>;
%template(FieldValuePairs) std::vector<std::pair<std::string, std::string>>;
Expand Down Expand Up @@ -122,3 +138,4 @@ T castSelectableObj(swss::Selectable *temp)
%include "notificationproducer.h"
%include "warm_restart.h"
%include "dbinterface.h"
%include "logger.h"
10 changes: 10 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from swsscommon import swsscommon

def test_set_log_level():
swsscommon.Logger.getInstance().setMinPrio(swsscommon.Logger.SWSS_INFO)
level = swsscommon.Logger.getInstance().getMinPrio()
assert level == swsscommon.Logger.SWSS_INFO

swsscommon.Logger.getInstance().setMinPrio(swsscommon.Logger.SWSS_ERROR)
level = swsscommon.Logger.getInstance().getMinPrio()
assert level == swsscommon.Logger.SWSS_ERROR
7 changes: 7 additions & 0 deletions tests/test_redis_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def test_DBInterface():
assert "field1" in fvs
assert fvs["field1"] == "value2"

# Test del
db.set("TEST_DB", "key3", "field4", "value5")
deleted = db.delete("TEST_DB", "key3")
assert deleted == 1
deleted = db.delete("TEST_DB", "key3")
assert deleted == 0

# Test dict.get()
assert fvs.get("field1") == "value2"
assert fvs.get("field1_noexisting") == None
Expand Down

0 comments on commit 3458442

Please sign in to comment.