Exemple #1
0
def get_sn_by_customer_id(obj, spn_info, customer):
    cf = obj.config 
    if customer == 'Ciena':
        # check to see if we already have one
        db_conn = database.check_branding_tbl(cf, cf.ser_no)
        if db_conn:
            obj.info("Serial number (%s) in ReBranding database!" % cf.ser_no)
            while 1:
                ans = upper(obj.user_input("Do you want to get another one from Ciena?[y/n]:"))
                if ans == 'N':
                    cust_sn = db_conn.customer_sn
                elif ans == 'Y':
                    obj.info("Contacting Ciena web service to get new serial number")
                    cust_sn = get_ciena_sn(spn_info)
                    obj.info("Got new sn '%s' which will replace '%s'" % \
                            (cust_sn, db_conn.customer_sn))

                    break
                else:
                    pass 
        else:
            obj.info("Serial number (%s) not in ReBranding database!" % cf.ser_no)
            obj.info("Contacting Ciena web service to get new serial number")
            cust_sn = get_ciena_sn(spn_info)
    else:  # default to do nothing
        cust_sn = cf.ser_no #None

    return cust_sn
Exemple #2
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.")