0156c21eff
Why I did it There is a bug that the Port attributes in CONFIG_DB will be cleared if using sudo config macsec port add Ethernet0 or sudo config macsec port del Ethernet0 How I did it To fetch the port attributes before set/remove MACsec field in port table. Signed-off-by: Ze Gan <ganze718@gmail.com>
35 lines
816 B
Python
35 lines
816 B
Python
import pytest
|
|
import mock_tables # lgtm [py/unused-import]
|
|
from unittest import mock
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_cfgdb():
|
|
cfgdb = mock.Mock()
|
|
CONFIG = {
|
|
'PORT': {
|
|
'Ethernet0': {
|
|
"admin_status": "up"
|
|
}
|
|
}
|
|
}
|
|
|
|
def get_entry(table, key):
|
|
if table not in CONFIG or key not in CONFIG[table]:
|
|
return {}
|
|
return CONFIG[table][key]
|
|
|
|
def set_entry(table, key, data):
|
|
CONFIG.setdefault(table, {})
|
|
CONFIG[table].setdefault(key, {})
|
|
CONFIG[table][key] = data
|
|
|
|
def get_keys(table):
|
|
return CONFIG[table].keys()
|
|
|
|
cfgdb.get_entry = mock.Mock(side_effect=get_entry)
|
|
cfgdb.set_entry = mock.Mock(side_effect=set_entry)
|
|
cfgdb.get_keys = mock.Mock(side_effect=get_keys)
|
|
|
|
yield cfgdb
|