def __init__(self, model=None, serial=None, cert=None): """ This is the constructor which initializes all attributes of CommunicatorEntity class @type model: C{str} @param model: Model Number of device Defaults to POC_COMM_EXTERNAL_TO_MODEL_MAPPING if none is provided. @type serial: C{str} @param serial: Serial Number of POC Communicator, random seven digit number is generated if none is provided. @type cert: C{str} @param cert: Communicator Certificate into database. Uses default certificate if none is provided. """ if model is None: model = POC_COMM_EXTERNAL_TO_MODEL_MAPPING[getExternal()] if serial is None: serial = generateSerialNumber() super(POCCommunicatorEntity, self).__init__(model, serial) if cert is None: self._certificate = DEFAULT_POC_COMM_CERT else: self._certificate = cert logger.info( "Created a POC Communicator with model = %s and serial = %s" % (self.modelNumber, self.serialNumber) )
def getUnusedPOCCommunicator(self): # Find a serial number not used, give up after 10 tries for i in range(10): serial = generateSerialNumber() commEntity = POCCommunicatorEntity(POC_COMM_EXTERNAL_TO_MODEL_MAPPING[self.context["external"]], serial) if not self.dataFactory._findDuplicatePOCComm(commEntity.modelNumber, commEntity.serialNumber): return commEntity time.sleep(2) else: msg = "Was not able to find a unique serial # for the test." self.log.error(msg) raise Exception("Was not able to find a unique serial # for the test.")
def __init__( self, model=None, serial=None, rfCenterFrequency=None, wakeUpAccessCode=None, systemBOLTimeStamp=datetime.datetime.now(), implantDate=datetime.date.today(), ): """ This is the constructor which initializes attributes of PGEntity class @type model: C{str} @param model: Model Number of PG (Required). @type serial: C{str} @param serial: Serial Number of PG. A random seven digit number is generated if none is provided. @type rfCenterFrequency: C{str} @param rfCenterFrequency: RF Center Frequency of PG. Defaults to Band-specific frequencies in the komodors.ini file. @type wakeUpAccessCode: C{str} @param wakeUpAccessCode: Wake-up Access code of PG. Defaults to '10002'. @type systemBOLTimeStamp: C{datetime.datetime} @param systemBOLTimeStamp: Begining of life timestamp of PG. Defaults to current date/time (i.e. now). @type implantDate: C{datetime.date} @param implantDate: Implant Date of PG. Defaults to today's date. """ if model is None: model = getImplantable() if serial is None: serial = generateSerialNumber() super(PGEntity, self).__init__(model, serial) if wakeUpAccessCode is not None: self._wakeUpAccessCode = str(wakeUpAccessCode) else: self._wakeUpAccessCode = perseus.config.getProperty("wakeupAccessCode", "PG", "10002") if rfCenterFrequency: self._rfCenterFrequency = str(rfCenterFrequency) else: self._rfCenterFrequency = self._getBandSpecificCenterFrequency() if isinstance(systemBOLTimeStamp, datetime.datetime): self._systemBOLTimeStamp = systemBOLTimeStamp else: raise TypeError("systemBOLTimeStamp must be a datetime.datetime object") if isinstance(implantDate, datetime.date): self._implantDate = implantDate else: raise TypeError("implantDate must be a datetime.date object") logger.info("Created a PG with model = %s and serial = %s" % (self.modelNumber, self.serialNumber))