示例#1
0
    def createRandomDevices(self, deviceType, number, custId='1'):
        deviceData = []
        for i in range(0, number):
            map = {}
            map['name'] = "autoDevice" + deviceType + str(i + 1)
            map['type'] = deviceType
            map['ip'] = randomGen.getRandomIPAddr()
            map['custId'] = custId
            deviceData.append(map)

        return self.__createDevice(deviceData)
示例#2
0
 def sendEvent(self, msg, type):
     self.sock = socket(AF_INET, SOCK_DGRAM)
     if type == 'syslog':
         port = SYSLOG_PORT
         if '$randomNum' in msg:
             msg = msg.replace('$randomNum',
                               randomGen.getRandomNum(100, 900))
         if '$randomIP' in msg:
             msg = msg.replace('$randomIP', randomGen.getRandomIPAddr())
     elif type == 'netflow':
         port = NETFLOW_PORT
         msg = GenerateNetFlowData.getNetFlowPacket(msg)
     try:
         self.sock.connect((self.dataCollector, port))
     except error:
         print 'Cannot open socket to %s' % self.dataCollector
         exit()
     self.sock.sendall(msg)
示例#3
0
def createUsers(number, custName, adminUser, adminPass, include, exclude=False):
    myCustList=[]
    for i in range(number):
        if custName=="random":
            myCustName="autoCust"+str(i+1)
        else:
            myCustName=custName

        if include=="random":
            myInclude=randomGen.getRandomIPAddr()

        myCustFullName="Full name for "+myCustName
        myDesc="Autotest the customer "+myCustName
        adminEmail=adminUser.split("/")[1]+'@test.com'

        myCust=CustModel.customer(myCustName, myCustFullName, myDesc, adminUser, adminPass, adminEmail, myInclude, excludeRange=exclude)
        myCustList.append(myCust)

    myObj=CustModel.config(myCustList)
    node=XMLHelper.pickle(root=myObj, fabric=dom.Document(), elementName='config')

    return node.toxml()
示例#4
0
    def __createDeviceType(self, type, deviceName, deviceIp, custId):
        oldMap=create_device_info[type]
        if type in create_device_addon:
            base, addon=create_device_addon[type].split('->')
            tmpMap=create_device_info[base]
            if addon=='base':
                for mapKey in oldMap.keys():
                    tmpMap[mapKey]=oldMap[mapKey]
            else:
                tmpMap[addon].append(oldMap)
            infoMap=tmpMap
        else:
            infoMap=oldMap
        myDevice=getClassObj('device', module='device')
        myDevice=hashToClassHelper.hashToClass(infoMap, myDevice, objModule='device')
        myDevice.name=deviceName
        myDevice.accessIp=deviceIp
        myDevice.interfaces[0].ipv4Addr=deviceIp
        if hasattr(myDevice, 'attribute'):
            myDevice.attribute['custId']=custId
        else:
            map={'custId':custId}
            setattr(myDevice, 'attribute', map)
        for key in ['processors', 'storages', 'interfaces', 'installedSoftware', 'runningSoftware', 'swServices']:
            if hasattr(myDevice, key):
                subobjs=getattr(myDevice, key)
                for sub in subobjs:
                    if key=='interfaces':
                        if not getattr(sub, 'ipv4Addr'):
                            setattr(sub, 'ipv4Addr', randomGen.getRandomIPAddr())
                    if hasattr(sub, 'attribute'):
                        sub.attribute['custId']=custId
                    else:
                        map={'custId':custId}
                        setattr(sub, 'attribute', map)

        return myDevice
示例#5
0
                            '$time', now.strftime("%b %d %H:%M:%S"))
                        setMsg1 = setMsg0.replace(
                            '$fullTime', now.strftime("%a %b %d %H:%M:%S %Y"))
                        setMsg2 = setMsg1.replace('$reporter', case.reporter)
                        myHandler.sendEvent(setMsg2)
                        time.sleep(120)

                for i in range(0, int(case.repeatCount)):
                    for j in range(0, len(case.events)):
                        if testSuite.method == 'netflow':
                            realMsg = GenerateNetFlowData.getNetFlowPacket(
                                case.events[j].incidentMsg)
                        else:
                            if '$randomIP' in case.events[j].incidentMsg:
                                ipMsg = case.events[j].incidentMsg.replace(
                                    "$randomIP", randomGen.getRandomIPAddr())
                            elif 'randomNum' in case.events[j].incidentMsg:
                                ipMsg = case.events[j].incidentMsg.replace(
                                    "$randomNum",
                                    randomGen.getRandomNum(100, 900))
                            else:
                                ipMsg = case.events[j].incidentMsg
                            realMsg = ipMsg.decode()
                        myHandler.sendEvent(realMsg)
                        logging.debug(realMsg)
                    if case.repeatInterval != '':
                        time.sleep(float(case.repeatInterval))

            myHandler.udpClientClose()

    finalResult = None
示例#6
0
 def device_net_ip(self, map):
     map['device_net_ip']=randomGen.getRandomIPAddr()