Exemple #1
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script    
    """
    ret_worklist = ERR_FAIL  # default
    ret_rpc = ERR_FAIL
    ret_datas = ""
    sn = obj.sn
    # data传参
    ParameterList = obj.dict_data.get("ParameterList")

    for nwf in [1]:
        try:
            u1 = User(sn, ip=worklistcfg.AGENT_HTTP_IP, port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE, sender=KEY_SENDER_WORKLIST, worklist_id=obj.id_)
            log.app_info("Auto process set parameter value: %s " % ParameterList)
            ret_rpc, ret_data = u1.set_parameter_values(ParameterList=ParameterList)

            if ret_rpc == ERR_SUCCESS:
                ret_datas = ret_datas + "\n" + str(ret_data)
                log.app_info("success:%s" % ret_data)
            else:
                log.app_err("fail:%s" % ret_data)
                break

            ret_worklist = ERR_SUCCESS
            obj.dict_ret["str_result"] = ret_datas

        except Exception, e:
            log.app_err(e)
            break
Exemple #2
0
def ChangeAccount(obj, sn, change_account=1):
    """
    功能描述: 更改电信维护密码
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志
    u1 = User(sn,
              ip=worklistcfg.AGENT_HTTP_IP,
              port=worklistcfg.AGENT_HTTP_PORT,
              page=worklistcfg.WORKLIST2AGENT_PAGE,
              sender=KEY_SENDER_WORKLIST,
              worklist_id=obj.id_)

    # 调用修改电信维护密码,参照贝曼随机生成
    para_list = []
    password = random.randrange(10000000, 99999999)
    password = "******" + str(password)
    para_list.append(
        dict(Name=
             'InternetGatewayDevice.DeviceInfo.X_CT-COM_TeleComAccount.Enable',
             Value='1'))
    para_list.append(
        dict(
            Name=
            'InternetGatewayDevice.DeviceInfo.X_CT-COM_TeleComAccount.Password',
            Value=password))
    for nwf in [1]:
        try:
            # 贝曼的报文显示延时2S即下发修改帐号OK.但我们这个平台延时需较长才能组包完成.
            if change_account == 1:
                #sleep(10)
                info = u"调用SetParameterValues设置参数,修改电信维护密码\n"
                log.app_info(info)
                ret_data_scr += info

                ret, ret_data = u1.set_parameter_values(
                    ParameterList=para_list)
                if (ret == ERR_SUCCESS):
                    info = u"修改电信维护密码成功.密码为:%s\n" % password
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    #对于失败的情况,直接返回失败
                    info = u"修改电信维护密码失败,退出执行,错误原因:%s\n" % ret_data
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
            else:
                info = u"无需修改电信维护密码\n"
                log.app_info(info)
                ret_data_scr += info
            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #3
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script    
    """
    ret_worklist = ERR_FAIL  # default
    ret_rpc = ERR_FAIL
    ret_datas = ""
    sn = obj.sn

    for nwf in [1]:
        try:

            # data传参
            password = random.randrange(10000000, 99999999)
            password = "******" + str(password)

            ParameterList = [
                dict(
                    Name=
                    "InternetGatewayDevice.DeviceInfo.X_CT-COM_TeleComAccount.Enable",
                    Value="1"),
                dict(
                    Name=
                    "InternetGatewayDevice.DeviceInfo.X_CT-COM_TeleComAccount.Password",
                    Value=password)
            ]

            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            log.app_info("Auto process set parameter value: %s " %
                         ParameterList)
            ret_rpc, ret_data = u1.set_parameter_values(
                ParameterList=ParameterList)

            if (ret_rpc == ERR_SUCCESS):
                ret_datas = ret_datas + "\n" + str(ret_data)
                log.app_info("success:%s" % ret_data)
            else:
                log.app_err("fail:%s" % ret_data)
                break

            ret_worklist = ERR_SUCCESS
            obj.dict_ret["str_result"] = ret_datas

        except Exception, e:
            log.app_err(e)
            break
Exemple #4
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script    
    """
    ret_worklist = ERR_FAIL  # default
    ret_rpc = ERR_FAIL
    ret_datas = ""
    sn = obj.sn

    for nwf in [1]:
        try:
            # data传参
            password = random.randrange(10000000, 99999999)
            password = "******" + str(password)

            ParameterList = [
                dict(Name=
                     "InternetGatewayDevice.X_CU_Function.Web.AdminPassword",
                     Value=password)
            ]
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            log.app_info("Auto process set parameter value: %s " %
                         ParameterList)
            ret_rpc, ret_data = u1.set_parameter_values(
                ParameterList=ParameterList)
            ret_datas = ret_datas + "\n" + str(ret_data)
            if ret_rpc == ERR_SUCCESS:
                info = "success:%s" % ret_data
                log.app_info(info)
            else:
                info = "fail:%s" % ret_data
                log.app_err(info)
                break

            ret_worklist = ERR_SUCCESS

        except Exception, e:
            info = str(e)
            log.app_err(info)
            ret_datas = ret_datas + "\n" + info
            break
