diff --git a/common/dbconnector.h b/common/dbconnector.h index 807f9e576..31cf0f1d8 100644 --- a/common/dbconnector.h +++ b/common/dbconnector.h @@ -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); diff --git a/common/dbinterface.cpp b/common/dbinterface.cpp index dc86ffade..dc1ea6f6b 100644 --- a/common/dbinterface.cpp +++ b/common/dbinterface.cpp @@ -106,7 +106,7 @@ std::vector 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"); } diff --git a/common/logger.h b/common/logger.h index 74d6f7992..145889843 100644 --- a/common/logger.h +++ b/common/logger.h @@ -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 { @@ -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 m_currentPrios; diff --git a/common/producerstatetable.h b/common/producerstatetable.h index 990dcdcb1..106e4f0ff 100644 --- a/common/producerstatetable.h +++ b/common/producerstatetable.h @@ -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(); diff --git a/common/producertable.h b/common/producertable.h index fadba2f36..0929aa001 100644 --- a/common/producertable.h +++ b/common/producertable.h @@ -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: diff --git a/common/schema.h b/common/schema.h index b67d4591d..0a580cc7c 100644 --- a/common/schema.h +++ b/common/schema.h @@ -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" @@ -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" @@ -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" diff --git a/common/table.h b/common/table.h index 3b045866c..f7250c372 100644 --- a/common/table.h +++ b/common/table.h @@ -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 = "", diff --git a/pyext/swsscommon.i b/pyext/swsscommon.i index c06badb08..b3731b737 100644 --- a/pyext/swsscommon.i +++ b/pyext/swsscommon.i @@ -1,5 +1,7 @@ %module swsscommon +%rename(delete) del; + %{ #include "schema.h" #include "dbconnector.h" @@ -21,6 +23,7 @@ #include "notificationconsumer.h" #include "notificationproducer.h" #include "warm_restart.h" +#include "logger.h" %} %include @@ -29,6 +32,19 @@ %include %include %include +%include + +%exception { + try + { + $action + } + SWIG_CATCH_STDEXCEPT // catch std::exception derivatives + catch (...) + { + SWIG_exception(SWIG_UnknownError, "unknown exception"); + } +} %template(FieldValuePair) std::pair; %template(FieldValuePairs) std::vector>; @@ -122,3 +138,4 @@ T castSelectableObj(swss::Selectable *temp) %include "notificationproducer.h" %include "warm_restart.h" %include "dbinterface.h" +%include "logger.h" diff --git a/tests/test_logger.py b/tests/test_logger.py new file mode 100644 index 000000000..178dc274e --- /dev/null +++ b/tests/test_logger.py @@ -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 diff --git a/tests/test_redis_ut.py b/tests/test_redis_ut.py index cc934e475..8cefc01db 100644 --- a/tests/test_redis_ut.py +++ b/tests/test_redis_ut.py @@ -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