在fitnesse中输入为:
|!-fit.ActionFixture-!|
|start |!-LgChssMngAct-! |
|enter | slot | 1 |
|enter | card_type | OAM |
|press | !-CreateChss-!|
|check | res_info |success |
|enter | slot | 2 |
|enter | card_type | !-S64F01-! |
|press | !-CreateChss-!|
|check | res_info | fail |
|press | Try|
|check | res_info |success |
python脚本如下:
from fit.ActionFixture import ActionFixture
import os
from onshs.ne import NetRing
class LgChssMngAct(ActionFixture):
_typeDict={
"slot": "Int",
"card_type": "String",
"res_info": "String",
"CreateChss": "String",
"Try": "String",
}
def __init__(self):
self.slot = 0
self.ne1 = NetRing()
self.ne1.connect("127.0.0.1",3333,'hokotelne','nerpc2002')
self.result = 'fail'
def slot(self, slot):
self.slot = slot
def card_type(self, card_type):
self.card_type = card_type
def CheckRet(self, ret):
if ret.find('success') == -1:
self.result = 'fail'
else:
self.result = 'success'
def CreateChss(self):
#print os.environ['PYTHONPATH']
#print os.environ['device_ip']
str = '$.ne.lgChss.cfging.0.CreateChss 0,0,%d,%s'%(self.slot, self.card_type)
#ret = self.ne1.send('$.ne.lgChss.cfging.0.CreateChss 0,0,%s,%s'%(self.slot, self.card_type))
ret = self.ne1.send(str)
self.CheckRet( ret )
def Try(self):
ret = self.ne1.send('$.ne.0.TryCommit 0')
self.CheckRet( ret )
def res_info(self):
return self.result
测试效果如下:
fit.ActionFixture | ||
start | LgChssMngAct | |
enter | slot | 1 |
enter | card_type | OAM |
press | CreateChss | |
check | res_info | success |
enter | slot | 2 |
enter | card_type | S64F01 |
press | CreateChss | |
check | res_info | fail |
press | Try | |
check | res_info | success |
小提示:
1:如果在python的telnetlib.py 的write函数报:
IAC TypeError: 'in ' requires string as left operand
则将write函数修改如下:
(http://mail.python.org/pipermail/python-bugs-list/2007-August/039274.html)
def write(self, buffer):
try:
buffer = buffer.replace(IAC, IAC+IAC)
except UnicodeError:
pass
self.msg("send %r", buffer)
self.sock.sendall(buffer)
2:
在python脚本中的CreateChss,Try必须在_typeDict中定义,类型好像无所谓,但必须要填一个