Exemple #5
0
def WAN(obj,
        sn,
        DeviceType,
        AccessMode,
        change_or_enable,
        dict_pvcorvlan,
        change_account=1):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."

    # 将传参数过来的字典中有效的PVC或VLAN提取出来
    tmp_pvcorvlan = []
    for i in dict_pvcorvlan:
        if dict_pvcorvlan[i][0] == 1:
            tmp_pvcorvlan.append([dict_pvcorvlan[i][1], dict_pvcorvlan[i][2]])
    if tmp_pvcorvlan == []:
        info = u"工单传参数错误,请检查\n"
        log.app_info(info)
        ret_data_scr += info
        return ret_res, ret_data_scr

    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)

            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找
            path2 = []
            para_list = []

            for i in xrange(len(ret_data_root['ParameterList'])):
                tmpflag = None
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #下面的临时变量可以根据上行方式,WAN连接类型进行修改
                if DeviceType == 'ADSL':
                    tmp_path2_1 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                elif DeviceType == 'LAN':
                    tmp_path2_1 = tmp_path2 + 'WANEthernetLinkConfig.X_CT-COM_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'EPON':
                    tmp_path2_1 = tmp_path2 + 'X_CT-COM_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'VDSL':
                    tmp_path2_1 = tmp_path2 + 'WANDSLLinkConfig.X_CT-COM_VLAN'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLAN值\n" % str(
                        i + 1)
                elif DeviceType == 'GPON':
                    tmp_path2_1 = tmp_path2 + 'X_CT-COM_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                else:
                    tmp_path2_1 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                log.app_err(info)
                ret_data_scr += info

                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(
                    ParameterNames=tmp_path2_1)
                if (ret2 == ERR_SUCCESS):
                    info = u"查询成功,返回:%s \n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    #当返回的PVC或VLAN与需要查找的相等时,处理;查到为空则继续往下
                    if ret_data2['ParameterList'] != []:
                        for j in xrange(len(tmp_pvcorvlan)):
                            #如果查到PVC相同,则标记;
                            if ret_data2['ParameterList'][0][
                                    'Value'] == tmp_pvcorvlan[j][0]:
                                #查到有匹配PVC
                                tmpflag = True
                                tmp_enable_or_change_value = tmp_pvcorvlan[j][
                                    1]
                                #将相应的PVC和Enable状态值删除
                                tmp_pvcorvlan.remove(tmp_pvcorvlan[j])
                                break
                            else:
                                #查不到匹配的PVC
                                tmpflag = False

                        if tmpflag != None:
                            # 查实例号.
                            if AccessMode == 'PPPoE' or AccessMode == "PPPoE_Bridged":
                                tmp_path2_2 = tmp_path2 + 'WANPPPConnection.'
                                info = u"开始调用GetParameterValues查找WANPPPConnection节点下的实例号\n"
                            else:
                                tmp_path2_2 = tmp_path2 + 'WANIPConnection.'
                                info = u"开始调用GetParameterValues查找WANIPConnection节点下的实例号\n"
                            log.app_info(info)
                            ret_data_scr += info

                            #sleep(3)
                            ret3, ret_data3 = u1.get_parameter_names(
                                ParameterPath=tmp_path2_2, NextLevel=1)
                            if (ret3 == ERR_SUCCESS):
                                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                                ret_data3 = DelOwnParameterNames(
                                    ret_data3, tmp_path2_2)

                                #当返回的PVC或VLAN与要绑定的相同时,待完善
                                # GCW 20130410 解决当查到为空时,无tmp_path2_3值而导致异常
                                tmp_path2_3 = []
                                if ret_data3['ParameterList'] == []:
                                    info = u"查找成功,返回为空。\n"
                                else:
                                    #如果查到PVC相同,则标记,(手动可能多实例的情况)
                                    #tmp_path2_3 = []  # 移到外层定义,避免在if中无定义上起后面问题
                                    for i in xrange(
                                            len(ret_data3['ParameterList'])):
                                        tmp_path2_3.append(
                                            ret_data3['ParameterList'][i]
                                            ['Name'])
                                    info = u"查找成功,返回为:%s \n" % tmp_path2_3
                                log.app_info(info)
                                ret_data_scr += info
                        if tmpflag == True:
                            # 如果是启用禁用PVC,则将使能路径和值追加,如果是修改PVC,则将WAN实例和PVC值追加
                            if change_or_enable == 'Enable':
                                for i in xrange(len(tmp_path2_3)):
                                    para_list.append(
                                        dict(Name=tmp_path2_3[i] + 'Enable',
                                             Value=tmp_enable_or_change_value))
                            elif change_or_enable == 'Change':
                                para_list.append(
                                    dict(Name=tmp_path2_1,
                                         Value=tmp_enable_or_change_value))
                            else:
                                info = u"参数错误.目前只支持启用禁用PVC(VLAN)或修改PVC(VLAN).\n"
                                log.app_info(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s \n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            #只要还有一个PVC没有查到,则失败,退出
            if len(tmp_pvcorvlan) != 0:
                info = u"有未查到的PVC或VLAN,请检查\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第四步,禁用或启用相应的PVC
            info = u"开始调用SetParameterValues设置相应WAN连接的参数\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)
            ret4, ret_data4 = u1.set_parameter_values(ParameterList=para_list)
            if (ret4 == ERR_SUCCESS):
                info = u"设置参数成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data4["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,直接返回错误
                info = u"设置参数失败,错误原因:%s\n" % ret_data4
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            # 调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #6
0
def WLAN(obj,
         sn,
         Num,
         dict_root,
         dict_WEPKey,
         dict_PreSharedKey,
         change_account=1,
         rollbacklist=[]):
    """                        
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    WLAN_ROOT_PATH = "InternetGatewayDevice.LANDevice.1.WLANConfiguration."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0
            # 第一步:调用GetParameterNames方法,查找当前有几个无线实例
            info = u"开始调用GetParameterNames方法,查找当前无线实例个数\n"
            log.app_info(info)
            ret_data_scr += info

            para_list = []
            path = WLAN_ROOT_PATH
            ret_root, ret_data1_root = u1.get_parameter_names(
                ParameterPath=path, NextLevel='1')
            # sleep(2)  # must be ;otherwise exception
            if ret_root == ERR_SUCCESS:
                info = u"查找当前无线实例个数成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data1_root = DelOwnParameterNames(ret_data1_root, path)
            else:
                # 对于失败的情况,直接返回失败
                info = u"查找当前无线实例失败.失败信息:%s\n" % ret_data1_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第二步:判断是否需要增加实例,如果不需要,则直接进入下一步的修改设置
            para_list = []
            path = WLAN_ROOT_PATH
            path2 = []
            # 将查到的实例号路径追加到列表中
            for i in xrange(len(ret_data1_root['ParameterList'])):
                path2.append(ret_data1_root['ParameterList'][i]['Name'])

            # 新建实例个数等于传参进来的个数减去查到已经存在的个数,但如要Num为0或者小于已有实例个数,则不需新建
            if int(Num) > len(ret_data1_root['ParameterList']):
                info = u"开始调用AddObject,增加无线实例\n"
                log.app_info(info)
                ret_data_scr += info
                for i in xrange(
                        int(Num) - len(ret_data1_root['ParameterList'])):
                    ret_addobject, ret_data_addobject = u1.add_object(
                        ObjectName=path)

                    # sleep(2)  # must be ;otherwise exception
                    if ret_addobject == ERR_SUCCESS:
                        instanceNum1 = ret_data_addobject["InstanceNumber"]
                        path2.append(path + instanceNum1 + '.')
                        info = u"增加无线实例成功,返回实例号:%s\n" % instanceNum1
                        log.app_info(info)
                        ret_data_scr += info
                        # GCW 20130327 增加回退机制
                        rollbacklist.append(path + instanceNum1 + '.')
                        rebootFlag = int(ret_data_addobject["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回失败
                        info = u"增加无线实例失败,失败信息:%s\n" % ret_data_addobject
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            else:
                info = u"已经开通的无线实例个数大于或等于 %s\n" % str(Num)
                log.app_info(info)
                ret_data_scr += info

            # 第三步:对队列各个参数进行配置
            for i in xrange(len(path2)):
                info = u"开始调用SetParameterValues对第%s个无线实例进行配置\n" % str(i + 1)
                log.app_info(info)
                ret_data_scr += info
                if dict_root['BeaconType'][1] == 'None':
                    # 不加密的情况
                    para_list = []
                    path = path2[i]
                    for j in dict_root:
                        if dict_root[j][0] == 1:
                            tmp_path = path + j
                            para_list.append(
                                dict(Name=tmp_path, Value=dict_root[j][1]))
                    if para_list == []:
                        return ret_res, ret_data_scr
                elif dict_root['BeaconType'][1] == 'Basic':
                    # WEP加密的情况
                    para_list = []
                    path = path2[i]
                    for j in dict_root:
                        if dict_root[j][0] == 1:
                            tmp_path = path + j
                            para_list.append(
                                dict(Name=tmp_path, Value=dict_root[j][1]))
                    if para_list == []:
                        return ret_res, ret_data_scr
                elif dict_root['BeaconType'][1] == 'WPA':
                    # WPA加密的情况
                    para_list = []
                    path = path2[i]
                    for j in dict_root:
                        if dict_root[j][0] == 1:
                            tmp_path = path + j
                            para_list.append(
                                dict(Name=tmp_path, Value=dict_root[j][1]))

                    # dict_PreSharedKey节点下的密钥也一起下发
                    path_PreSharedKey = path + 'PreSharedKey.1.'
                    for j in dict_PreSharedKey:
                        if dict_PreSharedKey[j][0] == 1:
                            tmp_path = path_PreSharedKey + j
                            para_list.append(
                                dict(Name=tmp_path,
                                     Value=dict_PreSharedKey[j][1]))
                    if para_list == []:
                        info = u"选择了WPA加密,但没有使能密钥的传参\n"
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                else:
                    # 其它的待完善.同时,需考虑在elif中兼容其它的方式
                    pass

                # 设置值
                ret_root, ret_data_root = u1.set_parameter_values(
                    ParameterList=para_list)
                # sleep(2)  # must be ;otherwise exception
                if ret_root == ERR_SUCCESS:
                    info = u"第%s个无线实例的参数配置成功\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data_root["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回错误
                    info = u"第%s个无线实例的参数配置失败,失败信息:%s\n" % (str(i + 1),
                                                           ret_data_root)
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 如果是WEP加密,则还需要设置KEY
                if dict_root['BeaconType'][1] == 'Basic':
                    info = u"开始调用SetParameterValues对第%s个无线实例的WEP密钥进行配置\n" % str(
                        i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    if dict_root['WEPKeyIndex'][0] != 1:
                        ret_data_scr += u"选择了WEP加密,但没有使能KEY索引的传参\n"
                        return ret_res, ret_data_scr  # KEY索引没有打开,不建议再判断索引值范围。
                    path_WEPKey = path2[i] + 'WEPKey.' + dict_root[
                        'WEPKeyIndex'][1] + '.WEPKey'
                    para_list = []
                    para_list.append(
                        dict(Name=path_WEPKey, Value=dict_WEPKey['WEPKey'][1]))
                    # 设置值
                    ret_WEPKey, ret_data_WEPKey = u1.set_parameter_values(
                        ParameterList=para_list)
                    # sleep(1)  # must be ;otherwise exception
                    if ret_WEPKey == ERR_SUCCESS:
                        info = u"对第%s个无线实例的WEP密钥进行配置成功\n" % str(i + 1)
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_WEPKey["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"对第%s个无线实例的WEP密钥进行配置失败,失败信息:%s\n" % (
                            str(i + 1), ret_data_WEPKey)
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if reboot_Yes == 1:

                # sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if ret != ERR_SUCCESS:
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改联通维护密码,目前密码固定为CUAdmin
            ret, ret_data = ChangeAccount_CU(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #7
0
def IPTVDisable(obj,
                sn,
                DeviceType,
                AccessMode,
                PVC_OR_VLAN,
                dict_root,
                dict_wanpppconnection,
                dict_wanipconnection,
                change_account=1):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用SetParameterValues设置X_CT-COM_IPTV参数:
            info = u"开始调用SetParameterValues设置X_CT-COM_IPTV参数\n"
            log.app_info(info)
            ret_data_scr += info

            para_list = []
            path = 'InternetGatewayDevice.Services.X_CT-COM_IPTV.'
            for i in dict_root:
                if dict_root[i][0] == 1:
                    tmp_path = path + i
                    para_list.append(dict(Name=tmp_path,
                                          Value=dict_root[i][1]))
            if para_list == []:
                return ret_res, ret_data_scr

            #sleep(3)  # must be ;otherwise exception
            ret, ret_data = u1.set_parameter_values(ParameterList=para_list)
            if (ret == ERR_SUCCESS):
                info = u"设置X_CT-COM_IPTV参数成功\n"
                log.app_info(info)
                ret_data_scr += info

                rebootFlag = int(ret_data["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,直接返回错误
                info = u"设置X_CT-COM_IPTV参数失败,错误原因:%s\n" % ret_data
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info

            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)
            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第三步:逐个查找,对于A上行,查PVC,其他的则查VLAN
            #path2 = []
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConection或WANIPConection节点路径保存,后面修改参数时有用
            WAN_Flag = None
            #直接调GetParameterValues  查PVC或VLAN
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                if DeviceType == 'ADSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                elif DeviceType == 'LAN':
                    tmp_path2 = tmp_path2 + 'WANEthernetLinkConfig.X_CT-COM_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'EPON':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'VDSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.X_CT-COM_VLAN'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLAN值\n" % str(
                        i + 1)
                elif DeviceType == 'GPON':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                else:
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(
                    ParameterNames=tmp_path2)
                if (ret2 == ERR_SUCCESS):
                    info = u"查询成功,返回:%s\n" % ret_data2
                    log.app_info(info)
                    ret_data_scr += info
                    # 当返回的PVC与要绑定的相同时,标记WAN_Flag,走修改流程
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        # 如果查到PVC或VLAN相同,则标记
                        if ret_data2['ParameterList'] != []:
                            if ret_data2['ParameterList'][0][
                                    'Value'] == PVC_OR_VLAN:
                                # 查到有匹配PVC
                                WAN_Flag = 0
                                path2 = ret_data_root['ParameterList'][i][
                                    'Name']
                                break
                            else:
                                # 查不到匹配的PVC
                                continue
                        else:
                            continue
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则说明没有匹配的WAN连接实例
            if WAN_Flag == None:
                WAN_Flag = 1

            # 查不到匹配的PVC或VLAN,不做任何事情
            if WAN_Flag == 1:
                info = u"查不到匹配的PVC或VLAN,不执行删除WANConnectionDevice实例的操作\n"
                log.app_info(info)
                ret_data_scr += info
                pass
            elif WAN_Flag == 0:
                #当查到有相匹配的PVC时的处理流程,则还需查WANPPPConnection下的三个节点是否一致
                #如果完全一致,直接删除WAN连接实例,否则待完善
                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    info = u"开始调用GetParameterNames查询WANPPPConnection实例\n"
                    tmp_path3 = path2 + 'WANPPPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    if AccessMode == "PPPoE_Bridged":
                        tmp_ConnectionType = "PPPoE_Bridged"
                    else:
                        tmp_ConnectionType = "IP_Routed"
                    tmp_X_CT_COM_LanInterface = dict_wanpppconnection[
                        'X_CT-COM_LanInterface'][1]
                    tmp_X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    info = u"开始调用GetParameterNames查询WANIPConnection实例\n"
                    tmp_path3 = path2 + 'WANIPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    tmp_ConnectionType = "IP_Routed"
                    tmp_X_CT_COM_LanInterface = dict_wanipconnection[
                        'X_CT-COM_LanInterface'][1]
                    tmp_X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)
                ret_tmp_path3 = []
                ret3, ret_data3 = u1.get_parameter_names(
                    ParameterPath=tmp_path3, NextLevel=1)
                if (ret3 == ERR_SUCCESS):
                    info = u"查询成功,返回%s\n" % ret_data3
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data3 = DelOwnParameterNames(ret_data3, tmp_path3)
                    #返回有路径,则保存
                    if ret_data3['ParameterList'] != []:
                        for tmp_index in xrange(len(
                                ret_data3['ParameterList'])):
                            ret_tmp_path3.append(
                                ret_data3['ParameterList'][tmp_index]['Name'])
                else:
                    #对于失败的情况,直接退出
                    info = u"查询失败,返回错误信息:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # 第2.2步,对于PPPOE查找X_CT-COM_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CT-COM_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CT-COM_ServiceList
                for i in xrange(len(ret_tmp_path3)):
                    info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的参数值\n" % str(
                        i + 1)
                    log.app_err(info)
                    ret_data_scr += info

                    tmp_path3_2 = []
                    tmp_path3_2.append(ret_tmp_path3[i] + 'ConnectionType')
                    tmp_path3_2.append(ret_tmp_path3[i] +
                                       'X_CT-COM_LanInterface')
                    tmp_path3_2.append(ret_tmp_path3[i] +
                                       'X_CT-COM_ServiceList')
                    #sleep(3)
                    ret3_2, ret_data3_2 = u1.get_parameter_values(
                        ParameterNames=tmp_path3_2)
                    if (ret3_2 == ERR_SUCCESS):
                        info = u"查找第%s个WAN连接实例下的参数值成功,返回:%s\n" % (str(i + 1),
                                                                  ret_data3_2)
                        log.app_info(info)
                        ret_data_scr += info

                        # 判断值是否相等,相等则直接删除WAN实例,否则就返回错误
                        WAN_Flag_1 = 0
                        for j in xrange(3):

                            if 'ConnectionType' in ret_data3_2[
                                    'ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j][
                                        'Value'] == tmp_ConnectionType:
                                    WAN_Flag_1 = 1
                                else:
                                    WAN_Flag_1 = 0
                                    break
                            elif 'X_CT-COM_LanInterface' in ret_data3_2[
                                    'ParameterList'][j]['Name'].split("."):
                                # 只要包含关系,就可认为是查到相等
                                # GCW 20130410 解决页面删除了绑定的LAN后导致此节点值为空的情况,不能执行split
                                #tmp_value = []
                                #tmp_value = ret_data3_2['ParameterList'][j]['Value'].split(',')
                                tmp_value = ret_data3_2['ParameterList'][j][
                                    'Value']
                                # GCW 20130413 手动页面删除绑定或工单中传参绑定为空时的异常处理。
                                if tmp_value == "" or tmp_value == None:
                                    if tmp_X_CT_COM_LanInterface == "":
                                        # 两者均为空,则匹配成功
                                        WAN_Flag_1 = 1
                                    else:
                                        # 两者只要有一个不为空,则匹配为不相等
                                        WAN_Flag_1 = 0
                                        break
                                else:
                                    if tmp_X_CT_COM_LanInterface == "":
                                        # 两者只要有一个不为空,则匹配为不相等
                                        WAN_Flag_1 = 0
                                        break
                                    else:
                                        if tmp_X_CT_COM_LanInterface in tmp_value:
                                            WAN_Flag_1 = 1
                                        else:
                                            WAN_Flag_1 = 0
                                            break
                            elif 'X_CT-COM_ServiceList' in ret_data3_2[
                                    'ParameterList'][j]['Name'].split("."):
                                # 只要包含关系,就可认为是查到相等
                                #tmp_value = []
                                #tmp_value = ret_data3_2['ParameterList'][j]['Value'].split(',')
                                tmp_value = ret_data3_2['ParameterList'][j][
                                    'Value']
                                if tmp_X_CT_COM_ServiceList in tmp_value:
                                    WAN_Flag_1 = 1
                                else:
                                    WAN_Flag_1 = 0
                                    break
                        #如果有一个不匹配,则认为没有开通IGMP的WAN连接,无法删除
                        if WAN_Flag_1 == 0:
                            info = u"查到与工单中有不匹配的参数,无法删除WAN连接实例\n"
                            log.app_err(info)
                            ret_data_scr += info
                            # GCW 20130419 IPTV取消工单,如果查不到匹配的WAN连接也可以认为成功
                            #return ret_res, ret_data_scr
                        else:
                            # 删除WAN连接实例
                            info = u"准备删除WANConnectionDevice实例\n"
                            log.app_info(info)
                            ret_data_scr += info

                            tmp_path = ret_tmp_path3[i].split('.')
                            path = ''
                            for i in xrange(len(tmp_path) - 3):
                                path = path + tmp_path[i] + '.'

                            #sleep(3)  # must be ;otherwise exception
                            ret3, ret_data3 = u1.delete_object(ObjectName=path)
                            if (ret3 == ERR_SUCCESS):
                                info = u"删除WANConnectionDevice实例成功\n"
                                log.app_info(info)
                                ret_data_scr += info

                                rebootFlag = int(ret_data3["Status"])
                                if (rebootFlag == 1):
                                    reboot_Yes = 1
                            else:
                                #对于失败的情况,直接退出
                                info = u"删除WANConnectionDevice实例失败,错误原因:%s\n" % ret_data3
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #8
0
def Eagleeyes(obj,
              sn,
              DeviceType,
              AccessMode,
              PortMappingEnabled,
              dict_PortMapping,
              change_account=1,
              rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)

            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回错误
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找
            path2 = []
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #如果需绑定到PPPoE,则查WANPPPConnection节点。同理,如果以后是想绑定到静态WAN连接,则可以查另外的节点,可开放
                #A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_path2 = tmp_path2 + 'WANPPPConnection.'
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANPPPConnection实例\n" % str(
                        i + 1)
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    tmp_path2 = tmp_path2 + 'WANIPConnection.'
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANIPConnection实例\n" % str(
                        i + 1)
                else:
                    info = u"参数错误,目前只支持PPPoE_Bridged\PPPoE\DHCP\Static\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                log.app_info(info)
                ret_data_scr += info
                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_names(
                    ParameterPath=tmp_path2, NextLevel=1)
                if (ret2 == ERR_SUCCESS):
                    info = u"查找第%s条WAN连接实例成功\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data2 = DelOwnParameterNames(ret_data2, tmp_path2)
                    #以下是只考虑返回值只有一个的情况.当然,空的时候则是什么也不做
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        for tmp_index in xrange(len(
                                ret_data2['ParameterList'])):
                            path2.append(
                                ret_data2['ParameterList'][tmp_index]['Name'])
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查找第%s条WAN连接实例失败,错误信息: %s\n" % (str(i + 1),
                                                            ret_data2)
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
            #如果查到当前的WAN连接下,均没有WANPPPConnection实例,则说明不能绑定到PPPOE下,退出。
            #同理,如果是绑定到静态WAN连接,而WAN连接下没有实例号,则退出
            if path2 == []:
                info = u"遍历WAN连接实例结束,但无发现可用的Connection实例号,请检查\n"
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            else:
                pass

            #第三步,然后对path2中的值进行循环查找,只要一查到INTERNET,则退出
            INTERNET_FLAG = False
            for i in xrange(len(path2)):
                info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的ConnectionType和X_CT-COM_ServiceList值\n" % str(
                    i + 1)
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130418 增加是路由还是桥的查找判断
                tmp_path3 = []
                tmp_path3.append(path2[i] + 'ConnectionType')
                tmp_path3.append(path2[i] + 'X_CT-COM_ServiceList')
                #sleep(3)
                ret3, ret_data3 = u1.get_parameter_values(
                    ParameterNames=tmp_path3)
                if (ret3 == ERR_SUCCESS):
                    info = u"查找第%s个WAN连接实例下的ConnectionType和X_CT-COM_ServiceList值成功,返回:%s\n" % (
                        str(i + 1), ret_data3)
                    log.app_info(info)
                    ret_data_scr += info
                    #如果查到有INTERNET,同退出当前循环
                    # GCW 20130410 修改为包含于的关系即可
                    # GCW 20130418 增加对路由或桥的判断
                    if AccessMode == "PPPoE_Bridged":
                        ConnectionType = "PPPoE_Bridged"
                    else:
                        ConnectionType = "IP_Routed"
                    # 只有桥对桥,路由对路由对比才有意义。
                    if ConnectionType == ret_data3['ParameterList'][0]['Value'] or \
                       ConnectionType == ret_data3['ParameterList'][1]['Value']:
                        # 全球眼固定是绑定到包含INTERNET的WAN连接的
                        if 'INTERNET' in ret_data3['ParameterList'][0]['Value'] or \
                           'INTERNET' in ret_data3['ParameterList'][1]['Value']:
                            INTERNET_FLAG = True
                            #记录包含INTERNET的节点路径
                            path3 = path2[i]
                            break
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查找第%s个WAN连接实例下的X_CT-COM_ServiceList值失败,返回:%s\n" % (
                        str(i + 1), ret_data3)
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            #如果一直都没有查到,怎么办?目前是直接返回失败
            if INTERNET_FLAG == False:
                info = u"经遍历查找,查无匹配的X_CT-COM_ServiceList包含INTERNET值的%s 连接,执行失败.\n" % AccessMode
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第四步,调用GetParameterNames方法,查找端口映射中是否有实例
            info = u"开始调用GetParameterNames方法,查找端口映射中是否有实例\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)
            PortMapping_flag = 0
            GetParameterNames_path4 = path3 + 'PortMapping.'
            ret4, ret_data4 = u1.get_parameter_names(
                ParameterPath=GetParameterNames_path4, NextLevel=1)
            if (ret4 == ERR_SUCCESS):
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data4 = DelOwnParameterNames(ret_data4,
                                                 GetParameterNames_path4)
                #如果查到有实例,则需查找是否所有参数一致,一致则不做任何修改,不一致则修改
                if ret_data4['ParameterList'] == []:
                    info = u"端口映射中没有实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    PortMapping_flag = 0  # 表示查无实例,后面需要新建
                else:
                    # 查到有实例,还需要判断是否与工单参数中的相同,相同才删除实例,否则也是不删
                    info = u"端口映射中已有实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    for j in xrange(len(ret_data4['ParameterList'])):
                        path = ret_data4['ParameterList'][j]['Name']
                        #sleep(3)
                        info = u"查找%s 下的参数,检查端口映射规则是否与工单中的完全一致\n" % path
                        log.app_info(info)
                        ret_data_scr += info
                        # 将字典中的追加,查找值然后进行比对
                        tmp_path = []  # 保存路径
                        tmp_Value = []  # 保存成对的参数,值

                        for k in dict_PortMapping:
                            if dict_PortMapping[k][0] == 1:
                                tmp_path.append(path + k)
                                tmp_Value.append([k, dict_PortMapping[k][1]])

                        ret4_2, ret_data4_2 = u1.get_parameter_values(
                            ParameterNames=tmp_path)
                        if (ret4_2 == ERR_SUCCESS):
                            tmp = len(ret_data4_2['ParameterList'])

                            # 判断所有值是否相等
                            for k in xrange(len(ret_data4_2['ParameterList'])):
                                tmpaa = ret_data4_2['ParameterList'][k]['Name']
                                for l in xrange(len(tmp_Value)):
                                    if tmp_Value[l][0] in ret_data4_2[
                                            'ParameterList'][k]['Name'].split(
                                                "."):
                                        if ret_data4_2['ParameterList'][k][
                                                'Value'] == tmp_Value[l][1]:
                                            PortMapping_flag = 1
                                            break
                                        else:
                                            PortMapping_flag = 0
                                            break
                                # GCW 20130410 参数不一致时,仍认为端口映射规则相同的问题
                                if PortMapping_flag == 0:
                                    break
                        else:
                            info = u"查找失败,退出工单执行\n"
                            log.app_info(info)
                            ret_data_scr += info
                            return ret_res, ret_data_scr
                        if PortMapping_flag == 1:
                            info = u"查找成功,且所有参数一致\n"
                            log.app_info(info)
                            ret_data_scr += info
                            path_4 = ret_data4['ParameterList'][j]['Name']
                            break
                        else:
                            info = u"查找成功,但此端口映射中的规则与工单中要求的不一致。\n"
                            log.app_info(info)
                            ret_data_scr += info
            else:
                #对于失败的情况,直接返回错误
                info = u"查找端口映射中是否有实例失败,错误信息:%s\n" % ret_data4
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果是开通业务,则需新增实例并下发参数,如果是取消业务,则直接删除实例
            if PortMappingEnabled == 'Enable':
                #第五步,调用AddObject新建实例
                if PortMapping_flag == 0:
                    info = u"本工单是开通业务,且端口映射中查无实例或实例中参数不等,开始调用AddObject新建实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    path5 = GetParameterNames_path4
                    #sleep(3)  # must be ;otherwise exception
                    ret5, ret_data5 = u1.add_object(ObjectName=path5)
                    if (ret5 == ERR_SUCCESS):
                        instanceNum1 = ret_data5["InstanceNumber"]
                        info = u"新建端口映射实例成功,返回实例号:%s\n" % instanceNum1
                        log.app_info(info)
                        ret_data_scr += info
                        # GCW 20130327 增加回退机制
                        rollbacklist.append(path5 + instanceNum1 + '.')
                        rebootFlag = int(ret_data5["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"新建端口映射实例失败,错误原因:%s\n" % ret_data5
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

                    #第六步:调用SetParameterValues设置参数
                    info = u"开始调用SetParameterValues设置端口映射参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    path6 = path5 + instanceNum1 + '.'
                    para_list6 = []
                    for i in dict_PortMapping:
                        if dict_PortMapping[i][0] == 1:
                            tmp_path = path6 + i
                            para_list6.append(
                                dict(Name=tmp_path,
                                     Value=dict_PortMapping[i][1]))
                    if para_list6 == []:
                        return ret_res, ret_data_scr
                    #sleep(3)  # must be ;otherwise exception
                    ret6, ret_data6 = u1.set_parameter_values(
                        ParameterList=para_list6)

                    if (ret6 == ERR_SUCCESS):
                        info = u"设置端口映射参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data6["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置端口映射参数失败,错误信息:%s\n" % ret_data6
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                else:
                    info = u"本工单是开通业务,但已有端口映射规则且所有参数均相等。不再新建。\n"
                    log.app_info(info)
                    ret_data_scr += info
            elif PortMappingEnabled == 'Disable':
                #第五步,调用删除实例
                if PortMapping_flag == 1:
                    # 删除WAN连接实例
                    #log.app_info (u"删除PortMapping实例\n")
                    info = u"本工单是取消业务,在端口映射中查到实例且参数完全一致,开始调用DelObject删除PortMapping实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                    path = path_4
                    #sleep(3)  # must be ;otherwise exception
                    ret5, ret_data5 = u1.delete_object(ObjectName=path)
                    if (ret5 == ERR_SUCCESS):
                        info = u"删除PortMapping实例成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data5["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接退出
                        info = u"删除PortMapping实例失败,错误原因:%s\n" % ret_data5
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                else:
                    info = u"本工单是取消业务,但查无所有参数均相等的实例可删除。\n"
                    log.app_info(info)
                    ret_data_scr += info
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #9
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script    
    """
    ret_worklist = ERR_FAIL  # default
    ret_rpc = ERR_FAIL
    ret_datas = ""
    bool_reboot = False
    instance_number = 1

    sn = obj.sn

    for nwf in [1]:
        try:

            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)

            # ----------------------------------------------------------
            log.app_info("first rpc")

            ret_rpc, ret_data = u1.set_parameter_values(ParameterList=[
                dict(
                    Name="InternetGatewayDevice.DeviceInfo.X_CU_Monitor.Enable",
                    Value="1")
            ])
            ret_datas = ret_datas + "\n" + str(ret_data)
            if ret_rpc == ERR_SUCCESS:
                log.app_info("success:%s" % ret_data)
            else:
                log.app_err("fail:%s" % ret_data)
                break

                # ----------------------------------------------------------
            log.app_info("second rpc")

            alarm_root_path = "InternetGatewayDevice.DeviceInfo.X_CU_Monitor.MonitorConfig."
            ret_rpc, ret_data = u1.add_object(ObjectName=alarm_root_path)
            ret_datas = ret_datas + "\n" + str(ret_data)
            if ret_rpc == ERR_SUCCESS:
                log.app_info("success:%s" % ret_data)

                status = int(ret_data["Status"])
                if status == 1:
                    bool_reboot = True
                instance_number = int(ret_data["InstanceNumber"])
            else:
                log.app_err("fail:%s" % ret_data)
                break

                # ----------------------------------------------------------
            log.app_info("third rpc")

            alarm_node_path = "%s%s." % (alarm_root_path, instance_number)
            ret_rpc, ret_data = u1.set_parameter_values(ParameterList=[
                dict(Name="%sParaList" % alarm_node_path,
                     Value=obj.dict_data["parameterlist"]),
                dict(Name="%sTimeList" % alarm_node_path,
                     Value=obj.dict_data["timelist"])
            ])
            ret_datas = ret_datas + "\n" + str(ret_data)
            if ret_rpc == ERR_SUCCESS:
                log.app_info("success:%s" % ret_data)

                status = int(ret_data["Status"])
                if status == 1:
                    bool_reboot = True
            else:
                log.app_err("fail:%s" % ret_data)
                break

            if bool_reboot:
                # ----------------------------------------------------------
                log.app_info("need reboot")

                ret_rpc, ret_data = u1.reboot()
                ret_datas = ret_datas + "\n" + str(ret_data)
                if ret_rpc == ERR_SUCCESS:
                    log.app_info("success:%s" % ret_data)
                else:
                    log.app_err("fail:%s" % ret_data)
                    break

                    # need del
            obj.dict_ret["node_add_object"] = alarm_node_path
            ret_worklist = ERR_SUCCESS

        except Exception, e:
            ret_datas = ret_datas + "\n" + str(e)

            log.app_err(e)
            break
