Esempio n. 1
0
    def test_method(self):
        errorCount = 0
        card_type = None
        cf = self.config
        login_info = self.config.login_info
        ftp_addr = self.config.ftp_addr
        spn_info = database.get_spn_info(self.config)
        # the following dictionary is ONLY for Ciena rebranding.
        self.data_args = {}
        self.data_args["process_id"] = ""
        self.data_args["serial_number"] = ""
        self.data_args["operator"] = "SLCOperator"
        self.data_args["tdate"] = time.strftime("%Y-%m-%d")
        self.data_args["start_time"] = self.timestamp(self.starttime)
        self.data_args["stop_time"] = ""
        self.data_args["comments"] = ""
        self.data_args["approved"] = "Approved"
        self.data_args["ciena_pn"] = spn_info.copr
        self.data_args["ciena_clei"] = spn_info.clei
        self.data_args["spn"] = self.config.ser_no
        self.data_args["test_status"] = "PASS"

        rebranding = database.BrandingSnLinkage
        self.info("Retrieved SPN info...%s" % spn_info)
        self.info("Please select the customer: ")
        ui = self.config.userinterface
        # look into the BrandingSnLinkage table to find a match to ser_no
        # given
        ser_no = self.config.ser_no
        # now get and display customer code, prompt user to select the type of customer.
        customers = database.get_customers(self.config)
        customer_list, customer_dict = build_customer_list(customers)
        customer = ui.choose(customer_list)

        if customer != "Ciena":
            self.data_args["operator"] = "OpnextOperator"
            self.data_args["serial_number"] = self.config.ser_no

        db_conn = database.check_branding_tbl(cf, ser_no)
        if (db_conn.uploaded) and (customer == "Ciena"):
            self.info("Upload not needed")
            pass
        else:
            customer_sn = db_conn.customer_sn
            customer_id = db_conn.customer_id

            if customer == "Ciena":
                self.data_args["serial_number"] = db_conn.customer_sn
                self.info("Updating Branding databse...")
                self.endtime = timelib.now()
                self.data_args["stop_time"] = self.timestamp(timelib.now())
                upload_req = CienaSoapUpload()  # CienaSoap()
                self.info("Logging Into Ciena's system...")
                login_res = upload_req.Login
                self.info("Getting Process ID...")
                res_id = upload_req.GetAvailableProcesses
                process_id = get_single_xml_value(res_id, "ID")
                self.data_args["process_id"] = process_id
                data_args = self.data_args
                self.diagnostic("DATA posted to Ciena's website: %s" % data_args)
                # TestDataWithTheSystem
                test_res1 = upload_req.SaveDataToTheSystem(
                    process_id=data_args["process_id"],
                    serial_number=data_args["serial_number"],
                    operator=data_args["operator"],
                    tdate=data_args["tdate"],
                    start_time=data_args["start_time"],
                    stop_time=data_args["stop_time"],
                    comments=data_args["comments"],
                    approved=data_args["approved"],
                    ciena_pn=data_args["ciena_pn"],
                    ciena_clei=data_args["ciena_clei"],
                    spn=data_args["spn"],
                    test_status=data_args["test_status"],
                )
            else:  # generic template
                # for generic customer, we write out the results to a xml
                # template structure.
                data_args = self.data_args
                data_args["cust_id"] = customer_id
                del data_args["ciena_pn"]
                data_args["pn"] = self.config.part_no
                data_args["clei"] = data_args["ciena_clei"]
                data_args["copr"] = spn_info.copr
                del data_args["ciena_clei"]
                del data_args["tdate"]
                t = GenericResultsTemplate()
                results_xml = t.results_data_tpl % (
                    data_args["cust_id"],
                    data_args["serial_number"],
                    data_args["operator"],
                    data_args["start_time"],
                    data_args["stop_time"],
                    data_args["test_status"],
                    data_args["approved"],
                    data_args["clei"],
                    data_args["copr"],
                    data_args["pn"],
                )

                # save the xml result to a directory
                filename = self.save_object(results_xml, "results.xml")
                f_obj = file(filename, "r")
                user_info = login_info[customer]
                ftp_path = upload_via_ericsson_ftp(f_obj, customer_sn, user_info)
                self.info("Result XML stored in '%s'" % ftp_path)
            uploaded_status = 1
            uploaded_time = datetime.datetime.fromtimestamp(timelib.now())
            database.update_branding_tbl(
                self.config,
                self.config.ser_no,
                self.config.part_no,
                customer_sn,
                customer_id,
                uploaded_status,
                uploaded_time,
            )

        return self.passed("DataUpload test passed.")
