Skip to content

Commit 3458442

Browse files
authored
Merge branch 'master' into dynamic-buffer-calculation
2 parents e37a6fb + a2c82ff commit 3458442

10 files changed

+91
-4
lines changed

common/dbconnector.h

+11
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ class DBConnector : public RedisContext
146146

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

149+
#ifdef SWIG
150+
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
151+
// but applications already followed the old behavior of auto renamed `_del`.
152+
// So we implemented old behavior for backward compatiblity
153+
// TODO: remove this function after applications use the function name `delete`
154+
%pythoncode %{
155+
def _del(self, *args, **kwargs):
156+
return self.delete(*args, **kwargs)
157+
%}
158+
#endif
159+
149160
bool exists(const std::string &key);
150161

151162
int64_t hdel(const std::string &key, const std::string &field);

common/dbinterface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ std::vector<std::string> DBInterface::keys(const std::string& dbName, const char
106106
auto keys = m_redisClient.at(dbName).keys(pattern);
107107
if (keys.empty())
108108
{
109-
std::string message = "DB '{" + dbName + "}' is empty!";
109+
std::string message = "DB '{" + dbName + "}' is empty with pattern '" + pattern + "'!";
110110
SWSS_LOG_WARN("%s", message.c_str());
111111
throw UnavailableDataError(message, "hset");
112112
}

common/logger.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ void err_exit(const char *fn, int ln, int e, const char *fmt, ...)
3737
err_exit(__FUNCTION__, __LINE__, e, (fmt), ##args); \
3838
}
3939

40+
#ifdef __GNUC__
41+
# define ATTRIBUTE_NORTEURN __attribute__ ((noreturn))
42+
#else
43+
# define ATTRIBUTE_NORTEURN
44+
#endif
4045

4146
class Logger
4247
{
@@ -130,7 +135,8 @@ class Logger
130135

131136
static void swssPrioNotify(const std::string &component, const std::string &prioStr);
132137
static void swssOutputNotify(const std::string &component, const std::string &outputStr);
133-
[[ noreturn ]] void settingThread();
138+
139+
ATTRIBUTE_NORTEURN void settingThread();
134140

135141
LogSettingChangeObservers m_settingChangeObservers;
136142
std::map<std::string, std::string> m_currentPrios;

common/producerstatetable.h

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ class ProducerStateTable : public TableBase, public TableName_KeySet
2424
const std::string &op = DEL_COMMAND,
2525
const std::string &prefix = EMPTY_PREFIX);
2626

27+
#ifdef SWIG
28+
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
29+
// but applications already followed the old behavior of auto renamed `_del`.
30+
// So we implemented old behavior for backward compatiblity
31+
// TODO: remove this function after applications use the function name `delete`
32+
%pythoncode %{
33+
def _del(self, *args, **kwargs):
34+
return self.delete(*args, **kwargs)
35+
%}
36+
#endif
37+
2738
void flush();
2839

2940
int64_t count();

common/producertable.h

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ class ProducerTable : public TableBase, public TableName_KeyValueOpQueues
3535
const std::string &op = DEL_COMMAND,
3636
const std::string &prefix = EMPTY_PREFIX);
3737

38+
#ifdef SWIG
39+
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
40+
// but applications already followed the old behavior of auto renamed `_del`.
41+
// So we implemented old behavior for backward compatiblity
42+
// TODO: remove this function after applications use the function name `delete`
43+
%pythoncode %{
44+
def _del(self, *args, **kwargs):
45+
return self.delete(*args, **kwargs)
46+
%}
47+
#endif
48+
3849
void flush();
3950

4051
private:

