def run_database_editor(uri=database.DBURI): import os database.connect2db(uri) theme = DatabaseTheme("(%BStrataDB%N)> ") io = CLI.ConsoleIO() ui = CLI.UserInterface(io, None, theme) cmd = DatabaseEditor(ui) cmd._reset_scopes() parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_database")) parser.interact()
def _update_uut(self): # now set the configuration db values tb = self._obj._config.get("testbed") if tb: uut = tb.UUT.godzilla sn = self._user_input("UUT SN? ") database.connect2db(self._obj._config.DBURI) for obj in database.UUTBuild.select(database.UUTBuild.q.UutSN==sn): uut.serialNumber = obj.UutSN uut.assemblyNumber = obj.UutAssyNum uut.revision = obj.UutAssyRev uut.Date = obj.Date self._obj._config.commit() else: self._print("No testbed set.")
def runtime_config(cf): """ connects to the database based on cf.DBURI, if the option --dburi is given then try to connect to the database specified by that command line option. Otherwise, use the default setting, which is 'localhost' """ if 'DBURI' in os.environ.keys(): cf.DBURI = os.environ['DBURI'] hostname = cf.get('DBURI') ##### if hostname is not None: dburi = 'mysql://*****:*****@%s/%s' % (hostname, cf.TESTRESULTS_DBURI) cf.DBURI = dburi database.connect2db(cf.DBURI)
def runtime_config(cf): """ connects to the database based on cf.DBURI, if the option --dburi is given then try to connect to the database specified by that command line option. Otherwise, use the default setting, which is 'localhost' """ # connect to the SQL database #cf.DBURI = "mysql://*****:*****@localhost/Titan" #uncomment to override slstorage cf.SPN_DBURI = "mysql://*****:*****@localhost/SPN" if 'DBURI' in os.environ.keys(): cf.DBURI = os.environ['DBURI'] hostname = cf.get('dburi') if 'L_BAND' in cf.testbedname: cf.DBURI = cf.DBURI + "_L_BAND" print "debug hostname=%s DBURI=%s" % (hostname, cf.DBURI) if hostname is not None: dburi = 'mysql://*****:*****@' + hostname + '/NextGen' cf.DBURI = dburi database.connect2db(cf.DBURI) connect_user(cf)
def lookup_uuts(self, rpt): """lookup_uuts(), returns a list of UUTs """ # cf is a RootContainer object cf = self._config # read slstorage element (the chasis) to get the number of slots there. #slots = cf.testbed._get_chassisItems().get_slots() ui = self._config.userinterface uut_dict = self.get_uuts_from_cmd_line() """ use the len of the dictionary to determine if UUTs are specified in the command line. """ # lists to store each uut information sn_list = [] newUUT_list = [] #cfuut_list = [] conf_dict = {} #plims = [d.name for (i,d) in slots] if len(uut_dict) > 0: sn_list = uut_dict.values() # extract plim values as specified else: # nothing is specified, prompt user pass #if self._config.plim is None: # plim = ui.choose(plims, len(plims)-1, prompt="Plimulator holding UUT? ") #else: # plim = self._config.plim #sn_list.append(plim) #print "Verifying UUT serial number against database." for sn in sn_list: serno = sn self._config.serno = serno try: dbuut = list(database.UUTBuild.select(database.UUTBuild.q.UutSN==serno))[0] except: # XXX: need to take care of DB handling sys_DBURI = cf.DBURI + "-1" print "serial number not found in local database -- try %s" % sys_DBURI database.disconnect() try: database.connect2db(sys_DBURI) dbuut = list(database.UUTBuild.select(database.UUTBuild.q.UutSN==serno))[0] except: ex, val, tb = sys.exc_info() ui.error("The serial number was not found in the database!") rpt.add_message("ERROR", "No matching serial number found.") raise TestSuiteAbort, "Suite aborted. UUT %s not found." %(serno) #ex, val, tb = sys.exc_info() #ui.error("The serial number \"%s\" returned from the UUT was not found in the database!" \ #%(serno)) #rpt.add_message("ERROR", "No matching serial number found.") #raise TestSuiteAbort, "Suite aborted. UUT %s not found." %(serno) ui.info("serial number was found") database.disconnect() database.connect2db(cf.DBURI) #reconnect back to local DB slot_name = self.get_key_by_value(uut_dict, serno) # dictionary value is now a dictionary too # the keys are 'uut_obj' 'plim_name' 'plim_ip' 'slot' and 'uut_id' conf_dict[serno] = {} # if the testbed has uses a XoomServer use the port and address tb = self._config.testbed ## value of the dictionary is a list conf_dict[serno]['slot'] = slot_name.split('slot')[1] # slot on which the card sits if cf.upgrade: uut_slot_name = "UUT_slot%s_mfgtest" % conf_dict[serno]['slot'] else: uut_slot_name = "UUT_slot%s" % (conf_dict[serno]['slot']) try: uut_slot_mike_name = "UUT_slot%s_mike" % (conf_dict[serno]['slot']) conf_dict[serno]['mike'] = tb[uut_slot_mike_name] #conf_dict[serno]['mike'].close() except: ui.diagnostic("Warning, Mike-shell is not found!") try: uut_slot_mike_debug_name = "%s_mike_debug" % (uut_slot_name) conf_dict[serno]['mike_debug'] = tb[uut_slot_mike_debug_name] except: ui.error("No mike_debug port defined in database!") conf_dict[serno]['obj'] = tb[uut_slot_name] conf_dict[serno]['id'] = dbuut.id # via SQL DB lookup cf.uut_id = dbuut.id self._config.uut_id = dbuut.id pn = cf.part_no if ((not cf.part_no.startswith('2'))): if not cf._IGNORE_SN_CHECK: ui.info("Verifying serial number on the board against command line") sn_from_card = conf_dict[serno]['obj'].SN if sn_from_card != serno: raise TestSuiteAbort, "Serial number provided '%s' does not match EEPROM entry '%s'" % (serno, sn_from_card) else: ui.info("Serial number provided '%s' matches EEPROM entry '%s'" % (serno, sn_from_card)) else: ui.info("Serial number check skipped...") else: ui.info("Serial number check skipped...")
def get_uut(self, rpt): """get_uut() """ cf = self._config ui = self._config.userinterface if not cf.has_key('ser_no') and not cf.slot_specified: serno = ui.user_input("Enter serial number of UUT: ") else: serno = cf.ser_no try: dbuut = list(database.UUTBuild.select(database.UUTBuild.q.UutSN==serno))[0] except: sys_DBURI = cf.DBURI + "-1" print "serial number not found in local database -- try %s" % sys_DBURI database.disconnect() try: database.connect2db(sys_DBURI) dbuut = list(database.UUTBuild.select(database.UUTBuild.q.UutSN==serno))[0] except: ex, val, tb = sys.exc_info() ui.error("The serial number was not found in the database!") rpt.add_message("ERROR", "No matching serial number found.") raise TestSuiteAbort, "Suite aborted. UUT %s not found." %(serno) ui.info("serial number was found") database.disconnect() database.connect2db(cf.DBURI) #reconnect back to local DB try: cfuut = cf.testbed['UUT'] # get 860 config self._config.testbed.uut_sw_version = cfuut.version() except: cfuut = cf.testbed.UUT self._config.testbed.uut_sw_version = None if not cf._IGNORE_SN_CHECK: if self._config.testbed.uut_sw_version is None: raise TestSuiteAbort, "UUT has not finished booting up yet, please wait for a minute and try again..." cfuut.serialNumber = dbuut.UutSN cfuut.modelNumber = dbuut.UutAssyNum cfuut.revision = dbuut.UutAssyRev cfuut.date = dbuut.Date cfuut.uut_id = dbuut.id self._config.testbed.support_sw_version = self._config.module_ID from copy import copy self._config.testbed.UUT_INFO = copy(cfuut) if ((not cf.part_no.startswith('2'))): if (not cf._IGNORE_SN_CHECK): sn_from_card = cfuut.get_sn() if sn_from_card != cfuut.serialNumber: raise TestSuiteAbort, "Serial number given '%s' does not match that of the card '%s'" % (cfuut.serialNumber, sn_from_card) else: ui.info("Serial number given '%s' matches that of the card '%s'" % (dbuut.UutSN, sn_from_card)) else: ui.info("Serial number check skipped...") else: ui.info("Serial number check skipped...") self._config.uut_id = cfuut.uut_id self._config.cfuut = cfuut return cfuut
def get_database_editor(parent, uri=database.DBURI): database.connect2db(uri) cmd = parent.clone(DatabaseEditor, DatabaseTheme()) cmd._setup(None, "(%BStrataDB%N)> ") return cmd
def _update_db(self, uut_id=None): ui = self.config.userinterface if self.config.testbedname is None or self.ITEST is None: self.info("Skipping database record...") return None # no testresults record for tests that don't test anything rdb = self.config.resultsdirbase burl = self.config.baseurl resultsxmlfile=os.path.join(os.path.expandvars(self.config.resultsdir), self.config.resultsfilename) if self.config.retest_logging: if self.config.comment is None: # no note given, then comment is just hard-coded to 'Retest # Approved. self.config.comment = 'Retest Approved.' else: self.config.comment = 'Retest Approved.' + self.config.comment if self.config.comment is not None: if self.config.comment.startswith('='): self.config.comment = self.config.comment[1:] if self.config.comment.startswith('"') and self.config.comment.endswith('"'): # get rid of quotes self.config.comment = self.config.comment[1:-1] if os.path.isfile(resultsxmlfile): resultsxmlfile = resultsxmlfile[len(rdb):] else: resultsxmlfile = None # use the hardcoded value if none is given. if uut_id is None: uut_id = self.config.testbed.UUT_INFO.uut_id passfail = str(self.disposition[0])[0] sw_version_dict =self.config.testbed.uut_sw_version try: uut_sw_version = sw_version_dict['MgmtFw'] except: uut_sw_version = 'N/A' support_sw_version=self.config.testbed.support_sw_version else: uut_obj = self._get_uut_obj(uut_id) #passfail = 'P' # XXX: take this out. try: passfail = str(self.disposition[uut_id])[0] except: passfail = str(self.disposition[0])[0] try: uut_sw_version = uut_obj.version()['Release'] except: # XXX temporary disable this until new Release SW. try: uut_sw_version = uut_obj.version().__repr__() except: uut_sw_version = 'N/A' support_sw_version = self.config.module_ID run_mode = self.config.run_mode database.connect2db(self.config.DBURI) signal.signal(signal.SIGCHLD, signal.SIG_IGN) #to avoid warning from pipe.close from commands.getoutput #if environment variable IDTYPE == UUID, then use UUID for database entry id, else implicit auto-increment integer is used. if (("IDTYPE" in os.environ.keys()) and (os.environ["IDTYPE"]=="UUID")): tr = database.TestResults( id = (commands.getoutput('uuidgen -t')).strip(), UutSN=uut_id, TestName=self.test_name, PartNo = self.config.part_no, StartTime=datetime.datetime.fromtimestamp(self.starttime), EndTime= datetime.datetime.fromtimestamp(self.endtime), StationID = self.config.testbed.name, TestScript = self.config.module_ID, ConfigFile = self.config.config_ID, ResultsXMLFile=resultsxmlfile, ResultsDataFile = ",".join(map(lambda s: burl + "/testresults/" + s[len(rdb)+1:], map(str, self.config.reportfilenames))), User=str(self.config.user), Comments = self.config.comment, #PassFail=str(self.disposition[uut_id])[0]) PassFail=passfail, UutSwVersion=uut_sw_version, SupportSwVersion=support_sw_version, RunMode = run_mode, ) else: tr = database.TestResults( UutSN=uut_id, TestName=self.test_name, PartNo = self.config.part_no, StartTime=datetime.datetime.fromtimestamp(self.starttime), EndTime= datetime.datetime.fromtimestamp(self.endtime), StationID = self.config.testbed.name, TestScript = self.config.module_ID, ConfigFile = self.config.config_ID, ResultsXMLFile=resultsxmlfile, ResultsDataFile = ",".join(map(lambda s: burl + "/testresults/" + s[len(rdb)+1:], map(str, self.config.reportfilenames))), User=str(self.config.user), Comments = self.config.comment, #PassFail=str(self.disposition[uut_id])[0]) PassFail=passfail, UutSwVersion=uut_sw_version, SupportSwVersion=support_sw_version, RunMode = run_mode, ) self.diagnostic("ID: %s" % tr.id) return tr.id