Esempio n. 2
0
    def test_method(self):
        errorCount = 0
        card_type = None
        card_slot = self.config.default_card_slot
        cf = self.config
        expected_card_type = self.config.default_card_type
        cardInfoTagList = self.config.cardInfoTagList
        if expected_card_type != 'SC_MFG':
            cardInfoObjList = [CARD_INFO]
        else:
            cardInfoObjList = [SC_MFG]
        spn_info = database.get_spn_info(self.config)
        if spn_info is None:
            raise TestSuiteAbort, "No entry for part_no '%s' found ins SPN database!" % self.config.part_no
        # the following dictionary is ONLY for Ciena rebranding.
        self.data_args = {}
        self.data_args['process_id']= ''
        self.data_args['serial_number'] = ''
        self.data_args['operator'] = 'SLCOperator'
        self.data_args['tdate'] = time.strftime("%Y-%m-%d")
        self.data_args['start_time'] = self.timestamp(self.starttime)
        self.data_args['stop_time'] = ''
        self.data_args['comments'] = ''
        self.data_args['approved'] = 'Approved'
        self.data_args['ciena_pn'] = spn_info.copr
        self.data_args['ciena_clei'] = spn_info.clei
        self.data_args['spn'] = self.config.ser_no
        self.data_args['test_status'] = 'PASS'
        

        self.info("Retrieved SPN info...%s" %  spn_info)
        self.info("Please select the customer: ")
        ui = self.config.userinterface
        # now get and display customer code, prompt user to select the type of customer.
        customers = database.get_customers(self.config)
        customer_list, customer_dict = build_customer_list(customers)
        customer = ui.choose(customer_list)

        # depending of the customer, we get the serial number differently
        customer_sn = get_sn_by_customer_id(self, spn_info, customer)
        if customer_sn:
            setattr(spn_info, 'sn', customer_sn)
            self.data_args['serial_number'] = customer_sn
        else:
            if customer == 'Ciena':
                raise TestSuiteAbort, "Unable to retrieve serial number from Ciena webservice!"
            else:
                # set the customer_sn same as given
                customer_sn = self.config.ser_no
            #customer_sn = ui.user_input("Please enter Customer ReBranding serial number: ")
            #setattr(spn_info, 'sn', customer_sn)
        
        if spn_info is None:
            if self.config.has_key('sopr'):
                self.failed("Unable to find match for sopr '%s' in SPN database" % cf.sopr)
            else:
                self.failed("Unable to find match for pn '%s' in SPN database" % cf.part_no)
            errorCount += 1
        else:
            #self.Zircon.bp_clear()   # clear buffer
            required_fields = self.config.required_fields
            if self.config.flags.IGNORE:
                required_fields = []  # ignore required_fields
                self.diagnostic("Warning: required fields from SPN are being ignored!")
                errorCount += 1
            spn_card_type = spn_info.card_type
            if spn_card_type.strip() != expected_card_type.strip():
                return self.error("Card type mismatch, expected: %s, got %s" % (expected_card_type, spn_card_type))
            else:
                card_type = expected_card_type

            for field in required_fields:
                val = getattr(spn_info, field)
                if val is None:
                    return self.error("Required field '%s' is empty in SPN databse, please correct it first!" % field)
            if card_type != 'SC_MFG':
                res = self.Zircon.bp_start(card_type, card_slot)
                if not res:
                    errorCount += 1
                    self.error("ERROR: problem with starting bp")
                    self.diagnostic(res)

            for obj, tag in zip(cardInfoObjList, cardInfoTagList):
                tagXf = obj()
                # display the info that will be stored into the EEPROM.
                # prompt if user accepts it or not.  If not, then display each in
                # turn
                cardInfoXmlTag = self.display_card_info(tag, tagXf, spn_info, required_fields)
                while 1:
                    ans = upper(self.user_input("Do you accept these values [y/n]:"))
                    if ans == 'N':
                        cardInfoXmlTag = self.enter_card_info_tag(tag, tagXf, spn_info, required_fields)
                        break
                    elif ans == 'Y':
                        break
                    else:
                        pass
            self.info("Writing data into EEPROM, please wait...")
            if card_type != 'SC_MFG':
                self.info("Clearing buffer...")
                self.Zircon.bp_clear()   # clear buffer
                self.Zircon.bp_data(cardInfoXmlTag) # write data
            else:
                self.Zircon.download(cardInfoXmlTag, True) # write data
                
            self.info("Verifying EEPROM contents...")
            if card_type != 'SC_MFG':
                res = self.Zircon.upload_card_info(card_type, card_slot)
            else:
                res = self.Zircon.upload_sc_mfg()

            self.info(res)
            rv = cmp_xml_tag(tagXf, res)
            # output the CARD_INFO XML tag to a file.
            self.save_object(res, self.config.MfgTagFileName)

            if rv:
                self.failed("Failed on verify on tag '%s'" % rv)
                errorCount += 1
            else:
                self.passed("EEPROM Contents verified successfully!")
            # XXX: do a final comparison agaist SPN database.  Fail test if
            # tagXf does not compare against required_fileds
            cmp_res = self.cmp_tag_vs_spn(tagXf, spn_info, required_fields)
            if not cmp_res:
                errorCount += 1
                self.failed("Data in EEPROM does not match SPN...")
        uploaded_status = 0
        if errorCount:
            return self.failed("ReBranding test failed.")
        else:
            self.info("Updating Branding databse...")
            self.endtime = timelib.now()
            customer_id = customer_dict[customer]
            utime = timelib.now()
            uploaded_time = datetime.datetime.fromtimestamp(utime)
