[mac-filter] change whitelist/blacklist to allowlist/denylist (#5507)

To promote inclusivity and eliminate any unintentional bias.
This commit is contained in:
Jonathan Hui
2020-09-11 16:03:39 -07:00
committed by GitHub
parent 11faac0aad
commit 5bffd8bc4d
162 changed files with 970 additions and 981 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ Syntax
::
./start.sh [-h] [--pattern PATTERN] [--delete-blacklist] [--skip SKIP]
./start.sh [-h] [--pattern PATTERN] [--delete-denylist] [--skip SKIP]
[--dry-run] [--result-file RESULT_FILE]
[--list-file LIST_FILE] [--continue-from CONTINUE_FROM]
[--auto-reboot] [--manual-reset] [--list-devices]
@@ -24,4 +24,4 @@ Syntax
If ``-l`` is given, ``NAME`` is the serial port device name. Otherwise ``NAME`` is test case name. This enables running single or multiple test cases directly.
Use ``./start.sh --help`` for a full list of options.
Use ``./start.sh --help`` for a full list of options.
@@ -40,7 +40,7 @@ class HistoryHelper(object):
self.data = json.load(open(filename, 'r'))
except Exception:
self.logger.exception('file may not exists')
self.data = {'golden_device_black_list': []}
self.data = {'golden_device_denylist': []}
self.save()
def save(self):
@@ -48,11 +48,11 @@ class HistoryHelper(object):
def mark_bad_golden_device(self, port):
self.logger.warning('mark serial port[%s] as bad', port)
self.data['golden_device_black_list'].append(port)
self.data['golden_device_denylist'].append(port)
self.save()
def is_bad_golden_device(self, port):
return port in self.data['golden_device_black_list']
return port in self.data['golden_device_denylist']
def __str__(self):
return json.dumps(self.data, indent=2)
@@ -377,10 +377,10 @@ class OpenThreadController(threading.Thread):
time.sleep(1)
self._req('netdataregister')
def enable_blacklist(self):
"""Enable blacklist feature"""
self._req('blacklist enable')
def enable_denylist(self):
"""Enable denylist feature"""
self._req('denylist enable')
def add_blacklist(self, mac):
"""Add a mac address to blacklist"""
self._req('blacklist add %s' % mac)
def add_denylist(self, mac):
"""Add a mac address to denylist"""
self._req('denylist add %s' % mac)
@@ -178,7 +178,7 @@ def discover(
pattern=['*.py'],
skip='efp',
dry_run=False,
blacklist=None,
denylist=None,
name_greps=None,
manual_reset=False,
delete_history=False,
@@ -202,11 +202,11 @@ def discover(
if delete_history:
os.system('del history.json')
if blacklist:
if denylist:
try:
excludes = [line.strip('\n') for line in open(blacklist, 'r').readlines() if not line.startswith('#')]
excludes = [line.strip('\n') for line in open(denylist, 'r').readlines() if not line.startswith('#')]
except BaseException:
logger.exception('Failed to open test case black list file')
logger.exception('Failed to open test case denylist file')
raise
else:
excludes = []
@@ -257,7 +257,7 @@ def discover(
logger.info('case[%s] skipped by name greps', case_name)
continue
# whitelist
# allowlist
if len(names) and case_name not in names:
logger.info('case[%s] skipped', case_name)
continue
@@ -278,9 +278,9 @@ def discover(
else:
continue_from = None
# black list
# denylist
if case_name in excludes:
logger.warning('case[%s] skipped for blacklist', case_name)
logger.warning('case[%s] skipped for denylist', case_name)
continue
# max devices
@@ -342,9 +342,9 @@ def main():
nargs='*',
default=None,
help='test case name, omit to test all')
parser.add_argument('--blacklist',
parser.add_argument('--denylist',
'-b',
metavar='BLACKLIST_FILE',
metavar='DENYLIST_FILE',
type=str,
help='file to list test cases to skip',
default=None)
@@ -38,8 +38,8 @@ class Router_5_3_3(HarnessCase):
def on_dialog(self, dialog, title):
if title.startswith('Start DUT'):
self.dut.enable_blacklist()
self.dut.add_blacklist('166e0a000000005')
self.dut.enable_denylist()
self.dut.add_denylist('166e0a000000005')
if __name__ == '__main__':
@@ -38,8 +38,8 @@ class Router_5_3_3(HarnessCase):
def on_dialog(self, dialog, title):
if title.startswith('Start DUT'):
self.dut.enable_blacklist()
self.dut.add_blacklist('166e0a000000005')
self.dut.enable_denylist()
self.dut.add_denylist('166e0a000000005')
if __name__ == '__main__':
+32 -32
View File
@@ -442,15 +442,15 @@ class OpenThreadTHCI(object):
else:
self.hasActiveDatasetToCommit = False
# restore whitelist/blacklist address filter mode if rejoin after
# restore allowlist/denylist address filter mode if rejoin after
# reset
if self.isPowerDown:
if self._addressfilterMode == 'whitelist':
if self.__setAddressfilterMode('whitelist'):
if self._addressfilterMode == 'allowlist':
if self.__setAddressfilterMode('allowlist'):
for addr in self._addressfilterSet:
self.addAllowMAC(addr)
elif self._addressfilterMode == 'blacklist':
if self.__setAddressfilterMode('blacklist'):
elif self._addressfilterMode == 'denylist':
if self.__setAddressfilterMode('denylist'):
for addr in self._addressfilterSet:
self.addBlockedMAC(addr)
@@ -898,14 +898,14 @@ class OpenThreadTHCI(object):
@API
def addBlockedMAC(self, xEUI):
"""add a given extended address to the blacklist entry
"""add a given extended address to the denylist entry
Args:
xEUI: extended address in hex format
Returns:
True: successful to add a given extended address to the blacklist entry
False: fail to add a given extended address to the blacklist entry
True: successful to add a given extended address to the denylist entry
False: fail to add a given extended address to the denylist entry
"""
print('%s call addBlockedMAC' % self.port)
print(xEUI)
@@ -920,16 +920,16 @@ class OpenThreadTHCI(object):
print('block device itself')
return True
if self._addressfilterMode != 'blacklist':
if self.__setAddressfilterMode('blacklist'):
self._addressfilterMode = 'blacklist'
if self._addressfilterMode != 'denylist':
if self.__setAddressfilterMode('denylist'):
self._addressfilterMode = 'denylist'
cmd = 'macfilter addr add %s' % macAddr
print(cmd)
ret = self.__executeCommand(cmd)[-1] == 'Done'
self._addressfilterSet.add(macAddr)
print('current blacklist entries:')
print('current denylist entries:')
for addr in self._addressfilterSet:
print(addr)
@@ -939,14 +939,14 @@ class OpenThreadTHCI(object):
@API
def addAllowMAC(self, xEUI):
"""add a given extended address to the whitelist addressfilter
"""add a given extended address to the allowlist addressfilter
Args:
xEUI: a given extended address in hex format
Returns:
True: successful to add a given extended address to the whitelist entry
False: fail to add a given extended address to the whitelist entry
True: successful to add a given extended address to the allowlist entry
False: fail to add a given extended address to the allowlist entry
"""
print('%s call addAllowMAC' % self.port)
print(xEUI)
@@ -956,16 +956,16 @@ class OpenThreadTHCI(object):
macAddr = self.__convertLongToHex(xEUI)
try:
if self._addressfilterMode != 'whitelist':
if self.__setAddressfilterMode('whitelist'):
self._addressfilterMode = 'whitelist'
if self._addressfilterMode != 'allowlist':
if self.__setAddressfilterMode('allowlist'):
self._addressfilterMode = 'allowlist'
cmd = 'macfilter addr add %s' % macAddr
print(cmd)
ret = self.__executeCommand(cmd)[-1] == 'Done'
self._addressfilterSet.add(macAddr)
print('current whitelist entries:')
print('current allowlist entries:')
for addr in self._addressfilterSet:
print(addr)
return ret
@@ -975,21 +975,21 @@ class OpenThreadTHCI(object):
@API
def clearBlockList(self):
"""clear all entries in blacklist table
"""clear all entries in denylist table
Returns:
True: successful to clear the blacklist
False: fail to clear the blacklist
True: successful to clear the denylist
False: fail to clear the denylist
"""
print('%s call clearBlockList' % self.port)
# remove all entries in blacklist
# remove all entries in denylist
try:
print('clearing blacklist entries:')
print('clearing denylist entries:')
for addr in self._addressfilterSet:
print(addr)
# disable blacklist
# disable denylist
if self.__setAddressfilterMode('disable'):
self._addressfilterMode = 'disable'
# clear ops
@@ -1003,21 +1003,21 @@ class OpenThreadTHCI(object):
@API
def clearAllowList(self):
"""clear all entries in whitelist table
"""clear all entries in allowlist table
Returns:
True: successful to clear the whitelist
False: fail to clear the whitelist
True: successful to clear the allowlist
False: fail to clear the allowlist
"""
print('%s call clearAllowList' % self.port)
# remove all entries in whitelist
# remove all entries in allowlist
try:
print('clearing whitelist entries:')
print('clearing allowlist entries:')
for addr in self._addressfilterSet:
print(addr)
# disable whitelist
# disable allowlist
if self.__setAddressfilterMode('disable'):
self._addressfilterMode = 'disable'
# clear ops
@@ -1319,7 +1319,7 @@ class OpenThreadTHCI(object):
self.networkDataRequirement = ''
# indicate if Thread device experiences a power down event
self.isPowerDown = False
# indicate AddressFilter mode ['disable', 'whitelist', 'blacklist']
# indicate AddressFilter mode ['disable', 'allowlist', 'denylist']
self._addressfilterMode = 'disable'
self._addressfilterSet = set() # cache filter entries
# indicate if Thread device is an active commissioner
+36 -36
View File
@@ -388,11 +388,11 @@ class OpenThread_WpanCtl(IThci):
"""
print('call setAddressFilterMode() %s' % mode)
try:
if mode in ('whitelist', 'blacklist'):
if mode in ('allowlist', 'denylist'):
cmd = self.wpan_cmd_prefix + 'setprop MAC:' + mode.capitalize() + ':Enabled 1'
elif mode == 'disable':
if self._addressfilterMode != 'disable':
assert self._addressfilterMode in ('whitelist', 'blacklist'), self._addressfilterMode
assert self._addressfilterMode in ('allowlist', 'denylist'), self._addressfilterMode
cmd = self.wpan_cmd_prefix + 'setprop MAC:' + self._addressfilterMode.capitalize() + ':Enabled 0'
else:
return True
@@ -416,15 +416,15 @@ class OpenThread_WpanCtl(IThci):
print('call startOpenThreadWpan')
try:
# restore whitelist/blacklist address filter mode if rejoin after
# restore allowlist/denylist address filter mode if rejoin after
# reset
if self.isPowerDown:
if self._addressfilterMode == 'whitelist':
if self.__setAddressfilterMode('whitelist'):
if self._addressfilterMode == 'allowlist':
if self.__setAddressfilterMode('allowlist'):
for addr in self._addressfilterSet:
self.addAllowMAC(addr)
elif self._addressfilterMode == 'blacklist':
if self.__setAddressfilterMode('blacklist'):
elif self._addressfilterMode == 'denylist':
if self.__setAddressfilterMode('denylist'):
for addr in self._addressfilterSet:
self.addBlockedMAC(addr)
time.sleep(1)
@@ -1021,14 +1021,14 @@ class OpenThread_WpanCtl(IThci):
ModuleHelper.WriteIntoDebugLogger('setNetworkkey() Error: ' + str(e))
def addBlockedMAC(self, xEUI):
"""add a given extended address to the blacklist entry
"""add a given extended address to the denylist entry
Args:
xEUI: extended address in hex format
Returns:
True: successful to add a given extended address to the blacklist entry
False: fail to add a given extended address to the blacklist entry
True: successful to add a given extended address to the denylist entry
False: fail to add a given extended address to the denylist entry
"""
print('%s call addBlockedMAC' % self.port)
print(xEUI)
@@ -1043,14 +1043,14 @@ class OpenThread_WpanCtl(IThci):
print('block device itself')
return True
if self._addressfilterMode != 'blacklist':
self.__setAddressfilterMode('blacklist')
if self._addressfilterMode != 'denylist':
self.__setAddressfilterMode('denylist')
cmd = self.wpan_cmd_prefix + 'insert MAC:Blacklist:Entries %s' % macAddr
cmd = self.wpan_cmd_prefix + 'insert MAC:Denylist:Entries %s' % macAddr
ret = self.__sendCommand(cmd)[0] != 'Fail'
self._addressfilterSet.add(macAddr)
print('current blacklist entries:')
print('current denylist entries:')
for addr in self._addressfilterSet:
print(addr)
@@ -1059,14 +1059,14 @@ class OpenThread_WpanCtl(IThci):
ModuleHelper.WriteIntoDebugLogger('addBlockedMAC() Error: ' + str(e))
def addAllowMAC(self, xEUI):
"""add a given extended address to the whitelist addressfilter
"""add a given extended address to the allowlist addressfilter
Args:
xEUI: a given extended address in hex format
Returns:
True: successful to add a given extended address to the whitelist entry
False: fail to add a given extended address to the whitelist entry
True: successful to add a given extended address to the allowlist entry
False: fail to add a given extended address to the allowlist entry
"""
print('%s call addAllowMAC' % self.port)
print(xEUI)
@@ -1076,14 +1076,14 @@ class OpenThread_WpanCtl(IThci):
macAddr = self.__convertLongToHex(xEUI)
try:
if self._addressfilterMode != 'whitelist':
self.__setAddressfilterMode('whitelist')
if self._addressfilterMode != 'allowlist':
self.__setAddressfilterMode('allowlist')
cmd = self.wpan_cmd_prefix + 'insert MAC:Whitelist:Entries %s' % macAddr
cmd = self.wpan_cmd_prefix + 'insert MAC:Allowlist:Entries %s' % macAddr
ret = self.__sendCommand(cmd)[0] != 'Fail'
self._addressfilterSet.add(macAddr)
print('current whitelist entries:')
print('current allowlist entries:')
for addr in self._addressfilterSet:
print(addr)
return ret
@@ -1092,25 +1092,25 @@ class OpenThread_WpanCtl(IThci):
ModuleHelper.WriteIntoDebugLogger('addAllowMAC() Error: ' + str(e))
def clearBlockList(self):
"""clear all entries in blacklist table
"""clear all entries in denylist table
Returns:
True: successful to clear the blacklist
False: fail to clear the blacklist
True: successful to clear the denylist
False: fail to clear the denylist
"""
print('%s call clearBlockList' % self.port)
# remove all entries in blacklist
# remove all entries in denylist
try:
print('clearing blacklist entries:')
print('clearing denylist entries:')
for addr in self._addressfilterSet:
print(addr)
# disable blacklist
# disable denylist
if self.__setAddressfilterMode('disable'):
# clear ops
for addr in self._addressfilterSet:
cmd = self.wpan_cmd_prefix + 'remove MAC:Blacklist:Entries ' + addr
cmd = self.wpan_cmd_prefix + 'remove MAC:Denylist:Entries ' + addr
self.__sendCommand(cmd)
self._addressfilterSet.clear()
@@ -1121,25 +1121,25 @@ class OpenThread_WpanCtl(IThci):
ModuleHelper.WriteIntoDebugLogger('clearBlockList() Error: ' + str(e))
def clearAllowList(self):
"""clear all entries in whitelist table
"""clear all entries in allowlist table
Returns:
True: successful to clear the whitelist
False: fail to clear the whitelist
True: successful to clear the allowlist
False: fail to clear the allowlist
"""
print('%s call clearAllowList' % self.port)
# remove all entries in whitelist
# remove all entries in allowlist
try:
print('clearing whitelist entries:')
print('clearing allowlist entries:')
for addr in self._addressfilterSet:
print(addr)
# disable whitelist
# disable allowlist
if self.__setAddressfilterMode('disable'):
# clear ops
for addr in self._addressfilterSet:
cmd = self.wpan_cmd_prefix + 'remove MAC:Whitelist:Entries ' + addr
cmd = self.wpan_cmd_prefix + 'remove MAC:Allowlist:Entries ' + addr
self.__sendCommand(cmd)
self._addressfilterSet.clear()
@@ -1453,7 +1453,7 @@ class OpenThread_WpanCtl(IThci):
self.networkDataRequirement = ''
# indicate if Thread device experiences a power down event
self.isPowerDown = False
# indicate AddressFilter mode ['disable', 'whitelist', 'blacklist']
# indicate AddressFilter mode ['disable', 'allowlist', 'denylist']
self._addressfilterMode = 'disable'
self._addressfilterSet = set() # cache filter entries
# indicate if Thread device is an active commissioner