flag = 1
log.info('Check the stack has elected Active and Standby')
if stk_count == 1:
output = uut.execute('show switch')
match = re.search('Active',output)
if match:
log.info('The Active has come up')
else:
log.info('The Active has not come up')
flag = 0
self.failed('The Active has not come up')
else:
loop_cnt = 50
for i in range(1,loop_cnt):
time.sleep(20)
output = uut.execute('show switch')
match = re.search('Standby',output)
match1 = re.search('Active',output)
if not match:
continue
elif match and match1:
log.info('The stack has elected Active and Standby')
log.info('Now Check the stack are in Ready state')
l_cnt = 15
for j in range(1,l_cnt):
time.sleep(20)
out = uut.execute('show switch')
match = re.search('HA sync in progress',out)
if match:
continue
else:
time.sleep(20)
break
input = uut.execute('show switch')
regex = re.compile('Ready')
check = regex.findall(input)
log.info('Check : %s',check)
status_count = len(regex.findall(input))
log.info('Status_count = %s', status_count)
if status_count!=stk_count:
flag = 0
log.info('Please Check the switch which is not in Ready state. Test Aborted')
break
elif i== 29:
log.info('Active and Standby Election not done properly')
flag = 0
return flag
output = uut.execute('show switch')
match = re.search('Active\s+([a-z0-9.]+)\s+(\d+).*Ready',output)
active_mac = match.group(1)
active_priority = match.group(2)
if stk_count>1:
match1 = re.search('Standby\s+([a-z0-9.]+)\s+(\d+).*Ready',output)
stdby_mac = match1.group(1)
stdby_priority = match1.group(2)
return (active_mac,active_priority,stdby_mac,stdby_priority)
else:
return (active_mac,active_priority)
log.info('Entering in to the getshowinfo proc %s' %uut)
switchinfo = defaultdict(dict)
uut.execute('enable')
output=uut.execute('show switch')
lines = output.splitlines()
for line in lines:
match = re.search("(\d+)\s+(\w+)\s+(\w+.\w+.\w+)\s+(\d+)\s+(\w+)\s+(\w+)", line)
'''
Switch/Stack Mac Address : 007e.9500.3000 - Local Mac Address
Mac persistency wait time: Indefinite
H/W Current
Switch# Role Mac Address Priority Version State
------------------------------------------------------------
*1 Active 007e.9500.3000 1 P2B Ready
2 Standby 682c.7bf7.1380 1 P2A Ready
3 Member 682c.7bf7.ce00 1 P2A Ready
'''
if match:
number = match.group(1)
switchinfo[number]['switch_no'] = int(match.group(1))
switchinfo[number]['role'] = match.group(2)
switchinfo[number]['mac_address'] = match.group(3)
switchinfo[number]['priority'] = int(match.group(4))
switchinfo[number]['version'] = match.group(5)
switchinfo[number]['state'] = match.group(6)
print(switchinfo)
return switchinfo
last_reset_reason = defaultdict(dict)
for sw_no in tot_sw_no:
cmd_to_execute = 'show logging onboard switch ' + sw_no + ' uptime detail'
reset_reason = uut.execute(cmd_to_execute)
reset_reason = reset_reason.splitlines()
for line in reset_reason:
if "Current reset reason" in line:
cur_reset_reason = line.split(':')[1]
cur_reset_reason_update = " ".join(cur_reset_reason.split())
log.info("Current Reset Reason is %s"%cur_reset_reason_update)
break
last_reason_line = re.search("([\d/]+)\s([\d:]+)\s+(.*)(\d+\s+\d+\s+\d+\s+\d+\s+\d+\s)",reset_reason[-3])
last_reason_line = " ".join(last_reason_line.groups()[2].split())
last_reset_reason[sw_no]['switch_number'] = sw_no
last_reset_reason[sw_no]['current_reset_reason'] = cur_reset_reason_update
last_reset_reason[sw_no]['last_reason_line'] = last_reason_line
return last_reset_reason
stack3-nyquist-1#sho logg onboard switch 1 uptime det
--------------------------------------------------------------------------------
UPTIME SUMMARY INFORMATION
--------------------------------------------------------------------------------
First customer power on : 12/21/2018 07:25:42
Total uptime : 1 years 18 weeks 6 days 20 hours 12 minutes
Total downtime : 0 years 21 weeks 4 days 4 hours 16 minutes
Number of resets : 932
Number of slot changes : 6
Current reset reason : Image Install
Current reset timestamp : 09/25/2020 14:54:39
Current slot : 1
Chassis type : 0
Current uptime : 0 years 0 weeks 4 days 17 hours 0 minutes
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
UPTIME CONTINUOUS INFORMATION
--------------------------------------------------------------------------------
Time Stamp | Reset | Uptime
MM/DD/YYYY HH:MM:SS | Reason | years weeks days hours minutes
--------------------------------------------------------------------------------
09/22/2020 16:39:24 Reload reason not captured 0 0 0 0 10
09/22/2020 16:44:06 Reload Command 0 0 0 0 0
09/22/2020 16:51:56 Reload reason not captured 0 0 0 0 5
09/22/2020 17:07:14 Reload reason not captured 0 0 0 0 10
09/25/2020 12:27:14 Image Install 0 0 0 2 59
09/25/2020 14:54:39 Image Install 0 0 0 2 0
--------------------------------------------------------------------------------
time.sleep(4)
child = pexpect.spawn(telnet_ssh + " " + ip + " " + power_port,timeout = 300)
if pdu_type == '':
child.expect('Username:',timeout = 300)
child.sendline(power_unit_username)
child.expect('Password:',timeout = 300)
child.sendline(power_unit_password)
child.expect(['#', '>'],timeout = 300)
else:
child.expect(['#', '>'],timeout = 300)
log.info(child)
try:
if pdu_type != '':
outlet_number = outlet_number.replace(',',' ')
poweroff_cmd = "/OFF " + str(outlet_number) + ',y'
poweron_cmd = "/ON " + str(outlet_number) + ',y'
else:
poweroff_cmd = "power outlets "+outlet_number+" off /y"
poweron_cmd = "power outlets "+outlet_number+" on /y"
child.sendline(poweroff_cmd)
child.sendline('\r')
log.info('sent off to outlet %s %s'%(ip,outlet_number))
time.sleep(10)
child.sendline(poweron_cmd)
child.sendline('\r')
log.info('sent on to outlet %s %s'%(ip,outlet_number))
child.sendline('\r')
child.expect(['#', '>'],timeout = 300)
string_op = child.before.decode('utf-8')
log.info("Power cycle command was issued and executed")
if(re.search(r"\^",string_op)):
raise InvalidExcpt
except InvalidExcpt:
log.info("Power Cycle command was not executed \n Command to power cycler was invalid")
return
IOx Infrastructure Summary:
---------------------------
IOx service (CAF) : Running
IOx service (HA) : Running
IOx service (IOxman) : Running
IOx service (Sec storage) : Not Running
Libvirtd : Running
Dockerd : Running
Application DB Sync Info : Available
Sync status : Successful
Last application sync time : 2020-09-28 20:46:50.069589
if((re.search("IOx\s+service\s+\(HA\)\s*\:\s*Running",out)) and (re.search("IOx\s+service\s+\(CAF\)\s*\:\s*Running",out)) and (re.search("IOx\s+service\s+\(IOxman\)\s*\:\s*Running",out
)) and (re.search("Libvirtd\s*\:\s*Running",out))) :
log.info('PASS : IOX service is running')
else :
self.failed('FAIL : IOX service is NOT running')