##            if customer == 'Ciena':
##                self.data_args['stop_time'] = self.timestamp(timelib.now())
##                upload_req = CienaSoapUpload()#CienaSoap()
##                self.info("Logging Into Ciena's system...")
##                login_res = upload_req.Login
##                self.info("Getting Process ID...")
##                res_id = upload_req.GetAvailableProcesses
##                process_id = get_single_xml_value(res_id, 'ID')
##                self.data_args['process_id'] = process_id
##                data_args = self.data_args
##                self.diagnostic("DATA posted to Ciena's website: %s" % data_args)
##                test_res1 = upload_req.TestDataWithTheSystem(process_id=data_args['process_id'],
##                                                             serial_number=data_args['serial_number'],
##                                                             operator = data_args['operator'],
##                                                             tdate = data_args['tdate'],
##                                                             start_time = data_args['start_time'],
##                                                             stop_time = data_args['stop_time'],
##                                                             comments = data_args['comments'],
##                                                             approved = data_args['approved'],
##                                                             ciena_pn = data_args['ciena_pn'],
##                                                             ciena_clei = data_args['ciena_clei'],
##                                                             spn = data_args['spn'],
##                                                             test_status = data_args['test_status'],
##                                                             )                

        database.update_branding_tbl(self.config, self.config.ser_no,
                self.config.part_no, customer_sn,
                customer_id, uploaded_status, uploaded_time)
        
        self.diagnostic("Please remember to print out the label for %s" % customer_sn)
        return self.passed("ReBranding test passed.")