1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| import re import time
class FlexE():
def __init__(self, dut): self.dut = dut
def check_flexe_client(self, clientid, phyname, timeslot, n=3):
flag = False if clientid == 'all': clientid = 'brief'
phyname = [self.dut.gldict[name] if name in self.dut.gldict.keys() else name for name in phyname]
try: for _ in range(n): if flag: break self.flexe_client_table = [] flexeclientstate = self.dut.send_cmd(f'show flexe-client {clientid}') value = flexeclientstate.split('\n') client_item = {} for line in value: if 'Flexeclient Name' in line: if (len(client_item.items()) != 0): self.flexe_client_table.append(client_item) res = re.findall('\w+ ?\w+: *[\w\-/]* ?[\w\-/]*\w', line) for item in res: key, value = item.split(':') client_item[key.strip()] = value.strip() elif 'Client Timeslot' in line: client_item['Timeslot'] = [] elif 'Phy Name' in line: res = re.findall('\w+ ?\w+: *[\w\-/,]* ?[\w\-/,]*\w', line) timeslotinfo = {} for item in res: key, value = item.split(':') timeslotinfo[key.strip()] = value.strip() client_item['Timeslot'].append(timeslotinfo) elif self.dut.prompt in line: break
if (len(client_item.items()) != 0): self.flexe_client_table.append(client_item)
if len(self.flexe_client_table) == 0: self.dut.sys_log('无flexe client表项, 继续检查') time.sleep(10) continue
for phy, slot in zip(phyname, timeslot): for clientinfo in self.flexe_client_table: for phydict in clientinfo['Timeslot']: if (phy == phydict['Phy Name']) and (slot == phydict['Timeslot']): flag = True break else: flag = False
if flag: break
if not flag: self.dut.sys_log( f"{'flexe-phy:' if phyname else ''} {phyname if phyname else ''}, {'timeslot:' if timeslot else ''} {timeslot if timeslot else ''} 检查异常,继续检查" ) time.sleep(10) else: break
except Exception as e: self.dut.sys_log(e)
finally: return flag
def flexe_client_proc(self, phyports, timeslots, groupid, clientid, mode=1): flag = False phyports = [self.dut.gldict[name] if name in self.dut.gldict.keys() else name for name in phyports] if mode == 1: self.dut.send_cmd(f'config terminal\n') for port in phyports: rs1 = self.dut.send_cmd(f'interface {port} \nexit', )
rs1 = self.dut.send_cmd(f'interface flexe-group {groupid}')
for index, port in enumerate(phyports, 1): self.dut.send_cmd(f'bind {port} phy-num {index}')
self.dut.send_cmd(f'exit')
self.dut.send_cmd(f'interface flexe-client {clientid}\n' f'timeslot {timeslots}\n' f'commit\n' f'withdraw') elif mode == 2: self.dut.send_cmd(f'config terminal\n' f'interface flexe-client {clientid}\n' f'no timeslot\n' f'exit\n' f'no interface flexe-client {clientid}')
self.dut.send_cmd(f'interface flexe-group {groupid}')
for port in phyports: self.dut.send_cmd(f'no bind {port}') self.dut.send_cmd(f'exit\nno interface flexe-group {groupid}')
for port in phyports: self.dut.send_cmd(f'no interface {port}') self.dut.send_cmd('commit') return flag
|