Exemple #10
0
def WANSetUP(obj,
             sn,
             WANEnable_Switch,
             DeviceType,
             AccessMode,
             PVC_OR_VLAN,
             dict_wanlinkconfig={},
             dict_wanpppconnection={},
             dict_wanipconnection={},
             change_account=1,
             rollbacklist=[]):
    ret_res = ERR_FAIL  # 返回成功或失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            # 第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            # sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)
            if ret_root == ERR_SUCCESS:
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                # 对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第二步:逐个查找
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConnection或WANIPConnection节点路径保存,后面修改参数时有用
            # 是否有查到已存在的类似WAN连接的状态位,符合以下标识,桥只关心PVC,其他的只关心X_CU_ServiceList
            # 0 Username和X_CU_ServiceList均相同
            # 1 Username和X_CU_ServiceList均不相同
            # 2 Username相同,X_CU_ServiceList不相同
            # 3 Username不相同,X_CU_ServiceList相同
            WAN_Flag = None
            # 如果是桥连接,则只查PVC,其他的查X_CU_ServiceList是否有相同的
            if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged':
                # 注意是调GetParameterNames,不同于桥时直接调GetParameterValues查值
                ret_tmp_path2 = []
                for i in xrange(len(ret_data_root['ParameterList'])):
                    # 不同的WAN连接模式,其节点路径不同
                    if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                        tmp_path2 = ret_data_root['ParameterList'][i][
                            'Name'] + 'WANPPPConnection.'
                        X_CU_COM_ServiceList = dict_wanpppconnection[
                            'X_CU_ServiceList'][1]
                        ConnectionType = dict_wanpppconnection[
                            'ConnectionType'][1]
                        info = u"开始调用GetParameterNames查找第%s条WAN连接WANPPPConnection实例\n" % str(
                            i + 1)
                    elif AccessMode == 'DHCP' or AccessMode == 'Static':
                        tmp_path2 = ret_data_root['ParameterList'][i][
                            'Name'] + 'WANIPConnection.'
                        X_CU_COM_ServiceList = dict_wanipconnection[
                            'X_CU_ServiceList'][1]
                        ConnectionType = dict_wanipconnection[
                            'ConnectionType'][1]
                        info = u"开始调用GetParameterNames查找第%s条WAN连接WANIPConnection实例\n" % str(
                            i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    # sleep(3)
                    ret2, ret_data2 = u1.get_parameter_names(
                        ParameterPath=tmp_path2, NextLevel=1)
                    if ret2 == ERR_SUCCESS:
                        info = u"查找第%s条WAN连接实例成功\n" % str(i + 1)
                        log.app_info(info)
                        ret_data_scr += info
                        # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                        ret_data2 = DelOwnParameterNames(ret_data2, tmp_path2)

                        if ret_data2['ParameterList']:
                            for tmp_index in xrange(
                                    len(ret_data2['ParameterList'])):
                                ret_tmp_path2.append(ret_data2['ParameterList']
                                                     [tmp_index]['Name'])
                    else:
                        # 对于失败的情况,直接退出
                        info = u"查找第%s条WAN连接实例失败,错误信息: %s\n" % (str(i + 1),
                                                                ret_data2)
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                # 第2.2步,对于PPPOE查找X_CU_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CU_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CU_ServiceList
                for i in xrange(len(ret_tmp_path2)):
                    info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的X_CU_ServiceList值\n" % str(
                        i + 1)
                    log.app_info(info)
                    ret_data_scr += info

                    tmp_path2_2 = []
                    tmp_path2_2.append(ret_tmp_path2[i] + 'X_CU_ServiceList')
                    # GCW 20130410对桥模式单独处理,避免修改PPPOE INTERNET为桥 INTERNET的情况
                    tmp_path2_2.append(ret_tmp_path2[i] + 'ConnectionType')
                    # sleep(3)
                    ret2_2, ret_data2_2 = u1.get_parameter_values(
                        ParameterNames=tmp_path2_2)
                    if ret2_2 == ERR_SUCCESS:
                        info = u"查找第%s个WAN连接实例下的X_CU_ServiceList和ConnectionType值成功,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        # 判断值是否相等,相等(或被包含)则只修改linkconfig节点的值即可,否则需走后面的正常流程新建WAN连接
                        if AccessMode == "PPPoE_Bridged":
                            ConnectionType = "PPPoE_Bridged"
                        else:
                            ConnectionType = "IP_Routed"

                        # GCW 20130417 路由对路由比较,桥对桥的比较才更合理
                        if ConnectionType == ret_data2_2['ParameterList'][0]['Value'] or \
                           ConnectionType == ret_data2_2['ParameterList'][1]['Value']:
                            # 如果非完全不相等,则需做特殊处理
                            if (ret_data2_2['ParameterList'][0]['Value'] in X_CU_COM_ServiceList \
                                    or ret_data2_2['ParameterList'][1]['Value'] in X_CU_COM_ServiceList) \
                                or (X_CU_COM_ServiceList in ret_data2_2['ParameterList'][0]['Value'] \
                                    or X_CU_COM_ServiceList in ret_data2_2['ParameterList'][1]['Value']):
                                # GCW 20130408 判断X_CU_ServiceList包含与被包含的关系做区分处理.
                                if (ret_data2_2['ParameterList'][0]['Value'] in X_CU_COM_ServiceList \
                                  or ret_data2_2['ParameterList'][1]['Value'] in X_CU_COM_ServiceList):
                                    info = u"当前CPE中的X_CU_ServiceList值包含于工单中要求的X_CU_ServiceList值:%s,\n" % X_CU_COM_ServiceList
                                    info += u"走修改WAN连接的流程,且重新下发X_CU_ServiceList值的修改\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 0  # 表示CPE当前值包含于工单,走修改WAN流程,且X_CU_ServiceList需下发
                                else:
                                    info = u"当前工单中的X_CU_ServiceList值:%s包含于CPE中的X_CU_ServiceList值,\n" % X_CU_COM_ServiceList
                                    info += u"走修改WAN连接流程,但不下发对X_CU_ServiceList值的修改.\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 3  # 表示工单中的值包含于当前CPE中,走修改WAN流程,但X_CU_ServiceList不需下发
                                path2_1 = ret_tmp_path2[i]
                                # 将上一层路径保存并退出循环,留给下一步直接修改linkconfig参数
                                # ret_tmp_path2[i]类似于InternetGatewayDevice.WANDevice.1.WANConnectionDevice.3.WANPPPConnection.1.
                                a = ret_tmp_path2[i].split('.')
                                for i in xrange(len(a) - 3):
                                    path2 += a[i]
                                    path2 += '.'  # 将当前的WANConnectionDevice.节点路径保存,后面修改参数时有用
                                break
                            else:
                                continue
                        else:
                            continue
                    else:
                        info = u"查找第%s个WAN连接实例下的X_CU_ServiceList值失败,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                if WAN_Flag == None:
                    info = u"查找不到匹配 %s 模式的WAN连接\n" % X_CU_COM_ServiceList
                    log.app_info(info)
                    ret_data_scr += info
                    WAN_Flag = 1
            else:
                info = u"输入的AccessMode参数不合法,请检查!\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            # 0 均相同,只修改LinkConfig.(参考a.1包)
            # 1 两者均不相同的情况下:等同于查到是空的情况,后续新建WAN连接参考a.2包)
            # 2 部分相同,而且关键点X_CU_ServiceList不相同的情况下:等同于查到是空的情况,后续新建WAN连接(参考a.3包)
            # 3 部分相同,而且关键点X_CU_ServiceList相同的情况下:等同于查到均相同的情况,只修改LinkConfig.(参考a.4包)
            if WAN_Flag == 1 or WAN_Flag == 2:
                # 第三--一步:新建WANConnectionDevice实例
                info = u"走X_CU_ServiceList不相同的流程(新建WAN连接).\n"
                log.app_info(info)
                ret_data_scr += info

                # 解决用户新建tr069WAN连接导致CPE与ACS通讯异常的问题,强制不准新建包含TR0069的WAN连接

                if (("tr069" in X_CU_COM_ServiceList)
                        or ("TR069" in X_CU_COM_ServiceList)):
                    info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建.\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                info = u"开始调用AddObject新建WANConnectionDevice实例\n"
                log.app_info(info)
                ret_data_scr += info

                Classpath = ROOT_PATH
                # sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=Classpath)
                if ret3 == ERR_SUCCESS:
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建WANConnectionDevice实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"新建WANConnectionDevice实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--二步:新建WANIPConnection或WANPPPConnection实例
                # 只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANPPPConnection实例\n"
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANIPConnection实例\n"
                log.app_info(info)
                ret_data_scr += info

                # sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(ObjectName=path4)

                if ret4 == ERR_SUCCESS:
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data4["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"新建实例实例失败,退出执行,错误原因:%s\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CU_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANEponLinkConfig参数\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'X_CU_WANVdslLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANVdslLinkConfig参数\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CU_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANGponLinkConfig参数\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                log.app_info(info)
                ret_data_scr += info
                """
                info = u"开始调用SetParameterValues设置参数\n"
                log.app_info(info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = tmp_path3 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    ret_data = u"参数列表为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if ret5 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    ret_data = u"参数列表为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if ret6 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 将WAN连接使能单独下发
                if WAN_Enable:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    # sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if ret_wan_enable == ERR_SUCCESS:
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            elif WAN_Flag == 0 or WAN_Flag == 3:
                # 当查到有相匹配的X_CU_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可
                # 第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'LAN':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANEthernetLinkConfig参数\n"
                    path5 = path2 + 'WANEthernetLinkConfig.'
                elif DeviceType == 'EPON':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CU_WANEponLinkConfig参数\n"
                    path5 = path2 + 'X_CU_WANEponLinkConfig.'                
                elif DeviceType == 'VDSL':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CU_WANVdslLinkConfig参数\n"
                    path5 = path2 + 'X_CU_WANVdslLinkConfig.'
                elif DeviceType == 'GPON':
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CU_WANGponLinkConfig参数\n"
                    path5 = path2 + 'X_CU_WANGponLinkConfig.'
                else:
                    info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                log.app_info (info)
                ret_data_scr += info
                """
                info = u"走X_CU_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改参数\n"
                log.app_info(info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        # 对于Linkconfig的PVC或VLAN节点删除,不做修改
                        # GCW 20130418 修改WAN连接参数时,对X_CU_Mode节点也不修改
                        if i == 'DestinationAddress' or i == 'VLANIDMark' or \
                           i == 'X_CU_VLAN' or i == "X_CU_Mode":
                            continue
                        tmp_path = path2 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数列表为空,请检查\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if ret5 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 修改SetParameterValues设置WANPPPConnection参数
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = path2_1
                para_list6 = []
                WAN_Enable = []

                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # GCW 20130408 判断X_CU_ServiceList包含与被包含的关系做区分处理.
                        # 标志位0表示X_CU_ServiceList值需以工单中的为准,重新下发,3表示不下发
                        if WAN_Flag == 0:
                            pass
                        else:
                            if i == 'X_CU_ServiceList':
                                continue
                        # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    return ret_res, ret_data_scr

                # sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if ret6 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 将WAN连接使能单独下发
                if WAN_Enable:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    # sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if ret_wan_enable == ERR_SUCCESS:
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if reboot_Yes == 1:

                # sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if ret != ERR_SUCCESS:
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改联通维护密码,目前密码固定为CUAdmin
            ret, ret_data = ChangeAccount_CU(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #11
0
def WLANMulti(obj,
              sn,
              Num,
              dict_root,
              dict_WEPKey,
              dict_PreSharedKey,
              change_account=0,
              rollbacklist=[]):
    """      
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    #绑定tr069模板类型,暂时只定义为上行方式
    DeviceType = 'ADSL'

    ROOT_PATH = "InternetGatewayDevice.LANDevice.1.WLANConfiguration."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查找当前有几个无线实例
            info = u"开始调用GetParameterNames方法,查找当前无线实例\n"
            log.app_info(info)
            ret_data_scr += info

            para_list = []
            path = ROOT_PATH
            ret_root, ret_data1_root = u1.get_parameter_names(
                ParameterPath=path, NextLevel='1')
            #sleep(2)  # must be ;otherwise exception
            if (ret_root == ERR_SUCCESS):
                info = u"查找当前无线实例成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data1_root = DelOwnParameterNames(ret_data1_root, path)
            else:
                #对于失败的情况,如何处理?
                info = u"查找当前无线实例失败,返回错误:%s\n" % ret_data1_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:直接增加N个实例。如果有个数超出范围的问题,则由CPE处理判断
            para_list = []
            path = ROOT_PATH
            path2 = []
            #将查到的实例号路径追加到列表中
            for i in xrange(len(ret_data1_root['ParameterList'])):
                path2.append(ret_data1_root['ParameterList'][i]['Name'])

            # 新建实例个数等于传参进来的个数减去查到已经存在的个数,但如要Num为0或者小于已有实例个数,则不需新建
            if (int(Num) > len(ret_data1_root['ParameterList'])):
                info = u"开始调用AddObject,增加无线实例\n"
                log.app_info(info)
                ret_data_scr += info

                for i in xrange(
                        int(Num) - len(ret_data1_root['ParameterList'])):
                    ret_addobject, ret_data_addobject = u1.add_object(
                        ObjectName=path)
                    #sleep(2)  # must be ;otherwise exception
                    if (ret_addobject == ERR_SUCCESS):
                        instanceNum1 = ret_data_addobject["InstanceNumber"]
                        path2.append(path + instanceNum1 + '.')
                        # GCW 20130327 增加回退机制
                        rollbacklist.append(path + instanceNum1 + '.')
                        info = u"增加无线实例成功,返回实例号:%s\n" % instanceNum1
                        log.app_info(info)
                        ret_data_scr += info

                        rebootFlag = int(ret_data_addobject["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回失败
                        info = u"增加无线实例失败,失败信息:%s\n" % ret_data_addobject
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            else:
                info = u"已经开通的无线实例个数大于或等于 %s\n" % str(Num)
                log.app_info(info)
                ret_data_scr += info

            # 第三步,使能X_CT-COM_APModuleEnable
            para_list = []
            info = u"开始调用SetParameterValues对各个无线实例的X_CT-COM_APModuleEnable进行使能\n"
            log.app_info(info)
            ret_data_scr += info

            for i in xrange(len(path2)):
                tmp_path = path2[i] + 'X_CT-COM_APModuleEnable'
                para_list.append(dict(Name=tmp_path, Value='1'))
            ret_root, ret_data_root = u1.set_parameter_values(
                ParameterList=para_list)
            #sleep(2)  # must be ;otherwise exception
            if (ret_root == ERR_SUCCESS):
                info = u"对所有无线实例的X_CT-COM_APModuleEnable进行使能成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data_root["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,直接返回错误
                info = u"对所有无线实例的X_CT-COM_APModuleEnable进行使能失败,返回错误:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第四步:对队列各个参数进行配置
            for i in xrange(len(path2)):
                info = u"对第%s个无线实例的参数进行配置\n" % str(i + 1)
                log.app_info(info)
                ret_data_scr += info
                # 根据电信的抓包,SSID1不修改,SSID2为WEP,SSID3和SSID4为不加密
                if i == 0:
                    # 对WLAN1不做任何修改
                    info = u"根据业务流程,对第%s个无线实例的参数不做修改\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    continue
                elif i == 1:
                    # WEP加密
                    para_list = []
                    path = path2[i]
                    for j in dict_root:
                        if dict_root[j][0] == 1:
                            tmp_path = path + j
                            para_list.append(
                                dict(Name=tmp_path, Value=dict_root[j][1]))
                    if para_list == []:
                        info = u"参数为空,请检查\n"
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
                elif i == 2:
                    # 不加密码
                    para_list = []
                    path = path2[i]
                    tmp_path_1 = path + 'Enable'
                    tmp_path_2 = path + 'BeaconType'
                    para_list.append(dict(Name=tmp_path_1, Value='1'))
                    para_list.append(dict(Name=tmp_path_2, Value='None'))
                    # 继续循环,以便将WLAN4的参数一起追加下发
                    info = u"根据业务流程,对第%s个无线实例的参数进行保存,与下一个无线实例参数一起下发\n" % str(
                        i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    continue
                elif i == 3:
                    # 不加密
                    path = path2[i]
                    tmp_path_1 = path + 'Enable'
                    tmp_path_2 = path + 'BeaconType'
                    para_list.append(dict(Name=tmp_path_1, Value='1'))
                    para_list.append(dict(Name=tmp_path_2, Value='None'))

                #设置值
                ret_root, ret_data_root = u1.set_parameter_values(
                    ParameterList=para_list)
                #sleep(2)  # must be ;otherwise exception
                if (ret_root == ERR_SUCCESS):
                    info = u"对第%s个无线实例的参数进行配置成功\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data_root["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回错误
                    info = u"对第%s个无线实例的参数进行配置失败,返回错误:%s\n" % (str(i + 1),
                                                              ret_data_root)
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 如果是WLAN2,则设置WEP密钥
                if i == 1:
                    info = u"对第%s个无线实例的WEP密钥进行配置\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info
                    if dict_root['WEPKeyIndex'][0] != 1:
                        info = u"传参时,字典中KEY索引没有打开,请检查\n"
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr  #KEY索引没有打开,不建议再判断索引值范围。
                    path_WEPKey = path2[i] + 'WEPKey.' + dict_root[
                        'WEPKeyIndex'][1] + '.WEPKey'
                    para_list = []
                    para_list.append(
                        dict(Name=path_WEPKey, Value=dict_WEPKey['WEPKey'][1]))
                    #设置值
                    ret_WEPKey, ret_data_WEPKey = u1.set_parameter_values(
                        ParameterList=para_list)
                    #sleep(1)  # must be ;otherwise exception
                    if (ret_WEPKey == ERR_SUCCESS):
                        info = u"对第%s个无线实例的WEP密钥进行配置成功\n" % str(i + 1)
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_WEPKey["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"对第%s个无线实例的WEP密钥进行配置失败,返回错误%s\n" % (
                            str(i + 1), ret_data_WEPKey)
                        log.app_info(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #12
0
def AddAnWAN(obj,
             sn,
             WANEnable_Switch,
             DeviceType,
             AccessMode,
             PVC_OR_VLAN,
             dict_wanlinkconfig={},
             dict_wanpppconnection={},
             dict_wanipconnection={},
             change_account=1,
             rollbacklist=[]):
    ret_res = ERR_FAIL  # 返回成功或失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接。\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=0)
            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功。\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s。\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged':

                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                    X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]

                elif AccessMode == 'DHCP' or AccessMode == 'Static':

                    X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]

                ret_find, pvcorvlan_items, serverlist_items, connect_type_items, laninterface_items, ret_data_find = _find_wan_server_and_connecttype(
                    u1, DeviceType, AccessMode, dict_wanpppconnection,
                    dict_wanipconnection, ret_data_root, ret_data_scr)

                if ret_find == ERR_SUCCESS:
                    ret_data_scr = ret_data_find
                else:
                    ret_data_scr = ret_data_find
                    return ret_res, ret_data_find

                if AccessMode == "PPPoE_Bridged":
                    ConnectionType = "PPPoE_Bridged"
                else:
                    ConnectionType = "IP_Routed"

            else:
                info = u"输入的AccessMode参数不合法,请检查!\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            WAN_Flag = None
            WAN_PVC = None  # 是否找到PVC
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径

            for i_pvcorvlan in pvcorvlan_items:

                if i_pvcorvlan['Value'] == PVC_OR_VLAN:
                    WAN_PVC = 0
                    path2 = i_pvcorvlan['Name']
                    tmp_link_list = path2.split('.')[0:-2]
                    path2 = '.'.join(tmp_link_list)
                    break
                else:
                    # 查不到匹配的PVC
                    continue

            if WAN_PVC == None:
                # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则走新建流程
                #对于未查找到相同PVC的,直接返回错误
                info = u"未查找到PVC或VLAN为 %s 的连接,请确认!" % PVC_OR_VLAN
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找

            # 是否有查到已存在的类似WAN连接的状态位,符合以下标识,桥只关心PVC,其他的只关心X_CT-COM_ServiceList

            modify_path = ""

            for i_connect in connect_type_items:

                tmp_ppp_list = i_connect['Name'].split('.')[0:-1]
                tmp_ppp_path = '.'.join(
                    tmp_ppp_list)  # 保存XXXX.WANPPPConnection.i.路径

                # 确定WAN,是否修改
                for j_serverlist in serverlist_items:

                    tmp_serverlist = j_serverlist['Name']

                    # 同一条WAN连接下进行比较
                    if tmp_ppp_path in tmp_serverlist:

                        # 桥对桥,路由对路由
                        if ConnectionType in i_connect['Value']:

                            if X_CT_COM_ServiceList in j_serverlist[
                                    'Value'] or j_serverlist[
                                        'Value'] in X_CT_COM_ServiceList:

                                modify_path = j_serverlist['Name']
                                if j_serverlist[
                                        'Value'] in X_CT_COM_ServiceList:

                                    info = u"当前CPE中的X_CT-COM_ServiceList值包含于工单中要求的X_CT-COM_ServiceList值:%s,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接的流程,且重新下发X_CT-COM_ServiceList值的修改。\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 0
                                else:
                                    info = u"当前工单中的X_CT-COM_ServiceList值:%s包含于CPE中的X_CT-COM_ServiceList值,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接流程,但不下发对X_CT-COM_ServiceList值的修改。\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 3

                                break

                            else:
                                continue

            #0 均相同,只修改LinkConfig.(参考a.1包)
            #1 两者均不相同的情况下:等同于查到是空的情况,后续新建WAN连接参考a.2包)
            #2 部分相同,而且关键点X_CT-COM_ServiceList不相同的情况下:等同于查到是空的情况,后续新建WAN连接(参考a.3包)
            #3 部分相同,而且关键点X_CT-COM_ServiceList相同的情况下:等同于查到均相同的情况,只修改LinkConfig.(参考a.4包)
            if WAN_Flag == None:
                #第三--一步:新建WANConnectionDevice实例
                info = u"走X_CT-COM_ServiceList不相同的流程(新建WAN连接)。\n"
                log.app_info(info)
                ret_data_scr += info

                # 解决用户新建tr069WAN连接导致CPE与ACS通讯异常的问题,强制不准新建包含TR0069的WAN连接

                if (("tr069" in X_CT_COM_ServiceList)
                        or ("TR069" in X_CT_COM_ServiceList)):
                    info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                """
                info = u"开始调用AddObject新建WANConnectionDevice实例。\n"
                log.app_info (info)
                ret_data_scr += info
                """

                #第三--二步:新建WANIPConnection或WANPPPConnection实例
                #只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = path2 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANPPPConnection实例。\n"
                else:
                    path4 = path2 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANIPConnection实例。\n"
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(ObjectName=path4)

                if (ret4 == ERR_SUCCESS):
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s 。\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data4["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"新建实例实例失败,退出执行,错误原因:%s 。\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 同一PVC下两条WAN连接不需要设置link层:
                """
                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数。\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数。\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig参数。\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig参数。\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数。\n"
                log.app_info (info)
                ret_data_scr += info
                
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = path5 + i
                        para_list5.append(dict(Name=tmp_path, Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    ret_data = u"参数列表为空,请检查。\n"
                    log.app_err (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info (info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data5
                    log.app_err (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                """
                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数。\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数。\n"
                log.app_info(info)
                ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    ret_data = u"参数列表为空,请检查。\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功。\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s 。\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            else:
                #第三--三步:调用SetParameterValues设置linkconfig参数:
                path2_list = modify_path.split('.')[0:-3]
                path2_1_list = modify_path.split('.')[0:-1]

                path2 = '.'.join(path2_list) + '.'
                path2_1 = '.'.join(path2_1_list) + '.'

                #当查到有相匹配的X_CT-COM_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可
                #第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数。\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'LAN':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANEthernetLinkConfig参数。\n"
                    path5 = path2 + 'WANEthernetLinkConfig.'
                elif DeviceType == 'EPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANEponLinkConfig参数。\n"
                    path5 = path2 + 'X_CT-COM_WANEponLinkConfig.'                
                elif DeviceType == 'VDSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'GPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANGponLinkConfig参数。\n"
                    path5 = path2 + 'X_CT-COM_WANGponLinkConfig.'
                else:
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数。\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                log.app_info (info)
                ret_data_scr += info
                
                para_list5 = []
                
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        #对于Linkconfig的PVC或VLAN节点删除,不做修改
                        # GCW 20130418 修改WAN连接参数时,对X_CT-COM_Mode节点也不修改
                        if i == 'DestinationAddress' or i == 'VLANIDMark' or \
                           i == 'X_CT-COM_VLANIDMark' or i == "X_CT-COM_Mode":
                            continue
                        tmp_path = path5 + i
                        para_list5.append(dict(Name=tmp_path, Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数列表为空,请检查。\n"
                    log.app_info (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info (info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data5
                    log.app_err (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                """
                # 修改SetParameterValues设置WANPPPConnection参数
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数。\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数。\n"
                    log.app_info(info)
                    ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = path2_1
                para_list6 = []
                WAN_Enable = []

                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理.
                        # 标志位0表示X_CT-COM_ServiceList值需以工单中的为准,重新下发,3表示不下发
                        if WAN_Flag == 0:
                            pass
                        else:
                            if i == 'X_CT-COM_ServiceList':
                                continue
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data6
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功。\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s 。\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #13
0
def WLANMultiWANSetUP(obj,
                      sn,
                      WANEnable_Switch,
                      DeviceType,
                      AccessMode,
                      PVC_OR_VLAN,
                      dict_wanlinkconfig={},
                      dict_wanpppconnection={},
                      dict_wanipconnection={},
                      change_account=1,
                      rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            WAN_Flag = 1  # 强制新建
            if WAN_Flag == 1 or WAN_Flag == 2:
                #第三--一步:新建WANConnectionDevice实例
                info = u"开始调用AddObject新建WANConnectionDevice实例\n"
                log.app_info(info)
                ret_data_scr += info
                Classpath = ROOT_PATH
                #sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=Classpath)
                if (ret3 == ERR_SUCCESS):
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建WANConnectionDevice实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"新建WANConnectionDevice实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--二步:新建WANIPConnection或WANPPPConnection实例
                #log.app_info (u"第四步:增加WANIPConnection或WANPPPConnection实例")
                #只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例.暂时不考虑桥
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANPPPConnection实例\n"
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANIPConnection实例\n"
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(ObjectName=path4)

                if (ret4 == ERR_SUCCESS):
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data4["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,如何处理?
                    #对于失败的情况,直接返回失败
                    info = u"新建实例实例失败,退出执行,错误原因:%s\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--三步:调用SetParameterValues设置linkconfig参数:

                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig参数\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'X_CT-COM_WANVdslLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANVdslLinkConfig参数\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig参数\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                log.app_info(info)
                ret_data_scr += info

                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = path5 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    ret_data = u"参数列表为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                #log.app_info (u"第六步:调用SetParameterValues设置参数")
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    ret_data = u"参数列表为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                # nwf 2013-07-12
                #sleep(130)
                ret, ret_data = u1.wait_next_inform(
                    sn, worklistcfg.REBOOT_WAIT_NEXT_INFORM_TIMEOUT)
                ret_data_scr += ret_data
                if ret != ERR_SUCCESS:
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #14
0
def QoS(obj,
        sn,
        DeviceType,
        dict_root,
        dict_app,
        list_value_type,
        dict_classification,
        dict_priorityQueue,
        change_account=1,
        rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 返回成功或失败
    ret_data_scr = ""  # 返回结果日志

    #QoS的根节点
    QoS_ROOT_PATH = "InternetGatewayDevice.X_CT-COM_UplinkQoS."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:启用QoS和设置调度策略、DSCP及其他标志
            info = u"开始启用QoS和设置调度策略、DSCP及其它标志\n"
            log.app_info(info)
            ret_data_scr += info
            para_list1 = []
            for i in dict_root:
                if dict_root[i][0] == 1:
                    tmp_path = QoS_ROOT_PATH + i
                    para_list1.append(
                        dict(Name=tmp_path, Value=dict_root[i][1]))

            if para_list1 == []:
                info = u"参数为空,请检查"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.set_parameter_values(
                ParameterList=para_list1)
            if (ret_root == ERR_SUCCESS):
                info = u"启用QoS和设置调度策略、DSCP及其它标志成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data_root["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,直接返回错误
                info = u"启用QoS和设置调度策略、DSCP及其它标志失败,错误原因:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:增加队列实例
            #针对基于业务的QoS保障测试-UDP工单,需要多个TYPE实例
            tmp_Classification_path = [
            ]  # GCW 20130418 增加一步新建Classification实例的动作
            list_path3 = []  # Classification.{i}.type.路径下需下发的参数列表
            # 取队列号
            class_num = dict_classification['ClassQueue'][1]
            for i in xrange(len(list_value_type)):
                # GCW 20130418比贝曼增加一步,新增加以下实例
                # InternetGatewayDevice.X_CT-COM_UplinkQoS.Classification.
                info = u"开始调用AddObject新建Classification实例\n"
                log.app_info(info)
                ret_data_scr += info
                Classification_path = "InternetGatewayDevice.X_CT-COM_UplinkQoS.Classification."
                #sleep(3)  # must be ;otherwise exception
                ret_add, ret_data_add = u1.add_object(
                    ObjectName=Classification_path)

                if (ret_add == ERR_SUCCESS):
                    instanceNum1 = ret_data_add["InstanceNumber"]
                    info = u"新建Classification实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_Classification_path.append(Classification_path +
                                                   instanceNum1 + ".")
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(Classification_path + instanceNum1 +
                                        ".")
                    rebootFlag = int(ret_data_add["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,返回失败
                    info = u"新建Classification实例失败,退出执行,错误原因:%s\n" % ret_data_add
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                info = u"开始调用AddObject新建type实例\n"
                log.app_info(info)
                ret_data_scr += info
                type_path = Classification_path + instanceNum1 + ".type."
                #sleep(3)  # must be ;otherwise exception
                ret_add, ret_data_add = u1.add_object(ObjectName=type_path)

                if (ret_add == ERR_SUCCESS):
                    instanceNum1 = ret_data_add["InstanceNumber"]
                    info = u"新建type实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130327 增加回退机制
                    # GCW 20130419 由于增加了步骤新建Classification实例,所以回滚直接删除Classification实例
                    # rollbacklist.append(type_path + instanceNum1 + ".")
                    rebootFlag = int(ret_data_add["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,返回失败
                    info = u"新建type实例失败,退出执行,错误原因:%s\n" % ret_data_add
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                list_path3.append(type_path + instanceNum1 + ".")

            #第三步:对队列各个参数进行配置
            #注意,电信规范上没有分开写,即可以解读为是在一个RPC中下发后面第三四五步的所有参数,
            #而且对A上行,还有要求VLAN,但贝曼工单抓包看这两点均没有.目前按贝曼实现,待完善!

            for i in xrange(len(list_path3)):
                info = u"开始调用SetParameterValues,对队列各个参数进行配置\n"
                log.app_info(info)
                ret_data_scr += info
                para_list3 = []
                dict_type = list_value_type[i]
                for j in dict_type:
                    if dict_type[j][0] == 1:
                        tmp_path = list_path3[i] + j
                        para_list3.append(
                            dict(Name=tmp_path, Value=dict_type[j][1]))
                if para_list3 == []:
                    info = u"参数为空,请检查\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret_type, ret_data_type = u1.set_parameter_values(
                    ParameterList=para_list3)

                if (ret_type == ERR_SUCCESS):
                    info = u"对队列各个参数进行配置成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data_type["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,返回失败
                    info = u"对队列各个参数进行配置失败,错误原因:%s\n" % ret_data_type
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            #可以有个开关控制是否将以下参数与上面的参数一起下发。电信规范上是一起
            #第四步:对流分类进行配置
            # GCW 20130418增加了对Classification的设置.
            info = u"开始调用SetParameterValues,对Classification参数进行配置\n"
            log.app_info(info)
            ret_data_scr += info
            #path4 = QoS_ROOT_PATH + "Classification." + class_num + "."

            para_list4 = []
            for i in xrange(len(tmp_Classification_path)):
                for j in dict_classification:
                    if dict_classification[j][0] == 1:
                        tmp_path = tmp_Classification_path[i] + j
                        para_list4.append(
                            dict(Name=tmp_path,
                                 Value=dict_classification[j][1]))
            if para_list4 == []:
                info = u"参数为空,请检查\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #sleep(3)  # must be ;otherwise exception
            ret_class, ret_data_class = u1.set_parameter_values(
                ParameterList=para_list4)
            if (ret_class == ERR_SUCCESS):
                info = u"对Classification进行配置成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data_class["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,返回失败
                info = u"对Classification进行配置失败,错误原因:%s\n" % ret_data_class
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第五步:对优先级队列进行配置
            info = u"开始调用SetParameterValues,对优先级队列进行配置\n"
            log.app_info(info)
            ret_data_scr += info
            path5 = QoS_ROOT_PATH + "PriorityQueue." + class_num + "."
            para_list5 = []
            for i in dict_priorityQueue:
                if dict_priorityQueue[i][0] == 1:
                    tmp_path = path5 + i
                    para_list5.append(
                        dict(Name=tmp_path, Value=dict_priorityQueue[i][1]))
            if para_list5 == []:
                return ret_res, ret_data_scr

            #sleep(3)  # must be ;otherwise exception
            ret_prio, ret_data_prio = u1.set_parameter_values(
                ParameterList=para_list5)

            if (ret_prio == ERR_SUCCESS):
                info = u"对优先级队列进行配置成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data_prio["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,返回失败
                info = u"对优先级队列进行配置失败,错误原因:%s\n" % ret_data_prio
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            # 第五步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #15
0
def test_script(obj):
    """
    obj = MsgWorklistExecute
    default function name= test_script
    """
    ret_worklist = ERR_FAIL  # default
    ret_rpc = ERR_FAIL
    ret_datas = ""
    sn = obj.sn

    for nwf in [1]:
        try:

            # 新的双向的DIGEST认证账号的生成规则为:old+8为随机数
            user_name = get_random_8str(_Config.CPE2ACS_LOGIN_NAME)
            password = get_random_8str(_Config.CPE2ACS_LOGIN_PASSWORD)
            connection_request_user_name = get_random_8str(
                _Config.ACS2CPE_LOGIN_NAME)
            connection_request_password = get_random_8str(
                _Config.ACS2CPE_LOGIN_PASSWORD)

            # 新的联通维护账号密码的生成规则为 “cuadmin” + 8位随机数
            # cu_account_password = get_random_8str("cuadmin")

            # 组建所有要设置的节点参数
            ParameterList = [
                dict(Name="InternetGatewayDevice.ManagementServer.Username",
                     Value=user_name),
                dict(Name="InternetGatewayDevice.ManagementServer.Password",
                     Value=password),
                dict(
                    Name=
                    "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername",
                    Value=connection_request_user_name),
                dict(
                    Name=
                    "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword",
                    Value=connection_request_password)
            ]
            # dict(Name="InternetGatewayDevice.X_CU_Function.Web.AdminPassword",
            #      Value=cu_account_password)]

            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            log.app_info("Auto process set parameter value: %s " %
                         ParameterList)
            ret_rpc, ret_data = u1.set_parameter_values(
                ParameterList=ParameterList)
            ret_datas = ret_datas + "\n" + str(ret_data)
            if ret_rpc == ERR_SUCCESS:
                info = "success:%s" % ret_data
                log.app_info(info)
            else:
                info = "fail:%s" % ret_data
                log.app_err(info)
                break

            # update 2 acs(修改密码后需要通知ACS)
            ret_rpc, ret_data = update_username_password_to_acs(
                sn, user_name, password, connection_request_user_name,
                connection_request_password)
            if ret_rpc != ERR_SUCCESS:
                info = "fail:%s" % ret_data
                log.app_err(info)
                break

            # -------------------------
            log.app_info("Auto process get rpc methods")
            ret_rpc, ret_data = u1.get_rpc_methods()
            ret_datas = ret_datas + "\n" + str(ret_data)
            if ret_rpc == ERR_SUCCESS:
                info = "success:%s" % ret_data
                log.app_info(info)
            else:
                info = "fail:%s" % ret_data
                log.app_err(info)
                break

            ret_worklist = ERR_SUCCESS

        except Exception, e:
            info = str(e)
            log.app_err(info)
            ret_datas = ret_datas + "\n" + info
            break
Exemple #16
0
def AddAnIPTV(obj,
              sn,
              WANEnable_Switch,
              DeviceType,
              AccessMode,
              PVC_OR_VLAN,
              dict_root,
              dict_wanpppconnection,
              dict_wanipconnection,
              change_account=1,
              rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0
            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=1)
            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #第二步:逐个查找,对于A上行,查PVC,其他的则查VLAN
            #path2 = []
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConection或WANIPConection节点路径保存,后面修改参数时有用
            PVC_Flag = None
            #直接调GetParameterValues  查PVC或VLAN
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                #A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                if DeviceType == 'ADSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                elif DeviceType == 'LAN':
                    tmp_path2 = tmp_path2 + 'WANEthernetLinkConfig.X_CT-COM_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CT-COM_VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'EPON':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'VDSL':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANVdslLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                elif DeviceType == 'GPON':
                    tmp_path2 = tmp_path2 + 'X_CT-COM_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(
                        i + 1)
                else:
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(
                        i + 1)
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(
                    ParameterNames=tmp_path2)
                if (ret2 == ERR_SUCCESS):
                    info = u"查询成功,返回:%s\n" % ret_data2
                    log.app_info(info)
                    ret_data_scr += info
                    # 当返回的PVC与要绑定的相同时,标记PVC_Flag,走修改流程
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        # 如果查到PVC或VLAN相同,则标记
                        if ret_data2['ParameterList'] != []:
                            if ret_data2['ParameterList'][0][
                                    'Value'] == PVC_OR_VLAN:
                                # 查到有匹配PVC
                                PVC_Flag = 0
                                path2 = ret_data_root['ParameterList'][i][
                                    'Name']
                                break
                            else:
                                # 查不到匹配的PVC
                                continue
                        else:
                            continue
                else:
                    #对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            WAN_Flag = None
            if PVC_Flag == 0:

                ret_tmp_path2 = []

                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_path2 = path2 + 'WANPPPConnection.'
                    X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]
                    ConnectionType = dict_wanpppconnection['ConnectionType'][1]
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANPPPConnection实例\n" % str(
                        i + 1)
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    tmp_path2 = path2 + 'WANIPConnection.'
                    X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]
                    ConnectionType = dict_wanipconnection['ConnectionType'][1]
                    info = u"开始调用GetParameterNames查找第%s条WAN连接WANIPConnection实例\n" % str(
                        i + 1)

                log.app_info(info)
                ret_data_scr += info
                ret_tmp_path2 = []
                #sleep(3)
                ret2, ret_data2 = u1.get_parameter_names(
                    ParameterPath=tmp_path2, NextLevel=1)
                if (ret2 == ERR_SUCCESS):
                    info = u"查找WAN连接实例成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data2 = DelOwnParameterNames(ret_data2, tmp_path2)

                    if ret_data2['ParameterList'] != []:
                        for tmp_index in xrange(len(
                                ret_data2['ParameterList'])):
                            ret_tmp_path2.append(
                                ret_data2['ParameterList'][tmp_index]['Name'])
                else:
                    #对于失败的情况,直接退出
                    info = u"查找WAN连接实例失败,错误信息: %s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第2.2步,对于PPPOE查找X_CT-COM_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CT-COM_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CT-COM_ServiceList
                for i in xrange(len(ret_tmp_path2)):
                    info = u"开始调用GetParameterValues查找第%s个WAN连接实例下的X_CT-COM_ServiceList值\n" % str(
                        i + 1)
                    log.app_info(info)
                    ret_data_scr += info

                    tmp_path2_2 = []
                    tmp_path2_2.append(ret_tmp_path2[i] +
                                       'X_CT-COM_ServiceList')
                    # GCW 20130410对桥模式单独处理,避免修改PPPOE INTERNET为桥 INTERNET的情况
                    tmp_path2_2.append(ret_tmp_path2[i] + 'ConnectionType')
                    #sleep(3)
                    ret2_2, ret_data2_2 = u1.get_parameter_values(
                        ParameterNames=tmp_path2_2)
                    if (ret2_2 == ERR_SUCCESS):
                        info = u"查找第%s个WAN连接实例下的X_CT-COM_ServiceList和ConnectionType值成功,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        # 判断值是否相等,相等(或被包含)则只修改linkconfig节点的值即可,否则需走后面的正常流程新建WAN连接
                        if AccessMode == "PPPoE_Bridged":
                            ConnectionType = "PPPoE_Bridged"
                        else:
                            ConnectionType = "IP_Routed"

                        # GCW 20130417 路由对路由比较,桥对桥的比较才更合理
                        if ConnectionType == ret_data2_2['ParameterList'][0]['Value'] or \
                           ConnectionType == ret_data2_2['ParameterList'][1]['Value']:
                            # 如果非完全不相等,则需做特殊处理
                            if (ret_data2_2['ParameterList'][0]['Value'] in X_CT_COM_ServiceList \
                                    or ret_data2_2['ParameterList'][1]['Value'] in X_CT_COM_ServiceList) \
                                or (X_CT_COM_ServiceList in ret_data2_2['ParameterList'][0]['Value'] \
                                    or X_CT_COM_ServiceList in ret_data2_2['ParameterList'][1]['Value']):
                                # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理.
                                if (ret_data2_2['ParameterList'][0]['Value'] in X_CT_COM_ServiceList \
                                  or ret_data2_2['ParameterList'][1]['Value'] in X_CT_COM_ServiceList):
                                    info = u"当前CPE中的X_CT-COM_ServiceList值包含于工单中要求的X_CT-COM_ServiceList值:%s,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接的流程,且重新下发X_CT-COM_ServiceList值的修改\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 0  #表示CPE当前值包含于工单,走修改WAN流程,且X_CT-COM_ServiceList需下发
                                else:
                                    info = u"当前工单中的X_CT-COM_ServiceList值:%s包含于CPE中的X_CT-COM_ServiceList值,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接流程,但不下发对X_CT-COM_ServiceList值的修改.\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 3  #表示工单中的值包含于当前CPE中,走修改WAN流程,但X_CT-COM_ServiceList不需下发
                                path2_1 = ret_tmp_path2[i]
                                #将上一层路径保存并退出循环,留给下一步直接修改linkconfig参数
                                #ret_tmp_path2[i]类似于InternetGatewayDevice.WANDevice.1.WANConnectionDevice.3.WANPPPConnection.1.
                                a = ret_tmp_path2[i].split('.')
                                for i in xrange(len(a) - 3):
                                    path2 += a[i]
                                    path2 += '.'  # 将当前的WANConnectionDevice.节点路径保存,后面修改参数时有用
                                break
                            else:
                                continue
                        else:
                            continue
                    else:
                        info = u"查找第%s个WAN连接实例下的X_CT-COM_ServiceList值失败,返回:%s\n" % (
                            str(i + 1), ret_data2_2)
                        log.app_info(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

                if WAN_Flag == None:
                    info = u"查找不到匹配 %s 模式的WAN连接\n" % X_CT_COM_ServiceList
                    log.app_info(info)
                    ret_data_scr += info
                    WAN_Flag = 1

            else:
                #对于未查找到相同PVC的,直接返回错误
                info = u"未查找到PVC或VLAN为 %s 的连接,请确认!" % PVC_OR_VLAN
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            if WAN_Flag == 1 or WAN_Flag == 2:
                #第三--一步:新建WANConnectionDevice实例
                info = u"走X_CT-COM_ServiceList不相同的流程(新建WAN连接).\n"
                log.app_info(info)
                ret_data_scr += info

                # 解决用户新建tr069WAN连接导致CPE与ACS通讯异常的问题,强制不准新建包含TR0069的WAN连接

                if (("tr069" in X_CT_COM_ServiceList)
                        or ("TR069" in X_CT_COM_ServiceList)):
                    info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建.\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 如果查找到相同的PVC,则在该PVC/VLAN下新建一个IPTV连接
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                    tmp_path3 = path2 + 'WANPPPConnection.'
                    info = u"查到匹配的PVC或VLAN,开始在该PVC或VLAN下新建一条实例。\n"

                elif AccessMode == 'DHCP' or AccessMode == 'Static':

                    tmp_path3 = path2 + 'WANIPConnection.'
                    info = u"查到匹配的PVC或VLAN,开始在该PVC或VLAN下新建一条实例。\n"
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=tmp_path3)

                if (ret3 == ERR_SUCCESS):
                    instanceNum1 = ret_data3["InstanceNumber"]
                    tmp_path4 = tmp_path3 + instanceNum1 + '.'
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rollbacklist.append(tmp_path4)
                    rebootFlag = int(ret_data3["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"新建实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                para_list6 = []
                WAN_Enable = []
                for j in tmp_values:
                    if tmp_values[j][0] == 1:
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and j == 'Enable':
                            WAN_Enable.append(
                                dict(Name=tmp_path4 + j,
                                     Value=tmp_values[j][1]))
                            continue

                        tmp_path = tmp_path4 + j
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[j][1]))

                if para_list6 == []:
                    info = u"参数为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"调用SetParameterValues设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"调用SetParameterValues设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,如何处理?
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            elif WAN_Flag == 0 or WAN_Flag == 3:
                """
                #当查到有相匹配的X_CT-COM_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可
                #第三--三步:调用SetParameterValues设置linkconfig参数:
                if DeviceType == 'ADSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'LAN':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANEthernetLinkConfig参数\n"
                    path5 = path2 + 'WANEthernetLinkConfig.'
                elif DeviceType == 'EPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANEponLinkConfig参数\n"
                    path5 = path2 + 'X_CT-COM_WANEponLinkConfig.'                
                elif DeviceType == 'VDSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANVdslLinkConfig参数\n"
                    path5 = path2 + 'X_CT-COM_WANVdslLinkConfig.'
                elif DeviceType == 'GPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANGponLinkConfig参数\n"
                    path5 = path2 + 'X_CT-COM_WANGponLinkConfig.'
                else:
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                log.app_info (info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        #对于Linkconfig的PVC或VLAN节点删除,不做修改
                        # GCW 20130418 修改WAN连接参数时,对X_CT-COM_Mode节点也不修改
                        if i == 'DestinationAddress' or i == 'VLANIDMark' or \
                           i == 'X_CT-COM_VLANIDMark' or i == "X_CT-COM_Mode":
                            continue
                        tmp_path = path5 + i
                        para_list5.append(dict(Name=tmp_path, Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数列表为空,请检查\n"
                    log.app_info (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功\n"
                    log.app_info (info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                """
                # 修改SetParameterValues设置WANPPPConnection参数
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                    log.app_info(info)
                    ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = path2_1
                para_list6 = []
                WAN_Enable = []

                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理.
                        # 标志位0表示X_CT-COM_ServiceList值需以工单中的为准,重新下发,3表示不下发
                        if WAN_Flag == 0:
                            pass
                        else:
                            if i == 'X_CT-COM_ServiceList':
                                continue
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用SetParameterValues设置X_CT-COM_IPTV参数:
            para_list7 = []
            path = 'InternetGatewayDevice.Services.X_CT-COM_IPTV.'
            for i in dict_root:
                if dict_root[i][0] == 1:
                    tmp_path = path + i
                    para_list7.append(
                        dict(Name=tmp_path, Value=dict_root[i][1]))
            if para_list7 == []:
                info = u"X_CT-COM_IPTV参数为空,请检查\n"
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            info = u"开始调用SetParameterValues设置X_CT-COM_IPTV节点参数\n"
            log.app_info(info)
            ret_data_scr += info

            #sleep(3)  # must be ;otherwise exception
            ret7, ret_data7 = u1.set_parameter_values(ParameterList=para_list7)
            if (ret7 == ERR_SUCCESS):
                info = u"设置参数成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data7["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,如何处理?
                info = u"设置参数失败,错误原因:%s\n" % ret_data7
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #17
0
def IPTVEnable(obj, sn, WANEnable_Switch, DeviceType,
               AccessMode, PVC_OR_VLAN,
               dict_root, dict_wanlinkconfig,
               dict_wanpppconnection,
               dict_wanipconnection,
               change_account=1,
               rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn, ip=worklistcfg.AGENT_HTTP_IP, port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE, sender=KEY_SENDER_WORKLIST, worklist_id=obj.id_)
            reboot_Yes = 0
            # 第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接\n"
            log.app_info(info)
            ret_data_scr += info
            # sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(ParameterPath=ROOT_PATH, NextLevel=1)
            if ret_root == ERR_SUCCESS:
                info = u"查询WAN连接成功\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                # 对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 第二步:逐个查找,对于A上行,查PVC,其他的则查VLAN
            # path2 = []
            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConnection或WANIPConnection节点路径保存,后面修改参数时有用
            WAN_Flag = None
            # 直接调GetParameterValues  查PVC或VLAN
            for i in xrange(len(ret_data_root['ParameterList'])):
                tmp_path2 = ret_data_root['ParameterList'][i]['Name']
                # A上行是关心PVC,LAN上行是关心VLAN,PON上行也是关心VLAN
                """
                if DeviceType == 'ADSL':
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(i+1)
                elif DeviceType == 'LAN':
                    tmp_path2 = tmp_path2 + 'WANEthernetLinkConfig.X_CU_VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点X_CU_VLANIDMark值\n" % str(i+1)
                elif DeviceType == 'EPON':
                    tmp_path2 = tmp_path2 + 'X_CU_WANEponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(i+1)
                elif DeviceType == 'VDSL':
                    tmp_path2 = tmp_path2 + 'X_CU_WANVdslLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(i+1)
                elif DeviceType == 'GPON':
                    tmp_path2 = tmp_path2 + 'X_CU_WANGponLinkConfig.VLANIDMark'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的VLAN节点VLANIDMark值\n" % str(i+1)
                else:
                    tmp_path2 = tmp_path2 + 'WANDSLLinkConfig.DestinationAddress'
                    info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点DestinationAddress值\n" % str(i+1)
                log.app_info (info)
                ret_data_scr += info
                """
                tmp_path2 = tmp_path2 + 'X_CU_VLAN'
                info = u"开始调用GetParameterValues,查询第%s个WAN连接的PVC节点值\n" % str(i + 1)
                ret_data_scr += info
                # sleep(3)
                ret2, ret_data2 = u1.get_parameter_values(ParameterNames=tmp_path2)
                if ret2 == ERR_SUCCESS:
                    info = u"查询成功,返回:%s\n" % ret_data2
                    log.app_info(info)
                    ret_data_scr += info
                    # 当返回的PVC与要绑定的相同时,标记WAN_Flag,走修改流程
                    if ret_data2['ParameterList'] == []:
                        pass
                    else:
                        # 如果查到PVC或VLAN相同,则标记
                        if ret_data2['ParameterList']:
                            if ret_data2['ParameterList'][0]['Value'] == PVC_OR_VLAN:
                                # 查到有匹配PVC
                                WAN_Flag = 0
                                path2 = ret_data_root['ParameterList'][i]['Name']
                                break
                            else:
                                # 查不到匹配的PVC
                                continue
                        else:
                            continue
                else:
                    # 对于失败的情况,直接返回错误
                    info = u"查询失败,错误信息%s\n" % ret_data2
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则走新建流程
            if WAN_Flag == None:
                WAN_Flag = 1

            # 查不到匹配的PVC或VLAN,则走新建流程,否则还需再查WANPPPConnection节点下的值
            if WAN_Flag == 0:
                # 当查到有相匹配的PVC时的处理流程,则还需查WANPPPConnection下的三个节点是否一致
                # 如果完全一致,则直接使能IGMP,否则需重新设置WANPPPConnection下的值(注意原有是INTERNET,重新下发是INTERNET,OTHER的情况)
                # return ret_res

                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_path3 = path2 + 'WANPPPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    if AccessMode == "PPPoE_Bridged":
                        tmp_ConnectionType = "PPPoE_Bridged"
                    else:
                        tmp_ConnectionType = "IP_Routed"
                    tmp_X_CU_LanInterface = dict_wanpppconnection['X_CU_LanInterface'][1]
                    tmp_X_CU_ServiceList = dict_wanpppconnection['X_CU_ServiceList'][1]
                    info = u"查到匹配的PVC或VLAN,开始调用GetParameterNames查询WANPPPConnection节点参数\n"
                elif AccessMode == 'DHCP' or AccessMode == 'Static':
                    tmp_path3 = path2 + 'WANIPConnection.'
                    # GCW 20130418 应该只区分是路由还是桥接
                    tmp_ConnectionType = "IP_Routed"
                    tmp_X_CU_LanInterface = dict_wanipconnection['X_CU_LanInterface'][1]
                    tmp_X_CU_ServiceList = dict_wanipconnection['X_CU_ServiceList'][1]
                    info = u"查到匹配的PVC或VLAN,开始调用GetParameterNames查询WANIPConnection节点参数\n"
                log.app_info(info)
                ret_data_scr += info

                # sleep(3)
                ret_tmp_path3 = []
                ret3, ret_data3 = u1.get_parameter_names(ParameterPath=tmp_path3, NextLevel=1)
                if ret3 == ERR_SUCCESS:
                    info = u"查询成功,返回:%s\n" % ret_data3
                    log.app_info(info)
                    ret_data_scr += info
                    # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                    ret_data3 = DelOwnParameterNames(ret_data3, tmp_path3)
                    # 返回有路径,则保存
                    if ret_data3['ParameterList']:
                        for tmp_index in xrange(len(ret_data3['ParameterList'])):
                            ret_tmp_path3.append(ret_data3['ParameterList'][tmp_index]['Name'])
                else:
                    # 对于失败的情况,直接退出
                    info = u"查询失败,返回:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # 第2.2步,对于PPPOE查找X_CU_ServiceList和Username值.
                # 由于贝曼有些版本只查X_CU_ServiceList,或者查到Username相同与否不影响判断结果,
                # 所以目前只支持查X_CU_ServiceList
                for i in xrange(len(ret_tmp_path3)):
                    info = u"开始调用GetParameterValues查询第%s个WAN连接的参数\n" % str(i + 1)
                    log.app_info(info)
                    ret_data_scr += info

                    tmp_path3_2 = []
                    tmp_path3_2.append(ret_tmp_path3[i] + 'ConnectionType')
                    tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_LanInterface')
                    tmp_path3_2.append(ret_tmp_path3[i] + 'X_CU_ServiceList')
                    # sleep(3)
                    ret3_2, ret_data3_2 = u1.get_parameter_values(ParameterNames=tmp_path3_2)
                    if ret3_2 == ERR_SUCCESS:
                        info = u"查询成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        # 判断值是否相等,相等则不修改,直接走IGMP使能
                        # 解决部分CPE不按顺序返回ConnectionType\X_CU_LanInterface\X_CU_ServiceList节点值的情况 gcw 20130516
                        WAN_Flag_1 = 1
                        for j in xrange(3):

                            if 'ConnectionType' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_ConnectionType:
                                    # WAN_Flag_1 = 1
                                    pass
                                else:
                                    # 路由和桥的区别时,需重新走新建WAN连接流程  GCW 20130506
                                    WAN_Flag_1 = 3
                                    break
                            elif 'X_CU_LanInterface' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_X_CU_LanInterface:
                                    # WAN_Flag_1 = 1
                                    pass
                                else:
                                    WAN_Flag_1 = 0
                                    # break
                            elif 'X_CU_ServiceList' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                                if ret_data3_2['ParameterList'][j]['Value'] == tmp_X_CU_ServiceList:
                                    # WAN_Flag_1 = 1
                                    pass
                                else:
                                    WAN_Flag_1 = 0
                                    # break
                        # 如果有一个不匹配,则修改WANPPPConnection节点下的值
                        if WAN_Flag_1 == 0:
                            # 对于查到是INTERNET,而待下发的是OTHER的话,贝曼的处理是重新修改为"INTERNET,OTHER"
                            # GCW 20130401 以下处理虽然符合贝曼,但不合理.重新定义为以传参为准.
                            # for j in xrange(3):
                            #    if 'X_CU_ServiceList' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                            #        if ret_data3_2['ParameterList'][j]['Value'] != tmp_X_CU_ServiceList:
                            #            tmp_X_CU_ServiceList = 'INTERNET,OTHER'

                            if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                                tmp_values = dict_wanpppconnection
                                info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改WANPPPConnection参数\n"
                            else:
                                tmp_values = dict_wanipconnection
                                info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改WANIPConnection参数\n"
                            log.app_info(info)
                            ret_data_scr += info

                            # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                            path6 = ret_tmp_path3[i]
                            para_list6 = []
                            WAN_Enable = []
                            for j in tmp_values:
                                if tmp_values[j][0] == 1:
                                    # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                                    if WANEnable_Switch == False and j == 'Enable':
                                        WAN_Enable.append(dict(Name=path6 + j, Value=tmp_values[j][1]))
                                        continue

                                    tmp_path = path6 + j
                                    # 如果是X_CU_ServiceList,则用修改后的值
                                    if j == 'X_CU_ServiceList':
                                        para_list6.append(dict(Name=tmp_path, Value=tmp_X_CU_ServiceList))
                                    else:
                                        para_list6.append(dict(Name=tmp_path, Value=tmp_values[j][1]))
                            if para_list6 == []:
                                info = u"参数为空,请检查\n"
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr

                            # sleep(3)  # must be ;otherwise exception
                            ret6, ret_data6 = u1.set_parameter_values(ParameterList=para_list6)
                            if ret6 == ERR_SUCCESS:
                                info = u"修改参数成功\n"
                                log.app_info(info)
                                ret_data_scr += info
                                rebootFlag = int(ret_data6["Status"])
                                if rebootFlag == 1:
                                    reboot_Yes = 1
                            else:
                                # 对于失败的情况,直接返回失败
                                info = u"修改参数失败,错误原因:%s\n" % ret_data6
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr

                            # 将WAN连接使能单独下发
                            if WAN_Enable:
                                info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                                log.app_info(info)
                                ret_data_scr += info
                                # sleep(3)  # must be ;otherwise exception
                                ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(ParameterList=WAN_Enable)
                                if ret_wan_enable == ERR_SUCCESS:
                                    info = u"设置WAN连接使能参数成功\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    rebootFlag = int(ret_data_wan_enable["Status"])
                                    if rebootFlag == 1:
                                        reboot_Yes = 1
                                else:
                                    # 对于失败的情况,如何处理?
                                    info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                                    log.app_err(info)
                                    ret_data_scr += info
                                    return ret_res, ret_data_scr
                        elif WAN_Flag_1 == 3:
                            WAN_Flag = 1  # 重置WAN_Flag标志位,走新建WAN连接流程
                        else:
                            info = u"查询到的值与用户工单中传参过来的相等,无需修改WAN连接参数\n"
                            log.app_info(info)
                            ret_data_scr += info
                    else:
                        info = u"查询失败,请检查\n"
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            if WAN_Flag == 1:
                # 第三--一步:新建WANConnectionDevice实例
                info = u"查不到匹配的PVC(VLAN)、或ConnectionType(模式)不匹配,走新建WAN连接。\n"
                log.app_info(info)
                ret_data_scr += info

                info = u"开始调用AddObject新建WANConnectionDevice实例。\n"
                log.app_info(info)
                ret_data_scr += info

                Classpath = ROOT_PATH
                # sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(
                    ObjectName=Classpath)
                if ret3 == ERR_SUCCESS:
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"新建实例失败,错误原因:%s\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--二步:新建WANIPConnection或WANPPPConnection实例
                # 只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例.暂时不考虑桥
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WANPPPConnection实例\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WANIPConnection实例\n"
                    log.app_info(info)
                    ret_data_scr += info

                # sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(
                    ObjectName=path4)

                if ret4 == ERR_SUCCESS:
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info

                    rebootFlag = int(ret_data4["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"新建实例失败,错误原因:%s\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--三步:调用SetParameterValues设置linkconfig参数:
                """
                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CU_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANEponLinkConfig参数\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'X_CU_WANVdslLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANVdslLinkConfig参数\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CU_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CU_WANGponLinkConfig参数\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数\n"
                log.app_info (info)
                ret_data_scr += info
                """
                info = u"开始调用SetParameterValues设置参数\n"
                log.app_info(info)
                ret_data_scr += info
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = tmp_path3 + i
                        para_list5.append(dict(Name=tmp_path, Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                # sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list5)
                if ret5 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数\n"
                log.app_info(info)
                ret_data_scr += info
                # 第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # 如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    info = u"参数为空,请检查\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(ParameterList=para_list6)
                if ret6 == ERR_SUCCESS:
                    info = u"设置参数成功\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if rebootFlag == 1:
                        reboot_Yes = 1
                else:
                    # 对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 将WAN连接使能单独下发
                if WAN_Enable:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数\n"
                    log.app_info(info)
                    ret_data_scr += info

                    # sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(ParameterList=WAN_Enable)
                    if ret_wan_enable == ERR_SUCCESS:
                        info = u"设置WAN连接使能参数成功\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if rebootFlag == 1:
                            reboot_Yes = 1
                    else:
                        # 对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            # 第七步:调用SetParameterValues设置X_CU_IPTV参数:
            para_list7 = []
            path = 'InternetGatewayDevice.X_CU_Function.IGMP.'
            for i in dict_root:
                if dict_root[i][0] == 1:
                    tmp_path = path + i
                    para_list7.append(dict(Name=tmp_path, Value=dict_root[i][1]))
            if para_list7 == []:
                info = u"X_CU_IPTV参数为空,请检查\n"
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            info = u"开始调用SetParameterValues设置X_CU_IPTV节点参数\n"
            log.app_info(info)
            ret_data_scr += info

            # sleep(3)  # must be ;otherwise exception
            ret7, ret_data7 = u1.set_parameter_values(ParameterList=para_list7)
            if ret7 == ERR_SUCCESS:
                info = u"设置参数成功\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data7["Status"])
                if rebootFlag == 1:
                    reboot_Yes = 1
            else:
                # 对于失败的情况,如何处理?
                info = u"设置参数失败,错误原因:%s\n" % ret_data7
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if reboot_Yes == 1:

                # sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if ret != ERR_SUCCESS:
                    ret_data_scr += ret_data
                    break

            # 第七步:调用修改联通维护密码,目前密码固定为CUAdmin
            ret, ret_data = ChangeAccount_CU(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #18
0
def WLANEnable(obj, sn, dict_ssid,
         change_account=1,
         rollbacklist=[]):
    """                        
    """
    ret_res = ERR_FAIL # 脚本返回值,成功或失败.缺省失败    
    ret_data_scr = "" # 返回结果日志
    
    # 入参处理
    tmp_ssid = []
    for i in dict_ssid:
        if dict_ssid[i][0] == 1:
            tmp_ssid.append([dict_ssid[i][1], dict_ssid[i][2]])
    if tmp_ssid == []:
        info = u"工单传参数错误,请检查\n"
        log.app_info (info)
        ret_data_scr += info
        return ret_res, ret_data_scr

    WLAN_ROOT_PATH = "InternetGatewayDevice.LANDevice.1.WLANConfiguration."
    for nwf in [1]:
        try:
            u1=User(sn, ip=worklistcfg.AGENT_HTTP_IP, port=worklistcfg.AGENT_HTTP_PORT, page=worklistcfg.WORKLIST2AGENT_PAGE, sender=KEY_SENDER_WORKLIST, worklist_id=obj.id_)
            reboot_Yes = 0
            #第一步:调用GetParameterNames方法,查找当前有几个无线实例
            info = u"开始调用GetParameterNames方法,查找当前无线实例个数\n"
            log.app_info (info)
            ret_data_scr += info
            
            para_list = []
            path = WLAN_ROOT_PATH
            ret_root, ret_data1_root = u1.get_parameter_names(ParameterPath=path, NextLevel='1')
            #sleep(2)  # must be ;otherwise exception
            if (ret_root == ERR_SUCCESS):
                info = u"查找当前无线实例个数成功。\n"
                log.app_info (info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data1_root = DelOwnParameterNames(ret_data1_root, path)
            else:
                #对于失败的情况,直接返回失败
                info = u"查找当前无线实例失败.失败信息:%s \n。" % ret_data1_root
                log.app_err (info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            
            para_list = []
           
            # 判断当前要启用或禁用的无线实例(SSID)是否存在,不存在则报错退出
            for i in xrange(len(tmp_ssid)):   
                
                tmp_para_path = path + tmp_ssid[i][0]
                tmp_flag = False
                
                for j in xrange(len(ret_data1_root['ParameterList'])):
                    
                    if ret_data1_root['ParameterList'][j]['Name'] in tmp_para_path:
                        para_list.append(dict(Name=tmp_para_path, Value=tmp_ssid[i][1]))
                        tmp_flag = True
                        break
                
                if tmp_flag == False:
                    #对于失败的情况,直接返回失败
                    info = u"未查找到节点为 %s 的无线实例,请确认。\n" % tmp_para_path
                    log.app_err (info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
            
            info = u"开始调用SetParameterValues设置无线实例启用或禁用。。。\n"
            log.app_info (info)
            ret_data_scr += info          
            
            #设置值
            ret_root, ret_data_root = u1.set_parameter_values(ParameterList=para_list)
            #sleep(2)  # must be ;otherwise exception
            if (ret_root == ERR_SUCCESS):
                info = u"设置无线实例启用或禁用成功。\n"
                log.app_info (info)
                ret_data_scr += info
                rebootFlag = int(ret_data_root["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                # 对于失败的情况,直接返回错误
                info = u"设置无线实例启用或禁用失败,详细信息: \n" % ret_data_root
                log.app_err (info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break
                
            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data
                
            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err (str(e))
            ret_data_scr += str(e)+'\n'
            return ret_res, ret_data_scr
Exemple #19
0
def IPV6VOIP(obj,
             sn,
             WANEnable_Switch,
             DeviceType,
             AccessMode,
             PVC_OR_VLAN,
             dict_voiceservice,
             dict_wanlinkconfig={},
             dict_wanpppconnection={},
             dict_wanipconnection={},
             change_account=1,
             rollbacklist=[]):
    """                        
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    voiceservice_path = "InternetGatewayDevice.Services.VoiceService.1."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0

            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接。\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=0)
            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功。\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s 。\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged':

                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                    X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]

                elif AccessMode == 'DHCP' or AccessMode == 'Static':

                    X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]

                ret_find, serverlist_items, connect_type_items, ret_data_find = _find_wan_server_and_connecttype(
                    u1, AccessMode, dict_wanpppconnection,
                    dict_wanipconnection, ret_data_root, ret_data_scr)

                if ret_find == ERR_SUCCESS:
                    ret_data_scr = ret_data_find
                else:
                    ret_data_scr = ret_data_find
                    return ret_res, ret_data_find

                if AccessMode == "PPPoE_Bridged":
                    ConnectionType = "PPPoE_Bridged"
                else:
                    ConnectionType = "IP_Routed"

            else:
                info = u"输入的AccessMode参数不合法,请检查!\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            WAN_Flag = None
            modify_path = None

            for i_connect in connect_type_items:

                tmp_ppp_list = i_connect['Name'].split('.')[0:-1]
                tmp_ppp_path = '.'.join(
                    tmp_ppp_list)  # 保存XXXX.WANPPPConnection.i.路径

                # 确定WAN,是否修改
                for j_serverlist in serverlist_items:

                    tmp_serverlist = j_serverlist['Name']

                    # 同一条WAN连接下进行比较
                    if tmp_ppp_path in tmp_serverlist:

                        # 桥对桥,路由对路由
                        if ConnectionType in i_connect['Value']:

                            if X_CT_COM_ServiceList in j_serverlist[
                                    'Value'] or j_serverlist[
                                        'Value'] in X_CT_COM_ServiceList:

                                modify_path = j_serverlist['Name']
                                if j_serverlist[
                                        'Value'] in X_CT_COM_ServiceList:

                                    info = u"当前CPE中的X_CT-COM_ServiceList值包含于工单中要求的X_CT-COM_ServiceList值:%s,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接的流程,且重新下发X_CT-COM_ServiceList值的修改。\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 0
                                else:
                                    info = u"当前工单中的X_CT-COM_ServiceList值:%s包含于CPE中的X_CT-COM_ServiceList值,\n" % X_CT_COM_ServiceList
                                    info += u"走修改WAN连接流程,但不下发对X_CT-COM_ServiceList值的修改。\n"
                                    log.app_info(info)
                                    ret_data_scr += info
                                    WAN_Flag = 3

                                break

                            else:
                                continue

            if WAN_Flag == None:
                info = u"查找不到匹配 %s 模式的WAN连接。" % X_CT_COM_ServiceList
                log.app_info(info)
                ret_data_scr += info
                WAN_Flag = 1

            # 下发VOIP参数
            voipflag = "Enabled"  #开通或取消VOIP工单的状态标识位
            para_list = []
            for i in dict_voiceservice:
                if dict_voiceservice[i][0] == 1:
                    tmp_path = voiceservice_path + i
                    # 根据传参进来字典中来查找是VOIP开通还是取消,
                    # 设置状态位来决定后面不要再走新建或修改WAN连接的流程
                    if "VoiceProfile.1.Line.1.Enable" == i:
                        voipflag = dict_voiceservice[i][1]
                    para_list.append(
                        dict(Name=tmp_path, Value=dict_voiceservice[i][1]))

            # 如果是VOIP取消工单,但又没有找到相等或包含X_CT-COM_ServiceList的WAN连接,则退出报成功
            if voipflag == "Disabled" and (WAN_Flag == 1 or WAN_Flag == 2):
                info = u"取消VOIP工单,但查不到%s 的WAN连接。\n" % X_CT_COM_ServiceList
                log.app_info(info)
                ret_data_scr += info
                ret_res = ERR_SUCCESS
                return ret_res, ret_data_scr

            info = u"开始调用SetParameterValues设置VOIP参数。\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret5, ret_data5 = u1.set_parameter_values(ParameterList=para_list)
            if (ret5 == ERR_SUCCESS):
                info = u"设置参数成功。\n"
                log.app_info(info)
                ret_data_scr += info
                rebootFlag = int(ret_data5["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
            else:
                #对于失败的情况,直接退出
                info = u"设置参数失败,错误原因:%s 。\n" % ret_data5
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            #0 均相同,只修改LinkConfig.(参考a.1包)
            #1 两者均不相同的情况下:等同于查到是空的情况,后续新建WAN连接参考a.2包)
            #2 部分相同,而且关键点X_CT-COM_ServiceList不相同的情况下:等同于查到是空的情况,后续新建WAN连接(参考a.3包)
            #3 部分相同,而且关键点X_CT-COM_ServiceList相同的情况下:等同于查到均相同的情况,只修改LinkConfig.(参考a.4包)
            if (WAN_Flag == 1 or WAN_Flag == 2) and voipflag == "Enabled":
                #第三--一步:新建WANConnectionDevice实例
                info = u"走X_CT-COM_ServiceList不相同的流程(新建WAN连接)。\n"
                log.app_info(info)
                ret_data_scr += info

                # 解决用户新建tr069WAN连接导致CPE与ACS通讯异常的问题,强制不准新建包含TR0069的WAN连接
                if "tr069" in X_CT_COM_ServiceList:
                    info = u"工单失败:为避免新建包含tr069模式的WAN连接对原有tr069WAN连接产生影响,所以不再新建。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                Classpath = ROOT_PATH
                #sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=Classpath)
                if (ret3 == ERR_SUCCESS):
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建WANConnectionDevice实例成功,返回实例号:%s 。\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"新建WANConnectionDevice实例失败,错误原因:%s 。\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--二步:新建WANIPConnection或WANPPPConnection实例
                #只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANPPPConnection实例。\n"
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WAN连接的WANIPConnection实例。\n"
                log.app_info(info)
                ret_data_scr += info

                #sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(ObjectName=path4)

                if (ret4 == ERR_SUCCESS):
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s 。\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data4["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"新建实例实例失败,退出执行,错误原因:%s 。\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--三步:调用SetParameterValues设置linkconfig参数:

                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数。\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig参数。\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig参数。\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig参数。\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig参数。\n"
                log.app_info(info)
                ret_data_scr += info

                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = path5 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    ret_data = u"参数列表为空,请检查。\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数。\n"
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数。\n"
                log.app_info(info)
                ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = tmp_path4 + '.'
                para_list6 = []
                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    ret_data = u"参数列表为空,请检查。\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data6
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功。\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s 。\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            elif (WAN_Flag == 0 or WAN_Flag == 3) and voipflag == "Enabled":
                #第三--三步:调用SetParameterValues设置linkconfig参数:
                path2_list = modify_path.split('.')[0:-3]
                path2_1_list = modify_path.split('.')[0:-1]

                path2 = '.'.join(path2_list) + '.'
                path2_1 = '.'.join(path2_1_list) + '.'

                #当查到有相匹配的X_CT-COM_ServiceList和Username值时的处理流程,不需要新建,只需更改WANIPConnection或WANPPPConnection节点下的参数即可
                #第三--三步:调用SetParameterValues设置linkconfig参数:
                # 针对v6工单,修改流程时不下发link层的修改

                if DeviceType == 'ADSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数。\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'LAN':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANEthernetLinkConfig参数。\n"
                    path5 = path2 + 'WANEthernetLinkConfig.'
                elif DeviceType == 'EPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANEponLinkConfig参数。\n"
                    path5 = path2 + 'X_CT-COM_WANEponLinkConfig.'
                elif DeviceType == 'VDSL':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改VDSL/ADSL兼容网关的WANDSLLinkConfig参数。\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                elif DeviceType == 'GPON':
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改X_CT-COM_WANGponLinkConfig参数。\n"
                    path5 = path2 + 'X_CT-COM_WANGponLinkConfig.'
                else:
                    info = u"走X_CT-COM_ServiceList相同的流程(修改WAN连接),开始调用SetParameterValues修改WANDSLLinkConfig参数。\n"
                    path5 = path2 + 'WANDSLLinkConfig.'
                log.app_info(info)
                ret_data_scr += info

                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        #对于Linkconfig的PVC或VLAN节点删除,不做修改
                        # GCW 20130418 修改WAN连接参数时,对X_CT-COM_Mode节点也不修改
                        if i == 'DestinationAddress' or i == 'VLANIDMark' or \
                           i == 'X_CT-COM_VLANIDMark' or i == "X_CT-COM_Mode":
                            continue
                        tmp_path = path5 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数列表为空,请检查。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception
                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                # 修改SetParameterValues设置WANPPPConnection参数
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection
                    info = u"开始调用SetParameterValues设置WANPPPConnection参数。\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    tmp_values = dict_wanipconnection
                    info = u"开始调用SetParameterValues设置WANIPConnection参数。\n"
                    log.app_info(info)
                    ret_data_scr += info

                #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                path6 = path2_1
                para_list6 = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        # GCW 20130408 判断X_CT-COM_ServiceList包含与被包含的关系做区分处理.
                        # 标志位0表示X_CT-COM_ServiceList值需以工单中的为准,重新下发,3(即else)表示不下发
                        if WAN_Flag == 0:
                            pass
                        else:
                            if i == 'X_CT-COM_ServiceList':
                                continue
                        tmp_path = path6 + i
                        para_list6.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))
                if para_list6 == []:
                    return ret_res, ret_data_scr

                #sleep(3)  # must be ;otherwise exception
                ret6, ret_data6 = u1.set_parameter_values(
                    ParameterList=para_list6)
                if (ret6 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data6["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data6
                    log.app_info(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #20
0
def IPV6IPTVEnable(obj,
                   sn,
                   WANEnable_Switch,
                   DeviceType,
                   AccessMode,
                   PVC_OR_VLAN,
                   dict_root,
                   dict_wanlinkconfig,
                   dict_wanpppconnection,
                   dict_wanipconnection,
                   change_account=1,
                   rollbacklist=[]):
    """
    """
    ret_res = ERR_FAIL  # 脚本返回值,成功或失败.缺省失败
    ret_data_scr = ""  # 返回结果日志

    ROOT_PATH = "InternetGatewayDevice.WANDevice.1.WANConnectionDevice."
    for nwf in [1]:
        try:
            u1 = User(sn,
                      ip=worklistcfg.AGENT_HTTP_IP,
                      port=worklistcfg.AGENT_HTTP_PORT,
                      page=worklistcfg.WORKLIST2AGENT_PAGE,
                      sender=KEY_SENDER_WORKLIST,
                      worklist_id=obj.id_)
            reboot_Yes = 0
            #第一步:调用GetParameterNames方法,查询WAN连接
            info = u"开始调用GetParameterNames方法,查询WAN连接。\n"
            log.app_info(info)
            ret_data_scr += info
            #sleep(3)  # must be ;otherwise exception
            ret_root, ret_data_root = u1.get_parameter_names(
                ParameterPath=ROOT_PATH, NextLevel=0)
            if (ret_root == ERR_SUCCESS):
                info = u"查询WAN连接成功。\n"
                log.app_info(info)
                ret_data_scr += info
                # GCW 20130329 解决部分CPE同时将当前路径返回的情况,将其删除
                ret_data_root = DelOwnParameterNames(ret_data_root, ROOT_PATH)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询WAN连接失败,错误信息:%s 。\n" % ret_data_root
                log.app_err(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            if AccessMode == 'PPPoE' or AccessMode == 'DHCP' or AccessMode == 'Static' or AccessMode == 'PPPoE_Bridged':

                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                    X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]

                elif AccessMode == 'DHCP' or AccessMode == 'Static':

                    X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]

                ret_find, pvcorvlan_items, serverlist_items, connect_type_items, laninterface_items, ret_data_find = _find_wan_server_and_connecttype(
                    u1, DeviceType, AccessMode, dict_wanpppconnection,
                    dict_wanipconnection, ret_data_root, ret_data_scr)

                if ret_find == ERR_SUCCESS:
                    ret_data_scr = ret_data_find
                else:
                    ret_data_scr = ret_data_find
                    return ret_res, ret_data_find

                if AccessMode == "PPPoE_Bridged":
                    ConnectionType = "PPPoE_Bridged"
                else:
                    ConnectionType = "IP_Routed"

            else:
                info = u"输入的AccessMode参数不合法,请检查!\n"
                log.app_info(info)
                ret_data_scr += info
                return ret_res, ret_data_scr

            WAN_Flag = None

            path2 = ''  # 保存查到有相同的PVC或关键参数值的WAN连接路径
            path2_1 = ''  # 保存WANPPPConection或WANIPConection节点路径保存,后面修改参数时有用

            for i_pvcorvlan in pvcorvlan_items:

                if i_pvcorvlan['Value'] == PVC_OR_VLAN:
                    WAN_Flag = 0
                    path2 = i_pvcorvlan['Name']
                    break
                else:
                    # 查不到匹配的PVC
                    continue

            # 如果一直没有查到相同的,则没有对WAN_Flag标志位做过修改,则走新建流程
            if WAN_Flag == None:
                WAN_Flag = 1

            # 查不到匹配的PVC或VLAN,则走新建流程,否则还需再查WANPPPConnection节点下的值
            if WAN_Flag == 0:

                # 不同的WAN连接模式,其节点路径不同
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':

                    # GCW 20130418 应该只区分是路由还是桥接
                    if AccessMode == "PPPoE_Bridged":
                        tmp_ConnectionType = "PPPoE_Bridged"
                    else:
                        tmp_ConnectionType = "IP_Routed"
                    tmp_X_CT_COM_LanInterface = dict_wanpppconnection[
                        'X_CT-COM_LanInterface'][1]
                    tmp_X_CT_COM_ServiceList = dict_wanpppconnection[
                        'X_CT-COM_ServiceList'][1]

                elif AccessMode == 'DHCP' or AccessMode == 'Static':

                    # GCW 20130418 应该只区分是路由还是桥接
                    tmp_ConnectionType = "IP_Routed"
                    tmp_X_CT_COM_LanInterface = dict_wanipconnection[
                        'X_CT-COM_LanInterface'][1]
                    tmp_X_CT_COM_ServiceList = dict_wanipconnection[
                        'X_CT-COM_ServiceList'][1]

                tmp_link_list = path2.split('.')[0:-2]
                tmp_link_path = '.'.join(
                    tmp_link_list)  # 保存XXXX.WANPPPConnection.i.路径

                WAN_Flag_server = 1
                WAN_Flag_connect = 1
                WAN_Flag_interface = 1

                if serverlist_items != []:

                    # 查找到pvc及对应连接方式的serverlist,connecttype以及interface
                    #X_CT_COM_ServiceList
                    for i_serverlist in serverlist_items:

                        if tmp_link_path in i_serverlist['Name']:

                            if i_serverlist[
                                    'Value'] == tmp_X_CT_COM_ServiceList:

                                pass
                            else:
                                tmp_path3_list = i_serverlist['Name'].split(
                                    '.')[0:-1]
                                ret_tmp_path3 = '.'.join(tmp_path3_list) + "."

                                WAN_Flag_server = 0

                    # ConnectionType
                    for i_connect_type in connect_type_items:

                        if tmp_link_path in i_connect_type['Name']:

                            if i_connect_type['Value'] == tmp_ConnectionType:

                                pass
                            else:
                                # 路由和桥的区别时,需重新走新建WAN连接流程  GCW 20130506
                                WAN_Flag_connect = 3
                                break

                    # X_CT_COM_LanInterface
                    for i_laninterface in laninterface_items:

                        if tmp_link_path in i_laninterface['Name']:

                            if i_laninterface[
                                    'Value'] == tmp_X_CT_COM_LanInterface:

                                pass
                            else:
                                tmp_path3_list = i_laninterface['Name'].split(
                                    '.')[0:-1]
                                ret_tmp_path3 = '.'.join(tmp_path3_list) + "."
                                WAN_Flag_interface = 0
                else:
                    # 查找到pvc但是没有对应连接方式的serverlist,connecttype以及interface,此时需要走新建流程
                    WAN_Flag_connect = 3

                if WAN_Flag_connect != 3:

                    #如果有一个不匹配,则修改WANPPPConnection节点下的值
                    if WAN_Flag_interface == 0 or WAN_Flag_server == 0:
                        #对于查到是INTERNET,而待下发的是OTHER的话,贝曼的处理是重新修改为"INTERNET,OTHER"
                        # GCW 20130401 以下处理虽然符合贝曼,但不合理.重新定义为以传参为准.
                        #for j in xrange(3):
                        #    if 'X_CT-COM_ServiceList' in ret_data3_2['ParameterList'][j]['Name'].split("."):
                        #        if ret_data3_2['ParameterList'][j]['Value'] != tmp_X_CT_COM_ServiceList:
                        #            tmp_X_CT_COM_ServiceList = 'INTERNET,OTHER'

                        info = u"查找到匹配的PVC(VLAN)但参数不匹配,走修改WAN连接。\n"
                        log.app_info(info)
                        ret_data_scr += info

                        if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                            tmp_values = dict_wanpppconnection
                            info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改参数。\n"
                        else:
                            tmp_values = dict_wanipconnection
                            info = u"查询到的值与用户工单中传参过来的有不相等情况,开始调用SetParameterValues修改参数。\n"
                        log.app_info(info)
                        ret_data_scr += info

                        #第三--四步:调用SetParameterValues设置WANPPPConnection参数:
                        # 同时下发IGMP参数;
                        path6 = ret_tmp_path3
                        para_list6 = []
                        WAN_Enable = []
                        for j in tmp_values:
                            if tmp_values[j][0] == 1:
                                #如果WAN连接使能需单独下发,则将使能的动作单独保存
                                if WANEnable_Switch == False and j == 'Enable':
                                    WAN_Enable.append(
                                        dict(Name=path6 + j,
                                             Value=tmp_values[j][1]))
                                    continue

                                tmp_path = path6 + j
                                # 如果是X_CT-COM_ServiceList,则用修改后的值
                                if (j == 'X_CT-COM_ServiceList'):
                                    para_list6.append(
                                        dict(Name=tmp_path,
                                             Value=tmp_X_CT_COM_ServiceList))
                                else:
                                    para_list6.append(
                                        dict(Name=tmp_path,
                                             Value=tmp_values[j][1]))

                        # IGMP参数
                        path = 'InternetGatewayDevice.Services.X_CT-COM_IPTV.'
                        for i in dict_root:
                            if dict_root[i][0] == 1:
                                tmp_path = path + i
                                para_list6.append(
                                    dict(Name=tmp_path, Value=dict_root[i][1]))

                        if para_list6 == []:
                            info = u"参数为空,请检查。\n"
                            log.app_err(info)
                            ret_data_scr += info
                            return ret_res, ret_data_scr

                        #sleep(3)  # must be ;otherwise exception
                        ret6, ret_data6 = u1.set_parameter_values(
                            ParameterList=para_list6)
                        if (ret6 == ERR_SUCCESS):
                            info = u"修改参数成功。\n"
                            log.app_info(info)
                            ret_data_scr += info
                            rebootFlag = int(ret_data6["Status"])
                            if (rebootFlag == 1):
                                reboot_Yes = 1
                        else:
                            #对于失败的情况,直接返回失败
                            info = u"修改参数失败,错误原因:%s 。\n" % ret_data6
                            log.app_err(info)
                            ret_data_scr += info
                            return ret_res, ret_data_scr

                        #将WAN连接使能单独下发
                        if WAN_Enable != []:
                            info = u"开始调用SetParameterValues设置WAN连接使能参数。\n"
                            log.app_info(info)
                            ret_data_scr += info
                            #sleep(3)  # must be ;otherwise exception
                            ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                                ParameterList=WAN_Enable)
                            if (ret_wan_enable == ERR_SUCCESS):
                                info = u"设置WAN连接使能参数成功。\n"
                                log.app_info(info)
                                ret_data_scr += info
                                rebootFlag = int(ret_data_wan_enable["Status"])
                                if (rebootFlag == 1):
                                    reboot_Yes = 1
                            else:
                                #对于失败的情况,如何处理?
                                info = u"设置WAN连接使能参数失败,错误原因:%s 。\n" % ret_data_wan_enable
                                log.app_err(info)
                                ret_data_scr += info
                                return ret_res, ret_data_scr
                    else:
                        info = u"查询到的值与用户工单中传参过来的相等,无需修改WAN连接参数 。\n"
                        log.app_info(info)
                        ret_data_scr += info

                else:
                    WAN_Flag = 1  # 重置WAN_Flag标志位,走新建WAN连接流程

            if WAN_Flag == 1:
                #第三--一步:新建WANConnectionDevice实例
                info = u"查不到匹配的PVC(VLAN)、或ConnectionType(模式)不匹配,走新建WAN连接。\n"
                log.app_info(info)
                ret_data_scr += info

                info = u"开始调用AddObject新建WANConnectionDevice实例。\n"
                log.app_info(info)
                ret_data_scr += info

                Classpath = ROOT_PATH
                #sleep(3)  # must be ;otherwise exception
                ret3, ret_data3 = u1.add_object(ObjectName=Classpath)
                if (ret3 == ERR_SUCCESS):
                    instanceNum1 = ret_data3["InstanceNumber"]
                    info = u"新建实例成功,返回实例号:%s 。\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info
                    tmp_path3 = Classpath + instanceNum1 + '.'
                    # GCW 20130327 增加回退机制
                    rollbacklist.append(tmp_path3)
                    rebootFlag = int(ret_data3["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接返回失败
                    info = u"新建实例失败,错误原因:%s 。\n" % ret_data3
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--二步:新建WANIPConnection或WANPPPConnection实例
                #只有是桥模式和路由PPPOE时,才新建WANPPPConnection实例.暂时不考虑桥
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    path4 = ROOT_PATH + instanceNum1 + '.WANPPPConnection.'
                    info = u"开始调用AddObject新建WANPPPConnection实例。\n"
                    log.app_info(info)
                    ret_data_scr += info
                else:
                    path4 = ROOT_PATH + instanceNum1 + '.WANIPConnection.'
                    info = u"开始调用AddObject新建WANIPConnection实例。\n"
                    log.app_info(info)
                    ret_data_scr += info

                #sleep(3)  # must be ;otherwise exception
                ret4, ret_data4 = u1.add_object(ObjectName=path4)

                if (ret4 == ERR_SUCCESS):
                    instanceNum1 = ret_data4["InstanceNumber"]
                    tmp_path4 = path4 + instanceNum1
                    info = u"新建实例成功,返回实例号:%s 。\n" % instanceNum1
                    log.app_info(info)
                    ret_data_scr += info

                    rebootFlag = int(ret_data4["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"新建实例失败,错误原因:%s 。\n" % ret_data4
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #第三--三步:调用SetParameterValues设置linkconfig参数:

                if DeviceType == 'ADSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n"
                elif DeviceType == 'LAN':
                    path5 = tmp_path3 + 'WANEthernetLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANEthernetLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n"
                elif DeviceType == 'EPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANEponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANEponLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n"
                elif DeviceType == 'VDSL':
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置VDSL/ADSL兼容网关的WANDSLLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n"
                elif DeviceType == 'GPON':
                    path5 = tmp_path3 + 'X_CT-COM_WANGponLinkConfig.'
                    info = u"开始调用SetParameterValues设置X_CT-COM_WANGponLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n"
                else:
                    path5 = tmp_path3 + 'WANDSLLinkConfig.'
                    info = u"开始调用SetParameterValues设置WANDSLLinkConfig,WANPPPConnection(或WANIPConnection)及IGMP参数。\n"
                log.app_info(info)
                ret_data_scr += info

                # 添加link层
                para_list5 = []
                for i in dict_wanlinkconfig:
                    if dict_wanlinkconfig[i][0] == 1:
                        tmp_path = path5 + i
                        para_list5.append(
                            dict(Name=tmp_path,
                                 Value=dict_wanlinkconfig[i][1]))
                if para_list5 == []:
                    info = u"参数为空,请检查。\n"
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr
                #sleep(3)  # must be ;otherwise exception

                # 添加ppp或ip层
                if AccessMode == 'PPPoE' or AccessMode == 'PPPoE_Bridged':
                    tmp_values = dict_wanpppconnection

                else:
                    tmp_values = dict_wanipconnection

                path6 = tmp_path4 + '.'

                WAN_Enable = []
                for i in tmp_values:
                    if tmp_values[i][0] == 1:
                        #如果WAN连接使能需单独下发,则将使能的动作单独保存
                        if WANEnable_Switch == False and i == 'Enable':
                            WAN_Enable.append(
                                dict(Name=path6 + i, Value=tmp_values[i][1]))
                            continue

                        tmp_path = path6 + i
                        para_list5.append(
                            dict(Name=tmp_path, Value=tmp_values[i][1]))

                # 添加IGMP
                # IGMP参数
                path = 'InternetGatewayDevice.Services.X_CT-COM_IPTV.'
                for i in dict_root:
                    if dict_root[i][0] == 1:
                        tmp_path = path + i
                        para_list5.append(
                            dict(Name=tmp_path, Value=dict_root[i][1]))

                ret5, ret_data5 = u1.set_parameter_values(
                    ParameterList=para_list5)
                if (ret5 == ERR_SUCCESS):
                    info = u"设置参数成功。\n"
                    log.app_info(info)
                    ret_data_scr += info
                    rebootFlag = int(ret_data5["Status"])
                    if (rebootFlag == 1):
                        reboot_Yes = 1
                else:
                    #对于失败的情况,直接退出
                    info = u"设置参数失败,错误原因:%s 。\n" % ret_data5
                    log.app_err(info)
                    ret_data_scr += info
                    return ret_res, ret_data_scr

                #将WAN连接使能单独下发
                if WAN_Enable != []:
                    info = u"开始调用SetParameterValues设置WAN连接使能参数。\n"
                    log.app_info(info)
                    ret_data_scr += info

                    #sleep(3)  # must be ;otherwise exception
                    ret_wan_enable, ret_data_wan_enable = u1.set_parameter_values(
                        ParameterList=WAN_Enable)
                    if (ret_wan_enable == ERR_SUCCESS):
                        info = u"设置WAN连接使能参数成功。\n"
                        log.app_info(info)
                        ret_data_scr += info
                        rebootFlag = int(ret_data_wan_enable["Status"])
                        if (rebootFlag == 1):
                            reboot_Yes = 1
                    else:
                        #对于失败的情况,直接返回错误
                        info = u"设置WAN连接使能参数失败,错误原因:%s 。\n" % ret_data_wan_enable
                        log.app_err(info)
                        ret_data_scr += info
                        return ret_res, ret_data_scr

            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):

                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break

            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data

            ret_res = ERR_SUCCESS
        except Exception, e:
            log.app_err(str(e))
            ret_data_scr += str(e) + '\n'
            return ret_res, ret_data_scr
Exemple #21
0
def SmartTV(obj,sn,
               X_CT_COM_Mode,
               X_CT_COM_VLAN,
               IPTV_Interface,
               change_account=1):
    """
    开通智能电视,即,将LAN侧(除绑定IPTV外的接口)与IPTV WAN连接的VLAN绑定
    """
    ret_res = ERR_FAIL # 返回成功或失败
    ret_data_scr = "" # 返回结果日志
    
    Lan_Interface_Path = "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig."
       
    for i in [1]:
        
        try:
            u1=User(sn, ip=worklistcfg.AGENT_HTTP_IP, port=worklistcfg.AGENT_HTTP_PORT, page=worklistcfg.WORKLIST2AGENT_PAGE, sender=KEY_SENDER_WORKLIST, worklist_id=obj.id_)
            reboot_Yes = 0

            ret, lan_iptv = ParseLANName(IPTV_Interface)
            if ret == ERR_FAIL:
                info = u'输入的X_CT_COM_LanInterface参数错误'
                log.app_err (info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            
            info = u"开始调用GetParameterNames方法,查询LANEthernetInterfaceConfig信息。\n"
            log.app_info (info)
            ret_data_scr += info
            ret_lan_device, ret_data_lan_device = u1.get_parameter_names(ParameterPath=Lan_Interface_Path, NextLevel=0)
            
            if (ret_lan_device == ERR_SUCCESS):
                info = u"查询LANEthernetInterfaceConfig信息成功。\n"
                log.app_info (info)
                ret_data_scr += info
                ret_data_lan_device = DelOwnParameterNames(ret_data_lan_device, Lan_Interface_Path)
            else:
                #对于失败的情况,直接返回失败
                info = u"查询LANEthernetInterfaceConfig信息失败,错误信息:%s 。\n" % ret_data_device_info
                log.app_err (info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            
            reg_LAN_Mode = "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.[1-9]+.X_CT-COM_Mode"
            reg_LAN_VLAN = "InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.[1-9]+.X_CT-COM_VLAN"
            
            bind_lan_list = []
            
            for i in xrange(len(ret_data_lan_device['ParameterList'])):
                
                tmp_lan_path = ret_data_lan_device['ParameterList'][i]['Name']
                
                m_Mode = re.match(reg_LAN_Mode,tmp_lan_path)
                m_VLAN = re.match(reg_LAN_VLAN,tmp_lan_path)
       
                if (m_Mode is not None) and (lan_iptv not in tmp_lan_path):
                    
                    bind_lan_list.append(dict(Name=tmp_lan_path,Value=X_CT_COM_Mode))
                
                if (m_VLAN is not None) and (lan_iptv not in tmp_lan_path):
                    
                    bind_lan_list.append(dict(Name=tmp_lan_path,Value=X_CT_COM_VLAN))
            
            if bind_lan_list == []:
                info = u"未查找到LAN侧的X_CT-COM_Mode和X_CT-COM_Vlan节点。"
                log.app_err (info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            
            info = u"开始调用SetParameterValues设置LAN侧的X_CT-COM_Mode和X_CT-COM_VLAN。\n"       
            log.app_info (info)
            ret_data_scr += info
            
            ret, ret_data = u1.set_parameter_values(ParameterList=bind_lan_list)
            if (ret == ERR_SUCCESS):
                info = u"设置参数成功。\n"
                log.app_info (info)
                ret_data_scr += info
                rebootFlag = int(ret_data["Status"])
                if (rebootFlag == 1):
                    reboot_Yes = 1
                
            else:
                #对于失败的情况,直接返回失败
                info = u"设置参数失败,错误原因:%s 。\n" % ret_data
                log.app_info (info)
                ret_data_scr += info
                return ret_res, ret_data_scr
            
            # 如果需要重启,则下发Reboot方法,目前采用静等待130S
            if (reboot_Yes == 1):
                #sleep(130)
                ret, ret_data = reboot_wait_next_inform(u1)
                if (ret != ERR_SUCCESS):
                    ret_data_scr += ret_data
                    break
            
            #第七步:调用修改电信维护密码,目前密码固定为nE7jA%5m
            ret, ret_data = ChangeAccount_CT(obj, sn, change_account)
            if ret == ERR_FAIL:
                ret_data_scr += ret_data
                return ret, ret_data_scr
            else:
                ret_data_scr += ret_data
            
            ret_res = ERR_SUCCESS
            
        except Exception, e:
            log.app_err (str(e))
            ret_data_scr += str(e)+'\n'
            return ret_res, ret_data_scr