Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ class HostConfigDaemon:
def callback(table, key, data):
if data is None:
op = "DEL"
data = {}
else:
op = "SET"
return func(key, op, data)
Expand Down
3 changes: 3 additions & 0 deletions tests/common/mock_configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def get_table(self, table_name):
def subscribe(self, table_name, callback):
self.handlers[table_name] = callback

def publish(self, table_name, key, op, data):
self.handlers[table_name](key, op, data)

def listen(self, init_data_handler=None):
for e in MockConfigDb.event_queue:
self.handlers[e[0]](e[0], e[1], self.get_entry(e[0], e[1]))
Expand Down
40 changes: 40 additions & 0 deletions tests/hostcfgd/hostcfgd_tacacs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,43 @@ def test_hostcfgd_sshd_not_empty(self, test_name, test_data):
]
mocked_syslog.assert_has_calls(expected)

@parameterized.expand(HOSTCFGD_TEST_TACACS_VECTOR)
def test_hostcfgd_delete_config_table(self, test_name, test_data):
"""
Test hostcfd delete config table check

Args:
test_name(str): test name
test_data(dict): test data which contains initial Config Db tables, and expected results

Returns:
None
"""
config_name = "config_db_local"
op_path = output_path + "/" + test_name + "_" + config_name
sop_path = sample_output_path + "/" + test_name + "_" + config_name
host_config_daemon = self.mock_hostcfgd(test_data, config_name, op_path, sop_path)
host_config_daemon.register_callbacks()

# render with delete config table
original_syslog = hostcfgd.syslog
with mock.patch('hostcfgd.syslog.syslog') as mocked_syslog:
mocked_syslog.LOG_INFO = original_syslog.LOG_INFO
mocked_syslog.LOG_ERR = original_syslog.LOG_ERR

# simulate subscribe callback
try:
host_config_daemon.__dict__['config_db'].publish('AAA', 'authorization', 'DEL', None)
except TypeError as e:
assert False

# check sys log
expected = [
mock.call(mocked_syslog.LOG_INFO, "file size check pass: {} size is (2139) bytes".format(hostcfgd.ETC_PAMD_SSHD)),
mock.call(mocked_syslog.LOG_INFO, "file size check pass: {} size is (4951) bytes".format(hostcfgd.ETC_PAMD_LOGIN)),
mock.call(mocked_syslog.LOG_INFO, "Found audisp-tacplus PID: "),
mock.call(mocked_syslog.LOG_INFO, "cmd - ['service', 'aaastatsd', 'stop']"),
mock.call(mocked_syslog.LOG_ERR, "['service', 'aaastatsd', 'stop'] - failed: return code - 1, output:\nNone"),
mock.call(mocked_syslog.LOG_INFO, "AAA Update: key: DEL, op: DEL, data: {}")
]
mocked_syslog.assert_has_calls(expected)