common/schema.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace swss {
3838
#define APP_FDB_TABLE_NAME "FDB_TABLE"
3939
#define APP_PFC_WD_TABLE_NAME "PFC_WD_TABLE"
4040
#define APP_SWITCH_TABLE_NAME "SWITCH_TABLE"
41-
41+
4242
#define APP_COPP_TABLE_NAME "COPP_TABLE"
4343
#define APP_VRF_TABLE_NAME "VRF_TABLE"
4444
#define APP_VNET_TABLE_NAME "VNET_TABLE"
@@ -78,7 +78,7 @@ namespace swss {
7878
#define APP_HW_MUX_CABLE_TABLE_NAME "HW_MUX_CABLE_TABLE"
7979
#define APP_MUX_CABLE_COMMAND_TABLE_NAME "MUX_CABLE_COMMAND_TABLE"
8080
#define APP_MUX_CABLE_RESPONSE_TABLE_NAME "MUX_CABLE_RESPONSE_TABLE"
81-
81+
8282
#define APP_SYSTEM_PORT_TABLE_NAME "SYSTEM_PORT_TABLE"
8383

8484
#define APP_MACSEC_PORT_TABLE_NAME "MACSEC_PORT_TABLE"
@@ -94,6 +94,8 @@ namespace swss {
9494
#define APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME "BUFFER_PORT_INGRESS_PROFILE_LIST_TABLE"
9595
#define APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME "BUFFER_PORT_EGRESS_PROFILE_LIST_TABLE"
9696

97+
#define APP_NEIGH_RESOLVE_TABLE_NAME "NEIGH_RESOLVE_TABLE"
98+
9799
/***** TO BE REMOVED *****/
98100

99101
#define APP_TC_TO_QUEUE_MAP_TABLE_NAME "TC_TO_QUEUE_MAP_TABLE"

common/table.h

+12
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ class Table : public TableBase, public TableEntryEnumerable {
152152
virtual void del(const std::string &key,
153153
const std::string &op = "",
154154
const std::string &prefix = EMPTY_PREFIX);
155+
156+
#ifdef SWIG
157+
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
158+
// but applications already followed the old behavior of auto renamed `_del`.
159+
// So we implemented old behavior for backward compatiblity
160+
// TODO: remove this function after applications use the function name `delete`
161+
%pythoncode %{
162+
def _del(self, *args, **kwargs):
163+
return self.delete(*args, **kwargs)
164+
%}
165+
#endif
166+
155167
virtual void hdel(const std::string &key,
156168
const std::string &field,
157169
const std::string &op = "",

pyext/swsscommon.i

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
%module swsscommon
22

3+
%rename(delete) del;
4+
35
%{
46
#include "schema.h"
57
#include "dbconnector.h"
@@ -21,6 +23,7 @@
2123
#include "notificationconsumer.h"
2224
#include "notificationproducer.h"
2325
#include "warm_restart.h"
26+
#include "logger.h"
2427
%}
2528

2629
%include <std_string.i>
@@ -29,6 +32,19 @@
2932
%include <std_map.i>
3033
%include <typemaps.i>
3134
%include <stdint.i>
35+
%include <exception.i>
36+
37+
%exception {
38+
try
39+
{
40+
$action
41+
}
42+
SWIG_CATCH_STDEXCEPT // catch std::exception derivatives
43+
catch (...)
44+
{
45+
SWIG_exception(SWIG_UnknownError, "unknown exception");
46+
}
47+
}
3248

3349
%template(FieldValuePair) std::pair<std::string, std::string>;
3450
%template(FieldValuePairs) std::vector<std::pair<std::string, std::string>>;
@@ -122,3 +138,4 @@ T castSelectableObj(swss::Selectable *temp)
122138
%include "notificationproducer.h"
123139
%include "warm_restart.h"
124140
%include "dbinterface.h"
141+
%include "logger.h"

tests/test_logger.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from swsscommon import swsscommon
2+
3+
def test_set_log_level():
4+
swsscommon.Logger.getInstance().setMinPrio(swsscommon.Logger.SWSS_INFO)
5+
level = swsscommon.Logger.getInstance().getMinPrio()
6+
assert level == swsscommon.Logger.SWSS_INFO
7+
8+
swsscommon.Logger.getInstance().setMinPrio(swsscommon.Logger.SWSS_ERROR)
9+
level = swsscommon.Logger.getInstance().getMinPrio()
10+
assert level == swsscommon.Logger.SWSS_ERROR

tests/test_redis_ut.py

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ def test_DBInterface():
146146
assert "field1" in fvs
147147
assert fvs["field1"] == "value2"
148148

149+
# Test del
150+
db.set("TEST_DB", "key3", "field4", "value5")
151+
deleted = db.delete("TEST_DB", "key3")
152+
assert deleted == 1
153+
deleted = db.delete("TEST_DB", "key3")
154+
assert deleted == 0
155+
149156
# Test dict.get()
150157
assert fvs.get("field1") == "value2"
151158
assert fvs.get("field1_noexisting") == None

0 commit comments

Comments
 (0)