--------------------------------------------------------------------------------
--                   Copyright, 2012-2013, Huawei Tech. Co., Ltd.
--                             All Rights Reserved
--------------------------------------------------------------------------------
-- Project Code    : OMM UPD V1.0
-- File name       : upd_atoms.lua
-- Description     : Agent侧升级流程模板
--------------------------------------------------------------------------------
-- History         :
--  1 Date         : 2012.12.20
--    Modification : 新增文件
--------------------------------------------------------------------------------
--执行状态表
g_UpdState =
{
    FlowId = 0,        --当前正在执行的流程的流水号
    AtomGroup = "",    --当前正在执行的升级原子组
    NodeIp = "",       --当前节点IP地址
    Step = "",         --当前步骤
    ParamList = {},    --参数列表
    Result = 0,        --原子组执行结果
    SyncFirmwareFlag = 0,     --同步标记，是否是第一次同步固件
    SyncVersionFlag = 0,      --同步标记，是否是第一次同步版本
    NodeNid = "",             --节点的NID
    MasterIp = "",
    HotPatchUpd = false,      --节点是否处于热补丁升级中
    IsRecoverToNormal = 3,     --热补丁回退、删除中发生异常重启，节点是否恢复成normal
    ConcurrentAtom = {}, -- 并发原子组表
    CannotSyncFlag = 0, --是否可以同步
    SyncSysAndFwFailFlag = 0, --同步控制框，BIOS，异构失败标志	
    PowerLostFlag = 0;--掉电标志
    FailAG = "",    --失败原子组
    FailStep = "",     --失败步骤
    SkipFlag = 0,     --是否可以忽略当前失败步骤
}
local MSG_RETRY_TIMES = 15;        --重发上报消息，重发时间
local MSG_RETRY_INTERVAL = 5;      --重发上报消息，重发间隔

local RET_OK = 0;        --函数执行结果: 成功
local RET_ERR = -1;      --函数执行结果: 失败
local RET_INIT = -1;     --原子组执行结果: 未执行
local RET_SUCC = 0;      --原子组执行结果: 执行成功
local RET_FAIL = 2;      --原子组执行结果: 执行失败、或者 升级失败且回退失败
local RET_RBK_SUCC = 3;  --原子组执行结果: 回退成功
local RET_TIMEOUT = 4;   --原子组执行结果: 执行超时
local ATOM_RET_SUCC = 0; --原子执行结果: 成功
local ATOM_RET_FAIL = 1; --原子执行结果: 失败

--交换机DMI状态
local DMI_UPGRADE_STAT_IDLE =0;
local DMI_UPGRADE_STAT_PREPARE_SUCCEED =1;
local DMI_UPGRADE_STAT_PREPARE_FAILED =2;
local DMI_UPGRADE_STAT_FILE_TXING =3;
local DMI_UPGRADE_STAT_FILE_TX_SUCCEED =4;
local DMI_UPGRADE_STAT_FILE_TX_FAILED =5;
local DMI_UPGRADE_STAT_UPGRADING =6;
local DMI_UPGRADE_STAT_UPGRADE_SUCCEED =7;
local DMI_UPGRADE_STAT_UPGRADE_FAILED =8;

-- 检查server升级信息
local UPD_CHECK_IS_IN_UPD = 20011;
local UPD_SET_SWAP_MASTER_FLAG = 20018;
--大规格升框所用参数(秒)
local SECONDS_PER_MINUTE = 60;
local MAX_FRAME_NUM = 61;
--升框额外的时间(分钟)
local EXTRATIME_WHEN_UPGRADE_FRAME = 5;
--升级单个框时间(秒)
local UPGRADE_SINGLE_DISK_ENCL_TIME = 240;
local UPGRADE_SINGLE_CTRL_ENCL_TIME = 1200;
--升框默认超时时间(分钟),保证大规格升框时间至少是这个超时时间
local UPGRADE_ENCL_DEFAULT_TIMEOUT = 30;

--驱动返回错误码，对应原子侧调用驱动接口返回DMI_FW_UPGRADE_PARAM_S中的FailedState
local DMI_UPGRADE_PREPARE_FAILED = "2"
local DMI_UPGRADE_FILE_TX_FAILED = "5"
local DMI_UPGRADE_UPGRADE_FAILED = "8"
--驱动返回的版本校验错误码，对应原子侧DMI_FW_VER_CHECK_S中Res
local DMI_UPGRADE_FW_VER_CORRECT = "0"
local DMI_UPGRADE_FW_VER_WRONG   = "1"

local ERRCODE_EQUAL = "errCode="
local ABNORMAL_REBOOT_ERR_CODE = 0X400333FF;



------------------------------
------原子执行结果定义------
------------------------------

----------------------------
------执行超时时间定义------
----------------------------

----------------------------
------仿真工程开关------
----------------------------
local g_WinSwitch = 0;

--================== UPD Framwork API ==========================================
--------------------------------------------------------------------------------
-- Func Name       : LogText(level, message, ...)
-- Description     : 日志打印函数
-- Caution         : 由升级框架注册给Lua使用
-- Input           : level: 日志级别, LL_DEBUG, LL_INFO, LL_WARN, LL_ERROR, LL_NOTICE
--                   message: 待打印的消息，可以字符串或者格式化字符串加上变参
-- Output          : 无
-- Return          : 无
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : timer.start(func, interval, mode)
-- Description     : 启动定时器
-- Caution         : 由升级框架注册给Lua使用
-- Input           : func: 定时器回调函数
--                   interval: 定时器间隔
--                   mode: 定时器模式, TIMER_NOLOOP -- 非循环 TIMER_LOOP -- 循环
-- Output          : 无
-- Return          : 定时器ID
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : timer.stop(timer_id)
-- Description     : 停止定时器
-- Caution         : 由升级框架注册给Lua使用
-- Input           : timer_id: 定时器ID
-- Output          : 无
-- Return          : 无
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : timer.tick()
-- Description     : 获取系统tick值
-- Caution         : 由升级框架注册给Lua使用
-- Input           :
-- Output          :
-- Return          : number: 系统tick值
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : timer.time()
-- Description     : 获取系统时间
-- Caution         : 由升级框架注册给Lua使用
-- Input           :
-- Output          :
-- Return          : number: 系统时间
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : ExecAtomGroup(atom_group, node_ip)
-- Description     : 通知节点执行指定的AtomGroup
-- Caution         : 由升级框架注册给Lua使用
-- Input           : atom_group: string 待执行的AtomGroup名称
--                   node_ip: string 节点的IP地址
--                   timeout: int AtomGroup的超时时间,建议取Atom的最大超时时间
--                   param_list: string 从Server侧传递到Agent侧的参数列表
-- Output          : 无
-- Return          : 消息发送结果, 0 -- 成功 -1 -- 失败
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : System(cmd, timeout)
-- Description     : 执行系统调用
-- Caution         : 由升级框架注册给Lua使用
-- Input           : cmd: 命令行字符串
--                   timeout: 命令行执行超时时间，单位为分钟
-- Output          : 无
-- Return          : 0-127 -- 子进程的返回值 128 -- 子进程异常结束
--                   129 -- 子进程超时 130 -- 内部错误
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : SyncState(file_name)
-- Description     : 同步升级状态文件
-- Caution         : 由升级框架注册给Lua使用
-- Input           : file_name: 待同步的升级状态文件名，包含全路径
-- Output          : 无
-- Return          : 无
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : ReportAtomExecResult(node_ip, atom_group, atom, result, progress)
-- Description     : 上报原子执行结果
-- Caution         : 由升级框架注册给Lua使用
-- Input           : node_ip: 本节点IP地址    atom_group: AtomGroup名称
--                   atom: Atom名称           result: Atom执行结果
--                   progress: 当前AtomGroup执行的进度
-- Output          : 无
-- Return          : 返回上报消息发送是否成功 0 -- 成功 1 -- 失败
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Func Name       : Serialize
-- Description     : 序列化Lua Table
-- Caution         : 由OMM维护, 请勿修改
-- Input           : o: Lua变量，支持number/string/boolean/tabl/nil这几种类型
-- Output          :
-- Return          : 返回变量序列化之后的字符串
--------------------------------------------------------------------------------
function Serialize(o)
    local s = "";
    local t = type(o);
    if t == "number" then
        s = s .. o;
    elseif t == "string" then
        s = s .. string.format("%q", o);
    elseif t == "boolean" then
        s = s .. tostring(o);
    elseif t == "table" then
        s = s .. "{\n";
        for k,v in pairs(o) do
            s = s .. " [" .. Serialize(k) .. "] = " .. Serialize(v) .. ",\n";
        end

        s = s .. "}\n";
    elseif t == nil then
        return nil;
    else
       LogText(LL_ERROR, "Cannot serialize type: " .. type(o));
    end

    return s;
end

--持久化升级状态到文件中
function SaveState()
    if (nil == g_UpdState) then
        LogText(LL_ERROR, "The state table is nil.");
        return;
    end

    local s = Serialize(g_UpdState);
    LogText(LL_NOTICE, "Serialized upd state:\n" .. s);
    local fn = "/startup_disk/conf/conf_local/upd_state_atoms.lua";

    --以只读打开文件来判断文件的存在性
    local is_exist = false;
    local ff = io.open(fn, "r");
    if ( ff ~= nil ) then
        ff:close();
        is_exist = true;
    end

    --以写+方式打开文件
    local f = io.open(fn, "w+");
    if (nil == f) then
    --解决启动盘短暂修复
    os.execute("sleep " .. 3);
    f = io.open(fn, "w+");
        if (nil == f) then
            LogText(LL_WARN, "Can not open flows state file.");
            return;
        end
    end

    --文件不存在创建新文件时，修改文件权限为644
    if ( is_exist == false ) then
        os.execute("chmod 664 " .. fn);
    end

    f:write(s);
    f:flush();
    f:close();
    os.execute("fsync " .. fn);
end
--------------------------------------------------------------------------------
-- Func Name       :保存节点的NID
-- Description     :
-- Caution         :
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function SaveNodeNid(Nid, MasterIp)
    LogText(LL_NOTICE, "SaveNodeNid.");
    g_UpdState.NodeNid = Nid;
    g_UpdState.MasterIp = MasterIp;
    SaveState(g_UpdState);
    return 0;
end

--检查并设置当前升级失败原子为可忽略状态
function CheckAndSetSkipFlag()
    LogText(LL_NOTICE, "Check and set skip flag for cur failed step.");
    if ((nil == g_UpdState.FailAG) or (nil == g_UpdState.FailStep) or ("" == g_UpdState.FailAG) or ("" == g_UpdState.FailStep)) then
        LogText(LL_NOTICE, "No failed step.");
        return RET_ERR;
    end
    g_UpdState.SkipFlag = 1;
    SaveState(g_UpdState);
    return RET_OK;
end

--从文件中加载升级状态
function LoadState()
    local fn = "/startup_disk/conf/conf_local/upd_state_atoms.lua";
    local f = io.open(fn, "r");
    if (nil == f) then
        --解决启动盘短暂修复
        os.execute("sleep " .. 3);
        local f = io.open(fn, "r");
        if (nil == f) then
            LogText(LL_WARN, "Can not open flows state file.");
            return;
        end
    end

    local s = f:read("*all");
    f:close();
    if (s == nil) or (s == "") then
        LogText(LL_WARN, "Atom state file is blank.");
        return;
    end

    s = "return " .. s;
    local func = loadstring(s);
    if (nil == func) then
        LogText(LL_WARN, "No content in flows state file.");
        return;
    end
    g_UpdState = func();
end

--替换命令行中的参数
function ReplaceParam(Cmd)
    LogText(LL_NOTICE, "Replace param for cmd: " .. Cmd);

    local p = "";
    local W = "";
    for w in string.gmatch(Cmd, "%$%b()") do                --匹配参数: $()
        W = string.gsub(w, "%W", "%%%1");                   --转义参数中的特殊字符
        p = string.sub(w, 3, -2);
        if (nil == g_UpdState.ParamList[p]) then
            LogText(LL_WARN, "Replaced param (" .. p .. ") in ParamList is nil.");
            g_UpdState.ParamList[p] = '""';
        end
        Cmd = string.gsub(Cmd, W, g_UpdState.ParamList[p]); --替换参数
    end

    LogText(LL_NOTICE, "Replaced cmd: " .. Cmd);
    return Cmd;
end



-- 将table转换成string
function Table2String(paramTable)
    local param = "{"
    for key, value in pairs(paramTable) do
        param = param .. key .. "='" .. value .. "',"
    end
    param = param .. "}"
    return param
end

-- 获取发送消息的重试时间和重试间隔,15次，每次间隔5S
function GetMsgRetryInfo()
    return MSG_RETRY_TIMES, MSG_RETRY_INTERVAL;
end
--------------------------------------------------------------------------------
-- Func Name       : Retry
-- Description     : 重试原子
-- Caution         : 由升级框架调用，函数名称、参数、返回值必须与模板一致
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function Retry(atom, ret)
    local _retry;
    _retry = function (atom, ret, times, interval)
        if (times <= 0) then
            return ret;
        end

        if (atom.retry[ret] ~= nil) then
            if (atom.retry[ret][1] <= 0) then
                return ret;
            end
            if(atom.retry[ret][3] ~= nil) then
                atom.retry[ret][3]();  --调用函数进行修复，之后进行再操作
            end
        else
            if (atom.retry['other'] == nil) then
                return ret;
            else
                if (atom.retry['other'][1] <= 0) then
                    return ret;
                end
                if(atom.retry['other'][3] ~= nil) then
                    atom.retry['other'][3]();  --调用函数进行修复，之后进行再操作
                end
            end
        end

        os.execute("sleep " .. interval);
        local ret = atom.func();
        return _retry(atom, ret, times - 1, interval);
    end

    if (atom ~= nil) and (atom.retry ~= nil) then
        if (atom.retry[ret] ~= nil) then
            local times = atom.retry[ret][1];
            local interval = atom.retry[ret][2];
            if (times <= 0) or (interval < 0) then
                LogText(LL_NOTICE, "(Retry) Times or interval is zero.");
                return ret;
            end

            if(atom.retry[ret][3] ~= nil) then
                atom.retry[ret][3]();  --调用函数进行修复，之后进行再操作
            end
            os.execute("sleep " .. interval);
            local ret = atom.func();
            return _retry(atom, ret, times - 1, interval);
        elseif (atom.retry['other'] ~= nil) then
            local times = atom.retry['other'][1];
            local interval = atom.retry['other'][2];
            if (times <= 0) or (interval < 0) then
                LogText(LL_NOTICE, "(Retry) Times or interval is zero.");
                return ret;
            end

            if(atom.retry['other'][3] ~= nil) then
                atom.retry['other'][3]();  --调用函数进行修复，之后进行再操作
            end
            os.execute("sleep " .. interval);
            local ret = atom.func();
            return _retry(atom, ret, times - 1, interval);
        else --对应的错误码不需要重试
            return ret;
        end
    else --不需要重试
        return ret;
    end
end
--================== UPD Framwork API ==========================================


--================== UPD Framwork Callback =====================================


--------------------------------------------------------------------------------
-- Func Name       : getErrInfoFromFile
-- Description     : 从文件中获取错误信息
-- Caution         : 从文件中获取每一行组装成table
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function getErrInfoFromFile(errCodeFileName)
    LogText(LL_NOTICE, "enter getErrInfoFromFile.");
    local errCodeInfo = {}
    local rfile = io.open(errCodeFileName, "r");
    if (nil == rfile) then
        LogText(LL_NOTICE, "Fail to open the file " .. errCodeFileName);
        return nil;
    end

    for str in rfile:lines() do
        LogText(LL_NOTICE, "the errInfo is: " .. str);
        local func = loadstring("return " .. str);
        local a = func();
        table.insert(errCodeInfo, a);
    end
    rfile:close();
    return errCodeInfo;
end

--------------------------------------------------------------------------------
-- Func Name       : getParaValueFromCmd
-- Description     : 从cmd中获取每个参数的值
-- Caution         :
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
--[[
function getParaValueFromCmd(cmdString, para)
    LogText(LL_NOTICE, "enter getFParaFromCmd.");
    local TblBySpace = SplitIPList(cmdString, " ");

    local j = 1;
    for i = 1,#TblBySpace do
        if (TblBySpace[i] == para) then
            j = i + 1
            break;
        end
    end

    if (nil ~= TblBySpace[j])then
        LogText(LL_NOTICE, "find the atom cmd para value " .. TblBySpace[j]);
        return TblBySpace[j];
    end
    return nil;
end
]]

--------------------------------------------------------------------------------
-- Func Name       : getCmdParaValueWhenConCurrent
-- Description     : 获取并发原子cmd中参数对应的值
-- Caution         :
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function getCmdParaValueWhenConCurrent(atomName, para)
    LogText(LL_NOTICE, "enter getCmdWhenConCurrent.");
    local AtomInfoTable = g_UpdState.ConcurrentAtom[g_UpdState.Step];

    for _, atomInfo in pairs (AtomInfoTable) do
        for _, funcInfo in pairs (atomInfo) do
            if (atomName == funcInfo.name) then
                LogText(LL_NOTICE, "find the atom cmd para value " .. funcInfo[para]);
                return funcInfo[para];
            end
        end
    end

    return nil;
end

--------------------------------------------------------------------------------
-- Func Name       : getErrInfoFileName
-- Description     : 获取错误码文件名字
-- Caution         : 非并发原子配置cmd，并发原子从cmd中获取参数对应的值
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function getErrInfoFileName(atomName)
    LogText(LL_NOTICE, "enter getErrInfoFileName.");

    local atomOpcode = nil;
    local cur_Atom = g_AtomGroupsTbl[g_UpdState.AtomGroup][g_UpdState.Step];
    --原子并发
    if (nil ~= cur_Atom.atom_func_tbl )then
        atomOpcode = getCmdParaValueWhenConCurrent(atomName, "fParaValue");
    else
        atomOpcode = cur_Atom.opcode;
    end

    if (nil == atomOpcode) then
        LogText(LL_NOTICE, "The atom: " .. atomName .. " has not atomOpcode.");
        return nil;
    end
    local fileName = "/tmp/".. atomOpcode .. ".upgrade_atom.err"
    LogText(LL_NOTICE, "The fileName is:" .. fileName);
    if(nil == file_exists(fileName))then
        LogText(LL_NOTICE, "The " .. fileName .. "is not exist.");
        return nil;
    end

    return fileName;
end

--------------------------------------------------------------------------------
-- Func Name       : getErrCodeInfo
-- Description     : 获取错误信息
-- Caution         :
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function getErrCodeInfo(atomName)
    --读出kern保存的错误码，然后匹配LUA中已经配置好的table
    LogText(LL_NOTICE, "enter getErrCodeInfo.");
    local fileName = getErrInfoFileName(atomName);
    if (nil == fileName) then
        LogText(LL_NOTICE, "The file is not exist.");
        return nil;
    end
    local errCodeInfo = {};
    errCodeInfo = getErrInfoFromFile(fileName);

    return errCodeInfo;
end

function findStrInTbl(str, tbl)
    if (nil == str) or (nil == tbl)then
        return false;
    end
    LogText(LL_NOTICE, "enter findStrInTbl.");

    for _, item in pairs (tbl) do
        if ( item == str) then
            LogText(LL_NOTICE, "Find the str in tbl " .. item);
            return true;
        end
    end

    return false;
end
--------------------------------------------------------------------------------
-- Func Name       : makeErrCode
-- Description     : 组装错误码,错误码分为两部分使用：升级lua为驱动组装错误码（0X40033300-0X4003335F）
--                 ：SYS及业务模块自己返回错误码在external_return.h里tagOM_UPGRADE_RETURN_VALUE_E (0X40033360-0X400333FF)
--                 ：保留错误码区间（0X40033400 ~0X400334FF）
-- Caution         :
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function makeErrCode(errInfo, atomName)
    LogText(LL_NOTICE, "enter makeErrCode.");
    local outSideErrCode = 0X40033300;
    local totalErrCode = nil;
    local realErrNo = nil;

    LogText(LL_NOTICE, "errInfo.id: " .. errInfo.id .. " errInfo.failStep = " .. errInfo.failStep .. " errInfo.failState = " .. errInfo.failState .." atomName: " .. atomName);

    local failAtomName = "failAtomName";
    local failState = "failState";
    local ErrNo = "ErrNo";

    local errInfoTable =
    {
        --框固件失败
        {
            [failAtomName] = g_Tbl_UpgradeEnclosureAtomName,
            [failState] = DMI_UPGRADE_PREPARE_FAILED,--准备失败
            [ErrNo] =  outSideErrCode,
        },
        {
            [failAtomName] = g_Tbl_UpgradeEnclosureAtomName,
            [failState] = DMI_UPGRADE_FILE_TX_FAILED,--传包失败
            [ErrNo] = outSideErrCode+1,
        },
        {
            [failAtomName] = g_Tbl_UpgradeEnclosureAtomName,
            [failState] = DMI_UPGRADE_UPGRADE_FAILED,--升级失败
            [ErrNo] = outSideErrCode+2,
        },
        {
            [failAtomName] = g_Tbl_UpgradeEnclosureAtomName,
            [failState] = DMI_UPGRADE_FW_VER_WRONG,--校验失败(升级时以及升级后校验)
            [ErrNo] = outSideErrCode+3,
        },
        --卡固件失败
        {
            [failAtomName] = g_Tbl_UpgradeCardAtomName,
            [failState] = DMI_UPGRADE_UPGRADE_FAILED,--升级失败
            [ErrNo] = outSideErrCode+4,
        },
        {
            [failAtomName] = g_Tbl_UpgradeCardAtomName,
            [failState] = DMI_UPGRADE_FW_VER_WRONG,--校验失败(升级时以及升级后校验)
            [ErrNo] = outSideErrCode+5,
        },
        --管理版失败
        {
            [failAtomName] = g_Tbl_UpgradeMgtAtomName,
            [failState] = DMI_UPGRADE_FILE_TX_FAILED,--传包失败
            [ErrNo] = outSideErrCode+6,
        },
        {
            [failAtomName] = g_Tbl_UpgradeMgtAtomName,
            [failState] = DMI_UPGRADE_UPGRADE_FAILED,--升级失败
            [ErrNo] = outSideErrCode+7,
        },
        {
            [failAtomName] = g_Tbl_UpgradeMgtAtomName,
            [failState] = DMI_UPGRADE_FW_VER_WRONG,--校验失败(升级时以及升级后校验)
            [ErrNo] = outSideErrCode+8,
        },
        --共享大卡失败
        {
            [failAtomName] = g_Tbl_UpgradeShareCardAtomName,
            [failState] = DMI_UPGRADE_FILE_TX_FAILED,--传包失败
            [ErrNo] = outSideErrCode+9,
        },
        {
            [failAtomName] = g_Tbl_UpgradeShareCardAtomName,
            [failState] = DMI_UPGRADE_UPGRADE_FAILED,--升级失败
            [ErrNo] = outSideErrCode+10,
        },
        {
            [failAtomName] = g_Tbl_UpgradeShareCardAtomName,
            [failState] = DMI_UPGRADE_FW_VER_WRONG,--校验失败(升级时以及升级后校验)
            [ErrNo] = outSideErrCode+11,
        },
        --SYS交互,升级在线准备失败
        {
            [failAtomName] = g_Tbl_UpgradeOnlinePrepareAtomName,
            [failState] = nil,
            [ErrNo] = nil,
        },
        --重启开工失败
        {
            [failAtomName] = g_Tbl_UpgradeAfterNormalRebootAtomName,
            [failState] = nil,
            [ErrNo] = nil,
        },
    };

    for _, errInfoElem in pairs (errInfoTable) do
        totalErrCode = nil;
        realErrNo = nil;
        if (true == findStrInTbl(atomName ,errInfoElem.failAtomName)) then
            --在线准备和恢复上电，SYS返回错误码，其他情况升级组装错误码
            if (g_Tbl_UpgradeOnlinePrepareAtomName == errInfoElem.failAtomName)
                or (g_Tbl_UpgradeAfterNormalRebootAtomName == errInfoElem.failAtomName) then
                realErrNo = errInfo.failState;

                if (nil ~= realErrNo) then
                    totalErrCode = atomName .. ".1.1:" .. realErrNo;
                    LogText(LL_NOTICE, "Sys Succeed to get the totalErrCode = " .. totalErrCode);
                    break;
                end

            elseif (errInfoElem.failState == errInfo.failState) then
                realErrNo = errInfoElem.ErrNo;

                if (nil ~= realErrNo) then
                    totalErrCode = atomName .. ".1.1:" .. errInfo.id .. "," .. errInfo.failStep .. "," .. realErrNo;
                    LogText(LL_NOTICE, "Succeed to get the totalErrCode = " .. totalErrCode);
                    break;
                end
            end
        end
    end

    return totalErrCode;
end

--------------------------------------------------------------------------------
-- Func Name       : ISCardReportErrInfo
-- Description     : 卡是否上报错误码，卡并发，由于其cmd 中-f值一样，所以文件中保存多有失败卡的记录，只上报当前失败的卡
-- Caution         :  返回true表示应该上报，否则不应该上报
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function ISCardReportErrInfo(errInfo, atom)
    if ("upgradeInterfaceCard" ~= g_UpdState.Step)then
        LogText(LL_NOTICE, "Not card conCurrent, so continue.");
        return true;
    end

    LogText(LL_NOTICE, "Enter ISCardReportErrInfo.");

    local fwName = nil;
    fwName = getCmdParaValueWhenConCurrent(atom, "mParaValue");
    --PCIE获取的fwName为nil,应该上报
    if (nil == fwName) then
        return true;
    end

    if (errInfo.failStep == fwName)then
        LogText(LL_NOTICE, "Continue, because find the card fwName: " .. errInfo.failStep);
        return true;
    end
    return false;
end

--------------------------------------------------------------------------------
-- Func Name       : printErrInfo
-- Description     : 打印组装的错误信息
-- Caution         :
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function printErrInfo(errInfoTable)
    LogText(LL_NOTICE, "enter printErrInfo.");
    for _, errInfo in pairs (errInfoTable) do
        LogText(LL_NOTICE, "errID: " .. errInfo.id .. ",errStep: " .. errInfo.failStep .. ",errState: " .. errInfo.failState);
    end
end

--------------------------------------------------------------------------------
-- Func Name       : ReportAtomErrorCode
-- Description     : 上报原子错误码
-- Caution         : 从文件中获取各条错误码信息，然后依次上报给JOB处理
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function ReportAtomErrorCode(execResult)
    if (ATOM_RET_SUCC == execResult.result) then
        return;
    end
    LogText(LL_NOTICE, "enter ReportAtomErrorCode.");
    local errInfoTable = {};
    errInfoTable = getErrCodeInfo(execResult.atom);
    if (nil == errInfoTable)then
        LogText(LL_NOTICE, "The errInfoTable is empty.");
        return;
    end

    printErrInfo(errInfoTable);

    for _, errInfo in pairs (errInfoTable) do
        local isContinue = false;
        isContinue = ISCardReportErrInfo(errInfo, execResult.atom);

        if ( true == isContinue ) then
            local errCode = makeErrCode(errInfo, execResult.atom);
            if (nil == errCode) then
                return;
            end
            LogText(LL_NOTICE, "The errCode is:" .. errCode);
            execResult.error_code = errCode;
            ReportAtomExecResultWithNewErrCode(execResult);
        end
    end
end

function isFinallySuccess(atom)

    if (g_UpdState.ParamList.retry ~= "retry") then
        LogText(LL_NOTICE, "not retry");
        return true;
    end

    if (atom.ownerAG == nil) then
        LogText(LL_NOTICE, "ownerAG nil");
        return true;
    end

    if (string.find(atom.ownerAG, g_UpdState.AtomGroup)) then
        LogText(LL_NOTICE, "FinallySuccess");
        return true;
    end
    LogText(LL_NOTICE, "not FinallySuccess");
    return false;
end

--删除错误码临时文件
function delErrInfoFile()
    LogText(LL_NOTICE, "Enter delErrInfoFile");
    os.execute("rm -rf /tmp/*.upgrade_atom.err");
end


--获取并发执行原子中失败的具体原子操作
function getFailStepWhenConCurrent(failStep)
    LogText(LL_NOTICE, "Enter getFailStepWhenConCurrent");
    local tmpFailStep = "";
    for _, func in pairs(g_UpdState.ConcurrentAtom[failStep]) do
        for _, f in pairs(func) do
            if ((nil ~= f["ret"]) and (0 ~= f["ret"])) then
               tmpFailStep = tmpFailStep .. f["name"] .. ",";
            end
        end
    end
    return tmpFailStep;
end

--------------------------------------------------------------------------------
-- Func Name       : Run
-- Description     : 执行指定的升级原子组
-- Caution         : 由升级框架调用，函数名称、参数、返回值必须与模板一致
-- Input           :
-- Output          :
-- Return          :
--------------------------------------------------------------------------------
function Run(FlowId, NodeIp, AtomGroup, ParamList)
    LogText(LL_NOTICE, "Node (" .. NodeIp .. ") run atom group (" .. AtomGroup .. "), flow id: " .. FlowId .. ", param list: " .. ParamList);
    LogText(LL_NOTICE, "StateTbl: Node (" .. g_UpdState.NodeIp .. ") ag (" .. g_UpdState.AtomGroup .. "), flow id: " .. g_UpdState.FlowId);

    --删除错误码临时文件
    delErrInfoFile();

    local func = loadstring("return " .. ParamList); --将字符串转换成table
    local params = func();

    --热补丁回退发生异常重启，需要重复回退当前批次，不再判重
    local isNeedCheckRepeat = true;
    if ((("RollbackHotpatch" == AtomGroup) or ("DeleteHotpatch" == AtomGroup)) and (0 == g_UpdState.IsRecoverToNormal)) then
        isNeedCheckRepeat = false;
    end

    --避免升级过程中异常重启,FlowId乱序,导致同步流程失败
    if (("SyncSysAndFirmware" == AtomGroup) or ("SyncPcieSwitch" == AtomGroup) or ("NotifySysReboot" == AtomGroup)) then
        isNeedCheckRepeat = false;
    end

    --如果是重复执行, 则直接返回上次的执行结果
    if (params.retry == nil or params.retry ~= "retry") and (FlowId == g_UpdState.FlowId) and (NodeIp == g_UpdState.NodeIp) and (AtomGroup == g_UpdState.AtomGroup) then
        if(true == isNeedCheckRepeat) then
            LogText(LL_WARN, "Repeated task.");
            return g_UpdState.Result;
        end
    end

    g_UpdState.FlowId = FlowId;
    g_UpdState.AtomGroup = AtomGroup;
    g_UpdState.NodeIp = NodeIp;
    g_UpdState.ParamList = {};
    g_UpdState.ParamList = params;
    g_UpdState.Step = "";
    g_UpdState.Result = RET_INIT;
    
    --如果没有执行忽略失败步骤的命令或者失败信息为空, 则需要清空
    if ((("OnlineUpgrade" ~= params.Flow) and ("OfflineUpgrade" ~= params.Flow))
        or (g_UpdState.SkipFlag == nil) or (nil == g_UpdState.FailStep) or (nil == g_UpdState.FailAG)
        or (g_UpdState.SkipFlag == 0) or ("" == g_UpdState.FailStep) or ("" == g_UpdState.FailAG)) then
        g_UpdState.FailAG = "";
        g_UpdState.FailStep = "";
        g_UpdState.SkipFlag = 0;
    end
    
    g_UpdState.PowerLostFlag = 0;
    SaveState(g_UpdState);
    Fsync();

    -- 第二阶段同版本的场景是第三阶段失败再次执行升级
    if ((g_UpdState.ParamList.stage == "2") and (g_UpdState.ParamList.pkgversion == g_UpdState.ParamList.rollversion)) then
        g_UpdState.Result = RET_SUCC;
        SaveState(g_UpdState);
        LogText(LL_NOTICE, "Third stage failed and retry, skip second stage, ag is " .. AtomGroup);
        return RET_SUCC;
    end

    --执行在线升级系统原子组前，检查是否需要重新执行在线升级准备
    if (AtomGroup == "UpgradeSystemWhenOnlineUpgrade") then
        local fn = "/OSM/update/prepare_succ.lua";
        if(nil == file_exists(fn))then
            local reExecResult = {node_ip=NodeIp,atom_group="UpgradeSystemWhenOnlineUpgrade",atom="NotifySysCtrlPrepareForOnline",start_time=os.time(),progress=10};
            reExecResult.result=2; reExecResult.error_code=10000; reExecResult.end_time=os.time();
            ReportAtomExecResult(reExecResult);
            LogText(LL_NOTICE, "The node is not prepared and need reprepare again.");
            if(NotifySysCtrlPrepareForOnline() ~= 0) then
                LogText(LL_NOTICE, "Failed to reprepare for online upgrade system.");
                reExecResult.result=ATOM_RET_FAIL; reExecResult.error_code=3; reExecResult.end_time=os.time();
                ReportAtomExecResult(reExecResult);
                ReportAtomErrorCode(reExecResult);
                return RET_FAIL;
            end
            reExecResult.result=ATOM_RET_SUCC; reExecResult.error_code=0; reExecResult.end_time=os.time();
            ReportAtomExecResult(reExecResult);
        end
    end
        
        -- 排除主机与阵列间单链路风险后要手动创建该文件，如果存在该文件，重试原子组返回成功
        local fn = "/OSM/update/ultrapath_flag.lua";
        if(nil ~= file_exists(fn) and AtomGroup == "SysCompatibleAfterReboot" and (params.retry == "retry"))then
                g_UpdState.Result = RET_SUCC;
        SaveState(g_UpdState);
        LogText(LL_NOTICE, "/OSM/update/ultrapath_flag.lua is exist, ag is " .. AtomGroup .. " return success.");
                DeleteUltrapathFile();
                return RET_SUCC;
        end
    
    --升级交换机原子组失败需要忽略时，是跳过整个原子组
    if (("UpgradePcieSw" == g_UpdState.AtomGroup) and (nil ~= g_UpdState.FailAG)
        and (nil ~= g_UpdState.SkipFlag) and ("UpgradePcieSw" == g_UpdState.FailAG) and (1 == g_UpdState.SkipFlag)) then
        g_UpdState.Result = RET_SUCC;
        g_UpdState.FailAG = "";
        g_UpdState.FailStep = "";
        g_UpdState.SkipFlag = 0;
        SaveState(g_UpdState);
        return RET_SUCC;
    end

    
    -- 找到入口原子，开始执行
    local atom_name;
    if ((params.retry == "retry") and (nil ~= params.pauseFlag) and (params.pauseFlag == "1")) then
        atom_name = g_AtomGroupsTbl[AtomGroup].entry;
    elseif ((AtomGroup == "UpgradeSystemWhenOnlineUpgrade" or AtomGroup == "RebootWhenOnlineUpgrade" or AtomGroup == "SysCompatibleAfterReboot")
        and (params.retry == "retry")) then
        setmetatable(g_AtomGroupsTbl.UpgradeSystemWhenOnlineUpgrade, { __index = g_AtomGroupsTbl.AgentPrepareForOnlineUpgrade });
        setmetatable(g_AtomGroupsTbl.RebootWhenOnlineUpgrade, { __index = g_AtomGroupsTbl.UpgradeSystemWhenOnlineUpgrade });
        setmetatable(g_AtomGroupsTbl.SysCompatibleAfterReboot, { __index = g_AtomGroupsTbl.RebootWhenOnlineUpgrade });
        atom_name = g_AtomGroupsTbl.AgentPrepareForOnlineUpgrade.entry;
    elseif ((AtomGroup == "RebootWhenOfflineUpgrade" or AtomGroup == "OfflineSysCompatibleAfterReboot") and (params.retry == "retry")) then
        g_AtomGroupsTbl.RebootWhenOfflineUpgrade = g_tbl_RebootWhenOfflineUpgrade;
        setmetatable(g_AtomGroupsTbl.RebootWhenOfflineUpgrade, { __index = g_AtomGroupsTbl.UpgradeSystemWhenOfflineUpgrade });
        setmetatable(g_AtomGroupsTbl.OfflineSysCompatibleAfterReboot, { __index = g_AtomGroupsTbl.RebootWhenOfflineUpgrade });
        atom_name = g_AtomGroupsTbl.UpgradeSystemWhenOfflineUpgrade.entry;
    else
        atom_name = g_AtomGroupsTbl[AtomGroup].entry;
    end

    local next_atom = g_AtomGroupsTbl[AtomGroup][atom_name];
    g_UpdState.Step = atom_name;
    SaveState(g_UpdState); ---保存第一个要执行的原子组信息

    -- 填写原子上报结果
    local execResult = {};
    execResult.node_ip = NodeIp;
    execResult.atom_group = AtomGroup;
    execResult.atom = atom_name;
    execResult.start_time = os.time();
    execResult.progress = next_atom.progress;
    -----上报原子执行中
    execResult.result = 2;
    execResult.error_code = 10000;
    execResult.end_time = os.time();
    ReportAtomExecResult(execResult);

    -- 执行原子
       --windows开关打开，并且配置了打桩返回值,则原子走打桩分支
    local ret=nil
    if ((g_WinSwitch == 1) and (next_atom.stubRet ~= nil)) then
         ret = next_atom.stubRet;
    else
        --当前原子是需要忽略的原子则置ret为0，直接跳过
        if ((nil ~= g_UpdState.FailStep) and (nil ~= g_UpdState.SkipFlag)
            and (g_UpdState.Step == g_UpdState.FailStep) and (g_UpdState.SkipFlag == 1)) then
            ret = 0;
            g_UpdState.FailAG = "";
            g_UpdState.FailStep = "";
            g_UpdState.SkipFlag = 0;
        else
            ret = next_atom.func();
            ret = Retry(next_atom, ret); --自动重试原子
        end
    end
    LogText(LL_NOTICE, "Atom (".. atom_name .. ") exec result: " .. ret);

    -- 填写执行结果

    if (ret >= 126) and (ret <= 131) then
        execResult.error_code = 3;
        --如果是上电同步BBU超时，则发出上电同步BBU失败告警
        SyncBBUAlarm(atom_name);
    else
        execResult.error_code = ret;
    end

    if (atom_name == "ExecRollbackHotpatchCheck" or atom_name == "ExecDeleteHotpatchCheck")then
        execResult.result = ret;
    else
        if (next_atom.retstate[ret] == "#Succ") then
            execResult.result = ATOM_RET_SUCC;
        else
            execResult.result = ATOM_RET_FAIL;
        end
    end

    execResult.end_time = os.time();

    -- 上报原子执行结果
    ReportAtomExecResult(execResult);

    --原子执行失败，上报错误码
    ReportAtomErrorCode(execResult);

    local next_atom_name = next_atom.retcode[ret];
    -------other属性
    while (true) do
        if (next_atom_name == nil) then
            LogText(LL_WARN, "Atom return unexpected code: " .. ret);

            next_atom_name = next_atom.retcode['other'];
            if (next_atom_name == nil) then
                LogText(LL_ERROR, "Not configured 'other'.");
                g_UpdState.Result = RET_FAIL;
                SaveState(g_UpdState);
                return RET_FAIL;
            end
        end

        --暂时保留当前已执行的原子名称
        local tmpStep = g_UpdState.Step;
        
        g_UpdState.Step = next_atom_name;
        SaveState(g_UpdState);

        LogText(LL_NOTICE, "---Next atom name: " .. next_atom_name .. "---");
        if (next_atom_name == "#SuccExit" and isFinallySuccess(next_atom)) then
            g_UpdState.Result = RET_SUCC;
            SaveState(g_UpdState);
            return RET_SUCC;
        elseif (next_atom_name == "#SuccRbk") then
            g_UpdState.Result = RET_RBK_SUCC;
            SaveState(g_UpdState);
            return RET_RBK_SUCC;
        elseif (next_atom_name == "#FailExit") then
            g_UpdState.Result = RET_FAIL;
            --记录当前失败原子
            if (nil ~= g_AtomGroupsTbl[g_UpdState.AtomGroup][tmpStep].atom_func_tbl )then
                g_UpdState.FailStep = getFailStepWhenConCurrent(tmpStep);
            else
                g_UpdState.FailStep = tmpStep;
            end
            g_UpdState.FailAG = g_UpdState.AtomGroup;
            --重新初始化SkipFlag，因为有可能残留前一次失败原子的忽略状态
            g_UpdState.SkipFlag = 0;
            SaveState(g_UpdState);
            return RET_FAIL;
        else
            if (next_atom.nextEntry) then
                local next_entry = SplitIPList(next_atom.nextEntry, ",");
                for _, entry in pairs(next_entry) do
                    if (g_AtomGroupsTbl[AtomGroup][entry] ~= nil) then
                        next_atom_name = entry;
                        break;
                    end
                end
                next_atom = g_AtomGroupsTbl[AtomGroup][next_atom_name];
                g_UpdState.Step = next_atom_name;
                SaveState(g_UpdState);
                LogText(LL_NOTICE, "---Next atom name: " .. next_atom_name .. "---");
            else
                next_atom = g_AtomGroupsTbl[AtomGroup][next_atom_name];
            end

            -- 填写原子执行结果
            execResult.atom = next_atom_name;
            execResult.progress =  next_atom.progress;
            execResult.start_time = os.time();
            -----上报原子执行中
            execResult.result = 2;
            execResult.error_code = 10000;
            execResult.end_time = os.time();
            ReportAtomExecResult(execResult);

            if (g_UpdState.PowerLostFlag == 1) then
                LogText(LL_ERROR, "power lost and suspend flow.");
                g_UpdState.Result = RET_FAIL;
                SaveState(g_UpdState);
                return RET_FAIL;   
            end
    
            --windows开关打开，并且配置了打桩返回值,则原子走打桩分支
            if ((g_WinSwitch == 1) and (next_atom.stubRet ~= nil)) then
               ret = next_atom.stubRet;
            else
                --当前原子是需要忽略的原子则置ret为0，直接跳过
                if ((nil ~= g_UpdState.FailStep) and (nil ~= g_UpdState.SkipFlag)
                    and (g_UpdState.Step == g_UpdState.FailStep) and (g_UpdState.SkipFlag == 1)) then
                    ret = 0;
                    g_UpdState.FailAG = "";
                    g_UpdState.FailStep = "";
                    g_UpdState.SkipFlag = 0;
                else
                    ret = next_atom.func();
                    ret = Retry(next_atom, ret); --自动重试原子
                end

            end
            LogText(LL_NOTICE, "Atom (".. next_atom_name .. ") exec result: " .. ret);

            if (ret >= 126) and (ret <= 131) then
                execResult.error_code = 3;
                --如果是上电同步BBU超时，则发出上电同步BBU失败告警
                SyncBBUAlarm(next_atom_name);
            else
                execResult.error_code = ret;
            end

            if (next_atom.retstate[ret] == "#Succ") then
                execResult.result = ATOM_RET_SUCC;
            else
                execResult.result = ATOM_RET_FAIL;
            end

            execResult.end_time = os.time();

            -- 上报原子执行结果
            ReportAtomExecResult(execResult);

            --原子执行失败，上报错误码
            ReportAtomErrorCode(execResult);

            next_atom_name = g_AtomGroupsTbl[AtomGroup][next_atom_name].retcode[ret];
    
            
            if (g_UpdState.PowerLostFlag == 1) then
                LogText(LL_ERROR, "power lost and suspend flow.");
                g_UpdState.Result = RET_FAIL;
                SaveState(g_UpdState);
                return RET_FAIL;   
            end
        end
    end

    g_UpdState.Result = RET_SUCC;
    SaveState(g_UpdState);
    return RET_SUCC;
end
--如果是上电同步BBU超时，则发出上电同步BBU失败告警
--------------------------------------------------------------------------------
-- Func Name       :SyncBBUAlarm
-- Description     :发送BBU上电同步失败告警
-- Caution         :
-- Input           :atom_name:原子名
-- Output          :无
-- Return          :无
--------------------------------------------------------------------------------
function SyncBBUAlarm(atom_name)
        LogText(LL_NOTICE, " enter SyncBBUAlarm ".. atom_name );
        if("UploadBBUWhenSync" == atom_name) or ("UpgradeBBUWhenSync" == atom_name) then
            LogText(LL_NOTICE, "SyncBBUAlarm ".. atom_name );
            SendBBUSyncFailureAlarm();
        end
        return;
end


function IsNeedWaitSysNormal()
    LogText(LL_NOTICE, " Exec IsNeedWaitSysNormal.");
    local NodeNoNeedWait = {["RebootSysWhenOfflineUpgrade"]=true, ["RebootSysWhenOfflineRollback"]=true, ["RebootSysWhenOnlineUpgrade"]=true,
                            ["RebootWhenOfflineRollback"]=true, ["RebootClusterWhenOfflineUpgrade"]=true,
                           };

    if(NodeNoNeedWait[g_UpdState.Step])then
        LogText(LL_NOTICE, "The node exec normal reboot and no need wait system normal:" .. g_UpdState.Step);
        return false;
    end
    LogText(LL_NOTICE, "The node exec anormal reboot and need wait system normal." );
    return true;
end

function IsMasterInUpd()
    LogText(LL_NOTICE, "Judge Master is in upgrade.");
    local MaxRetryTimes = 3; -- 如若失败 最多再重试三次 间隔10秒
    --此处加睡眠防止server侧恢复慢时，全局升级状态变量未恢复
    os.execute("sleep " .. 15);

    -- AgentSendSyncMsgToServer 会返回三种结果
    -- (-1) 发消息失败或其他处理失败  需要等待
    -- ( 0) C中的FALSE 当前无升级流程 无需等待
    -- ( 1) C中的TRUE  当前正在升级   需要等待

    for i = 0, MaxRetryTimes do
        local iRet = AgentSendSyncMsgToServer{opcode = UPD_CHECK_IS_IN_UPD};
        if (1 == iRet) then
            LogText(LL_NOTICE, "IsMasterInUpd return true.");
            return true;
        elseif (0 == iRet) then
            LogText(LL_NOTICE, "IsMasterInUpd return false.");
            return false;
        end

        LogText(LL_NOTICE, "Check master is in upgrading or not, retry (" .. i .. ") times.");
        os.execute("sleep " .. 10);
    end

    LogText(LL_NOTICE, "IsMasterInUpd return true.");
    return true;
end

--离线升级准备之后，单独重启的场景，这里是没办法恢复obj的
function IsNeedWaitObj(AtomGroup)
    LogText(LL_NOTICE, "Wait Obj AtomGroup=" .. AtomGroup);
    if ("UpgradeSystemWhenOfflineUpgrade" == AtomGroup) then
        LogText(LL_NOTICE, "No need Wait.");
        return false;
    end

    if ("UpgradePcieSw" == AtomGroup) then
        LogText(LL_NOTICE, "No need Wait.");
        return false;
    end

    return true;
end
--------------------------------------------------------------------------------
-- Func Name       :ReportAbnormalRebootInfo
-- Description     :上报异常复位atom
-- Caution         :
-- Input           :
-- Output          :无
-- Return          :无
--------------------------------------------------------------------------------
function ReportAbnormalRebootInfo()
    LogText(LL_NOTICE, "Enter ReportAbnormalRebootInfo");

    local execResult = {};

    execResult.node_ip = g_UpdState.NodeIp;
    execResult.atom_group = g_UpdState.AtomGroup;
    execResult.atom = g_UpdState.Step;
    execResult.start_time = os.time();
    execResult.progress = 0;
    execResult.result = ATOM_RET_FAIL;
    --错误码约定为AbnormalReboot.1.1:错误码，显示在异常复位时执行AG的原因部分
    execResult.error_code = "AbnormalReboot.1.1:" .. ABNORMAL_REBOOT_ERR_CODE;

    ReportAtomExecResultWithNewErrCode(execResult);
end


--升级过程中重启起来的时候，需要重新关闭例测
function RecoverDmiStatus()
    LogText(LL_NOTICE, "Recover Dmi Status.");
    local file = "/startup_disk/conf/conf_local/state_upd.lua";

    local f = io.open(file, "r");
    if (nil == f) then
        os.execute("sleep " .. 3);
        local f = io.open(file, "r");
        if (nil == f) then
            LogText(LL_ERROR, "Open file failed.");
            return;
        end
    end

    local flow = f:read();
    f:close();

    if(nil == flow)then
        LogText(LL_NOTICE, "It is nil, must be manually touched.");
        return;
    end

    if((flow == "OnlineUpgrade") or (flow == "OfflineUpgrade"))then
        LogText(LL_NOTICE, "It is in upgrading, stop the routine test.");
        System("/OSM/bin/upgrade_atom -f NOTIFY_DRV_UPD_EVENT -u 1 -m OnlineUpgrade -w all", 1);
    end

    return;
end


--创建恢复中等待系统normal以及obj的
function CreateResumeStateFile()
    local resumeStateFile = "/OSM/script/upd_agent_state";

    System("rm -rf /OSM/script/upd_agent_state", 1);
    System("touch /OSM/script/upd_agent_state", 1);

    local f = io.open(resumeStateFile, "r");
    if (nil == f) then
        LogText(LL_NOTICE, "Create resume state failed.");
        System("touch /OSM/script/upd_agent_state", 1);
        return 0;
    end
    LogText(LL_NOTICE, "Create resume state succeed.");
    f:close();

    os.execute("chmod 664 " .. resumeStateFile);

    return 0;
end

--进程复位，恢复执行当前流程
function Resume()
    LogText(LL_NOTICE, "Resume: AtomGroup=" .. g_UpdState.AtomGroup .. " Step=" .. g_UpdState.Step);
    local ret = 0;
    
    CreateResumeStateFile();
    g_UpdState.PowerLostFlag = 0;
    SaveState(g_UpdState);
    local file = "/startup_disk/conf/conf_local/state_upd.lua";
    local faultfile = "/startup_disk/conf/conf_local/state_version.lua";

    --若升级文件存在且故障文件不存在则需要判断是否等待normal，否则不判断
    if(nil ~= file_exists(file) and nil == file_exists(faultfile) and IsMasterInUpd())then
        RecoverDmiStatus();
        if (IsNeedWaitSysNormal()) then
            LogText(LL_NOTICE, "Reboot when upgrading and need wait sys normal.");
            g_UpdState.IsRecoverToNormal = AfterNormalReboot();
            if(nil ~= file_exists(file) and IsMasterInUpd() and (0 == g_UpdState.IsRecoverToNormal) and IsNeedWaitObj(g_UpdState.AtomGroup)) then
                upgrade_Check_Obj();
            end
        end
    end

    System("rm -rf /OSM/script/upd_agent_state", 1);

    if ((nil == g_UpdState) or (nil == g_UpdState.AtomGroup) or ("" == g_UpdState.AtomGroup) or ("SyncSysAndFirmware" == g_UpdState.AtomGroup)
        or ( "SyncPcieSwitch" == g_UpdState.AtomGroup) or ("SyncRebootCheck" == g_UpdState.AtomGroup)) then
        LogText(LL_NOTICE, "System is init state or sync.");
        return RET_INIT;
    end

    --当Step为空时，不能保证没有执行任何原子，为了避免原子重复执行，也为了保证可以处理任意时间点得重启，不再重新执行，而是返回失败
    if (g_UpdState.Step == "") then
        LogText(LL_NOTICE, " Abnormal reboot when upgrading and return fail.");
        return RET_FAIL;
    elseif (g_UpdState.Step == "#SuccExit") then --当前执行成功，则直接返回成功
        g_UpdState.Result = RET_SUCC;
        SaveState(g_UpdState);
        return RET_SUCC;
    elseif (g_UpdState.Step == "#SuccRbk") then  --当前回退成功，则直接返回成功
        g_UpdState.Result = RET_RBK_SUCC;
        SaveState(g_UpdState);
        return RET_RBK_SUCC;
    elseif (g_UpdState.Step == "#FailExit") then --当前执行失败，则直接返回失败
        g_UpdState.Result = RET_FAIL;
        SaveState(g_UpdState);
        return RET_FAIL;
    end

    if ((g_UpdState.AtomGroup == "UpgradeSystemWhenOnlineUpgrade" or g_UpdState.AtomGroup == "RebootWhenOnlineUpgrade" or g_UpdState.AtomGroup == "SysCompatibleAfterReboot")
        and (g_UpdState.ParamList.retry == "retry")) then
        setmetatable(g_AtomGroupsTbl.UpgradeSystemWhenOnlineUpgrade, { __index = g_AtomGroupsTbl.AgentPrepareForOnlineUpgrade });
        setmetatable(g_AtomGroupsTbl.RebootWhenOnlineUpgrade, { __index = g_AtomGroupsTbl.UpgradeSystemWhenOnlineUpgrade });
        setmetatable(g_AtomGroupsTbl.SysCompatibleAfterReboot, { __index = g_AtomGroupsTbl.RebootWhenOnlineUpgrade });
    elseif ((g_UpdState.AtomGroup == "RebootWhenOfflineUpgrade" or g_UpdState.AtomGroup == "OfflineSysCompatibleAfterReboot") and (g_UpdState.ParamList.retry == "retry")) then
        g_AtomGroupsTbl.RebootWhenOfflineUpgrade = g_tbl_RebootWhenOfflineUpgrade;
        setmetatable(g_AtomGroupsTbl.RebootWhenOfflineUpgrade, { __index = g_AtomGroupsTbl.UpgradeSystemWhenOfflineUpgrade });
        setmetatable(g_AtomGroupsTbl.OfflineSysCompatibleAfterReboot, { __index = g_AtomGroupsTbl.RebootWhenOfflineUpgrade });
    end

    --找到当前正在执行的原子，当发生正常重启后，恢复流程继续执行，否则认为发生异常重启，返回失败。
    local next_atom = g_AtomGroupsTbl[g_UpdState.AtomGroup][g_UpdState.Step];
    if (next_atom == nil) then
        LogText(LL_NOTICE, "Not found atom: " .. g_UpdState.Step);
        g_UpdState.Result = RET_FAIL;
        SaveState(g_UpdState);
        return RET_FAIL;
    end

    -- 填写原子上报结果
    local execResult = {}
    execResult.node_ip = g_UpdState.NodeIp
    execResult.atom_group = g_UpdState.AtomGroup
    execResult.atom = g_UpdState.Step;
    execResult.start_time = os.time();
    execResult.progress = next_atom.progress;

    -- 执行原子为重启原子时，直接返回成功，继续后续的流程，否则，直接认为发生了异常重启，返回失败。
    if (not IsNeedWaitSysNormal()) then
        LogText(LL_NOTICE, " Normal reboot when atom (".. g_UpdState.Step .. ") exec. " );
        ret = 0;
    else
        LogText(LL_NOTICE, " Abnormal reboot when atom (".. g_UpdState.Step .. ") exec. " );
        ReportAbnormalRebootInfo();
        --热补丁删除、回退时,返回特殊值5标志是由于异常复位导致的重启
        if ( ("RollbackHotpatch" == g_UpdState.AtomGroup) or  ("DeleteHotpatch" == g_UpdState.AtomGroup)) then
            --发生异常重启后，能恢复上电成功
            if(0 == g_UpdState.IsRecoverToNormal) then
                g_UpdState.Result = 5;
                SaveState(g_UpdState);
                return 5;
            end
        end

        g_UpdState.Result = RET_FAIL;
        g_UpdState.Step = "#FailExit";
        SaveState(g_UpdState);
        return RET_FAIL;
    end

    execResult.error_code = ret;

    if (next_atom.retstate[ret] == "#Succ") then
        execResult.result = ATOM_RET_SUCC;
    else
        execResult.result = ATOM_RET_FAIL;
    end

    execResult.end_time = os.time();

    -- 上报原子执行结果
    ReportAtomExecResult(execResult);

    --原子执行失败，上报错误码
    ReportAtomErrorCode(execResult);

    local next_atom_name = next_atom.retcode[ret];
    if (nil == next_atom_name) then
        LogText(LL_WARN, "Atom return unexpected code: " .. ret);

        next_atom_name = next_atom.retcode['other'];
        if (next_atom_name == nil) then
            LogText(LL_ERROR, "Not configured 'other'.");
            g_UpdState.Result = RET_FAIL;
            SaveState(g_UpdState);
            return RET_FAIL;
        end
    end

    while (true) do
        --暂时保留当前已执行的原子名称
        local tmpStep = g_UpdState.Step;

        g_UpdState.Step = next_atom_name;
        SaveState(g_UpdState);

        LogText(LL_NOTICE, "---" .. next_atom_name .. "---");
        if (next_atom_name == "#SuccExit" and isFinallySuccess(next_atom)) then
            g_UpdState.Result = RET_SUCC;
            SaveState(g_UpdState);
            return RET_SUCC;
        elseif (next_atom_name == "#SuccRbk") then
            g_UpdState.Result = RET_RBK_SUCC;
            SaveState(g_UpdState);
            return RET_RBK_SUCC;
        elseif (next_atom_name == "#FailExit") then
            g_UpdState.Result = RET_FAIL;
            --记录当前失败原子
            if (nil ~= g_AtomGroupsTbl[g_UpdState.AtomGroup][tmpStep].atom_func_tbl )then
                g_UpdState.FailStep = getFailStepWhenConCurrent(tmpStep);
            else
                g_UpdState.FailStep = tmpStep;
            end
            g_UpdState.FailAG = g_UpdState.AtomGroup;
            --重新初始化SkipFlag，因为有可能残留前一次失败原子的忽略状态
            g_UpdState.SkipFlag = 0;
            SaveState(g_UpdState);
            return RET_FAIL;
        else
            if (next_atom.nextEntry) then
                local next_entry = SplitIPList(next_atom.nextEntry, ",");
                for _, entry in pairs(next_entry) do
                    if (g_AtomGroupsTbl[g_UpdState.AtomGroup][entry] ~= nil) then
                        next_atom_name = entry;
                        break;
                    end
                end
                next_atom = g_AtomGroupsTbl[g_UpdState.AtomGroup][next_atom_name];
                g_UpdState.Step = next_atom_name;
                SaveState(g_UpdState);
                LogText(LL_NOTICE, "---Next atom name: " .. next_atom_name .. "---");
            else
                next_atom = g_AtomGroupsTbl[g_UpdState.AtomGroup][next_atom_name];
            end

            -- 填写执行结果
            execResult.atom = next_atom_name;
            execResult.progress = next_atom.progress;
            execResult.start_time = os.time();
            -----上报原子执行中
            execResult.result = 2;
            execResult.error_code = 10000;
            execResult.end_time = os.time();
            ReportAtomExecResult(execResult);

            -- 执行升级原子
            local ret=nil
            if ((g_WinSwitch == 1) and (next_atom.stubRet ~= nil)) then
                ret = next_atom.stubRet;
            else
                --当前原子是需要忽略的原子则置ret为0，直接跳过
                if ((nil ~= g_UpdState.FailStep) and (nil ~= g_UpdState.SkipFlag)
                    and (g_UpdState.Step == g_UpdState.FailStep) and (g_UpdState.SkipFlag == 1)) then
                    ret = 0;
                    g_UpdState.FailAG = "";
                    g_UpdState.FailStep = "";
                    g_UpdState.SkipFlag = 0;
                else
                    ret = next_atom.func();
                    ret = Retry(next_atom, ret); --自动重试原子
                end
            end
            LogText(LL_NOTICE, "Atom (".. next_atom_name .. ") exec result: " .. ret);

            execResult.error_code = ret;

            if (next_atom.retstate[ret] == "#Succ") then
                execResult.result = ATOM_RET_SUCC;
            else
                execResult.result = ATOM_RET_FAIL;
            end

            execResult.end_time = os.time();

            -- 上报原子执行结果
            ReportAtomExecResult(execResult);

            --原子执行失败，上报错误码
            ReportAtomErrorCode(execResult);

            next_atom_name = g_AtomGroupsTbl[g_UpdState.AtomGroup][next_atom_name].retcode[ret];
            if (next_atom_name == nil) then
                LogText(LL_WARN, "Atom return unexpected code: " .. ret);

                next_atom_name = next_atom.retcode['other'];
                if (next_atom_name == nil) then
                    LogText(LL_ERROR, "Not configured 'other'.");
                    g_UpdState.Result = RET_FAIL;
                    SaveState(g_UpdState);
                    return RET_FAIL;
                end
            end
        end
    end

    g_UpdState.Result = RET_SUCC;
    SaveState(g_UpdState);
    return RET_SUCC;
end

--调用系统命令 fsync 使内存中的数据刷到硬盘中,避免重启丢失
--使用System命令，防止fsync命令挂住
function Fsync()
    LogText(LL_NOTICE, "Sync memery data to disk.");
    local ret;
    local cmd = "fsync /startup_disk/conf/conf_local/upd_state_atoms.lua";
    ret=System(cmd, 2);
    LogText(LL_NOTICE, "End to sync memery data to disk, result is " .. ret);
end

--------------------------------------------------------------------------------
-- Func Name       : GetCurTask
-- Description     : 获取当前正在执行的任务信息
-- Caution         : 由升级框架调用，函数名称、参数、返回值必须与模板一致
-- Input           :
-- Output          :
-- Return          : 返回值1: int 执行结果, RET_OK: 成功, RET_ERR: 失败
--                   返回值2: int 流程的流水号
--                   返回值3: string 原子组名称
--                   返回值4: string 节点的IP地址
--------------------------------------------------------------------------------
function GetCurTask()
    if (g_UpdState == nil) then
        return RET_ERR, nil, nil, nil;
    else
        return RET_OK, g_UpdState.FlowId, g_UpdState.AtomGroup, g_UpdState.NodeIp;
    end
end


-- 查询当前正在执行的原子组

function GetCurAtomGroup()
    if ((nil == g_UpdState) or (nil == g_UpdState.AtomGroup) or ("" == g_UpdState.AtomGroup)) then
        return nil;
    else
        return g_UpdState.AtomGroup;
    end
end
--================== UPD Framwork Callback =====================================

--================== Atoms =====================================================
--------======================下载包原子实现
function file_exists(path)
    local file = io.open(path, "rb")
    if file then
        file:close()
        return true;
    end
    return nil;
end

function SplitIPList(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
   local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
   if not nFindLastIndex then
    nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
    break
   end
   nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
   nFindStartIndex = nFindLastIndex + string.len(szSeparator)
   nSplitIndex = nSplitIndex + 1
end
    return nSplitArray
end

function PreHandleCopyPkg()
    local filepath = g_UpdState.ParamList.pkgpath;
    local pkgpath = string.match(filepath, "/.+/");

    local index = string.find(filepath, ";")
    if(nil == index)then
        LogText(LL_NOTICE, "No need to prehandle copy pkg.");
        System("rm /OSM/script/UpgradeFile.xml", 1);
        System("rm /startup_disk/conf/conf_local/UpgradeFile.xml", 1);
        return 0;
    end

    local cfgxml = string.sub(filepath, index+1);
    local srcfile = pkgpath .. cfgxml;
    --拷贝批次配置文件
    local iRet=TransSomethingByRealIP{virtual_ip = g_UpdState.ParamList.ip, trans_type = "GET_FILE", src = srcfile, dst = pkgpath, timeout=2};
    if(0 ~= iRet) then
        System("rm -rf /OSM/update/*", 1);
    end

    --拷贝成功后，修改参数为正常情况下的参数(删除xml配置文件)
    g_UpdState.ParamList.pkgpath = string.sub(filepath, 1, index-1);
    SaveState(g_UpdState);
    LogText(LL_NOTICE, "Succeed to get pkg from node (" .. g_UpdState.ParamList.ip .. ")" .. g_UpdState.ParamList.pkgpath);
    return 0;
end

function CheckAndRepaireSysdisk()
    LogText(LL_NOTICE, "--Exec CheckSysdisk---");
    local cmd = "/OSM/script/os_system_update.sh -q ";
    return System(cmd, 2);
end

function CopyPkgFromOtherNode()
    LogText(LL_NOTICE, "Exec CopyPkgFromOtherNode, pkgip is: " .. g_UpdState.ParamList.ip .. " pkgpath is: " .. g_UpdState.ParamList.pkgpath);
    local result = PreHandleCopyPkg();
    if(0 ~= result)then
        LogText(LL_NOTICE, "Failed to get xml from node (" .. g_UpdState.ParamList.ip .. ").");
        return result;
    end

    --获取包路径，用于拼接os_get_file.sh调用参数
    local filepath = g_UpdState.ParamList.pkgpath;
    local pkgpath = string.match(filepath, "/.+/");
    local iRet=TransSomethingByRealIP{virtual_ip = g_UpdState.ParamList.ip, trans_type = "GET_FILE", src = filepath, dst = pkgpath, timeout=5};
    if(0 ~= iRet) then
        System("rm -rf /OSM/update/*", 1);
    end

    LogText(LL_NOTICE, "Copy Pkg From Other Node, result is: " .. iRet);
    return iRet;
end

--解压升级包
function UnzipUpgradePkg()
    LogText(LL_NOTICE, "--Exec UnzipUpgradePkg---");

    local filepath = g_UpdState.ParamList.pkgpath;
    local pkgpath = string.match(filepath, "/.+/");

    if(nil == pkgpath)then
        return 4;
    end

    local index = string.find(filepath, ";")
    if(nil ~= index)then
        LogText(LL_NOTICE, "Need to delete xml file in paramlist.");
        --首先将配置文件拷贝到/OSM/script和/startup_disk/conf/conf_local目录下并删除/OSM/update下的配置文件
        local despath = "/OSM/script";
        local cfgxml = string.sub(filepath, index+1);
        local srcfile = pkgpath .. cfgxml;
        local cmd = "cp " .. srcfile .. " " .. despath;
        LogText(LL_NOTICE, "Need copy xml:" .. cmd);
        System(cmd, 1);
        despath = "/startup_disk/conf/conf_local";
        cmd = "cp " .. srcfile .. " " .. despath;
        LogText(LL_NOTICE, "copy xml for checking front link:" .. cmd);
        System(cmd, 1);
        System("rm /OSM/update/UpgradeFile.xml", 1);
        g_UpdState.ParamList.pkgpath = string.sub(filepath, 1, index-1);
        filepath = g_UpdState.ParamList.pkgpath;
    else
        LogText(LL_NOTICE, "Need delete xml.");
        System("rm /OSM/script/UpgradeFile.xml" , 1);
        System("rm /startup_disk/conf/conf_local/UpgradeFile.xml", 1);
    end

    local pkgtype;
    _, _, pkgtype = string.find(filepath, ".*/(.+)%.tgz");
    if(nil == pkgtype)then
        return 4;
    end

    if("SYS_software" == pkgtype)then
        LogText(LL_NOTICE, "UnzipUpgradePkg:This is SYS_software.tgz.");

         local cmd = "/OSM/script/os_system_update.sh -t " .. filepath;
        LogText(LL_NOTICE, "In UnzipUpgradePkg, exec cmd: " .. cmd);
        return System(cmd, 6);
    elseif("hotpatch" == pkgtype)then
        LogText(LL_NOTICE, "UnzipUpgradePkg:This is hotpatch.tgz.");

        local cmd = "/OSM/script/os_upgrade_hotpatch.sh -v /OSM/update/hotpatch.tgz";
        local iRet = System(cmd, 3);
        if(0 ~= iRet)then
            LogText(LL_NOTICE, "Creat hotpatch version fail.");
            return 4;
        end
        cmd = "cp /tmp/hotpatch_version.conf /startup_disk/conf/";
        iRet = System(cmd, 3);
        if(0 ~= iRet)then
            LogText(LL_NOTICE, "Bak hotpatch version fail.");
            return 4;
        end
        os.rename("/startup_disk/conf/hotpatch_version.conf", "/startup_disk/conf/hotpatch_version_bak.conf");
        LogText(LL_NOTICE, "Bak hotpatch version Succeed.");
        return 10;
    elseif("aslpatch" == pkgtype)then
        LogText(LL_NOTICE, "UnzipUpgradePkg:This is aslpatch.tgz.");

        local cmd = "/OSM/script/os_system_update.sh -C " .. filepath;
        LogText(LL_NOTICE, "In UnzipUpgradePkg, exec cmd: " .. cmd);
        return System(cmd, 6);
    elseif("oem" == pkgtype)then
        local cmd = "/OSM/script/upgrade_common.sh -d " .. filepath;
        LogText(LL_NOTICE, "In Unzip oem package, exec cmd: " .. cmd);
        return System(cmd, 6);
    elseif("diskfw" == pkgtype)then
        local cmd = "/OSM/script/os_system_update.sh -T " .. filepath;
        LogText(LL_NOTICE, "In Unzip disk package, exec cmd: " .. cmd);
        return System(cmd, 6);  
    else
        LogText(LL_ERROR, "==Invalied g_UpdState.ParamList.pkgpath=".. filepath.. "pkgtype=".. pkgtype);
        return 4;
    end


end

--校验升级包
function VerifyUpgradePkg()
    LogText(LL_NOTICE, "--Exec VerifyUpgradePkg---");

    local filepath = g_UpdState.ParamList.pkgpath;
    local pkgpath = string.match(filepath, ".-/");

    if(nil == pkgpath)then
        return 4;
    end
    local index = string.find(filepath, ";")
    if(nil ~= index)then
        LogText(LL_NOTICE, "Need to delete xml file in paramlist.");
        g_UpdState.ParamList.pkgpath = string.sub(filepath, 1, index-1);
        filepath = g_UpdState.ParamList.pkgpath;
    end

    local pkgtype;
    _, _, pkgtype = string.find(filepath, ".*/(.+)%.tgz");
    if(nil == pkgtype)then
        return 4;
    end

    if("SYS_software" == pkgtype)then
        LogText(LL_NOTICE, "VerifyUpgradePkg:This is SYS_software.tgz.");
         local cmd = "/OSM/script/os_system_update.sh -c";
        LogText(LL_NOTICE, "In VerifyUpgradePkg, exec cmd: " .. cmd);
        return System(cmd, 3);
    elseif("hotpatch" == pkgtype)then
        LogText(LL_NOTICE, "VerifyUpgradePkg:This is hotpatch.tgz.");
        return 10;
    elseif("aslpatch" == pkgtype)then
        LogText(LL_NOTICE, "VerifyUpgradePkg:This is aslpatch.tgz.");
        --校验异构支持包的完整性以及校验异构支持包是否重复安装，操作成功0；操作错误返回1；重复安装9;于大包版本不一致，返回8
        local cmd = "/OSM/script/os_system_update.sh -D ";
        LogText(LL_NOTICE, "In VerifyUpgradePkg, exec cmd: " .. cmd);
        return System(cmd, 6);
    elseif("oem" == pkgtype)then
        LogText(LL_NOTICE, "VerifyUpgradePkg:This is oem.tgz.");
        os.remove("/OSM/update/oem.tgz");
        return 0;
    elseif("diskfw" == pkgtype)then
        local cmd = "/OSM/script/os_system_update.sh -U";
        LogText(LL_NOTICE, "In verify disk package, exec cmd: " .. cmd);
        return System(cmd, 6);
    else
        LogText(LL_ERROR, "==Invalied g_UpdState.ParamList.pkgpath=".. filepath.. "pkgtype=".. pkgtype);
        return 4;
    end

end

--================== 插入同步使用的Atoms =====================================================
--框接入同步
function upgrade_enclosure_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_enclosure_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t sync -v $(version) -w $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    if (System(cmd, 11) ~= RET_OK) then
        return RET_ERR;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_SINGLE_ENCLOSURE_FW -t sync -v $(version) -w $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 11);
end

--管理板接入同步
function upgrade_MGMT_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_MGMT_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_MGMT_BOARD -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    if (System(cmd, 15) ~= RET_OK) then
        return RET_ERR;
    end
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_MGMT_BOARD_FW -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 15);
end

--BBU接入同步上传
--当前BBU传包C原子侧，不关心传包结果，都返回OK，传包失败必然导致升级失败
function UploadBBUWhenInster()
    LogText(LL_NOTICE, "--Exec UploadBBUWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_BBU_FW -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 18);
end
--BBU接入同步
function UpgradeBBUWhenInster()
    LogText(LL_NOTICE, "--Exec UpgradeBBUWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_BBU_UPDATE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 26);
end

--SAS接入同步
function UpgradeSASWhenInster()
    LogText(LL_NOTICE, "--Exec UpgradeSASWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m EIF -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--12G SAS接入同步
function Upgrade12GSASWhenInster()
    LogText(LL_NOTICE, "--Exec Upgrade12GSASWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 12GSAS -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--16G FC接入同步
function Upgrade16GFCWhenInster()
    LogText(LL_NOTICE, "--Exec Upgrade16GFCWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 16GFC -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--FCoE接入同步
function UpgradeFCoEWhenInster()
    LogText(LL_NOTICE, "--Exec UpgradeFCoEWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m FCoE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--TOE接入同步
function UpgradeTOEWhenInster()
    LogText(LL_NOTICE, "--Exec UpgradeTOEWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m TOE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--IXGBE接入同步
function upgrade_IXGBE_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_IXGBE_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IXGBE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--56GIB接入同步
function upgrade_56GIB_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_56GIB_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 56GIB -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--56GIB上电同步
function Upgrade56GIBWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade56GIBWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 56GIB -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

-------------------插入同步时校验版本的函数---2016.1.28 by songchunyao-------------------------------------------
--框插入升级前校验
function upgrade_enclosure_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_enclosure_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_DISK_ENCL_FW_COMPATIBLE -t sync -v $(version) -w $(INSERT_PORT_ID) -h ignore";
    cmd = ReplaceParam(cmd);
    return System(cmd, 2);
end

--管理板插入升级前校验
function upgrade_MGMT_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_MGMT_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_MGMT_BOARD_FW_COMPATIBLE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 2);
end

--IXGB接口卡插入升级前校验
function upgrade_IXGBE_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_IXGBE_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IXGBE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--56GIB卡插入升级前校验
function upgrade_56GIB_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_56GIB_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 56GIB -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--ACC卡插入升级前校验
function upgrade_ACC_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_ACC_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m ACC_FPGA -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--10GBaseT卡插入升级前校验
function upgrade_10GBaseT_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_10GBaseT_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 10GE_EL -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--SmartIO卡插入升级前校验
function upgrade_SmartIO_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_SmartIO_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m SmartIO -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--IOC高密卡插入升级前校验
function upgrade_IOCHD_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_IOCHD_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE_CALL_DMI -m IOC_HD -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--IOC10GE卡插入升级前校验
function upgrade_IOC10GE_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_IOC10GE_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE_CALL_DMI -m IOC_10GE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC_8G卡插入升级前校验
function upgrade_IOC8G_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_IOC8G_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IOC_8G -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC_16G卡插入升级前校验
function upgrade_IOC16G_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_IOC16G_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IOC_16G -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--BBU插入升级前校验
function upgrade_BBU_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_BBU_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_BBU_COMPATIBLE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--SAS卡插入升级前校验
function upgrade_SAS_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_SAS_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m EIF -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--FCOE卡插入前校验
function upgrade_FCOE_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_FCOE_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m FCoE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--TOE卡插入前校验
function upgrade_TOE_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_TOE_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m TOE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--PCIE卡插入前校验
function upgrade_PCIE_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_PCIE_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_PCIE_COMPATIBLE -m PCIE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--12GSAS卡插入前校验
function upgrade_12GSAS_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_12GSAS_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 12GSAS -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--16GFC卡插入前校验
function upgrade_16GFC_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_16GFC_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 16GFC -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--大卡插入前校验
function upgrade_12GSAS_SHARE_CARD_compatible_check_when_insert()
    LogText(LL_NOTICE, "---Exec upgrade_12GSAS_SHARE_CARD_compatible_check_when_insert");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_12GSAS_SHARA_CARD_COMPATIBLE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
-------------------插入同步时校验版本的函数---2016.1.28 by songchunyao end-------------------------------------------

--56GIB接口卡升级
function upgrade_56GIB()
    LogText(LL_NOTICE, "--Exec upgrade_56GIB---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 56GIB -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

--56GIB接口卡回退
function rollback_56GIB()
    LogText(LL_NOTICE, "--Exec rollback_56GIB---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 56GIB -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

--升级后校验
function upgrade_56GIB_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_56GIB_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 56GIB -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--回退后校验
function rollback_56GIB_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_56GIB_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 56GIB -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end
--SmartIO接入同步
function upgrade_SmartIO_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_SmartIO_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m SmartIO -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--SmartIO上电同步
function UpgradeSmartIOWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeSmartIOWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m SmartIO -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

--SmartIO接口卡升级
function upgrade_SmartIO()
    LogText(LL_NOTICE, "--Exec upgrade_SmartIO---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m SmartIO -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

--SmartIO接口卡回退
function rollback_SmartIO()
    LogText(LL_NOTICE, "--Exec rollback_SmartIO---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m SmartIO -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

--SmartIO接口卡升级后校验
function upgrade_SmartIO_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_SmartIO_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m SmartIO -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--SmartIO接口卡回退后校验
function rollback_SmartIO_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_SmartIO_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m SmartIO -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--IOC高密卡接入同步
function upgrade_IOCHD_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_IOCHD_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_HD -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC高密卡上电同步
function UpgradeIOCHDWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeIOCHDWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_HD -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC高密卡升级
function upgrade_IOCHD()
    LogText(LL_NOTICE, "--Exec upgrade_IOCHD---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_HD -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC高密卡回退
function rollback_IOCHD()
    LogText(LL_NOTICE, "--Exec rollback_IOCHD---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_HD -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC高密卡升级后校验
function upgrade_IOCHD_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_IOCHD_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE_CALL_DMI -m IOC_HD -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--IOC高密卡回退后校验
function rollback_IOCHD_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_IOCHD_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE_CALL_DMI -m IOC_HD -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end
--IOC10GE卡接入同步
function upgrade_IOC10GE_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_IOC10GE_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_10GE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC10GE卡上电同步
function UpgradeIOC10GEWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeIOC10GEWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_10GE -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC10GE卡升级
function upgrade_IOC10GE()
    LogText(LL_NOTICE, "--Exec upgrade_IOC10GE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_10GE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC10GE卡回退
function rollback_IOC10GE()
    LogText(LL_NOTICE, "--Exec rollback_IOC10GE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_10GE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC10GE卡升级后校验
function upgrade_IOC10GE_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_IOC10GE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE_CALL_DMI -m IOC_10GE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC10GE卡回退后校验
function rollback_IOC10GE_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_IOC10GE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE_CALL_DMI -m IOC_10GE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--ACC接入同步
function upgrade_ACC_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_ACC_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m ACC_FPGA -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--ACC上电同步
function UpgradeACCWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeACCWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m ACC_FPGA -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--ACC接口卡升级
function upgrade_ACC()
    LogText(LL_NOTICE, "--Exec upgrade_ACC---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m ACC_FPGA -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--ACC接口卡回退
function rollback_ACC()
    LogText(LL_NOTICE, "--Exec rollback_ACC---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m ACC_FPGA -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--ACC升级后校验
function upgrade_ACC_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_ACC_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m ACC_FPGA -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--ACC回退后校验
function rollback_ACC_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_ACC_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m ACC_FPGA -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end
--IOC_8G接入同步
function upgrade_IOC8G_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_IOC8G_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_8G -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC_8G上电同步
function UpgradeIOC8GWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeIOC8GWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_8G -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC_8G接口卡升级
function upgrade_IOC8G()
    LogText(LL_NOTICE, "--Exec upgrade_IOC8G---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_8G -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC_8G接口卡回退
function rollback_IOC8G()
    LogText(LL_NOTICE, "--Exec rollback_IOC8G---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_8G -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC_8G升级后校验
function upgrade_IOC8G_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_IOC8G_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IOC_8G -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC_8G回退后校验
function rollback_IOC8G_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_IOC8G_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IOC_8G -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end


--IOC_16G接入同步
function upgrade_IOC16G_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_IOC16G_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_16G -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC_16G上电同步
function UpgradeIOC16GWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeIOC16GWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_16G -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC_16G接口卡升级
function upgrade_IOC16G()
    LogText(LL_NOTICE, "--Exec upgrade_IOC16G---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_16G -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC_16G接口卡回退
function rollback_IOC16G()
    LogText(LL_NOTICE, "--Exec rollback_IOC16G---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_16G -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--IOC_16G升级后校验
function upgrade_IOC16G_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_IOC16G_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IOC_16G -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--IOC_16G回退后校验
function rollback_IOC16G_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_IOC16G_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IOC_16G -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

--10GBaseT接入同步
function upgrade_10GBaseT_when_insert()
    LogText(LL_NOTICE, "--Exec upgrade_10GBaseT_when_insert---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 10GE_EL -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--PCIE接入同步
function UpgradePCIEWhenInster()
    LogText(LL_NOTICE, "--Exec UpgradePCIEWhenInster---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_PCIE_UPDATE -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--================== 上电同步使用Atoms begin=====================================================
function SysCompatibleCheck()
    LogText(LL_NOTICE, "--Exec SysCompatibleCheckWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_SYS_COMPATIBLE -t sync -v $(version) -n all -w all -h " .. g_UpdState.ParamList.SyncPowerFlag;
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 5);
    return ret;
end

---版本同步重启后的版本验证
function VersionCompatibleAfterReboot()
    LogText(LL_NOTICE, "--Exec VersionCompatibleAfterReboot---");
    --3与UPG_FAIL_HANDLE保持一致，不兼容则同步版本失败，设置失败位图
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_CHECK_SYS_AFTER_REBOOT -t sync -v $(version) -d 3";
    cmd = ReplaceParam(cmd);
    local ret = System(cmd, 5);
    return ret;
end

function CheckSSD()
    LogText(LL_NOTICE, "--Exec check sys disk---" .. g_UpdState.ParamList.syncflag);
    local cmd = "/OSM/script/upgrade_preck.sh -w";
    return System(cmd, 3);
end

function GetSourceIp()
    local SourceIpList = SplitIPList(g_UpdState.ParamList.SourcIp, ",");
    for _, SourceIp in pairs(SourceIpList) do
        local index = string.find(SourceIp, ":");
        local nodeip = string.sub(SourceIp, 1, index-1);
        local ip = string.sub(SourceIp, index+1);
        if(g_UpdState.NodeIp == nodeip) then
            g_UpdState.ParamList.ip = ip;
            LogText(LL_NOTICE, "GetSourceIp return ip:" .. ip);
            break;
        end
    end
end
function CtrlFwCompatibleAfterReboot()
    LogText(LL_NOTICE, "---Exec upgrade_enclosure_compatible_check");
    --3与UPG_FAIL_HANDLE保持一致，不兼容则同步失败，设置失败位图
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE -t sync -v $(version) -h ctrl -d 3";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 5)
    return ret;
end
function UpgradeCtrlWhenPowerOn()
    LogText(LL_NOTICE, "--Exec UPGRADE_CHIP_WHEN_POWERON---");
    local bSetFail = 0;
    --版本一致时，升级失败才设置隔离。枚举与UPG_FAIL_HANDLE保持一致
    if (g_UpdState.SyncVersionFlag == 0)then
        bSetFail = 3;
    end
        
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -h ctrl -v $(version) -t sync -d " .. bSetFail;
    cmd = ReplaceParam(cmd);
    if (System(cmd, 15) ~= RET_OK) then
        --版本一致，升级失败则报失败
        g_UpdState.SyncSysAndFwFailFlag = 1;
        SaveState(g_UpdState);
        if (g_UpdState.SyncVersionFlag == 0)then    
            return 1;
        end
        return 0;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_CHIP_WHEN_POWERON -v $(version) -t sync -d " .. bSetFail;
    cmd = ReplaceParam(cmd);
    if (System(cmd, 15) ~= RET_OK) then
        --版本一致，升级失败则报失败
        g_UpdState.SyncSysAndFwFailFlag = 1;
        SaveState(g_UpdState);
        if (g_UpdState.SyncVersionFlag == 0)then    
            return 1;
        end
        return 0;
    end
    
    return 0;
end

function SyncOemFromMaster()
    LogText(LL_NOTICE, "Sync oem from master.");
    local oem_name = "/startup_disk/image/oem.tgz";
    if(nil ~= file_exists(oem_name))then
        LogText(LL_NOTICE, "I have oem, no need to sync.");
        return 0;
    end

    if(nil == g_UpdState.ParamList.oemflag) then---主控是老版本，无法判断是否有oem包，需要同步
        LogText(LL_NOTICE, "Master is old version.");
    else
        if("1" == g_UpdState.ParamList.oemflag) then---主控是新版本，有oem包，需要同步
            LogText(LL_NOTICE, "Master is new version and master has oem package.");
        else---主控是新版本，没有oem包，就不同步了
            LogText(LL_NOTICE, "Master is new version and master no have oem package.");
            return 0;
        end
    end

    local cmd_sync_oem = "/OSM/bin/upgrade_atom -f SYNC_OEM_FROM_MASTER";
    local ret=System(cmd_sync_oem, 3);
    LogText(LL_NOTICE, "Sync oem package from master result is " .. ret);
    return 0;
end

function SyncDiskFileFromMaster()
    LogText(LL_NOTICE, "Sync diskfile from master.");
    local diskfile_name = "/startup_disk/image/boot/update_pkg/diskfirmware/hddfw.conf";
    if(nil ~= file_exists(diskfile_name))then
        LogText(LL_NOTICE, "I have disk file, no need to sync.");
        return 0;
    end

    if((nil ~= g_UpdState.ParamList.diskfileflag) and ("1" == g_UpdState.ParamList.diskfileflag)) then
        local cmd_sync_diskfile = "/OSM/bin/upgrade_atom -f SYNC_DISK_FILE_FROM_MASTER";
        local ret=System(cmd_sync_diskfile, 3);
        LogText(LL_NOTICE, "Sync disk file from master result is " .. ret);
        return 0;
    end

    return 0;
end

function SyncUpgradeBIOS()
    LogText(LL_NOTICE, "---Exec SyncUpgradeBIOS");
    local TmpRet = 0;
    local cmd = "/OSM/script/os_system_update.sh -Y $(version)";
    cmd = ReplaceParam(cmd);
    TmpRet = System(cmd, 40);
    --版本一致，升级失败则报失败
    if (TmpRet ==1)then
        g_UpdState.SyncSysAndFwFailFlag = 1;
        SaveState(g_UpdState);
        if (g_UpdState.SyncVersionFlag == 0)then
            return 1;
        end
    end
    --置同步固件重启标识
    if (TmpRet ==2)then
        if(1 == CreateNeedRebootFlagFile()) then
            LogText(LL_WARN, "Fail to create the need reboot flag.");
        end
        g_UpdState.SyncFirmwareFlag = 1
        SaveState(g_UpdState);
    end
    return 0;
end
function SyncUpgradeDM()
    LogText(LL_NOTICE, "--Exec Sync DM Version");
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DM_SYNC";
    System(cmd, 1);
    return;
end

--创建固件同步开始的状态文件，有此文件说明同步固件流程已开始
function CreateSyncFwStartFile()
    local SyncFwStartFile = "/tmp/syncFw_start.lua";

    System("touch /tmp/syncFw_start.lua", 1);

    local f = io.open(SyncFwStartFile, "r");
    if (nil == f) then
        LogText(LL_NOTICE, "Create sync fw start file failed.");
        System("touch /tmp/syncFw_start.lua", 1);
        return 0;
    end
    LogText(LL_NOTICE, "Create sync fw start file succeed.");
    f:close();

    return 0;
end

--系统控制通知的同步版本(1)和同步固件(2)，如果同步版本已经设置不能同步，固件也跳过(3)
function JudgeSyncType()
    LogText(LL_NOTICE, "--Exec SyncSysVersion---syncflag" .. g_UpdState.ParamList.syncflag);
    if((g_UpdState.ParamList.syncflag == "2") and (g_UpdState.CannotSyncFlag == 1))then
            LogText(LL_NOTICE, "can not sync fw.");
            g_UpdState.CannotSyncFlag = 0;
            SaveState(g_UpdState);
            return 3;
    end
    --当开始同步固件时，创建流程开始标记文件；用于解决系统在开工normal之前，硬盘框接入事件被丢弃，最终硬盘框固件没有升级的问题
    if (g_UpdState.ParamList.syncflag == "2") then
        CreateSyncFwStartFile();
    end
    return tonumber(g_UpdState.ParamList.syncflag);
end
function InitSyncFlag()
    g_UpdState.CannotSyncFlag = 0;
    g_UpdState.SyncFirmwareFlag = 0;
    g_UpdState.SyncSysAndFwFailFlag = 0;
    g_UpdState.SyncVersionFlag = 0;
    SaveState(g_UpdState);
    return;
end
---系统控制通知系统进行版本同步
function SyncSysVersion()
    local fn = "/OSM/update/need_reboot.lua";
    local f = io.open(fn, "r");
    SyncUpgradeDM();
    --同步版本成功，固件也成功，且进行了重启，直接校验。如果固件同步失败，继续重启，以新版本再同步一次
    if ((g_UpdState.SyncVersionFlag == 1) and (g_UpdState.SyncSysAndFwFailFlag ~= nil) and (g_UpdState.SyncSysAndFwFailFlag == 0) and (nil == f))then
        InitSyncFlag();
        return 1;
    end
    --没有同步版本，但固件同步成功了且进行了重启，直接校验
    if ((g_UpdState.SyncVersionFlag == 0) and (g_UpdState.SyncSysAndFwFailFlag ~= nil) and (g_UpdState.SyncSysAndFwFailFlag == 0) and (g_UpdState.SyncFirmwareFlag == 1) and (nil == f))then
        InitSyncFlag();
        return 1;
    end 
    if (nil ~= f)then
        f:close();
    end
    
    --每次同步前初始化
    InitSyncFlag();
    local TmpRet = 0;
    ---获取源IP
    GetSourceIp();
    --3与UPG_FAIL_HANDLE保持一致，同步失败，设置失败位图
    local cmd = "/OSM/bin/upgrade_atom -f SYNC_SOFTWARE_FROM_OTHER_IP -t sync -v $(version) -p $(ip) -h $(WholeSyncIP) -d 3";
    cmd = ReplaceParam(cmd);
    TmpRet = System(cmd, 30);
    LogText(LL_NOTICE, "SyncSysVersion return " .. TmpRet);
    --不能同步的特殊返回值
    if (TmpRet == 9)then
        g_UpdState.CannotSyncFlag = 1;
        SaveState(g_UpdState);
        return 9;
    elseif ((TmpRet == 0))then
        g_UpdState.SyncVersionFlag = 1;
        SaveState(g_UpdState);
        return 0;
    --不需要同步的特殊返回值
    elseif (TmpRet == 8)then
        g_UpdState.SyncVersionFlag = 0;
        SaveState(g_UpdState);
        return 0;
    ----大系统同步失败,升级失败
    else
        return 4;   
    end
end

-- 同步控制框
function UpgradeEnclosureWhenSync()

    LogText(LL_NOTICE, "--Exec UpgradeEnclosureWhenSync---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t sync -v $(version) -h ctrl";
    cmd = ReplaceParam(cmd);
    if (System(cmd, 30) ~= RET_OK) then
        return RET_ERR;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_SINGLE_ENCLOSURE_FW -t sync -v $(version) -h ctrl";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

--当前BBU传包C原子侧，不关心传包结果，都返回OK，传包失败必然导致升级失败
function UploadBBUWhenSync()
    LogText(LL_NOTICE, "--Exec Upload BBU---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_BBU_FW -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 18);
end

function UpgradeBBUWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade BBU---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_BBU_UPDATE -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 26);
end

function UpgradeSASWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade SAS---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m EIF -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end


function Upgrade12GSASWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade 12GSAS---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 12GSAS -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

function Upgrade16GFCWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade 16GFC---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 16GFC -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
function UpgradeFCoEWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade FCoE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m FCoE -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

function UpgradeTOEWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade TOE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m TOE -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

function UpgradeIXGBEWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade IXGBE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IXGBE -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

function Upgrade10GBaseTWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade 10GBaseT---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 10GE_EL -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end

function UpgradePCIEWhenSync()
    LogText(LL_NOTICE, "--Exec Upgrade PCIE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_PCIE_UPDATE -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

function UpgradeMGMTWhenSync()
    LogText(LL_NOTICE, "--Exec UpgradeMGMTWhenSync---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_MGMT_BOARD -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    if (System(cmd, 15) ~= RET_OK) then
        return RET_ERR;
    end
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_MGMT_BOARD_FW -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

function ISNeedReboot()
    LogText(LL_NOTICE, "--Exec ISNeedReboot---");
    local bSetFail = 0;
    --版本一致时，升级失败才设置隔离。枚举与UPG_FAIL_HANDLE保持一致
    if (g_UpdState.SyncVersionFlag == 0)then
        bSetFail = 3;
    end
    local cmd = "/OSM/bin/upgrade_atom -f SYNC_REBOOT_ATOM -t sync -v $(version) -d " .. bSetFail;
    cmd = ReplaceParam(cmd);
    local iRet = System(cmd, 3);
    --需要重启，设置需要重启标志文件
    if(iRet == 2)then
        if(1 == CreateNeedRebootFlagFile()) then
            LogText(LL_WARN, "Fail to create the need reboot flag.");
        end
        g_UpdState.SyncFirmwareFlag = 1
        SaveState(g_UpdState);
    end
    return iRet;
end
--------------------------------------------------------------------------------
-- Func Name       :CreateNeedRebootFlagFile
-- Description     :创建需要重启标志文件，同步版本后判断需要重启时设置
--------------------------------------------------------------------------------
function CreateNeedRebootFlagFile()
    local fn = "/OSM/update/need_reboot.lua";
    local f = io.open(fn, "w+");
    if (nil == f) then
        return 1;
    end
    LogText(LL_NOTICE, "Create reboot flag file success.");
    f:close();
    return 0;
end
---同步版本后判断是否需要重启(新增原子，当前版本与目标版本不一致则需要重启，否则不重启)
function SyncSysVersionReboot()
    LogText(LL_NOTICE, "--Exec SyncSysVersionReboot---");
    --3与UPG_FAIL_HANDLE保持一致,失败需要设置失败位图
    local cmd = "/OSM/bin/upgrade_atom -f SYNC_SYS_REBOOT_ATOM -t sync -v $(version) -d 3";
    cmd = ReplaceParam(cmd);
    local iRet = System(cmd, 3);
    --需要重启，设置需要重启标志文件
    if(iRet == 2)then
        if(1 == CreateNeedRebootFlagFile()) then
            LogText(LL_WARN, "Fail to create the need reboot flag.");
        end
    end
    return iRet;
end

--调用系统命令 sync 使内存中的数据刷到硬盘中,避免重启丢失
function SyncMemeryToDisk()
    LogText(LL_NOTICE, "Sync memery data to disk.");
    Fsync();
    os.execute("sleep " .. 30);
end

-----同步完成后，通知系统控制重启
function SyncRebootCheck()
    LogText(LL_NOTICE, "--Exec SyncRebootCheck---");
    Fsync();
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_SYS_POWER_ON_RESURT -t sync ";
    return System(cmd, 7);
end

--================== 上电同步使用Atoms end=====================================================

----升级过程中，重启后判断系统是否达到normal状态
function AfterNormalReboot()
    LogText(LL_NOTICE, "--Exec After Normal Reboot---");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_NORMAL_AFTER_REBOOT";
    return System(cmd, 20);
end

--离线及在线升级相关原子定义
-- 离线升级准备
function NotifySysCtrlPrepareForOffline()
    LogText(LL_NOTICE, "---Exec Notify sys ctrl---");
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_SYS_PREPARE_FOR_OFFLINE_UPDATE -c $(nidlist) -v $(pkgversion) -h $(rollversion)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end

function SleepBeforeReboot()
    LogText(LL_NOTICE, "---Exec SleepBeforeReboot---");
    os.execute("sleep " .. 1200);
    LogText(LL_NOTICE, "---It has sleep 20min, reboot failed---");
    return 3;
end


---离线升级重启
function RebootSysWhenOfflineUpgrade()
    LogText(LL_NOTICE, "---Exec RebootSysWhenOfflineUpgrade---");
    local cmd = "/OSM/bin/upgrade_atom -f OFFLINE_REBOOT -c $(nidlist)";
    cmd = ReplaceParam(cmd);
    SyncMemeryToDisk();
    os.execute("sleep " .. 60);
    System(cmd, 7);
    return SleepBeforeReboot();
end
---离线升级重启
function RebootClusterWhenOfflineUpgrade()
    LogText(LL_NOTICE, "---Exec RebootClusterWhenOfflineUpgrade---");
    local cmd = "/OSM/bin/upgrade_atom -f OFFLINE_REBOOT -c $(nidlist)";--组装成功节点位图
    cmd = ReplaceParam(cmd);
    SyncMemeryToDisk();
    os.execute("sleep " .. 60);
    System(cmd, 7);
    return SleepBeforeReboot();
end

---离线升级失败后回退重启(TODO：测试所有节点失败回退，获取的成功位图为0，重启会失败)
function RebootSysWhenOfflineRollback()
    LogText(LL_NOTICE, "---Exec RebootSysWhenOfflineRollback---");
    local cmd = "/OSM/bin/upgrade_atom -f OFFLINE_REBOOT -c '" .. g_UpdState.NodeNid .."'";
    SyncMemeryToDisk();
    os.execute("sleep " .. 60);
    System(cmd, 7);
    return SleepBeforeReboot();
end

--离线升级重试复位、升级后校验AG时，升级完成后复位节点使用该函数
function RebootNodeWhenRetryOfflineUpgrade()
    LogText(LL_NOTICE, "---Exec RebootNodeWhenRetryOfflineUpgrade---");
    local cmd = "/OSM/bin/upgrade_atom -f OFFLINE_REUPGRADE_REBOOT";
    SyncMemeryToDisk();
    os.execute("sleep " .. 60);
    local ret = System(cmd, 7);
    if (ret ~= 0) then
        LogText(LL_NOTICE, "Failed to notify sys reboot node.");
        return ret;
    end
    LogText(LL_NOTICE, "Succeed to notify sys reboot node, now wait 10min.");
    os.execute("sleep " .. 600);
    LogText(LL_NOTICE, "---It has sleep 10min, reboot failed---");
    return 3;
end

---在线升级重启
function RebootSysWhenOnlineUpgrade()
    LogText(LL_NOTICE, "---Exec RebootSysWhenOnlineUpgrade---");
    local cmd = "/OSM/bin/upgrade_atom -f ONLINE_REBOOT -c '" .. g_UpdState.NodeNid .."'";
    cmd = ReplaceParam(cmd);
    SyncMemeryToDisk();
    return System(cmd, 7);
end

-- BBU相关原子
--升级
function upgrade_BBU()
    local cmd;

    LogText(LL_NOTICE, "--Exec upload_BBU---");
    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_BBU_FW -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    if (System(cmd, 18) ~= RET_OK) then
        return RET_OK;
    end

    LogText(LL_NOTICE, "--Exec upgrade_BBU---");
    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_BBU_UPDATE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    System(cmd, 26);
    return RET_OK;
end
--升级后校验
function upgrade_BBU_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_BBU_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_BBU_COMPATIBLE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    System(cmd, 5);
    return RET_OK;
end
--回退BBU
function rollback_BBU()
    local cmd;

    LogText(LL_NOTICE, "--Exec upload_BBU_when_rollback---");
    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_BBU_FW -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    if (System(cmd, 18) ~= RET_OK) then
        return RET_OK;
    end

    LogText(LL_NOTICE, "--Exec rollback_BBU---");
    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_BBU_UPDATE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    System(cmd, 26);
    return RET_OK;
end
--SAS接口卡相关原子
--升级
function upgrade_SAS()
    LogText(LL_NOTICE, "---Exec upgrade_SAS---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m EIF -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_SAS_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_SAS_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m EIF -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_SAS()
    LogText(LL_NOTICE, "---Exec rollback_SAS---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m EIF -t rollback -v $(rollversion)  -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_SAS_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_SAS_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m EIF -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end


--12GSAS接口卡相关原子
--升级
function upgrade_12GSAS()
    LogText(LL_NOTICE, "---Exec upgrade_12GSAS---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 12GSAS -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_12GSAS_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_12GSAS_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 12GSAS -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end
--回退
function rollback_12GSAS()
    LogText(LL_NOTICE, "---Exec rollback_12GSAS---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 12GSAS -t rollback -v $(rollversion)  -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_12GSAS_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_12GSAS_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 12GSAS -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end

--16GFC接口卡相关原子
--升级
function upgrade_16GFC()
    LogText(LL_NOTICE, "---Exec upgrade_16GFC---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 16GFC -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_16GFC_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_16GFC_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 16GFC -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_16GFC()
    LogText(LL_NOTICE, "---Exec rollback_16GFC---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 16GFC -t rollback -v $(rollversion)  -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_16GFC_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_16GFC_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 16GFC -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--FCoE接口卡相关原子
--升级
function upgrade_FCOE()
    LogText(LL_NOTICE, "---Exec upgrade_FCOE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m FCoE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_FCOE_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_FCOE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m FCoE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_FCOE()
    LogText(LL_NOTICE, "---Exec rollback_FCOE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m FCoE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_FCOE_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_FCOE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m FCoE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--TOE接口卡相关原子
--升级
function upgrade_TOE()
    LogText(LL_NOTICE, "---Exec upgrade_TOE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m TOE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_TOE_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_TOE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m TOE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_TOE()
    LogText(LL_NOTICE, "---Exec rollback_TOE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m TOE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_TOE_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_TOE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m TOE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--IXGBE接口卡相关原子
--升级
function upgrade_IXGBE()
    LogText(LL_NOTICE, "---Exec upgrade_IXGBE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IXGBE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_IXGBE_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_IXGBE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IXGBE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_IXGBE()
    LogText(LL_NOTICE, "---Exec rollback_IXGBE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IXGBE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_IXGBE_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_IXGBE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m IXGBE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--10GBaseT接口卡相关原子
--升级
function upgrade_10GBaseT()
    LogText(LL_NOTICE, "---Exec upgrade_10GBaseT---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 10GE_EL -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--升级后校验
function upgrade_10GBaseT_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_10GBaseT_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 10GE_EL -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_10GBaseT()
    LogText(LL_NOTICE, "---Exec rollback_10GBaseT---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 10GE_EL -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 20);
end
--回退后校验
function rollback_10GBaseT_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_10GBaseT_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_INTERFACE_CARD_COMPATIBLE -m 10GE_EL -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--PCIE接口卡相关原子
--升级
function upgrade_PCIE()
    LogText(LL_NOTICE, "---Exec upgrade_PCIE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_PCIE_UPDATE -m PCIE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end
--升级后校验
function upgrade_PCIE_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_PCIE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_PCIE_COMPATIBLE -m PCIE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_PCIE()
    LogText(LL_NOTICE, "---Exec rollback_PCIE---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_PCIE_UPDATE -m PCIE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 7);
end
--回退后校验
function rollback_PCIE_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_PCIE_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_PCIE_COMPATIBLE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--SYS相关原子
--升级
function upgrade_SYS()
    LogText(LL_NOTICE, "---Exec upgrade_SYS");
    local cmd = "/OSM/script/os_system_update.sh -P $(pkgversion)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 10);
end

function upgrade_BIOS()
    LogText(LL_NOTICE, "---Exec upgrade_BIOS");
    local cmd = "/OSM/script/os_system_update.sh -Y $(pkgversion)";
    cmd = ReplaceParam(cmd);
    local ret = System(cmd, 40);
    if (ret == 2)then
       return 0;
    end
    return ret;
    
end

--升级后校验
function upgrade_SYS_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_SYS_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_SYS_COMPATIBLE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end
--回退
function rollback_SYS()
    LogText(LL_NOTICE, "---Exec rollback_SYS");
    local cmd = "/OSM/script/roll_back_sys.sh $(rollversion)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

function rollback_BIOS()
    LogText(LL_NOTICE, "---Exec rollback upgrade_BIOS");
    local cmd = "/OSM/script/os_system_update.sh -Y $(rollversion)";
    cmd = ReplaceParam(cmd);
    local ret = System(cmd, 40);
    if (ret == 2)then
       return 0;
    end
    return ret;
end

--回退后校验
function rollback_SYS_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_SYS_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_SYS_COMPATIBLE -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 5);
end

--管理板升级相关原子
--升级
function upgrade_MGMT()
    LogText(LL_NOTICE, "---Exec upgrade_MGMT");
    -- 专家模式下重试需要重新上传升级包
    if (g_UpdState.ParamList.retry == "retry") then
        LogText(LL_NOTICE, "Upgrade failed and retry trans mgmt.");
        -- 管理板两节点并发传包，而升级在一个节点进行，此处无法保证节点包都传完了才进行升级，因此强制为同步类型即在一个节点串行传包
        local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_MGMT_BOARD -t sync -v $(pkgversion) -n all";
        cmd = ReplaceParam(cmd);
        ret = System(cmd, 30);
        if (0 ~= ret) then
            return ret;
        end
    end

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_MGMT_BOARD_FW -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 30);
end
--升级后校验
function upgrade_MGMT_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_MGMT_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_MGMT_BOARD_FW_COMPATIBLE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 2);
    --8代表不在本控升级
    if (8 == ret) then
        return 0;
    end
    return ret;
end
--回退
function rollback_MGMT()
    LogText(LL_NOTICE, "---Exec rollback_MGMT");
    -- 管理板两节点并发传包，而升级在一个节点进行，此处无法保证节点包都传完了才进行升级，因此强制为同步类型即在一个节点串行传包
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_MGMT_BOARD -t sync -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 30);
    if (0 ~= ret) then
        return ret;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_MGMT_BOARD_FW -t rollback -v $(rollversion) -n all";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 30);
    if (ret ~= RET_OK) then
        LogText(LL_NOTICE, "Upgrade mgmt failed when rollback.");
        return ret;
    end
    return ret;
end

--升级硬盘框
function upgrade_DiskEnclosure()

    LogText(LL_NOTICE, "---Exec upgrade_DiskEnclosure");
    -- 专家模式下重试需要重新上传升级包
    if (g_UpdState.ParamList.retry == "retry") then
        LogText(LL_NOTICE, "Upgrade failed and retry trans enclosure.");
        local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t upgrade -v $(pkgversion) -w all";
        cmd = ReplaceParam(cmd);
        ret = System(cmd, 61);
        if (ret ~= 0) then
            return ret;
        end
    end

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_DISK_ENCLOSURE_IN_MIDDLE -t upgrade -v $(pkgversion) -w all -a 1";
    cmd = ReplaceParam(cmd);

    return System(cmd, 30);
end
--升级后校验
function upgrade_DiskEnclosure_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_DiskEnclosure_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_DISK_ENCL_FW_COMPATIBLE -t upgrade -v $(pkgversion) -w all";
    cmd = ReplaceParam(cmd);
    return System(cmd, 2);
end
--回退硬盘框
function rollback_DiskEnclosure()
    LogText(LL_NOTICE, "---Exec rollback_DiskEnclosure");
    -- 硬盘框 (仅考虑中低端即可)
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t rollback -w all -v $(rollversion)";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 61);
    if (0 ~= ret) then
        return ret;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_DISK_ENCLOSURE_IN_MIDDLE -t rollback -v $(rollversion) -w all -a 0";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 30);
    if (ret ~= RET_OK) then
        LogText(LL_NOTICE, "Upgrade disk enclosure failed when exception.");
        return ret;
    end
    return ret;
end

function isDowngrade()
    local Cmd = "/OSM/script/os_system_update.sh -O";
    local Ret = System(Cmd, 1);
    if(RET_OK ~= Ret) then
    -- 通过版本号判断是否是降级 支持往830 1030 1230降级
    if (string.find(g_UpdState.ParamList.pkgversion, "^32001") or string.find(g_UpdState.ParamList.pkgversion, "^31801")) then
        LogText(LL_NOTICE, "It's downgrade, version is " .. g_UpdState.ParamList.pkgversion);
        return 0;
    end

    -- 通过版本号判断是否是从830 1030 1230升级到630过程中失败换630备件后的再升级场景
    if (string.find(g_UpdState.ParamList.rollversion, "^32001") or string.find(g_UpdState.ParamList.rollversion, "^31801")) then
        LogText(LL_NOTICE, "It's SparePart, version is " .. g_UpdState.ParamList.rollversion);
        return 0;
    end
    end
    return 1;
end

function isRollbackDown()
    LogText(LL_NOTICE, "isRollbackDown, pkgversion = " .. g_UpdState.ParamList.pkgversion .. "rollversion = " .. g_UpdState.ParamList.rollversion);
    local Cmd = "/OSM/script/os_system_update.sh -O";
    local Ret = System(Cmd, 1);
    if(RET_OK ~= Ret) then
    -- 通过版本号判断是否是从830 1030 1230升级到630过程中失败回退
    if (string.find(g_UpdState.ParamList.rollversion, "^32001") or string.find(g_UpdState.ParamList.rollversion, "^31801")) then
        LogText(LL_NOTICE, "It's rollback, version is " .. g_UpdState.ParamList.rollversion);
        return 0;
    end

    -- 通过版本号判断是否是降级830 1030 1230过程中失败回退
    if (string.find(g_UpdState.ParamList.pkgversion, "^32001") or string.find(g_UpdState.ParamList.pkgversion, "^31801")) then
        LogText(LL_NOTICE, "It's rollback, version is " .. g_UpdState.ParamList.pkgversion);
        return 0;
    end
    end
    return 1;
end

--框升级相关原子
--升级
function upgrade_enclosure()
    LogText(LL_NOTICE, "---Exec upgrade_enclosure");

    local ret, cmd;

    -- 专家模式下 框升级失败重启需要重新上传升级包
    -- 判断框是否升级失败
    if (g_UpdState.ParamList.retry == "retry") then
        cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t upgrade -v $(pkgversion) -h ctrl";
        cmd = ReplaceParam(cmd);
        ret = System(cmd, 30);
        if (ret ~= 0) then
            return ret;
        end
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_SINGLE_ENCLOSURE_FW -t upgrade -v $(pkgversion) -h ctrl";
    cmd = ReplaceParam(cmd);

    ret = System(cmd, 30);
    if (0 ~= ret) then
        for i = 1, 6 do -- 等待6分钟 (6 * 60)
            LogText(LL_NOTICE, "Upgrade enclosure failed, sleep a while: " .. i);
            os.execute("sleep " .. 60);
        end
        return ret;
    end

    return ret;
end
--升级后校验
function upgrade_enclosure_compatible_check()
    LogText(LL_NOTICE, "---Exec upgrade_enclosure_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE -t upgrade -v $(pkgversion) -h ctrl";
    cmd = ReplaceParam(cmd);
    return System(cmd, 2);
end
--回退
--框拆成了两个原子 单独对控制框的操作需要分别执行这两个动作 还需要添加 ctrl 参数
function rollback_enclosure()
    --判断回退是否是R版本回退降级，如果是，则需要构造版本配套表
    LogText(LL_NOTICE, "Judge R Version downgrade when RollbackSystem.");
    local cmd = "/OSM/script/os_system_update.sh -a $(rollversion)";
    cmd = ReplaceParam(cmd);
    System(cmd, 2);

    LogText(LL_NOTICE, "---Exec rollback_enclosure");
    local ret = 0;

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t rollback -v $(rollversion) -h ctrl";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 30);
    if (0 ~= ret) then
        return ret
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_SINGLE_ENCLOSURE_FW -t rollback -v $(rollversion) -h ctrl";
    cmd = ReplaceParam(cmd);
    ret = System(cmd, 30);
    if (0 ~= ret) then
        return ret
    end

    return ret;
end
--回退后校验
function rollback_enclosure_compatible_check()
    LogText(LL_NOTICE, "---Exec rollback_enclosure_compatible_check");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE -t rollback -v $(rollversion) -h ctrl";
    cmd = ReplaceParam(cmd);
    return System(cmd, 2);
end


-----在线升级差异原子实现
--检查obj是否恢复
function upgrade_Check_Obj()
    LogText(LL_NOTICE, "---Exec upgrade_Check_Obj---");
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_CHECK_OBJ";
    cmd = ReplaceParam(cmd);
    return System(cmd, 61);
end

--检查控制器是否恢复
function check_ctrl_normal()
    LogText(LL_NOTICE, "---Exec check_ctrl_normal---");
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_CTRL_NORMAL";
    cmd = ReplaceParam(cmd);
    return System(cmd, 122);
end

function GetNodeNidByCfg(cfgnid, NidType)
    local CfgToNid;
    if(1 == tonumber(NidType))then
        CfgToNid = {["0A"]="0",  ["0B"]="1",  ["0C"]="2",  ["0D"]="3",
                    ["1A"]="4",  ["1B"]="5",  ["1C"]="6",  ["1D"]="7",
                    ["2A"]="8",  ["2B"]="9",  ["2C"]="10", ["2D"]="11",
                    ["3A"]="12", ["3B"]="13", ["3C"]="14", ["3D"]="15"};
    else
        CfgToNid = {["0A"]="0",  ["0B"]="1",  ["1A"]="2",  ["1B"]="3",
                    ["2A"]="4",  ["2B"]="5",  ["3A"]="6",  ["3B"]="7",
                    ["4A"]="8",  ["4B"]="9",  ["5A"]="10", ["5B"]="11",
                    ["6A"]="12", ["6B"]="13", ["7A"]="14", ["7B"]="15"};
    end
    for k, v in pairs(CfgToNid) do
        if(cfgnid == k) then
            LogText(LL_NOTICE, "GetNodeNidByCfg:" .. v);
            return v;
        end
    end
    LogText(LL_NOTICE, "GetNodeNidByCfg return nil." );
    return nil
end

function ConvertCfgBatchFormat(CfgBatchNode, nidType)
    local batchInfoList = "";
    while true do
        local index = string.find(CfgBatchNode, ";");
        if (nil == index) then
            --格式转换完成
            break;
        end
        --依次获取当前批次节点信息,首先在最后一个节点后面加一个分隔符","方便处理
        local list = string.sub(CfgBatchNode, 1, index - 1);
        list = list .. ",";
        for w in string.gmatch(list, "%d.-,") do
            node = string.gsub(w, "," , "");
            tmpNid = GetNodeNidByCfg(node,nidType);
            batchInfoList = batchInfoList .. tmpNid .. ",";
        end
        --删除多加上的","
        batchInfoList = string.sub(batchInfoList, 1, -2);
        batchInfoList = batchInfoList .. ";";
        --获取后更新要升级的节点列表删除当前批次节点
        CfgBatchNode = string.sub(CfgBatchNode, index + 1);
    end
    return batchInfoList;
end

function GetBatchWithNid(batchInfoList)
    local str_ret = "";
    local index1 = string.find(batchInfoList, ";");
    local index2 = string.find(batchInfoList, g_UpdState.NodeNid);
    if (index1 < index2) then
        batchInfoList = string.sub(batchInfoList,index1+1);
    end
    while index1 < index2 do
        index1 = string.find(batchInfoList,";");
        index2 = string.find(batchInfoList,g_UpdState.NodeNid);
        if (index1 > index2) then
            break;
        end
        batchInfoList = string.sub(batchInfoList,index1+1);
    end
    str_ret = string.sub(batchInfoList, 1, index1-1);
    str_ret = str_ret .. ",";
    return str_ret;
end

--获取与g_UpdState.NodeNid不同升级批次的节点信息
function GetBatchInfo()
    LogText(LL_NOTICE, "Begin to get batch info for checking host path. nid is " .. g_UpdState.NodeNid);
    local str_ret = "";
    local batchInfoList = "";

    if ((nil == g_UpdState.ParamList.NodeTotalNum) or (0 == string.len(g_UpdState.ParamList.NodeTotalNum))) then
        LogText(LL_NOTICE, "g_UpdState.ParamList.NodeTotalNum is nil and no need check.");
        return str_ret;
    end

    --1、默认批次
    local fn = "/startup_disk/conf/conf_local/UpgradeFile.xml";
    local f = io.open(fn, "r");
    if (nil == f) then
        LogText(LL_NOTICE, "No upgrade xml file and upgrade by defalut batch.");
        --根据集群节点个数g_UpdState.ParamList.NodeTotalNum返回不含g_UpdState.NodeNid的默认升级批次节点信息
        for i = 0, (tonumber(g_UpdState.ParamList.NodeTotalNum) - 1) do
            if((i % 2) ~= (tonumber(g_UpdState.NodeNid) % 2)) then
                str_ret = str_ret .. i .. ",";
            end
        end
        LogText(LL_NOTICE, "1.The batchInfoList that without nid " .. g_UpdState.NodeNid .. " is " .. str_ret);
        return str_ret;
    end

    local head="<".."Batch"..">"
    local tail="</".."Batch"..">"
    local data = f:read("*all");
    f:close();
    _,_,value=string.find(data, head .. "(.-)" .. tail);
    if('0' == value)then
        --一个一个节点升级
        for i = 0, (tonumber(g_UpdState.ParamList.NodeTotalNum) - 1) do
            if(i ~= tonumber(g_UpdState.NodeNid)) then
                str_ret = str_ret .. i .. ",";
            end
        end

        LogText(LL_NOTICE, "2.The batchInfoList that without nid " .. g_UpdState.NodeNid .. " is " .. str_ret);
        return str_ret;
    else
        --获取各个批次配置的节点信息
        head="<".."NodeList"..">";
        tail="</".."NodeList"..">";
        _,_,value=string.find(data, head .. "(.-)" .. tail);
        --最后一个批次没有加分隔符;首先加一个方便后续处理
        local CfgBatchNode = value .. ";";
        local index = string.find(CfgBatchNode, "C");
        local nidType = 0;
        if(index ~= nil)then
            --V3_6U_NID_TYPE
            nidType = 1;
        end
        --先将"0C;0B,0D;0A;"转换成"2;1,3;0;"格式
        batchInfoList = ConvertCfgBatchFormat(CfgBatchNode, nidType);
        --获取与g_UpdState.NodeNid同一升级批次的节点信息，格式为"1,3,"
        str_ret = GetBatchWithNid(batchInfoList);
        --将批次信息"1;2,3;4;"转"1,2,3,4,"格式
        batchInfoList = string.gsub(batchInfoList, ";", ",");
        --找到str_ret在batchInfoList中的起止位置
        index1, index2 = string.find(batchInfoList, str_ret);
        --获取与g_UpdState.NodeNid不同批次的节点信息，格式为"1,3,"
        str_ret = string.sub(batchInfoList, 1, index1-1) .. string.sub(batchInfoList, index2+1);
        LogText(LL_NOTICE, "3.The batchInfoList that without nid " .. g_UpdState.NodeNid .. " is " .. str_ret);
        return str_ret;
    end
end

--检查前端链路
function CheckFrontLink()
    --获取与g_UpdState.NodeNid不同升级批次的节点信息，格式"1,2,"
    local batchInfo = GetBatchInfo();
    if ("" == batchInfo) then
        return 0;
    end
    local cmd = "/OSM/bin/upgrade_atom -f CHECK_FRONT_LINK_IS_REDUNDANT -h " .. batchInfo;

    cmd = ReplaceParam(cmd);
    local iRet = System(cmd, 10);
    if (0 == iRet) then
        LogText(LL_NOTICE, "front link is redundant.");
        return 0;
    end
    LogText(LL_NOTICE, "front link is not redundant.");
    return iRet;
end

--设置掉电标志
function SetPowerLostFlag(powerlostflag)
    LogText(LL_NOTICE, "---Set power lost flag---");
    if (nil == g_UpdState.PowerLostFlag) or (0 == g_UpdState.PowerLostFlag) then
        g_UpdState.PowerLostFlag = powerlostflag;
        SaveState(g_UpdState);
    end
    return 0;
end

--在线升级准备前检查前端链路冗余状态
function check_front_link_is_redundant()
    LogText(LL_NOTICE, "---Exec check_front_link_is_redundant---");

    local iRet = CheckFrontLink();
    return iRet;
end

--升级准备前检查端口漂移是否可用
function Check_port_drift()
    LogText(LL_NOTICE, "---Exec check_port_drift---");

    local cmd = "/OSM/bin/upgrade_atom -f CHECK_PORT_DRIFT ";

    cmd = ReplaceParam(cmd);
    local iRet = System(cmd, 10);
    if (0 == iRet) then
        LogText(LL_NOTICE, "Port drift is ok.");
        return 0;
    end
    LogText(LL_NOTICE, "Port drift is not ready");
    return iRet;
end

-- 在线升级准备(不需要参数)
function NotifySysCtrlPrepareForOnline()
    LogText(LL_NOTICE, "---Exec NotifySysCtrlPrepareForOnline---");
    --避免部分节点重复执行在线准备操作
    local fn = "/OSM/update/prepare_succ.lua";
    if(nil ~= file_exists(fn))then
        LogText(LL_NOTICE, "The node has prepared and no need prepare again.");
        return 0;
    end
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_SYS_PREPARE_FOR_ONLINE_UPDATE ";
    SyncMemeryToDisk();
    os.execute("sleep " .. 50);
    local iRet = System(cmd, 242);
    if(0 == iRet)then
        LogText(LL_NOTICE, "Exec NotifySysCtrlPrepareForOnline succeed.");
        local f = io.open(fn, "w+");
        if (nil == f) then
            LogText(LL_WARN, "Create prepare state file fail.");
        end
    LogText(LL_WARN, "begin to set swapmasterflag.");
        local iRet = AgentSendSyncMsgToServer{opcode = UPD_SET_SWAP_MASTER_FLAG};
    if (0 == iRet) then
            LogText(LL_WARN, "set swapmasterflag success.");
        end
    end
    return iRet;
end

--检查多路径告警
function CheckUltraPathAlarm()

    local cmd = "/OSM/script/upgrade_preck.sh -u";

    -- 最后一批不检查多路径告警 少睡6分钟 缩短升级时间
    if ("0" == g_UpdState.ParamList.RollBackFlag)then
        LogText(LL_NOTICE, "The last batch do not check ultrapath alarm.");
        return 0;
    end

    local ret = System(cmd, 15);
    LogText(LL_NOTICE, "Check Ultra Path alarm ret = " .. ret);

    return ret;
end

--异常重启时发生主备倒换后，判断是否等待normal
function check_normal_when_rollback()
    LogText(LL_NOTICE, "---Exec check_normal_when_rollback---");
    if("1" == g_UpdState.ParamList.CheckNormal)then
        LogText(LL_NOTICE, "---Need wait normal---");
        AfterNormalReboot();
        upgrade_Check_Obj();
    end
    return 0;
end

--PCIE交换机相关原子
--获取PCIE交换机节点信息
function GetPcieSwState(PcieSwId)
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_GET_PCIE_SW_STATE -n "..PcieSwId;
    return System(cmd, 5);
end

function checkIsPCIENeedUpd()
    --PCIE升级同步标志文件，存在在跳过PCIE升级以及同步
    local PcieFlagFile = "/startup_disk/conf/conf_local/state_pcie.lua";
    if (nil ~= file_exists(PcieFlagFile)) then
        LogText(LL_NOTICE, "Pcie flag file exists: " .. PcieFlagFile .. " and skip PCIE upgrade.");
        return 0;
    end
    -- 单控/双控/6U多控设备不需要升级pcie
    if(1 == CheckIsExistPcie()) then
        LogText(LL_NOTICE, "not exist pcie, no need to upgrade pcie switch.");
        return 0;
    end

    LogText(LL_NOTICE, "Need upgrade pcie.");
    return 1;
end

function checkIsPCIENeedRbk()
    -- 单控/双控/6U多控设备不需要回退pcie
    if(1 == CheckIsExistPcie()) then
        LogText(LL_NOTICE, "not exist pcie, no need to rollback pcie switch.");
        return 0;
    end

    LogText(LL_NOTICE, "Need rollback pcie.");
    return 1;
end

--检查交换机0的状态
function checkstate_PCIE_SW0()
    --获取0号PCIE交换机状态
    local state;
    state = GetPcieSwState(0);

    LogText(LL_NOTICE, "PCIE sw0 state is ." .. state);

    --交换机状态OK
    if ( (DMI_UPGRADE_STAT_FILE_TX_SUCCEED == state) or (DMI_UPGRADE_STAT_IDLE == state) ) then
        return 0;
    end

    --上次升级成功，但是交换机没有reboot，交换机状态乱了。
    if ( (DMI_UPGRADE_STAT_FILE_TX_FAILED == state) or (DMI_UPGRADE_STAT_UPGRADE_FAILED == state)) then
        return 1;
    end

    --正在升级中,需要等待最大90s
    if ( DMI_UPGRADE_STAT_FILE_TXING == state ) then
        return 2;
    end

    --交换机状态不是预期值。
    return 3;
end

--检查交换机1的状态
function checkstate_PCIE_SW1()
    --获取1号PCIE交换机状态
    local state;
    state = GetPcieSwState(1);
    LogText(LL_NOTICE, "PCIE sw1 state is ." .. state);

    --交换机状态OK
    if ( (DMI_UPGRADE_STAT_FILE_TX_SUCCEED == state) or (DMI_UPGRADE_STAT_IDLE == state) ) then
        return 0;
    end

    --上次升级成功，但是交换机没有reboot，交换机状态乱了。
    if ( (DMI_UPGRADE_STAT_FILE_TX_FAILED == state) or (DMI_UPGRADE_STAT_UPGRADE_FAILED == state)) then
        return 1;
    end

    --正在升级中,需要等待最大90s
    if ( DMI_UPGRADE_STAT_FILE_TXING == state ) then
        return 2;
    end

    --交换机状态乱了。
    return 1;
end

-- 升级完 PCIE 0 后检查当前链路状态
function CheckPcieLinkStateAfterUpdPcie()
    LogText(LL_NOTICE, "Check pcie switch link state.");
    local cmd = "/OSM/script/upgrade_pcie.sh -a";
    return System(cmd, 25);
end

--获取PCIE交换机包文件名称
function GetPcieSwPkgName(version)

    if (nil == version) then
        version = g_UpdState.ParamList.pkgversion;
    LogText(LL_NOTICE, "change version ");
    end

    LogText(LL_NOTICE, "version "..version);

    if ((g_UpdState.AtomGroup == "SyncPcieSwitch") or (g_UpdState.AtomGroup == "InsertSyncPcieSwitch")) then
        local cmd = "/OSM/script/upgrade_pcie.sh -d ";
        LogText(LL_NOTICE, "exec cmd /OSM/script/upgrade_pcie.sh -d ");
        System(cmd, 10);
    else
        local cmd = "/OSM/script/upgrade_pcie.sh -f "..version;
        LogText(LL_NOTICE, "exec cmd /OSM/script/upgrade_pcie.sh -f " .. version);
        System(cmd, 10);
    end

    local fn = "/OSM/update/pcie_version_pkg";
    local f = io.open(fn, "r");
    if (nil == f) then
        LogText(LL_WARN, "Can not read PCIE pkg version file.");
        return nil;
    end

    local line = f:read();
    f:close();
    if (line == nil) or (line == "") then
        LogText(LL_WARN, "PCIE pkg version file is blank.");
        return nil;
    end

    return line;
end

--获取PCIE交换机包文件信息，离线升级交换机时从bak取包，在线时从tmp取包
function checkpacket_PCIE_SW()
    LogText(LL_NOTICE, "---Exec checkpacket_PCIE_SW---");

    --获取包文件名
    PkgName = GetPcieSwPkgName(g_UpdState.ParamList.version);
    if(PkgName == nil)then
        LogText(LL_ERROR, "checkpacket_PCIE_SW::GetPcieSwPkgName error");
        return 1;
    end

    LogText(LL_NOTICE, "Pcie pkg path is: " .. PkgName);

    if(nil == file_exists(PkgName))then
        return 1;
    else
        return 0;
    end
end

--升级或同步时，检查交换机版本
function checkversion_PCIE_SW(PcieSwId)
    LogText(LL_NOTICE, "---Exec checkversion_PCIE_SW---" .. g_UpdState.ParamList.version);
    --检查0号交换机版本和升级包中的版本是否一致
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_CHK_PCIE_SW_VERSION -v " .. g_UpdState.ParamList.version .. " -n " ..PcieSwId;
    return System(cmd, 5);
end

--回退时，检查交换机版本
function checkversion_PCIE_SW_Rollback(PcieSwId)
    LogText(LL_NOTICE, "---Exec checkversion_PCIE_SW_Rollback---" .. g_UpdState.ParamList.rollversion);

    --检查0号交换机版本和升级包中的版本是否一致
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_CHK_PCIE_SW_VERSION -v " .. g_UpdState.ParamList.rollversion .. " -n " ..PcieSwId;
    return System(cmd, 5);
end

--升级或同步时，检查0号交换机版本
function checkversion_PCIE_SW0()
    return checkversion_PCIE_SW(0);
end

--升级或同步时，检查1号交换机版本
function checkversion_PCIE_SW1()
    return checkversion_PCIE_SW(1);
end

--回退时，检查0号交换机版本
function checkversion_PCIE_SW0_Rollback()
    return checkversion_PCIE_SW_Rollback(0);
end

--回退时，检查1号交换机版本
function checkversion_PCIE_SW1_Rollback()
    return checkversion_PCIE_SW_Rollback(1);
end

function checkversionInserted_PCIE_SW()
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        return checkversion_PCIE_SW(0);
    else
        return checkversion_PCIE_SW(1);
    end
end

function checkversionInserted_PCIE_SW_AFT()
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        return checkversion_PCIE_SW(0);
    else
        return checkversion_PCIE_SW(1);
    end
end

function Set_PCIE_Path(PcieSwId, PCIEPath)
    local PkgName;
    local RollBackPath;

    --PCIE交换机升级可用的IP地址在atom中获取

    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_TRANS_PCIE_SW_PKG -n "..PcieSwId.." -h "..":"..PCIEPath;
    LogText(LL_NOTICE, "Exec cmd (" .. cmd .. ") to PCIE.");
    return System(cmd, 6);
end

--上传PCIE升级包
function Trans_PCIE_SW_Pkg(PcieSwId)
    local upgradePCIEpath;
    local PkgName;

    PkgName = GetPcieSwPkgName(g_UpdState.ParamList.version);
    if(PkgName == nil)then
        LogText(LL_ERROR, "Set_PCIE_Path::GetPcieSwPkgName error");
        return RET_FAIL;
    end

    --转成驱动要求的//startup_disk//image//boot_osp_tmp//update_pkg//PANGEA_V2R1C01//pcie_pkg//格式
    upgradePCIEpath = string.gsub(PkgName, "/", "//");

    LogText(LL_NOTICE, "Set_PCIE_Path::PCIE PkgName is: "..upgradePCIEpath);
    return Set_PCIE_Path(PcieSwId, upgradePCIEpath)
end

--上传0号PCIE升级包
function Trans_PCIE_SW0_Pkg()
    LogText(LL_NOTICE, "---Exec Trans_PCIE_SW0_Pkg---");
    return Trans_PCIE_SW_Pkg(0);
end

--上传1号PCIE升级包
function Trans_PCIE_SW1_Pkg()
    LogText(LL_NOTICE, "---Exec Trans_PCIE_SW1_Pkg---");
    return Trans_PCIE_SW_Pkg(1);
end

function TransInserted_PCIE_SW_Pkg()
    LogText(LL_NOTICE, "---Exec Trans_PCIE_SW_Pkg---");
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        return Trans_PCIE_SW_Pkg(0);
    else
        return Trans_PCIE_SW_Pkg(1);
    end
end

function Check_PCIE_SW_TransPkg_State(PcieSwId)
    LogText(LL_NOTICE, "---Exec Check_PCIE_SW_TransPkg_State PcieSwId is"..PcieSwId);
    local state;
    state = GetPcieSwState(PcieSwId);
    LogText(LL_NOTICE, "---get PcieSwState is "..state);

    --正在上传包
    if ( DMI_UPGRADE_STAT_FILE_TXING == state ) then
        return 2;
    end

    --传输交换机包完成
    if ( DMI_UPGRADE_STAT_FILE_TX_SUCCEED == state ) then
        return 0;
    end

    --传输交换机包失败
    if (  DMI_UPGRADE_STAT_FILE_TX_FAILED == state ) then
        return 1;
    end

    --不是预期的状态
    return 3;
end

function Check_PCIE_SW0_TransPkg_State()
    os.execute("sleep " .. 9);
    return Check_PCIE_SW_TransPkg_State(0);
end

function Check_PCIE_SW1_TransPkg_State()
    os.execute("sleep " .. 9);
    return Check_PCIE_SW_TransPkg_State(1);
end

function CheckInserted_PCIE_SW_TransPkg_State()
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        os.execute("sleep " .. 9);
        return Check_PCIE_SW_TransPkg_State(0);
    else
        os.execute("sleep " .. 9);
        return Check_PCIE_SW_TransPkg_State(1);
    end
end

function Check_PCIE_SW_reboot_State(PcieSwId)

    local state;
    state = GetPcieSwState(PcieSwId);
    LogText(LL_NOTICE, "---get pcieState is "..PcieSwId..state);

    --升级失败
    if ( DMI_UPGRADE_STAT_UPGRADE_FAILED == state ) then
        return 1;
    end

    --升级成功
    if ( DMI_UPGRADE_STAT_IDLE == state ) then
        return 0;
    end

    --其他状态，需要重试
    return 2;
end

function Check_PCIE_SW0_reboot_State()
    LogText(LL_NOTICE, "---Exec Check_PCIE_SW0_reboot_State---");
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_WAIT_PCIE -n "..0;
    local iRet = System(cmd, 15); 
    if(0 ~= iRet)then
        LogText(LL_NOTICE, "Wait pcie fail.");
        return 4;
    end
    return Check_PCIE_SW_reboot_State(0);
end

function Check_PCIE_SW1_reboot_State()
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_WAIT_PCIE -n "..1;
    local iRet = System(cmd, 15);  
    if(0 ~= iRet)then
        LogText(LL_NOTICE, "Wait pcie fail.");
        return 4;
    end
    return Check_PCIE_SW_reboot_State(1);
end

function CheckInserted_PCIE_SW_reboot_State()
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_WAIT_PCIE -n "..0;
    	local iRet = System(cmd, 15);  
        if(0 ~= iRet)then
            LogText(LL_NOTICE, "Wait pcie fail.");
            return 4;
        end
        return Check_PCIE_SW_reboot_State(0);
    else
        local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_WAIT_PCIE -n "..1;
    	local iRet = System(cmd, 15);  
        if(0 ~= iRet)then
            LogText(LL_NOTICE, "Wait pcie fail.");
            return 4;
        end
       return Check_PCIE_SW_reboot_State(1);
    end
end

--复位PCIE交换，执行升级
function reboot_PCIE_SW(PcieSwId)
    LogText(LL_NOTICE, "---Exec reboot_PCIE_SW,PcieSwId is： "..PcieSwId);
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_REBOOT_PCIE_SW -n "..PcieSwId;
    return System(cmd, 6);
end

--复位0号PCIE交换机
function reboot_PCIE_SW0()
    return reboot_PCIE_SW(0);
end

--复位PCIE交换机
function reboot_PCIE_SW1()
    return reboot_PCIE_SW(1);
end

--复位PCIE交换机
function rebootInserted_PCIE_SW()
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        return reboot_PCIE_SW(0);
    else
        return reboot_PCIE_SW(1);
    end
end

--回退PCIE交换机
function rollback_PCIE_SW(PcieSwId)
    local RollBackPath;

    PkgName = GetPcieSwPkgName(g_UpdState.ParamList.rollversion);
    if(PkgName == nil)then
        LogText(LL_ERROR, "Set_PCIE_Path::GetPcieSwPkgName error");
        return RET_FAIL;
    end

    --转成驱动要求的//startup_disk//image//boot_osp_tmp//update_pkg//PANGEA_V2R1C01//pcie_pkg//格
    RollBackPath = string.gsub(PkgName, "/", "//");

    LogText(LL_NOTICE, "Set_PCIE_Path::PCIE PkgName is: "..RollBackPath);
    return Set_PCIE_Path(PcieSwId, RollBackPath);

end

--回退0号PCIE交换机
function rollback_PCIE_SW0()
    LogText(LL_NOTICE, "---Exec rollback_PCIE_SW0---");
    return rollback_PCIE_SW(0);

end

--回退PCIE交换机
function rollback_PCIE_SW1()
    LogText(LL_NOTICE, "---Exec rollback_PCIE_SW1---");
    return rollback_PCIE_SW(1);
end

function CleanUpBakWhenRollback()
    local cmd = "/OSM/script/upgrade_pcie.sh -e";
    return System(cmd, 6);
end

--通知驱动开始和结束
function NotifyDrvUpdStart()
    NotifyDrvUpdState{upd_state = 1, upd_flowname = g_UpdState.ParamList.Flow, upd_locationid = g_UpdState.ParamList.INSERT_PORT_ID};
    return 0
end
function NotifyDrvUpdEnd()
    NotifyDrvUpdState{upd_state = 2, upd_flowname = g_UpdState.ParamList.Flow, upd_locationid = g_UpdState.ParamList.INSERT_PORT_ID};
    return 0;
end
--通知驱动不需要升级
function NotifyDrvNoNeedUpd()
    NotifyDrvUpdState{upd_state = 3, upd_flowname = g_UpdState.ParamList.Flow, upd_locationid = g_UpdState.ParamList.INSERT_PORT_ID};
    return 0;
end
--热补丁相关原子
--安装热补丁
function ExecInstallHotpatch()
    LogText(LL_NOTICE, "---Exec ExecInstallHotpatch---");
    g_UpdState.HotPatchUpd = true;
    SaveState(g_UpdState);
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UPGRADE  -t upgrade ";
    return System(cmd, 15);
end

--确认热补丁
function ExecConfirmHotPatch()
    LogText(LL_NOTICE, "---Exec ExecConfirmHotPatch---");
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UPGRADECONFIRM  -t upgrade ";
    return System(cmd, 2);
end

--设置热补丁是否升级标记
function ExecResetHotPatchUpd()
    LogText(LL_NOTICE, "---Exec ExecResetHotPatchUpd---");
    g_UpdState.HotPatchUpd = false;
    SaveState(g_UpdState);
    return 0;
end

--升级失败后判断补丁是否需要回退
function ExecIsNeedRollback()
    LogText(LL_NOTICE, "---Exec ExecIsNeedRollback---");
    local cmd = "/OSM/script/os_system_update.sh -x ";
    return System(cmd, 3);
end

--回退热补丁(升级热补丁内部回退)
function ExecRollbackHotPatch()
    LogText(LL_NOTICE, "---Exec ExecRollbackHotPatch---");
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UPGRADE  -t rollback ";
    return System(cmd, 32);
end

--回退热补丁
function ExecRollbackHotPatchWhenRollback()
    LogText(LL_NOTICE, "---Exec ExecRollbackHotPatch---");
    --回退补丁前，判断patch链接，是否真的存在，此处用于回退热补丁过程中发生异常重启
    local preCmd = "/OSM/script/upgrade_common.sh -l";
    local patchLinkSign = System(preCmd, 3);
    if(0 == patchLinkSign) then
        LogText(LL_NOTICE, "---The patch link to patch_cur---");
        local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UPGRADE  -t rollback ";
        return System(cmd, 32);
    else
        LogText(LL_NOTICE, "---The patch link to patch_bak---");
    return 0;
    end
end

--回退补丁版本校验
function ExecRollbackConfirm()
    LogText(LL_NOTICE, "---Exec ExecRollbackConfirm---");
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UPGRADECONFIRM  -t rollback ";
    return System(cmd, 2);
end

--回退前的检查
function ExecRollbackHotpatchCheck()
    LogText(LL_NOTICE, "---Exec ExecRollbackHotpatchCheck---");
    local cmd = "/OSM/bin/upgrade_atom -f GET_HOTPATCH_ACTIVE_TYPE -t rollback ";
    return System(cmd, 3);
end

--删除热补丁前检查
function ExecDeleteHotpatchCheck()
    LogText(LL_NOTICE, "---Exec ExecDeleteHotpatchCheck---");
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UNINSTAL_ACT ";
    return System(cmd, 3);
end

--删除热补丁
function ExecDeleteHotpatch()
    LogText(LL_NOTICE, "---Exec ExecDeleteHotpatch---");
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UNINSTAL ";
    return System(cmd, 32);
end

--删除热补丁后版本校验
function ExecDeleteHotpatchConfirm()
    LogText(LL_NOTICE, "---Exec ExecDeleteHotpatchConfirm---");
    local cmd = "/OSM/bin/upgrade_atom -f HOTPATCH_UNINSTAL_CONFIRM ";
    return System(cmd, 2);
end
--安装特殊补丁
function ExecInstallSpecialPatch()
    LogText(LL_NOTICE, "---Exec ExecInstallSpecialPatch---");
    local checkCmd = "/OSM/script/os_system_update.sh  -J /OSM/update/hotpatch.tgz";
    local cmd;
    local isSpecScript = System(checkCmd, 2);
    if (1 == isSpecScript) then
       LogText(LL_NOTICE, "The package is PreProcess script package.");
       cmd = "/OSM/script/os_system_update.sh -K ";
    else
       LogText(LL_NOTICE, "The package is special patch.");
       cmd = "/OSM/script/os_upgrade_coldpatch.sh -p /OSM/update/hotpatch.tgz";
    end
    return System(cmd, 10);
end

function CheckPcieSwitchPackage()
    ---/// PCIE同步标记文件 有此文件则不执行PCIE同步
    ---/// 调试功能 手动产生此文件可跳过PCIE同步流程
    local PcieFlagFile = "/startup_disk/conf/conf_local/state_pcie.lua";
    if (nil ~= file_exists(PcieFlagFile)) then
        LogText(LL_NOTICE, "Pcie flag file is exist: " .. PcieFlagFile);
        return 10;
    end

    ---/// 版本同步时不执行PCIE同步
    if(g_UpdState.ParamList.syncflag == "1") then
        LogText(LL_NOTICE, "Do not exec sync pcie when sync sys.");
        return 10;
    end

    return checkpacket_PCIE_SW();
end

function CheckIsExistPcie()
    local cmd = "/OSM/script/upgrade_pcie.sh -c";
    --单控/双控制,多控6U返回1,否则返回0
    return System(cmd, 3);
end

function CheckPcieSwitchState()
    --获取交换机个数
    local PCIE_SW_STANDARD_NUM = 2;
    local PcieSwNum = 0;
    local state0 = checkstate_PCIE_SW0();
    local state1 = checkstate_PCIE_SW1();

    if( 0 ==  state0 or 1 == state0 ) then
        PcieSwNum = PcieSwNum + 1;
    end

    if( 0 == state1 or 1 == state1 ) then
        PcieSwNum = PcieSwNum + 1;
    end

    LogText(LL_NOTICE, "Get PcieSw number: " .. PcieSwNum);

    if(PCIE_SW_STANDARD_NUM == PcieSwNum)then
        return 0;
    end

    return 1;
end

function CheckInsertedPcieSwitchState()
    local state;
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        state = checkstate_PCIE_SW0();
    else
        state = checkstate_PCIE_SW1();
    end

    if( 0 ==  state or 1 == state ) then
        return 0;
    end

    return 1;
end

function IsolatePcieSwitch(SwitchId)
    local cmd = "/OSM/bin/upgrade_atom -f NOTIFY_DEV_ISOLATE_PCIE_SW -n " .. SwitchId;
    LogText(LL_NOTICE, "Exec (" .. cmd .. ") to isolate pcie.");
    System(cmd, 2); --不关心隔离结果
    return 0;
end

function IsolatePcieSwitch_0()
    return IsolatePcieSwitch(0);
end

function IsolatePcieSwitch_1()
    return IsolatePcieSwitch(1);
end

function IsolateInsertedPcieSwitch()
    if (g_UpdState.ParamList.INSERT_PORT_ID == "0") then
        return IsolatePcieSwitch(0);
    else
        return IsolatePcieSwitch(1);
    end
end
--删除无效的异构包
function ExecDeleteInvalidAslPackage()
    LogText(LL_NOTICE, "--ExecDeleteInvalidAslPackage");
    local cmd= "/OSM/script/asl_del_old_package.sh";
    return System(cmd,3);
end

--拷贝异构包
function ExecCopyAslPackage()
    LogText(LL_NOTICE, "--Exec ExecCopyAslPackage");
    local cmd = "/OSM/script/asl_copy_new_package.sh";
    return System(cmd, 3);
end

--删除已经安装且本批次需要安装的异构包
function ExecUnInstallAslPackage()
    LogText(LL_NOTICE, "--ExecUnInstallAslPackage");
    local cmd = "/OSM/bin/upgrade_atom -f ASLPATCH_UNINSTALL -h $(asl_name) -e 0";
    cmd = ReplaceParam(cmd);
    return System(cmd,3);
end

--安装异构支持包
function ExecInstallAslPatch()
    LogText(LL_NOTICE, "--Exec ExecinstallAslPatch");
    local cmd= "/OSM/bin/upgrade_atom -f ASLPATCH_INSTALL -h $(asl_name) -e $(asl_version)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 3);
end

--修改异构支持包的链接
function ExecResetLinkToAslPatch()
    LogText(LL_NOTICE, "--Exec ExecResetLinkToAslPatch");
    local cmd= "/OSM/bin/upgrade_atom -f ASLPATCH_RESETLINK -h $(asl_name) -e $(asl_version)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 3);
end

--异构包升级失败回退
function ExecRbkAslPatchWhenFail()
    LogText(LL_NOTICE, "--Exec ExecRbkAslPatchWhenFail");
    local cmd= "/OSM/bin/upgrade_atom -f ASLPATCH_ROLLBACK -h $(asl_name) -e $(oldasl_version)";
    cmd = ReplaceParam(cmd);
    return System(cmd, 3);
end

--同步过程中比较异构包版本是否一致
function AslVersionCompatibleCheck()
    LogText(LL_NOTICE, "--Exec AslVersionCompatibleCheck");
    if (g_UpdState.SyncVersionFlag == 1)then    
        LogText(LL_NOTICE, "--it has sync version,no need sync asl alone");
        return 0;
    end

    local  cmd = "/OSM/bin/upgrade_atom -f ASLPATCH_VERCHECK -h $(aslver)";
    cmd = ReplaceParam(cmd);
    return System(cmd,5);
end

--同步过来的文件进行安装的过程
function SyncAslPatch()
    LogText(LL_NOTICE, "--Exec SyncAslPatch");
    local TmpRet = 0;
    local bSetFail = 0;
    --版本一致时，升级失败才设置隔离。枚举与UPG_FAIL_HANDLE保持一致
    if (g_UpdState.SyncVersionFlag == 0)then
        bSetFail = 3;
    end
    local cmd = "/OSM/bin/upgrade_atom  -t sync -f ASLPATCH_SYNC -d " .. bSetFail;
    cmd = ReplaceParam(cmd);
    TmpRet = System(cmd, 10);
    --需要重启，设置需要重启标志文件
    if(TmpRet == 0)then
        if(1 == CreateNeedRebootFlagFile()) then
            LogText(LL_WARN, "Fail to create the need reboot flag.");
        end
        g_UpdState.SyncFirmwareFlag = 1;
        SaveState(g_UpdState);
        return 0;
    end
    --版本一致，升级失败则报失败
    if(TmpRet ~= 0)then
        g_UpdState.SyncSysAndFwFailFlag = 1;
        SaveState(g_UpdState);
        if (g_UpdState.SyncVersionFlag == 0)then    
            return 1;
        end
    end
    return 0;   
end

function AslVerCheckAfterReboot()
   LogText(LL_NOTICE, "--Exec AslVerCheckAfterReboot");
   --3与UPG_FAIL_HANDLE保持一致，不兼容需要设置失败位图
   local  cmd = "/OSM/bin/upgrade_atom  -t sync -f ASLPATCH_VERCHECK -h $(aslver) -d 3";
   cmd = ReplaceParam(cmd);
   return System(cmd,5);
end

--------------------------------------------------------------------------------
-- Func Name       :DeleteUltrapathFile
-- Description     :开始执行升级流程时清除上次升级可能遗留的ultrapath_flag.lua文件
-- Caution         :
-- Return          : void   
--                 : void
--------------------------------------------------------------------------------
function DeleteUltrapathFile()
    local fileName = "/OSM/update/ultrapath_flag.lua";
        if(nil == file_exists(fileName))then
        LogText(LL_NOTICE, "The " .. fileName .. "is not exist.");
        return;
    end
    local rm = os.remove(fileName);
    if (nil == rm) then
        LogText(LL_WARN, "Delete ultrapath_flag.lua fail.");
        --内存文件删除失败不返回错误
                return;
    end
        
        LogText(LL_NOTICE, "Delete ultrapath_flag.lua succed" );
        return;
end

--================== 630 新增原子 begin ========================================

function UploadShareCardWhenInster()

    LogText(LL_NOTICE, "--Exec UploadShareCardWhenInster---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_SHARA_CARD -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);

    return System(cmd, 10);
end

function UpgradeShareCardWhenInster()

    LogText(LL_NOTICE, "--Exec UpgradeShareCardWhenInster---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_12GSAS_SHARA_CARD -t sync -v $(version) -n $(INSERT_PORT_ID)";
    cmd = ReplaceParam(cmd);

    return System(cmd, 30);
end

function preUploadShareCard()

    LogText(LL_NOTICE, "---Exec preUploadShareCard---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_SHARA_CARD -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "preUploadShareCard", ag = "UploadPreupd", cmd = cmd, timeout = 10,
        fParaValue = "UPGRADE_TRANSFER_SHARA_CARD"};
end

function ReUploadShareCard()

    LogText(LL_NOTICE, "---Exec ReUploadShareCard---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_SHARA_CARD -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    
    return System(cmd, 10);
end

function preUploadEnclosure()

    LogText(LL_NOTICE, "---Exec preUploadEnclosure---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t upgrade -v $(pkgversion) -w all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "preUploadEnclosure", ag = "UploadPreupd", cmd = cmd, timeout = 61,
        fParaValue = "UPGRADE_TRANSFER_ENCLOSURE"};
end

function ReUploadEnclosure()

    LogText(LL_NOTICE, "---Exec ReUploadEnclosure---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t upgrade -v $(pkgversion) -w all";
    cmd = ReplaceParam(cmd);

    return System(cmd, 61);
end

function preUploadMgmtBoard()

    LogText(LL_NOTICE, "---Exec preUploadMgmtBoard---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_MGMT_BOARD -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);
    System(cmd, 10);
    return 0;
end

function postUpgradeShareCard()

    LogText(LL_NOTICE, "---Exec postUpgradeShareCard---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_12GSAS_SHARA_CARD -t upgrade -v $(pkgversion) -n all -a $(updType)";
    cmd = ReplaceParam(cmd);

    return 0, {name = "postUpgradeShareCard", ag = "UpgradePostupd", cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_12GSAS_SHARA_CARD"};
end

function postUpgradeDiskEnclosureForHigh()

    LogText(LL_NOTICE, "---Exec postUpgradeDiskEnclosureForHigh---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_ENCLOSURE_FW -t upgrade -v $(pkgversion) -w all -a $(updType)";
    cmd = ReplaceParam(cmd);

    return 0, {name = "postUpgradeDiskEnclosureForHigh", ag = "UpgradePostupd", cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_ENCLOSURE_FW"};
end

function postUpgradeDiskEnclosureForMiddle()

    LogText(LL_NOTICE, "---Exec postUpgradeDiskEnclosureForMiddle---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_DISK_ENCLOSURE_IN_MIDDLE -t upgrade -v $(pkgversion) -w all -a $(updType)";
    cmd = ReplaceParam(cmd);

    return 0, {name = "postUpgradeDiskEnclosureForMiddle", ag = "UpgradePostupd", cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_DISK_ENCLOSURE_IN_MIDDLE"};
end


function postUpgradeBbu()

    LogText(LL_NOTICE, "---Exec postUpgradeBbu---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_BBU_UPDATE_BACKGROUND -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "postUpgradeBbu", ag = "UpgradePostupd", cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_BBU_UPDATE_BACKGROUND"};
end

function postUpgradeMgmt()

    LogText(LL_NOTICE, "---Exec postUpgradeMgmt---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_MGMT_BOARD_FW_BACKGROUND -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "postUpgradeMgmt", ag = "UpgradePostupd", cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_MGMT_BOARD_FW_BACKGROUND"};
end

function isNeedUploadForConcurrent()

    -- 第三阶段专家模式场景
    if (g_UpdState.ParamList.stage ~= "3") then
        LogText(LL_NOTICE, "It not the third stage, not need to upload.");
        return false;
    end

    if (g_UpdState.ParamList.retry == "retry") then
        LogText(LL_NOTICE, "It is the professional mode.");
        return true;
    end

    LogText(LL_NOTICE, "It is not the professional mode.");
    return false;
end

-- 第三阶段可能需要上传的原子有 磁盘框 大卡
-- 大卡 硬盘框 三个不同固件 不相互耦合
function UploadMe(ret, name)

    -- 如果执行成功或者没有执行就不用重新传包了
    if (ret == 0 or ret == nil) then -- ret为nil是不是也该传一下 ret为nil表示没有执行该原子 控制器重启了上传的固件还有效吗 -- 有效
        LogText(LL_NOTICE, "No need to reload in the professional mode for ret OK or nil.");
        return RET_OK;
    end

    if (name == "postUpgradeShareCard") then
        LogText(LL_NOTICE, "Reload sharecard in the professional mode.");
        return ReUploadShareCard();
    elseif (name == "postUpgradeDiskEnclosureForHigh") then
        LogText(LL_NOTICE, "Reload high diskenclosure in the professional mode.");
        return ReUploadEnclosure();
    elseif (name == "postUpgradeDiskEnclosureForMiddle") then
        LogText(LL_NOTICE, "Reload middle diskenclosure in the professional mode.");
        return ReUploadEnclosure();
    elseif (name == "postUpgradeMgmt") then
        LogText(LL_NOTICE, "Reload mgmt in the professional mode.");
        return preUploadMgmtBoard();
    end

    -- 除此之外原子失败无需上传操作
    LogText(LL_NOTICE, "No need to reload in the professional mode for other atoms.");
    return RET_OK;
end

function UploadForConcurrent()

    LogText(LL_NOTICE, "Reload firmware in professional mode.");

    -- 遍历并发组 原子执行结果非0的原子都需要重新上传
    for _, atomTbl in pairs(g_UpdState.ConcurrentAtom) do
        for _, atomTb2 in pairs(atomTbl) do
            for _, atom in pairs(atomTb2) do
                if (UploadMe(atom.ret, atom.name) ~= RET_OK) then
                    LogText(LL_NOTICE, "Reload firmware failed in professional mode.");
                    return RET_ERR;
                end
            end
        end
    end

    LogText(LL_NOTICE, "Reload firmware successed in professional mode.");
    return RET_OK;
end

-- 0: FALSE 非高端; 1: TRUE 高端
function JudgeEnclosureType()

    LogText(LL_NOTICE, "---Exec JudgeEnclosureType---");

    -- 第三阶段专家模式 对于失败的固件需要重新上传固件
    if (isNeedUploadForConcurrent() == true) then
        UploadForConcurrent();
    end

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_CHECK_IS_HIGH";
    return System(cmd, 10);
end

function UpgradeShareCardWhenSync()

    LogText(LL_NOTICE, "---Exec UpgradeShareCardWhenSync---");

    if (g_UpdState.ParamList.SyncPowerFlag == "2") then
        LogText(LL_NOTICE, "The repoweron sync fw, no need upgrade.");
        return 0;
    end

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_SHARA_CARD -t sync -v $(version) -n all";
    cmd = ReplaceParam(cmd);

    if (System(cmd, 10) ~= RET_OK) then
        LogText(LL_NOTICE, "Transfer sharecard failed when exec UpgradeShareCardWhenSync.");
        return RET_ERR;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_12GSAS_SHARA_CARD -t sync -v $(version) -n all -a 1";
    cmd = ReplaceParam(cmd);

    return System(cmd, 30);
end

function UpgradeEnclosureForHighWhenSync()

    LogText(LL_NOTICE, "---Exec UpgradeEnclosureForHighWhenSync---");

    if (g_UpdState.ParamList.SyncPowerFlag == "2") then
        LogText(LL_NOTICE, "The repoweron sync fw, no need upgrade.");
        return 0;
    end

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t sync -v $(version) -w all";
    cmd = ReplaceParam(cmd);

    if (System(cmd, 61) ~= RET_OK) then
        LogText(LL_NOTICE, "Transfer high enclosure failed when exec UpgradeEnclosureForHighWhenSync.");
        return RET_ERR;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_ENCLOSURE_FW -t sync -v $(version) -w all -a 1";
    cmd = ReplaceParam(cmd);

    return System(cmd, 30);
end

function UpgradeEnclosureForMiddleWhenSync()

    LogText(LL_NOTICE, "---Exec UpgradeEnclosureForMiddleWhenSync---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_TRANSFER_ENCLOSURE -t sync -v $(version) -w all";
    cmd = ReplaceParam(cmd);

    if (System(cmd, 61) ~= RET_OK) then
        LogText(LL_NOTICE, "Transfer middle enclosure failed when exec UpgradeEnclosureForMiddleWhenSync.");
        return RET_ERR;
    end

    cmd = "/OSM/bin/upgrade_atom -f UPGRADE_DISK_ENCLOSURE_IN_MIDDLE -t sync -v $(version) -w all -a 1";
    cmd = ReplaceParam(cmd);

    return System(cmd, 30);
end

-- 在线升级可靠性原子
-- 检查BDM的后端多路径告警并调用MP的接口查询后端多路径是否正常
function CheckDiskLinkIsNormal()

    LogText(LL_NOTICE, "---Exec CheckDiskLinkIsNormal---");

    -- 最后一批重启后不检查外部LUN的链路
    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_CHECK_DISK_LINK -t upgrade -h " .. g_UpdState.ParamList.RollBackFlag;
    cmd = ReplaceParam(cmd);

    return System(cmd, 15);
end

-- 第二阶段 接口卡并发原子
function upd_c_SAS()

    local iRet = upgrade_SAS_compatible_check();
    --返回0表示固件兼容，兼容时不应该去升级了，所以返回特殊值1，不组装参数到C并发
    if (0 == iRet) then
        LogText(LL_NOTICE, "---SAS is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_SAS---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m EIF -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_SAS", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "EIF"};
end

function upd_c_12GSAS()

    local iRet = upgrade_12GSAS_compatible_check();
    if (0 == iRet) then
        LogText(LL_NOTICE, "---12GSAS is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_12GSAS---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 12GSAS -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_12GSAS", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "12GSAS"};
end

function upd_c_16GFC()

    local iRet = upgrade_16GFC_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---16GFC is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_16GFC---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 16GFC -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_16GFC", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "16GFC"};
end

function upd_c_FCOE()

    local iRet = upgrade_FCOE_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---FCOE is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_FCOE---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m FCoE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_FCOE", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "FCoE"};
end

function upd_c_TOE()

    local iRet = upgrade_TOE_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---TOE is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_TOE---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m TOE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_TOE", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "TOE"};
end

function upd_c_IXGBE()

    local iRet = upgrade_IXGBE_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---IXGBE is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_IXGBE---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IXGBE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_IXGBE", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "IXGBE"};
end

function upd_c_10GBaseT()

    local iRet = upgrade_10GBaseT_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---10GBaseT is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_10GBaseT---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 10GE_EL -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_10GBaseT", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "10GE_EL"};
end

function upd_c_IOC8G()

    local iRet = upgrade_IOC8G_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---IOC8G is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_IOC8G---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_8G -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_IOC8G", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "IOC_8G"};
end

function upd_c_IOC16G()

    local iRet = upgrade_IOC16G_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---IOC16G is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_IOC16G---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m IOC_16G -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_IOC16G", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "IOC_16G"};
end

function upd_c_56GIB()

    local iRet = upgrade_56GIB_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---56GIB is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_56GIB---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m 56GIB -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_56GIB", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "56GIB"};
end

function upd_c_IOCHD()

    local iRet = upgrade_IOCHD_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---IOCHD is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_IOCHD---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_HD -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_IOCHD", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_INTERFACE_CARD_CALL_DMI", mParaValue = "IOC_HD"};
end

function upd_c_IOC10GE()

    local iRet = upgrade_IOC10GE_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---IOC10GE is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_IOC10GE---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD_CALL_DMI -m IOC_10GE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_IOC10GE", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_INTERFACE_CARD_CALL_DMI", mParaValue = "IOC_10GE"};
end

function upd_c_ACC()

    local iRet = upgrade_ACC_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---ACC is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_ACC---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m ACC_FPGA -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_ACC", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 30,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "ACC_FPGA"};
end

function upd_c_SmartIO()

    local iRet = upgrade_SmartIO_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---SmartIO is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_SmartIO---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_INTERFACE_CARD -m SmartIO -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_SmartIO", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 20,
        fParaValue = "UPGRADE_INTERFACE_CARD", mParaValue = "SmartIO"};
end

function upd_c_PCIE()

    local iRet = upgrade_PCIE_compatible_check();
    if (0 == iRet)then
        LogText(LL_NOTICE, "---PCIE is no need upgrade.--");
        return 1;
    end

    LogText(LL_NOTICE, "---Exec upd_c_PCIE---");

    local cmd = "/OSM/bin/upgrade_atom -f UPGRADE_PCIE_UPDATE -m PCIE -t upgrade -v $(pkgversion) -n all";
    cmd = ReplaceParam(cmd);

    return 0, {name = "upd_c_PCIE", ag = g_UpdState.AtomGroup, cmd = cmd, timeout = 7,
        fParaValue = "UPGRADE_PCIE_UPDATE"};
end

--================== 630 新增原子 end ==========================================

--================== Atoms =====================================================
--兼容老版本
function what_is_this()
    --nothing
    return 0;
end

g_tbl_RebootWhenOfflineUpgrade =
{
    entry = "RebootClusterWhenOfflineUpgrade",
    RebootClusterWhenOfflineUpgrade =
    {
        func = RebootNodeWhenRetryOfflineUpgrade,
        retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        progress = 100,
        stubRet = 0,
        nextEntry = "AfterNormalReboot",
        ownerAG = "RebootWhenOfflineUpgrade",
    },
}

g_Tbl_UploadPackageWhenUpgrade =
{
    entry = "InstallSysPkg",
    InstallSysPkg =
    {
        func = what_is_this,
        retcode = { [0] = "upload_BBU", ['other'] = "#SuccRbk" },
        retstate = {[0] = "#Succ"},
        progress = 10,
        stubRet = 0,
    },

    upload_BBU =
    {
        func = what_is_this,
        retcode = { [0] = "#SuccExit", ['other'] = "#SuccRbk" },
        retstate = {[0] = "#Succ"},
        progress = 30,
        stubRet = 0,
    },
}

g_Tbl_UploadPackageWhenRollback =
{
    entry = "check_normal_when_rollback",
    check_normal_when_rollback =
    {
        func = what_is_this,
        retcode = { [0] = "upload_BBU_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },

    upload_BBU_when_rollback =
    {
        func = what_is_this,
        retcode = { [0] = "#SuccRbk", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
}

function table_is_empty(t)
    return next(t) == nil;
end

function transFuncToStr(func)
    local tmpStr = "";
    for k,v in pairs(g_Tbl_UpgradeFuncToStringForSkip) do
        if (k == func) then
            tmpStr = v;
        end
    end
    return tmpStr;
end

--针对并发升级的原子，忽略粒度为原子内部并发升级的小原子，所有失败的小原子是保存在g_UpdState.FailStep里的，格式为xxx,xxx,
function is_failStep(curStepFunc)
    local curStepStr = transFuncToStr(curStepFunc);
    if (("" == curStepStr) or (nil == g_UpdState.FailAG) or (nil == g_UpdState.FailStep)
        or ("" == g_UpdState.FailAG) or ("" == g_UpdState.FailStep)) then
        g_UpdState.SkipFlag = 0;
        return false;
    end

    local index1, index2 = string.find(g_UpdState.FailStep, curStepStr);
    if ((nil ~= index1) and (nil ~= index2)) then
        --将curStep从g_UpdState.FailStep中删除
        --g_UpdState.FailStep格式为xxx,xxx,
        g_UpdState.FailStep = string.sub(g_UpdState.FailStep, 1, index1-1) .. string.sub(g_UpdState.FailStep, index2+2);
        return true;
    end
    return false;
end

-- SR-0000469169 升级过程中对性能要求限制 20150306
function concurrentHandle()

    local ret;
    local AtomFuncTable = g_AtomGroupsTbl[g_UpdState.AtomGroup][g_UpdState.Step].atom_func_tbl;

    if (g_UpdState.ConcurrentAtom == nil) then
        g_UpdState.ConcurrentAtom = {};
    end
    g_UpdState.ConcurrentAtom[g_UpdState.Step] = {};

    for _, func in pairs(AtomFuncTable) do
        local tbl = {};
        for _, f in pairs(func) do
            --在失败列表中小原子为忽略状态，需要跳过，即不需要加入table
            if (not is_failStep(f)) then
                local ret, atom_tbl = f();
                if (0 == ret) then
                   table.insert(tbl, atom_tbl);
                end
            end
        end
        if (not table_is_empty(tbl)) then
            table.insert(g_UpdState.ConcurrentAtom[g_UpdState.Step], tbl);
        end
    end

    --并发升卡之前先校验，版本不一致会写错误码文件，真正升级所有原子之前删除错误码临时文件
    delErrInfoFile();

    if ( 0 == #(g_UpdState.ConcurrentAtom[g_UpdState.Step]) )then
        LogText(LL_NOTICE, "Concurrent table is empty, so no need concurrent.");
        return 0;
    end

    -- 执行并发组
    LogText(LL_NOTICE, "Build concurrent table successed, let's concurrent.");
    return Concurrent{atom_num = #(g_UpdState.ConcurrentAtom[g_UpdState.Step])};
end

function GetConcurrentAtomNum(AtomIndex)

    LogText(LL_NOTICE, "Get concurrent atom num, atomindex is " .. AtomIndex);
    return #g_UpdState.ConcurrentAtom[g_UpdState.Step][AtomIndex];
end

function GetConcurrentAtomInfo(atomIndex, exIndex)

    LogText(LL_NOTICE, "Get concurrent atom info, atomindex is " .. atomIndex .. " exindex is " .. exIndex);

    local AtomInfo = g_UpdState.ConcurrentAtom[g_UpdState.Step][atomIndex];
    return AtomInfo[exIndex].name, AtomInfo[exIndex].ag, AtomInfo[exIndex].cmd, AtomInfo[exIndex].timeout;
end

function SetConcurrentAtomResult(atomIndex, exIndex, atomResult)

    LogText(LL_NOTICE, "Set concurrent atom result, atomindex is " .. atomIndex .. " exindex is " .. exIndex .. " result is " .. atomResult);
    local AtomInfo = g_UpdState.ConcurrentAtom[g_UpdState.Step][atomIndex];

    AtomInfo[exIndex].ret = atomResult;

    local execResult = {};
    execResult.node_ip = g_UpdState.NodeIp;
    execResult.atom_group = AtomInfo[exIndex].ag;
    execResult.atom = AtomInfo[exIndex].name;
    execResult.result = atomResult;

    LogText(LL_NOTICE, "atom: " .. AtomInfo[exIndex].name .. " AG: " .. AtomInfo[exIndex].ag .. " result: " .. atomResult);
    --原子执行失败，上报错误码
    ReportAtomErrorCode(execResult);
    return;
end



g_Tbl_UpgradeEnclosureAtomName = {"preUploadEnclosure", "upgrade_enclosure", "postUpgradeDiskEnclosureForHigh", "postUpgradeDiskEnclosureForMiddle", "upgrade_enclosure_compatible"};

g_Tbl_UpgradeMgtAtomName = {"preUploadMgmtBoard", "postUpgradeMgmt"};

g_Tbl_UpgradeCardAtomName = {"upd_c_SAS", "upd_c_12GSAS", "upd_c_16GFC", "upd_c_FCOE", "upd_c_TOE", "upd_c_IXGBE", "upd_c_10GBaseT", "upd_c_IOC8G", "upd_c_IOC16G", "upd_c_56GIB", "upd_c_IOCHD", "upd_c_IOC10GE", "upd_c_ACC", "upd_c_SmartIO", "upd_c_PCIE", "upgrade_SAS_compatible", "upgrade_SAS_when_upgrade_SAS_compatible_fail", "upgrade_12GSAS_compatible", "upgrade_12GSAS_when_upgrade_12GSAS_compatible_fail", "upgrade_16GFC_compatible", "upgrade_FCOE_compatible", "upgrade_16GFC_when_upgrade_16GFC_compatible_fail", "upgrade_FCOE_when_upgrade_FCOE_compatible_fail", "upgrade_TOE_compatible", "upgrade_TOE_when_upgrade_TOE_compatible_fail", "upgrade_IXGBE_compatible", "upgrade_IXGBE_when_upgrade_IXGBE_compatible_fail", "upgrade_10GBaseT_compatible", "upgrade_10GBaseT_when_upgrade_10GBaseT_compatible_fail", "upgrade_IOC8G_compatible", "upgrade_IOC8G_when_upgrade_IOC8G_compatible_fail", "upgrade_IOC16G_compatible", "upgrade_IOC16G_when_upgrade_IOC16G_compatible_fail", "upgrade_56GIB_compatible", "upgrade_56GIB_when_upgrade_56GIB_compatible_fail", "upgrade_SmartIO_compatible", "upgrade_SmartIO_when_upgrade_SmartIO_compatible_fail", "upgrade_IOCHD_compatible", "upgrade_IOCHD_when_upgrade_IOCHD_compatible_fail", "upgrade_IOC10GE_compatible", "upgrade_IOC10GE_when_upgrade_IOC10GE_compatible_fail", "upgrade_ACC_compatible", "upgrade_ACC_when_upgrade_ACC_compatible_fail","upgrade_PCIE_compatible", "upgrade_PCIE_when_upgrade_PCIE_compatible_fail"};

g_Tbl_UpgradeShareCardAtomName = {"preUploadShareCard", "postUpgradeShareCard"};
g_Tbl_UpgradeOnlinePrepareAtomName = {"NotifySysCtrlPrepareForOnline", "NotifySysCtrlPrepareForOnline_when_rbk"};
g_Tbl_UpgradeAfterNormalRebootAtomName = {"AfterNormalReboot", "AfterNormalReboot_when_rollback", "upgrade_Check_Obj_WhenOnline"};

g_Tbl_UpgradeFuncToStringForSkip =
{
[upd_c_SAS] = "upd_c_SAS",
[upd_c_12GSAS] = "upd_c_12GSAS",
[upd_c_16GFC] = "upd_c_16GFC",
[upd_c_FCOE] = "upd_c_FCOE",
[upd_c_ACC] = "upd_c_ACC",
[upd_c_SmartIO] = "upd_c_SmartIO",
[upd_c_IOC16G] = "upd_c_IOC16G",
[upd_c_IOCHD] = "upd_c_IOCHD",
[upd_c_IOC10GE] = "upd_c_IOC10GE",
[upd_c_IOC8G] = "upd_c_IOC8G",
[upd_c_PCIE] = "upd_c_PCIE",
[upd_c_56GIB] = "upd_c_56GIB",
[upd_c_TOE] = "upd_c_TOE",
[upd_c_IXGBE] = "upd_c_IXGBE",
[upd_c_10GBaseT] = "upd_c_10GBaseT",
[preUploadShareCard] = "preUploadShareCard",
[preUploadEnclosure] = "preUploadEnclosure",
[postUpgradeShareCard] = "postUpgradeShareCard",
[postUpgradeDiskEnclosureForHigh] = "postUpgradeDiskEnclosureForHigh",
[postUpgradeBbu] = "postUpgradeBbu",
[postUpgradeMgmt] = "postUpgradeMgmt",
[postUpgradeDiskEnclosureForMiddle] = "postUpgradeDiskEnclosureForMiddle",
};

g_Tbl_UpgradeSystem =
{
    entry = "upgrade_enclosure",
    --升级控制框
    upgrade_enclosure =
    {
        func = upgrade_enclosure,
        retcode = { [0] = "isDowngrade", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_SINGLE_ENCLOSURE_FW",
    },
    --判断是否是降级到830或者1230,需要在重启前升级硬盘框,BBU,管理板;硬盘框升级在12Gsas卡之前完成，卡升级可能清除掉缓上报时间
    isDowngrade =
    {
        func = isDowngrade,
        retcode = { [0] = "upgrade_DiskEnclosure", ['other'] = "upgradeInterfaceCard" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
    --升级硬盘框
    upgrade_DiskEnclosure =
    {
        func = upgrade_DiskEnclosure,
        retcode = { [0] = "upgrade_BBU", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_DISK_ENCLOSURE_IN_MIDDLE",
    },
    -- 升级BBU
    upgrade_BBU =
    {
        func = upgrade_BBU,
        retcode = { [0] = "upgrade_MGMT", ['other'] = "#FailExit"},
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
    --升级MGMT
    upgrade_MGMT =
    {
        func = upgrade_MGMT,
        retcode = { [0] = "upgradeInterfaceCard", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_MGMT_BOARD_FW",
    },
    -- 总计15张卡并发
    upgradeInterfaceCard =
    {
        func = concurrentHandle,
        --新增并发升级原子，务必刷新g_Tbl_UpgradeFuncToStringForSkip，否则无法实现忽略功能
        atom_func_tbl =
        {
            {upd_c_SAS},    {upd_c_12GSAS},  {upd_c_16GFC},    {upd_c_FCOE},
            {upd_c_TOE},    {upd_c_IXGBE},   {upd_c_10GBaseT}, {upd_c_IOC8G},
            {upd_c_IOC16G}, {upd_c_56GIB},   {upd_c_IOCHD},    {upd_c_IOC10GE},
            {upd_c_ACC},    {upd_c_SmartIO}, {upd_c_PCIE},
        },
        retcode = {[0] = "upgrade_BIOS", ['other'] = "#FailExit"},
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
    --升级BIOS
    upgrade_BIOS =
    {
        func = upgrade_BIOS,
        retcode = { [0] = "upgrade_SYS", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },

    --升级SYS
    upgrade_SYS =
    {
        func = upgrade_SYS,
        retcode = { [0] = "#SuccExit", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        nextEntry = "RebootSysWhenOnlineUpgrade,RebootClusterWhenOfflineUpgrade",
        ownerAG = "UpgradeSystemWhenOfflineUpgrade,UpgradeSystemWhenOnlineUpgrade",
    },
}

g_Tbl_RollbackSystem =
{
    entry = "upgrade_enclosure_when_rollback",
    --回退控制框，先判断是否是回退到830、1230、h1，如果是，则需要对版本配套表做兼容性处理
    upgrade_enclosure_when_rollback =
    {
        func = rollback_enclosure,
        retcode = { [0] = "upgrade_SAS_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_SINGLE_ENCLOSURE_FW",
    },
    upgrade_SAS_when_rollback =
    {
        func = rollback_SAS,
        retcode = { [0] = "upgrade_12GSAS_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_12GSAS_when_rollback =
    {
        func = rollback_12GSAS,
        retcode = { [0] = "upgrade_16GFC_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_16GFC_when_rollback =
    {
        func = rollback_16GFC,
        retcode = { [0] = "upgrade_FCOE_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_FCOE_when_rollback =
    {
        func = rollback_FCOE,
        retcode = { [0] = "upgrade_TOE_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_TOE_when_rollback =
    {
        func = rollback_TOE,
        retcode = { [0] = "upgrade_IXGBE_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_IXGBE_when_rollback =
    {
        func = rollback_IXGBE,
        retcode = { [0] = "upgrade_10GBaseT_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_10GBaseT_when_rollback =
    {
        func = rollback_10GBaseT,
        retcode = { [0] = "upgrade_IOC8G_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_IOC8G_when_rollback =
    {
        func = rollback_IOC8G,
        retcode = { [0] = "upgrade_IOC16G_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_IOC16G_when_rollback =
    {
        func = rollback_IOC16G,
        retcode = { [0] = "upgrade_56GIB_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_56GIB_when_rollback =
    {
        func = rollback_56GIB,
        retcode = { [0] = "upgrade_SmartIO_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_SmartIO_when_rollback =
    {
        func = rollback_SmartIO,
        retcode = { [0] = "upgrade_IOCHD_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_IOCHD_when_rollback =
    {
        func = rollback_IOCHD,
        retcode = { [0] = "upgrade_IOC10GE_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_IOC10GE_when_rollback =
    {
        func = rollback_IOC10GE,
        retcode = { [0] = "upgrade_ACC_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_ACC_when_rollback =
    {
        func = rollback_ACC,
        retcode = { [0] = "upgrade_PCIE_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_INTERFACE_CARD",
    },
    upgrade_PCIE_when_rollback =
    {
        func = rollback_PCIE,
        retcode = { [0] = "isRollbackDown", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_PCIE_UPDATE",
    },
    --通过版本号判断是否是从830 1030 1230升级到630过程中失败回退，需要回退硬盘框，BBU，管理板
    isRollbackDown =
    {
        func = isRollbackDown,
        retcode = { [0] = "upgrade_DiskEnclosure_when_rollback", ['other'] = "upgrade_BIOS_when_rollback" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
    --回退硬盘框
    upgrade_DiskEnclosure_when_rollback =
    {
        func = rollback_DiskEnclosure,
        retcode = { [0] = "upgrade_BBU_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_DISK_ENCLOSURE_IN_MIDDLE",
    },
    --回退BBU
    upgrade_BBU_when_rollback =
    {
        func = rollback_BBU,
        retcode = { [0] = "upgrade_MGMT_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
    --回退管理板
    upgrade_MGMT_when_rollback =
    {
        func = rollback_MGMT,
        retcode = { [0] = "upgrade_BIOS_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        opcode = "UPGRADE_MGMT_BOARD_FW",
    },

    upgrade_BIOS_when_rollback =
    {
        func = rollback_BIOS,
        retcode = { [0] = "upgrade_SYS_when_rollback", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },

    upgrade_SYS_when_rollback =
    {
        func = rollback_SYS,
        retcode = { [0] = "#SuccRbk", ['other'] = "#FailExit" },
        retstate = {[0] = "#Succ"},
        stubRet = 0,
    },
}

g_Tbl_SyncPcieSwitch =
{
    entry = "CheckPcieSwitchPackage",
    CheckPcieSwitchPackage =
    {
        func = CheckPcieSwitchPackage,
        ---/// 0 包存在; 1 包不存在; 2 包不存在 同步失败
        retcode = {[0] = "CheckIsExistPcie", [10] = "#SuccExit", ['other'] = "#SuccExit"},
        retstate = {[0] = "#Succ", [10] = "#Succ"},
        stubRet = 0,
        progress = 100,
    },
    CheckIsExistPcie =
    {
        func = CheckIsExistPcie,
        ---/// 0 多控设备,非6U设备; 1 双控设备; other 同步失败;
        retcode = {[0] = "CheckPcieSwitchState", ['other'] = "#SuccExit"},
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        progress = 100,
    },
    CheckPcieSwitchState =
    {
        func = CheckPcieSwitchState,
        ---/// 0 两个交换机状态OK; 1 没有两个状态OK的交换机;
        retcode = {[0] = "CheckPcieSwitchVersion_0", ['other'] = "#SuccExit"},
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
    CheckPcieSwitchVersion_0 =
    {
        func = checkversion_PCIE_SW0,
        ---/// 0 版本相同; 2 版本不相同; other：同步成功
        retcode = {[0] = "checkversion_PCIE_SW1", [2] = "Trans_PCIE_SW0_Pkg", ['other'] = "#SuccExit"},
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, [2] = {0, 0}, ['other']={3, 10}},
        stubRet = 2,
        progress = 100,
    },
    Trans_PCIE_SW0_Pkg =
    {
        func = Trans_PCIE_SW0_Pkg,
        ---/// 0 升级成功 重启交换机; other 升级失败
        retcode = {[0] = "Check_PCIE_SW0_TransPkg_State", ['other'] = "IsolatePcieSwitch_0"},
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
     --查询传包状态
    Check_PCIE_SW0_TransPkg_State =
    {
        func = Check_PCIE_SW0_TransPkg_State,
        --0：交换机包上传完成  1：交换机包传输失败  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯失败
        retcode = { [0] = "reboot_PCIE_SW0", [2]="IsolatePcieSwitch_0", ['other'] = "IsolatePcieSwitch_0" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, [2] ={12, 1}, ['other']={4, 21}},
        stubRet = 0,
        progress = 100,
    },
    --重启PCIE交换机
    reboot_PCIE_SW0 =
    {
        func = reboot_PCIE_SW0,
        --0：重启成功 其他：失败，需要重试
        retcode = { [0] = "Check_PCIE_SW0_reboot_State", ['other'] = "IsolatePcieSwitch_0" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
    --重启后检查交换机升级状态
    Check_PCIE_SW0_reboot_State =
    {
        func = Check_PCIE_SW0_reboot_State,
        --0：升级成功  1：升级失败，需要回退，其他：通讯异常,重试5分钟
        retcode = { [0] = "checkversion_PCIE_SW0_after_upg", [1] = "IsolatePcieSwitch_0", ['other'] = "IsolatePcieSwitch_0" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, [1] = {0, 0}, ['other'] = {3, 1}},
        stubRet = 0,
        progress = 100,
    },
    --升级完成后检查交换机版本
    checkversion_PCIE_SW0_after_upg =
    {
        func = checkversion_PCIE_SW0,
        --0：版本相同 其他：版本异常
        retcode = { [0] = "checkversion_PCIE_SW1", ['other'] = "IsolatePcieSwitch_0" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']= {3, 10}},
        stubRet = 0,
        progress = 100,
    },
    IsolatePcieSwitch_0 =
    {
        func = IsolatePcieSwitch_0,
        retcode = {[0] = "checkversion_PCIE_SW1", ['other'] = "checkversion_PCIE_SW1"},
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
    --检查1号交换机版本，版本相同直接返回升级成功  版本不相同则开始升级
    checkversion_PCIE_SW1 =
    {
        func = checkversion_PCIE_SW1,
        --0：版本相同   2：版本不同     其他：通讯失败
        retcode = { [0] = "#SuccExit", [2] = "Trans_PCIE_SW1_Pkg", ['other'] = "#SuccExit" },
        retstate = {[0] = "#Succ", [2] = "#Succ"},
        retry = {[0] = {0, 0}, [2] = {0, 0}, ['other']={3, 10}},
        stubRet = 2,
        progress = 100,
    },
    --上传PCIE交换机包
    Trans_PCIE_SW1_Pkg =
    {
        func = Trans_PCIE_SW1_Pkg,
        --0：传包成功  其他：传包失败，需要重试
        retcode = { [0] = "Check_PCIE_SW1_TransPkg_State", ['other'] = "IsolatePcieSwitch_1" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
     --查询传包状态
    Check_PCIE_SW1_TransPkg_State =
    {
        func = Check_PCIE_SW1_TransPkg_State,
        --0：交换机包上传完成 1：1号交换机包传输失败，需要回退0号交换机  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯异常
        retcode = { [0] = "reboot_PCIE_SW1", [2]="IsolatePcieSwitch_1", ['other'] = "IsolatePcieSwitch_1" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, [2] ={12, 1}, ['other']={4, 21}},
        stubRet = 0,
        progress = 100,
    },
    --重启PCIE交换机
    reboot_PCIE_SW1 =
    {
        func = reboot_PCIE_SW1,
        --0：重启成功 其他：失败，需要重试
        retcode = { [0] = "Check_PCIE_SW1_reboot_State", ['other'] = "IsolatePcieSwitch_1" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
    --重启后检查交换机状态
    Check_PCIE_SW1_reboot_State =
    {
        func = Check_PCIE_SW1_reboot_State,
        --0：升级成功  1：升级失败  其他：重试（在交换机启动所需最大超时时间内（5分钟）重试）
        retcode = { [0] = "checkversion_PCIE_SW1_after_upg", [1] = "IsolatePcieSwitch_1", ['other'] = "IsolatePcieSwitch_1" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, [1]={0,0}, ['other'] = {3, 1}},
        stubRet = 0,
        progress = 100,
    },
    --升级完成后检查交换机版本
    checkversion_PCIE_SW1_after_upg =
    {
        func = checkversion_PCIE_SW1,
        --0：版本相同   其他：版本不同
        retcode = { [0] = "#SuccExit", ['other'] = "IsolatePcieSwitch_1" },
        retstate = {[0] = "#Succ"},
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        stubRet = 0,
        progress = 100,
    },
    ---///隔离1号交换机
    IsolatePcieSwitch_1 =
    {
        func = IsolatePcieSwitch_1,
        ---/// 0 0号交换机正常 1号交换机异常 同步成功; 1 0号1号交换机都异常 同步失败; other 同步失败
        retcode = {[0] = "#SuccExit", [1] = "#SuccExit", ['other'] = "#SuccExit"},
        retstate = {[0] = "#Succ"},
        stubRet = 0,
        retry = {[0] = {0, 0}, ['other']={3, 10}},
        progress = 100,
    },
}

--升级原子组表
g_AtomGroupsTbl =
{ 
    RepaireSysdisk =
    {
        entry = "CheckAndRepaireSysdisk",
        CheckAndRepaireSysdisk =
        {
            func = CheckAndRepaireSysdisk,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
    },
    CopyPackage =
    {
        entry = "CopyPkgFromOtherNode",
        CopyPkgFromOtherNode =
        {
            func = CopyPkgFromOtherNode,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
    },
    UnzipUpgradePackage =
    {
        entry = "UnzipUpgradePkg",
        UnzipUpgradePkg =
        {
            func = UnzipUpgradePkg,
            retcode = {[0] = "#SuccExit",[10] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ",[10] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
    },
    VerifyUpgradePackage =
    {
        entry = "VerifyUpgradePkg",
        VerifyUpgradePkg =
        {
            func = VerifyUpgradePkg,
            retcode = {[0] = "#SuccExit",[10] = "#SuccExit",[8] = "#FailExit", [9] = "#FailExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ",[10] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
    },
    --当前脚本中删除函数返回值为1
    DeleteUpgradePackage =
    {
        entry = "DeleteUpgradePkg",
        DeleteUpgradePkg =
        {
            func = DeleteUpgradePkg,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
    },

    -- 上电同步过程中 交换机同步失败流程内将其隔离之 对外的结果始终是成功的
    SyncPcieSwitch = g_Tbl_SyncPcieSwitch,

    --同步系统软件及固件
    SyncSysAndFirmware =
    {
        entry = "CheckSSD",
        CheckSSD =
        {
            func = CheckSSD,
            retcode = {[0] = "JudgeSyncType", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ", [1] = "#Succ", [2] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        -- 判断是同步版本还是同步固件,同步版本阶段把所有需要重启生效的全升级了，做到重启一次。当前涉及热补丁，控制框，BIOS,异构补丁。
        JudgeSyncType =
        {
            func = JudgeSyncType,
            retcode = {[1] = "SyncSysAndNeedRebootFw", [2] = "SyncNoNeedRebootFw", [3] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            stubRet = 0,
            progress = 50,
        },
        ----返回值0是正常同步了版本。1是重启后校验，判断是否可以直接校验原则，步骤都执行成功，且重启过
        SyncSysAndNeedRebootFw =
        {
            func = SyncSysVersion,
            retcode = {[0] = "SyncSysVersionReboot", [1] = "VersionCompatibleAfterReboot", [9] = "#SuccExit",['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [1] = "#Succ", [2] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        ---判断版本同步是否需要重启，当需要重启(版本不一致)时，设置重启位图
        SyncSysVersionReboot =
        {
            func = SyncSysVersionReboot,
            retcode = {[0] = "SyncBIOS", [2] = "SyncBIOS", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        ---同步BIOS，由于BIOS在goall脚本中也会同步，系统版本一致时，此处BIOS肯定是不需要升级，不再单独判断BIOS是否需要重启生效
        SyncBIOS =
        {
            func = SyncUpgradeBIOS,
            retcode = {[0] = "SyncCtrl", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        ---同步控制框
        SyncCtrl =
        {
            func = UpgradeCtrlWhenPowerOn,
            retcode = {[0] = "ISCtrlNeedReboot", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        ---判断控制框升级是否需要重启，当需要重启时，设置重启位图
        ISCtrlNeedReboot =
        {
            func = ISNeedReboot,
            retcode = {[0] = "AslVersionCompatibleCheck", [2] = "AslVersionCompatibleCheck", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ",[2] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        AslVersionCompatibleCheck =
        {
            func = AslVersionCompatibleCheck,
            retcode = {[0] = "SyncOemFromMaster", ['other'] = "SyncAslPatch"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 40,
        },
        --异构包同步了设置了重启标志
        SyncAslPatch =
        {
            func = SyncAslPatch,
            retcode = {[0] = "SyncOemFromMaster",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 40,
        },
        --同步OEM包，不需要重启,不判返回值
        SyncOemFromMaster =
        {
            func = SyncOemFromMaster,
            retcode = {[0] = "SyncDiskFileFromMaster",  ['other'] = "SyncDiskFileFromMaster"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 40,
        },
        --同步硬盘红黑榜，不需要重启,不判返回值
        SyncDiskFileFromMaster =
        {
            func = SyncDiskFileFromMaster,
            retcode = {[0] = "#SuccExit",  ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 40,
        },
        
        --重启后校验是否同步成功
        VersionCompatibleAfterReboot =
        {
            func = VersionCompatibleAfterReboot,
            retcode = {[0] = "CtrlFwCompatibleAfterReboot", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        CtrlFwCompatibleAfterReboot =
        {
            func = CtrlFwCompatibleAfterReboot,
            retcode = {[0] = "AslVerCheckAfterReboot", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        AslVerCheckAfterReboot =
        {
            func = AslVerCheckAfterReboot,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 40,
        },
        --同步不需要升级的固件，判断所有固件是否兼容
        SyncNoNeedRebootFw =
        {
            func = SysCompatibleCheck,
            --------------3:是否
            retcode = {[0] = "#SuccExit", [1] = "JudgeEnclosureType",['other'] = "JudgeEnclosureType"},
            retstate = {[0] = "#Succ",[1] = "#Succ", [2] = "#Succ", [4] = "#Succ"},
            stubRet = 0,
            progress = 40,
        },
        -- 区分高中低端设备类型
        JudgeEnclosureType =
        {
            func = JudgeEnclosureType,
            retcode = {[0] = "UpgradeEnclosureForMiddleWhenSync", [1] = "UpgradeShareCardWhenSync", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            stubRet = 0,
            progress = 50,
        },
        -- 同步大卡
        UpgradeShareCardWhenSync =
        {
            func = UpgradeShareCardWhenSync,
            retcode = {[0] = "UpgradeEnclosureForHighWhenSync", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 50,
        },
        -- 同步高端设备硬盘框
        UpgradeEnclosureForHighWhenSync =
        {
            func = UpgradeEnclosureForHighWhenSync,
            retcode = {[0] = "UploadBBUWhenSync", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 50,
        },
        -- 同步中低端设备硬盘框
        UpgradeEnclosureForMiddleWhenSync =
        {
            func = UpgradeEnclosureForMiddleWhenSync,
            retcode = {[0] = "UploadBBUWhenSync", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 50,
        },
        UploadBBUWhenSync =
        {
            func = UploadBBUWhenSync,
            retcode = {[0] = "UpgradeBBUWhenSync",  ['other'] = "UpgradeSASWhenSync"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeBBUWhenSync =
        {
            func = UpgradeBBUWhenSync,
            retcode = {[0] = "UpgradeSASWhenSync",  ['other'] = "UpgradeSASWhenSync"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeSASWhenSync =
        {
            func = UpgradeSASWhenSync,
            retcode = {[0] = "Upgrade12GSASWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        Upgrade12GSASWhenSync =
        {
            func = Upgrade12GSASWhenSync,
            retcode = {[0] = "Upgrade16GFCWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        Upgrade16GFCWhenSync =
        {
            func = Upgrade16GFCWhenSync,
            retcode = {[0] = "UpgradeFCoEWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeFCoEWhenSync =
        {
            func = UpgradeFCoEWhenSync,
            retcode = {[0] = "UpgradeTOEWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeTOEWhenSync =
        {
            func = UpgradeTOEWhenSync,
            retcode = {[0] = "UpgradeIXGBEWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeIXGBEWhenSync =
        {
            func = UpgradeIXGBEWhenSync,
            retcode = {[0] = "Upgrade10GBaseTWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        Upgrade10GBaseTWhenSync =
        {
            func = Upgrade10GBaseTWhenSync,
            retcode = {[0] = "UpgradeIOC8GWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeIOC8GWhenSync =
        {
            func = UpgradeIOC8GWhenSync,
            retcode = {[0] = "UpgradeIOC16GWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeIOC16GWhenSync =
        {
            func = UpgradeIOC16GWhenSync,
            retcode = {[0] = "Upgrade56GIBWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        Upgrade56GIBWhenSync =
        {
            func = Upgrade56GIBWhenSync,
            retcode = {[0] = "UpgradeSmartIOWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeSmartIOWhenSync =
        {
            func = UpgradeSmartIOWhenSync,
            retcode = {[0] = "UpgradeIOCHDWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeIOCHDWhenSync =
        {
            func = UpgradeIOCHDWhenSync,
            retcode = {[0] = "UpgradeIOC10GEWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeIOC10GEWhenSync =
        {
            func = UpgradeIOC10GEWhenSync,
            retcode = {[0] = "UpgradeACCWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeACCWhenSync =
        {
            func = UpgradeACCWhenSync,
            retcode = {[0] = "UpgradePCIEWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradePCIEWhenSync =
        {
            func = UpgradePCIEWhenSync,
            retcode = {[0] = "UpgradeMGMTWhenSync",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeMGMTWhenSync =
        {
            func = UpgradeMGMTWhenSync,
            retcode = {[0] = "#SuccExit",  ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
    },
    --通知系统控制重启
    NotifySysReboot =
    {
        entry = "SyncRebootCheck",
        SyncRebootCheck =
        {
            func = SyncRebootCheck,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 10,
        },
    },

    --框接入同步
    SyncFrame =
    {
        entry = "upgrade_enclosure_compatible_check_when_insert",
        upgrade_enclosure_compatible_check_when_insert =
        {
            func = upgrade_enclosure_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_enclosure_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_enclosure_when_insert =
        {
            func = upgrade_enclosure_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --管理板接入同步
    SyncMGMT =
    {
        entry = "upgrade_MGMT_compatible_check_when_insert",
        upgrade_MGMT_compatible_check_when_insert =
        {
            func = upgrade_MGMT_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_MGMT_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_MGMT_when_insert =
        {
            func = upgrade_MGMT_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --IXGBE接入同步
    SyncIXGBE =
    {
        entry = "upgrade_IXGBE_compatible_check_when_insert",
        upgrade_IXGBE_compatible_check_when_insert =
        {
            func = upgrade_IXGBE_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_IXGBE_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_IXGBE_when_insert =
        {
            func = upgrade_IXGBE_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --56GIB接入同步
    Sync56GIB =
    {
        entry = "upgrade_56GIB_compatible_check_when_insert",
        upgrade_56GIB_compatible_check_when_insert =
        {
            func = upgrade_56GIB_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_56GIB_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_56GIB_when_insert =
        {
            func = upgrade_56GIB_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --ACC接入同步
    SyncACC =
    {
        entry = "upgrade_ACC_compatible_check_when_insert",
        upgrade_ACC_compatible_check_when_insert =
        {
            func = upgrade_ACC_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_ACC_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_ACC_when_insert =
        {
            func = upgrade_ACC_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --10GBaseT接入同步
    Sync10GBaseT =
    {
        entry = "upgrade_10GBaseT_compatible_check_when_insert",
        upgrade_10GBaseT_compatible_check_when_insert =
        {
            func = upgrade_10GBaseT_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_10GBaseT_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_10GBaseT_when_insert =
        {
            func = upgrade_10GBaseT_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --SmartIO接入同步
    SyncSmartIO =
    {
        entry = "upgrade_SmartIO_compatible_check_when_insert",
        upgrade_SmartIO_compatible_check_when_insert =
        {
            func = upgrade_SmartIO_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_SmartIO_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_SmartIO_when_insert =
        {
            func = upgrade_SmartIO_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    
    --IP Scale-out组网的环境更换SmartIO卡
    SyncSmartIOInOfflineStatus =
    {
        entry = "upgrade_SmartIO_compatible_check_when_insert",
        upgrade_SmartIO_compatible_check_when_insert =
        {
            func = upgrade_SmartIO_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_SmartIO_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_SmartIO_when_insert =
        {
            func = upgrade_SmartIO_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    --IOCHD接入同步
    SyncIOCHD =
    {
        entry = "upgrade_IOCHD_compatible_check_when_insert",
        upgrade_IOCHD_compatible_check_when_insert =
        {
            func = upgrade_IOCHD_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_IOCHD_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_IOCHD_when_insert =
        {
            func = upgrade_IOCHD_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },

    --IOC10GE接入同步
    SyncIOC10GE =
    {
        entry = "upgrade_IOC10GE_compatible_check_when_insert",
        upgrade_IOC10GE_compatible_check_when_insert =
        {
            func = upgrade_IOC10GE_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_IOC10GE_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_IOC10GE_when_insert =
        {
            func = upgrade_IOC10GE_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    --IOC8G接入同步
    SyncIOC8G =
    {
        entry = "upgrade_IOC8G_compatible_check_when_insert",
        upgrade_IOC8G_compatible_check_when_insert =
        {
            func = upgrade_IOC8G_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_IOC8G_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_IOC8G_when_insert =
        {
            func = upgrade_IOC8G_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    --IOC16G接入同步
    SyncIOC16G =
    {
        entry = "upgrade_IOC16G_compatible_check_when_insert",
        upgrade_IOC16G_compatible_check_when_insert =
        {
            func = upgrade_IOC16G_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "upgrade_IOC16G_when_insert", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        upgrade_IOC16G_when_insert =
        {
            func = upgrade_IOC16G_when_insert,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    --插入BBU同步
    SyncBBU =
    {
        entry = "upgrade_BBU_compatible_check_when_insert",
        upgrade_BBU_compatible_check_when_insert =
        {
            func = upgrade_BBU_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "UploadBBUWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        UploadBBUWhenInster =
        {
            func = UploadBBUWhenInster,
            retcode = {[0] = "UpgradeBBUWhenInster", [2] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeBBUWhenInster =
        {
            func = UpgradeBBUWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", [2] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    SyncSAS =
    {
        entry = "upgrade_SAS_compatible_check_when_insert",
        upgrade_SAS_compatible_check_when_insert =
        {
            func = upgrade_SAS_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "UpgradeSASWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        UpgradeSASWhenInster =
        {
            func = UpgradeSASWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", [2] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    SyncFCoE =
    {
        entry = "upgrade_FCOE_compatible_check_when_insert",
        upgrade_FCOE_compatible_check_when_insert =
        {
            func = upgrade_FCOE_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "UpgradeFCoEWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        UpgradeFCoEWhenInster =
        {
            func = UpgradeFCoEWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", [2] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    SyncTOE =
    {
        entry = "upgrade_TOE_compatible_check_when_insert",
        upgrade_TOE_compatible_check_when_insert =
        {
            func = upgrade_TOE_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "UpgradeTOEWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        UpgradeTOEWhenInster =
        {
            func = UpgradeTOEWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", [2] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    SyncPCIE =
    {
        entry = "upgrade_PCIE_compatible_check_when_insert",
        upgrade_PCIE_compatible_check_when_insert =
        {
            func = upgrade_PCIE_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "UpgradePCIEWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        UpgradePCIEWhenInster =
        {
            func = UpgradePCIEWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", [2] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    Sync12GSAS =
    {
        entry = "upgrade_12GSAS_compatible_check_when_insert",
        upgrade_12GSAS_compatible_check_when_insert =
        {
            func = upgrade_12GSAS_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "Upgrade12GSASWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        Upgrade12GSASWhenInster =
        {
            func = Upgrade12GSASWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    Sync16GFC =
    {
        entry = "upgrade_16GFC_compatible_check_when_insert",
        upgrade_16GFC_compatible_check_when_insert =
        {
            func = upgrade_16GFC_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "Upgrade16GFCWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        Upgrade16GFCWhenInster =
        {
            func = Upgrade16GFCWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    SyncSHARECARD =
    {
        entry = "upgrade_12GSAS_SHARE_CARD_compatible_check_when_insert",
        upgrade_12GSAS_SHARE_CARD_compatible_check_when_insert =
        {
            func = upgrade_12GSAS_SHARE_CARD_compatible_check_when_insert,
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 20,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "UploadShareCardWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        UploadShareCardWhenInster =
        {
            func = UploadShareCardWhenInster,
            retcode = {[0] = "UpgradeShareCardWhenInster", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 60,
        },
        UpgradeShareCardWhenInster =
        {
            func = UpgradeShareCardWhenInster,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 90,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
    },
    InsertSyncPcieSwitch =
    {
        entry = "CheckPcieSwitchPackage",
        CheckPcieSwitchPackage =
        {
            func = CheckPcieSwitchPackage,
            ---/// 0 包存在; 1 包不存在; 2 包不存在 同步失败
            retcode = {[0] = "CheckInsertedPcieSwitchState", [10] = "#SuccExit", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ", [10] = "#Succ"},
            stubRet = 0,
            progress = 100,
        },
        CheckInsertedPcieSwitchState =
        {
            func = CheckInsertedPcieSwitchState,
            ---/// 0 交换机状态OK; 1 没有状态OK的交换机;
            retcode = {[0] = "checkversionInserted_PCIE_SW", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            stubRet = 0,
            progress = 100,
        },
        checkversionInserted_PCIE_SW =
        {
            func = checkversionInserted_PCIE_SW,
            ---/// 0 版本相同; 2 版本不相同; other：同步成功
            retcode = {[0] = "NotifyDrvNoNeedUpd", [2] = "NotifyDrvUpdStart", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [2] = {0, 0}, ['other']={3, 10}},
            stubRet = 2,
            progress = 100,
        },
        NotifyDrvNoNeedUpd =
        {
            func = NotifyDrvNoNeedUpd,
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 30,
        },
        NotifyDrvUpdStart =
        {
            func = NotifyDrvUpdStart,
            retcode = {[0] = "TransInserted_PCIE_SW_Pkg", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={0, 0}},
            stubRet = 0,
            progress = 100,
        },
        TransInserted_PCIE_SW_Pkg =
        {
            func = TransInserted_PCIE_SW_Pkg,
            ---/// 0 升级成功 重启交换机; other 升级失败
            retcode = {[0] = "CheckInserted_PCIE_SW_TransPkg_State", ['other'] = "IsolateInsertedPcieSwitch"},
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            stubRet = 0,
            progress = 100,
        },
         --查询传包状态
        CheckInserted_PCIE_SW_TransPkg_State =
        {
            func = CheckInserted_PCIE_SW_TransPkg_State,
            --0：交换机包上传完成  1：交换机包传输失败  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯失败
            retcode = { [0] = "rebootInserted_PCIE_SW", [2]="IsolateInsertedPcieSwitch", ['other'] = "IsolateInsertedPcieSwitch" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [2] ={12, 1}, ['other']={4, 21}},
            stubRet = 0,
            progress = 100,
        },
        --重启PCIE交换机
        rebootInserted_PCIE_SW =
        {
            func = rebootInserted_PCIE_SW,
            --0：重启成功 其他：失败，需要重试
            retcode = { [0] = "CheckInserted_PCIE_SW_reboot_State", ['other'] = "IsolateInsertedPcieSwitch" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            stubRet = 0,
            progress = 100,
        },
        --重启后检查交换机升级状态
        CheckInserted_PCIE_SW_reboot_State =
        {
            func = CheckInserted_PCIE_SW_reboot_State,
            --0：升级成功  1：升级失败，需要回退，其他：通讯异常,重试5分钟
            retcode = { [0] = "checkversionInserted_PCIE_SW_AFT", [1] = "IsolateInsertedPcieSwitch", ['other'] = "IsolateInsertedPcieSwitch" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0, 0}, ['other'] = {3, 1}},
            stubRet = 0,
            progress = 100,
        },
        --升级完成后检查交换机版本
        checkversionInserted_PCIE_SW_AFT =
        {
            func = checkversionInserted_PCIE_SW_AFT,
            --0：版本相同 其他：版本异常
            retcode = { [0] = "NotifyDrvUpdEnd", ['other'] = "IsolateInsertedPcieSwitch" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']= {3, 10}},
            stubRet = 0,
            progress = 100,
        },
        IsolateInsertedPcieSwitch =
        {
            func = IsolateInsertedPcieSwitch,
            retcode = {[0] = "NotifyDrvUpdEnd", ['other'] = "NotifyDrvUpdEnd"},
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            stubRet = 0,
            progress = 100,
        },
        NotifyDrvUpdEnd =
        {
            func = NotifyDrvUpdEnd,
            retcode = {[0] = "#SuccExit", ['other'] = "#SuccExit"},
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={0, 0}},
            stubRet = 0,
            progress = 100,
        },
    },
    UploadPreupd =
    {
        entry = "preUploadShareCardAndEncl",

        preUploadShareCardAndEncl =
        {
            func = concurrentHandle,
            --新增并发升级原子，务必刷新g_Tbl_UpgradeFuncToStringForSkip，否则无法实现忽略功能
            atom_func_tbl =
            {
                {preUploadShareCard},
                {preUploadEnclosure},
            },
            retcode = {[0] = "preUploadMgmtBoard", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            progress = 5,
        },

        preUploadMgmtBoard =
        {
            func = preUploadMgmtBoard,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 5,
            stubRet = 0,
            opcode = "UPGRADE_TRANSFER_MGMT_BOARD",
        },
    },

    UpgradePostupd =
    {
        entry = "JudgeEnclosureType",
        JudgeEnclosureType =
        {
            func = JudgeEnclosureType,
            retcode = {[0] = "upgradePostUpdForMiddle", [1] = "upgradePostUpdForHigh", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            progress = 5,
            opcode = "UPGRADE_CHECK_IS_HIGH",
        },
        upgradePostUpdForHigh =
        {
            func = concurrentHandle,
            --新增并发升级原子，务必刷新g_Tbl_UpgradeFuncToStringForSkip，否则无法实现忽略功能
            atom_func_tbl =
            {
                {postUpgradeShareCard, postUpgradeDiskEnclosureForHigh},
                {postUpgradeBbu, postUpgradeMgmt},
            },
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            progress = 5,
        },
        upgradePostUpdForMiddle =
        {
            func = concurrentHandle,
            --新增并发升级原子，务必刷新g_Tbl_UpgradeFuncToStringForSkip，否则无法实现忽略功能
            atom_func_tbl =
            {
                {postUpgradeDiskEnclosureForMiddle},
                {postUpgradeBbu, postUpgradeMgmt},
            },
            retcode = {[0] = "#SuccExit", ['other'] = "#FailExit"},
            retstate = {[0] = "#Succ"},
            progress = 5,
        },
    },

    --离线升级传包最多5个原子
    UploadPackageWhenOfflineUpgrade = g_Tbl_UploadPackageWhenUpgrade,

    --离线升级准备1个原子(在集群主执行，执行失败，流程结束)
    PrepareForUpdateWhenOfflineUpgrade =
    {
        entry = "NotifySysCtrlPrepareForOffline",
        NotifySysCtrlPrepareForOffline =
        {
            func = NotifySysCtrlPrepareForOffline,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 10,
        },
    },

    --离线回退前准备(在集群主执行，执行失败，流程结束)
    PrepareForUpdateWhenOfflineUpgradeRbk =
    {
        entry = "NotifySysCtrlPrepareForOffline_when_rbk",
        NotifySysCtrlPrepareForOffline_when_rbk =
        {
            func = NotifySysCtrlPrepareForOffline,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            progress = 10,
        },
    },

    --离线升级最多21个原子SYS,FPGA,MANAGEMANAGECHIP,CPLD,BBU,EIF,FCoE,TOE,PCIE
    UpgradeSystemWhenOfflineUpgrade = g_Tbl_UpgradeSystem,

    --1个原子
    RebootWhenOfflineUpgrade =
    {
        entry = "RebootClusterWhenOfflineUpgrade",
        RebootClusterWhenOfflineUpgrade =
        {
            func = RebootClusterWhenOfflineUpgrade,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },
    ---离线升级重启后兼容性检查，检查失败不回退，不设置 10个原子
    OfflineSysCompatibleAfterReboot =
    {
        entry = "AfterNormalReboot",
        --校验节点是否正常开工
        AfterNormalReboot =
        {
            func = AfterNormalReboot,
            retcode = { [0] = "upgrade_Check_Obj_WhenOffline", ['other'] = "#FailExit" },---重启失败配置
            retry = {[0] = {0, 0}, [3] = {0, 0}, ['other'] = {3, 10}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_NORMAL_AFTER_REBOOT",
        },
        upgrade_Check_Obj_WhenOffline =
        {
            func = upgrade_Check_Obj,
            retcode = { [0] = "upgrade_SYS_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, [3] = {0, 0}, ['other'] = {3, 10}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验系统软件升级结果
        upgrade_SYS_compatible =
        {
            func = upgrade_SYS_compatible_check,
            retcode = { [0] = "upgrade_enclosure_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验控制框升级结果
        upgrade_enclosure_compatible =
        {
            func = upgrade_enclosure_compatible_check,
            retcode = { [0] = "isRollbackDown", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE",
        },
        isRollbackDown =
        {
            func = isRollbackDown,
            retcode = { [0] = "upgrade_DiskEnclosure_compatible", ['other'] = "upgrade_SAS_compatible" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验硬盘框升级结果
        upgrade_DiskEnclosure_compatible =
        {
            func = upgrade_DiskEnclosure_compatible_check,
            retcode = { [0] = "upgrade_BBU_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_DISK_ENCL_FW_COMPATIBLE",
        },
        --校验BBU升级结果
        upgrade_BBU_compatible =
        {
            func = upgrade_BBU_compatible_check,
            retcode = { [0] = "upgrade_MGMT_compatible", [2] = "upgrade_BBU_when_upgrade_BBU_compatible_fail", ['other'] = "upgrade_MGMT_compatible" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        upgrade_BBU_when_upgrade_BBU_compatible_fail =
        {
            func = upgrade_BBU,
            retcode = { [0] = "upgrade_MGMT_compatible", ['other'] = "upgrade_MGMT_compatible" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --校验MGMT升级结果
        upgrade_MGMT_compatible =
        {
            func = upgrade_MGMT_compatible_check,
            retcode = { [0] = "upgrade_SAS_compatible", ['other'] = "upgrade_MGMT_when_upgrade_MGMT_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_MGMT_BOARD_FW_COMPATIBLE",
        },
        upgrade_MGMT_when_upgrade_MGMT_compatible_fail =
        {
            func = upgrade_MGMT,
            retcode = { [0] = "upgrade_SAS_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_MGMT_BOARD_FW",
        },
        --校验SAS升级结果
        upgrade_SAS_compatible =
        {
            func = upgrade_SAS_compatible_check,
            retcode = { [0] = "upgrade_12GSAS_compatible", ['other'] = "upgrade_SAS_when_upgrade_SAS_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_SAS_when_upgrade_SAS_compatible_fail =
        {
            func = upgrade_SAS,
            retcode = { [0] = "upgrade_12GSAS_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验12G SAS升级结果
        upgrade_12GSAS_compatible =
        {
            func = upgrade_12GSAS_compatible_check,
            retcode = { [0] = "upgrade_16GFC_compatible", ['other'] = "upgrade_12GSAS_when_upgrade_12GSAS_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_12GSAS_when_upgrade_12GSAS_compatible_fail =
        {
            func = upgrade_12GSAS,
            retcode = { [0] = "upgrade_16GFC_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验16G FC升级结果
        upgrade_16GFC_compatible =
        {
            func = upgrade_16GFC_compatible_check,
            retcode = { [0] = "upgrade_FCOE_compatible", ['other'] = "upgrade_16GFC_when_upgrade_16GFC_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_16GFC_when_upgrade_16GFC_compatible_fail =
        {
            func = upgrade_16GFC,
            retcode = { [0] = "upgrade_FCOE_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验FCOE升级结果
        upgrade_FCOE_compatible =
        {
            func = upgrade_FCOE_compatible_check,
            retcode = { [0] = "upgrade_TOE_compatible", ['other'] = "upgrade_FCOE_when_upgrade_FCOE_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_FCOE_when_upgrade_FCOE_compatible_fail =
        {
            func = upgrade_FCOE,
            retcode = { [0] = "upgrade_TOE_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验TOE升级结果
        upgrade_TOE_compatible =
        {
            func = upgrade_TOE_compatible_check,
            retcode = { [0] = "upgrade_IXGBE_compatible", ['other'] = "upgrade_TOE_when_upgrade_TOE_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_TOE_when_upgrade_TOE_compatible_fail =
        {
            func = upgrade_TOE,
            retcode = { [0] = "upgrade_IXGBE_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验IXGBE升级结果
        upgrade_IXGBE_compatible =
        {
            func = upgrade_IXGBE_compatible_check,
            retcode = { [0] = "upgrade_10GBaseT_compatible", ['other'] = "upgrade_IXGBE_when_upgrade_IXGBE_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_IXGBE_when_upgrade_IXGBE_compatible_fail =
        {
            func = upgrade_IXGBE,
            retcode = { [0] = "upgrade_10GBaseT_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验10GBaseT升级结果
        upgrade_10GBaseT_compatible =
        {
            func = upgrade_10GBaseT_compatible_check,
            retcode = { [0] = "upgrade_IOC8G_compatible", ['other'] = "upgrade_10GBaseT_when_upgrade_10GBaseT_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_10GBaseT_when_upgrade_10GBaseT_compatible_fail =
        {
            func = upgrade_10GBaseT,
            retcode = { [0] = "upgrade_IOC8G_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验IOC8G升级结果
        upgrade_IOC8G_compatible =
        {
            func = upgrade_IOC8G_compatible_check,
            retcode = { [0] = "upgrade_IOC16G_compatible", ['other'] = "upgrade_IOC8G_when_upgrade_IOC8G_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_IOC8G_when_upgrade_IOC8G_compatible_fail =
        {
            func = upgrade_IOC8G,
            retcode = { [0] = "upgrade_IOC16G_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验IOC16G升级结果
        upgrade_IOC16G_compatible =
        {
            func = upgrade_IOC16G_compatible_check,
            retcode = { [0] = "upgrade_56GIB_compatible", ['other'] = "upgrade_IOC16G_when_upgrade_IOC16G_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_IOC16G_when_upgrade_IOC16G_compatible_fail =
        {
            func = upgrade_IOC16G,
            retcode = { [0] = "upgrade_56GIB_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },

        --校验56GIB升级结果
        upgrade_56GIB_compatible =
        {
            func = upgrade_56GIB_compatible_check,
            retcode = { [0] = "upgrade_SmartIO_compatible", ['other'] = "upgrade_56GIB_when_upgrade_56GIB_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_56GIB_when_upgrade_56GIB_compatible_fail =
        {
            func = upgrade_56GIB,
            retcode = { [0] = "upgrade_SmartIO_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验SmartIO升级结果
        upgrade_SmartIO_compatible =
        {
            func = upgrade_SmartIO_compatible_check,
            retcode = { [0] = "upgrade_IOCHD_compatible", ['other'] = "upgrade_SmartIO_when_upgrade_SmartIO_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_SmartIO_when_upgrade_SmartIO_compatible_fail =
        {
            func = upgrade_SmartIO,
            retcode = { [0] = "upgrade_IOCHD_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验IOCHD升级结果
        upgrade_IOCHD_compatible =
        {
            func = upgrade_IOCHD_compatible_check,
            retcode = { [0] = "upgrade_IOC10GE_compatible", ['other'] = "upgrade_IOCHD_when_upgrade_IOCHD_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_IOCHD_when_upgrade_IOCHD_compatible_fail =
        {
            func = upgrade_IOCHD,
            retcode = { [0] = "upgrade_IOC10GE_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验IOC10GE升级结果
        upgrade_IOC10GE_compatible =
        {
            func = upgrade_IOC10GE_compatible_check,
            retcode = { [0] = "upgrade_ACC_compatible", ['other'] = "upgrade_IOC10GE_when_upgrade_IOC10GE_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_IOC10GE_when_upgrade_IOC10GE_compatible_fail =
        {
            func = upgrade_IOC10GE,
            retcode = { [0] = "upgrade_ACC_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },
        --校验ACC升级结果
        upgrade_ACC_compatible =
        {
            func = upgrade_ACC_compatible_check,
            retcode = { [0] = "upgrade_PCIE_compatible", ['other'] = "upgrade_ACC_when_upgrade_ACC_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        upgrade_ACC_when_upgrade_ACC_compatible_fail =
        {
            func = upgrade_ACC,
            retcode = { [0] = "upgrade_PCIE_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            opcode = "UPGRADE_INTERFACE_CARD",
        },

        --校验PCIE升级结果
        upgrade_PCIE_compatible =
        {
            func = upgrade_PCIE_compatible_check,
            retcode = { [0] = "#SuccExit", ['other'] = "upgrade_PCIE_when_upgrade_PCIE_compatible_fail" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            nextEntry = nil,
            ownerAG = "OfflineSysCompatibleAfterReboot",
            opcode = "UPGRADE_GET_PCIE_COMPATIBLE",
        },
        upgrade_PCIE_when_upgrade_PCIE_compatible_fail =
        {
            func = upgrade_PCIE,
            retcode = { [0] = "#SuccExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
            nextEntry = nil,
            ownerAG = "OfflineSysCompatibleAfterReboot",
            opcode = "UPGRADE_PCIE_UPDATE",
        },
    },


    ---离线升级失败后上传固件包及手动回退传包 4个
    UploadFirmwareWhenOfflineUpgradeRollback = g_Tbl_UploadPackageWhenRollback,

    ----1个
    PrepareForUpdateWhenOfflineRollback =
    {
        entry = "NotifySysCtrlPrepareForOffline",
        NotifySysCtrlPrepareForOffline =
        {
            func = NotifySysCtrlPrepareForOffline,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 10,
            stubRet = 0,
        },
    },

    ---离线升级失败后回退系统及手动回退系统 9个
    RollbackSystemWhenOfflineUpgrade = g_Tbl_RollbackSystem,

    --1个
    RollbackRebootWhenOfflineUpgrade =
    {
        entry = "RebootSysWhenOfflineUpgrade",
        RebootSysWhenOfflineUpgrade =
        {
            func = RebootSysWhenOfflineUpgrade,
            retcode = { [0] = "#SuccRbk", [1] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

    },
    ---离线升级失败
    RebootWhenOfflineRollback =
    {
        entry = "RebootSysWhenOfflineRollback",
        RebootSysWhenOfflineRollback =
        {
            func = RebootSysWhenOfflineRollback,
            retcode = { [0] = "#SuccRbk", [1] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

    },

    ---在线升级失败后回退重启及校验
    SysCompatibleAfterOnlineRollbackReboot =
    {
        entry = "AfterNormalReboot_when_rollback",

        --校验节点是否正常开工
        AfterNormalReboot_when_rollback =
        {
            func = check_ctrl_normal,
            retcode = { [0] = "upgrade_SYS_compatible_when_rollback", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, [3] = {0, 0}, ['other'] = {3, 10}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_NORMAL_AFTER_REBOOT",
        },

        --校验系统软件回退结果
        upgrade_SYS_compatible_when_rollback =
        {
            func = rollback_SYS_compatible_check,
            retcode = { [0] = "upgrade_enclosure_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验框固件回退结果
        upgrade_enclosure_compatible_when_rollback =
        {
            func = rollback_enclosure_compatible_check,
            retcode = { [0] = "upgrade_SAS_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE",
        },
        --校验SAS回退结果
        upgrade_SAS_compatible_when_rollback =
        {
            func = rollback_SAS_compatible_check,
            retcode = { [0] = "upgrade_12GSAS_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验12G SAS回退结果
        upgrade_12GSAS_compatible_when_rollback =
        {
            func = rollback_12GSAS_compatible_check,
            retcode = { [0] = "upgrade_16GFC_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验16G FC回退结果
        upgrade_16GFC_compatible_when_rollback =
        {
            func = rollback_16GFC_compatible_check,
            retcode = { [0] = "upgrade_FCOE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验FCOE回退结果
        upgrade_FCOE_compatible_when_rollback =
        {
            func = rollback_FCOE_compatible_check,
            retcode = { [0] = "upgrade_TOE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验TOE回退结果
        upgrade_TOE_compatible_when_rollback =
        {
            func = rollback_TOE_compatible_check,
            retcode = { [0] = "upgrade_IXGBE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IXGBE回退结果
        upgrade_IXGBE_compatible_when_rollback =
        {
            func = rollback_IXGBE_compatible_check,
            retcode = { [0] = "upgrade_10GBaseT_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验10GBaseT回退结果
        upgrade_10GBaseT_compatible_when_rollback =
        {
            func = rollback_10GBaseT_compatible_check,
            retcode = { [0] = "upgrade_IOC8G_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC8G回退结果
        upgrade_IOC8G_compatible_when_rollback =
        {
            func = rollback_IOC8G_compatible_check,
            retcode = { [0] = "upgrade_IOC16G_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC16G回退结果
        upgrade_IOC16G_compatible_when_rollback =
        {
            func = rollback_IOC16G_compatible_check,
            retcode = { [0] = "upgrade_56GIB_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验56GIB回退结果
        upgrade_56GIB_compatible_when_rollback =
        {
            func = rollback_56GIB_compatible_check,
            retcode = { [0] = "upgrade_SmartIO_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验SmartIO回退结果
        upgrade_SmartIO_compatible_when_rollback =
        {
            func = rollback_SmartIO_compatible_check,
            retcode = { [0] = "upgrade_IOCHD_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOCHD回退结果
        upgrade_IOCHD_compatible_when_rollback =
        {
            func = rollback_IOCHD_compatible_check,
            retcode = { [0] = "upgrade_IOC10GE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC10GE回退结果
        upgrade_IOC10GE_compatible_when_rollback =
        {
            func = rollback_IOC10GE_compatible_check,
            retcode = { [0] = "upgrade_ACC_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验ACC回退结果
        upgrade_ACC_compatible_when_rollback =
        {
            func = rollback_ACC_compatible_check,
            retcode = { [0] = "upgrade_PCIE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验PCIE回退结果
        upgrade_PCIE_compatible_when_rollback =
        {
            func = rollback_PCIE_compatible_check,
            retcode = { [0] = "#SuccRbk", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_PCIE_COMPATIBLE",
        },
    },

    ---离线升级失败后回退重启及校验
    SysCompatibleAfterRollbackReboot =
    {
        entry = "AfterNormalReboot_when_rollback",
        --校验节点是否正常开工
        AfterNormalReboot_when_rollback =
        {
            func = AfterNormalReboot,
            retcode = { [0] = "upgrade_Check_Obj_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_NORMAL_AFTER_REBOOT",
        },
        --校验节点obj是否恢复正常
        upgrade_Check_Obj_when_rollback =
        {
            func = upgrade_Check_Obj,
            retcode = { [0] = "upgrade_SYS_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验系统软件回退结果
        upgrade_SYS_compatible_when_rollback =
        {
            func = rollback_SYS_compatible_check,
            retcode = { [0] = "upgrade_enclosure_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验框固件回退结果
        upgrade_enclosure_compatible_when_rollback =
        {
            func = rollback_enclosure_compatible_check,
            retcode = { [0] = "upgrade_SAS_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE",
        },
        --校验SAS回退结果
        upgrade_SAS_compatible_when_rollback =
        {
            func = rollback_SAS_compatible_check,
            retcode = { [0] = "upgrade_12GSAS_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验12G SAS回退结果
        upgrade_12GSAS_compatible_when_rollback =
        {
            func = rollback_12GSAS_compatible_check,
            retcode = { [0] = "upgrade_16GFC_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验16G FC回退结果
        upgrade_16GFC_compatible_when_rollback =
        {
            func = rollback_16GFC_compatible_check,
            retcode = { [0] = "upgrade_FCOE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验FCOE回退结果
        upgrade_FCOE_compatible_when_rollback =
        {
            func = rollback_FCOE_compatible_check,
            retcode = { [0] = "upgrade_TOE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验TOE回退结果
        upgrade_TOE_compatible_when_rollback =
        {
            func = rollback_TOE_compatible_check,
            retcode = { [0] = "upgrade_IXGBE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IXGBE回退结果
        upgrade_IXGBE_compatible_when_rollback =
        {
            func = rollback_IXGBE_compatible_check,
            retcode = { [0] = "upgrade_10GBaseT_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验10GBaseT回退结果
        upgrade_10GBaseT_compatible_when_rollback =
        {
            func = rollback_10GBaseT_compatible_check,
            retcode = { [0] = "upgrade_IOC8G_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC8G回退结果
        upgrade_IOC8G_compatible_when_rollback =
        {
            func = rollback_IOC8G_compatible_check,
            retcode = { [0] = "upgrade_IOC16G_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC16G回退结果
        upgrade_IOC16G_compatible_when_rollback =
        {
            func = rollback_IOC16G_compatible_check,
            retcode = { [0] = "upgrade_56GIB_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验56GIB回退结果
        upgrade_56GIB_compatible_when_rollback =
        {
            func = rollback_56GIB_compatible_check,
            retcode = { [0] = "upgrade_SmartIO_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验SmartIO回退结果
        upgrade_SmartIO_compatible_when_rollback =
        {
            func = rollback_SmartIO_compatible_check,
            retcode = { [0] = "upgrade_IOCHD_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOCHD回退结果
        upgrade_IOCHD_compatible_when_rollback =
        {
            func = rollback_IOCHD_compatible_check,
            retcode = { [0] = "upgrade_IOC10GE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC10GE回退结果
        upgrade_IOC10GE_compatible_when_rollback =
        {
            func = rollback_IOC10GE_compatible_check,
            retcode = { [0] = "upgrade_ACC_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验ACC回退结果
        upgrade_ACC_compatible_when_rollback =
        {
            func = rollback_ACC_compatible_check,
            retcode = { [0] = "upgrade_PCIE_compatible_when_rollback", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验PCIE回退结果
        upgrade_PCIE_compatible_when_rollback =
        {
            func = rollback_PCIE_compatible_check,
            retcode = { [0] = "#SuccRbk", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_PCIE_COMPATIBLE",
        },
    },


    ---在线升级传包(执行后，不需要回退的原子，当执行失败时，配置#SuccRbk)
    UploadPackageWhenOnlineUpgrade = g_Tbl_UploadPackageWhenUpgrade,

    --在线升级准备(原子返回值配置与传包类似)
    AgentPrepareForOnlineUpgrade =
    {
        entry = "check_front_link_is_redundant",
        check_front_link_is_redundant =
        {
            func = check_front_link_is_redundant,
            retcode = { [0] = "Check_port_drift", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        Check_port_drift =
        {
            func = Check_port_drift,
            retcode = { [0] = "NotifySysCtrlPrepareForOnline", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        NotifySysCtrlPrepareForOnline =
        {
            func = NotifySysCtrlPrepareForOnline,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 10,
            stubRet = 0,
            nextEntry = "upgrade_enclosure",
            ownerAG = "AgentPrepareForOnlineUpgrade",
            opcode = "NOTIFY_SYS_PREPARE_FOR_ONLINE_UPDATE",
        },
    },
        --在线升级准备(原子返回值配置与传包类似)
    ManagerPrepareForOnlineUpgrade =
    {
        entry = "check_front_link_is_redundant",
        check_front_link_is_redundant =
        {
            func = check_front_link_is_redundant,
            retcode = { [0] = "Check_port_drift", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        Check_port_drift =
        {
            func = Check_port_drift,
            retcode = { [0] = "NotifySysCtrlPrepareForOnline", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        NotifySysCtrlPrepareForOnline =
        {
            func = NotifySysCtrlPrepareForOnline,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 10,
            stubRet = 0,
            opcode = "NOTIFY_SYS_PREPARE_FOR_ONLINE_UPDATE",
        },
    },
    ---在线升级系统软件及固件
    UpgradeSystemWhenOnlineUpgrade = g_Tbl_UpgradeSystem,

    ---在线升级重启(原子返回值配置与传包leis)
    RebootWhenOnlineUpgrade =
    {
        entry = "RebootSysWhenOnlineUpgrade",
        RebootSysWhenOnlineUpgrade =
        {
            func = RebootSysWhenOnlineUpgrade,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            nextEntry = "AfterNormalReboot",
            ownerAG = "RebootWhenOnlineUpgrade",
            opcode = "ONLINE_REBOOT",
        },
    },
    ---在线升级重启后校验版本信息
    SysCompatibleAfterReboot =
    {
        entry = "AfterNormalReboot",

        --校验节点是否正常开工
        AfterNormalReboot =
        {
            func = AfterNormalReboot,
            retcode = { [0] = "upgrade_Check_Obj_WhenOnline", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, [3] = {0, 0}, ['other'] = {3, 10}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_NORMAL_AFTER_REBOOT",
        },
       --在线升级检查obj恢复情况
        upgrade_Check_Obj_WhenOnline =
        {
            func = upgrade_Check_Obj,
            retcode = { [0] = "upgrade_SYS_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, [3] = {0, 0}, ['other'] = {3, 10}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_CHECK_OBJ",
        },

        --校验系统软件升级结果
        upgrade_SYS_compatible =
        {
            func = upgrade_SYS_compatible_check,
            retcode = { [0] = "upgrade_enclosure_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验控制框升级结果
        upgrade_enclosure_compatible =
        {
            func = upgrade_enclosure_compatible_check,
            retcode = { [0] = "isRollbackDown", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_ENCLOSURE_FW_COMPATIBLE",
        },
        isRollbackDown =
        {
            func = isRollbackDown,
            retcode = { [0] = "upgrade_DiskEnclosure_compatible", ['other'] = "upgrade_SAS_compatible" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        --校验硬盘框升级结果
        upgrade_DiskEnclosure_compatible =
        {
            func = upgrade_DiskEnclosure_compatible_check,
            retcode = { [0] = "upgrade_BBU_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_DISK_ENCL_FW_COMPATIBLE",
        },
        --校验BBU升级结果
        upgrade_BBU_compatible =
        {
            func = upgrade_BBU_compatible_check,
            retcode = { [0] = "upgrade_MGMT_compatible", [2] = "upgrade_BBU_when_upgrade_BBU_compatible_fail", ['other'] = "upgrade_MGMT_compatible" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        upgrade_BBU_when_upgrade_BBU_compatible_fail =
        {
            func = upgrade_BBU,
            retcode = { [0] = "upgrade_MGMT_compatible", ['other'] = "upgrade_MGMT_compatible" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --校验MGMT升级结果
        upgrade_MGMT_compatible =
        {
            func = upgrade_MGMT_compatible_check,
            retcode = { [0] = "upgrade_SAS_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_MGMT_BOARD_FW_COMPATIBLE",
        },
        --校验SAS升级结果
        upgrade_SAS_compatible =
        {
            func = upgrade_SAS_compatible_check,
            retcode = { [0] = "upgrade_12GSAS_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_SAS}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验12G SAS升级结果
        upgrade_12GSAS_compatible =
        {
            func = upgrade_12GSAS_compatible_check,
            retcode = { [0] = "upgrade_16GFC_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_12GSAS}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验16G FC升级结果
        upgrade_16GFC_compatible =
        {
            func = upgrade_16GFC_compatible_check,
            retcode = { [0] = "upgrade_FCOE_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_16GFC}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验FCOE升级结果
        upgrade_FCOE_compatible =
        {
            func = upgrade_FCOE_compatible_check,
            retcode = { [0] = "upgrade_TOE_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_FCOE}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验TOE升级结果
        upgrade_TOE_compatible =
        {
            func = upgrade_TOE_compatible_check,
            retcode = { [0] = "upgrade_IXGBE_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_TOE}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验IXBGE升级结果
        upgrade_IXGBE_compatible =
        {
            func = upgrade_IXGBE_compatible_check,
            retcode = { [0] = "upgrade_10GBaseT_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_IXGBE}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验10GBaseT升级结果
        upgrade_10GBaseT_compatible =
        {
            func = upgrade_10GBaseT_compatible_check,
            retcode = { [0] = "upgrade_IOC8G_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_10GBaseT}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验IOC8G升级结果
        upgrade_IOC8G_compatible =
        {
            func = upgrade_IOC8G_compatible_check,
            retcode = { [0] = "upgrade_IOC16G_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_IOC8G}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC16G升级结果
        upgrade_IOC16G_compatible =
        {
            func = upgrade_IOC16G_compatible_check,
            retcode = { [0] = "upgrade_56GIB_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_IOC16G}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验56GIB升级结果
        upgrade_56GIB_compatible =
        {
            func = upgrade_56GIB_compatible_check,
            retcode = { [0] = "upgrade_SmartIO_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_56GIB}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验SmartIO升级结果
        upgrade_SmartIO_compatible =
        {
            func = upgrade_SmartIO_compatible_check,
            retcode = { [0] = "upgrade_IOCHD_compatible", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOCHD升级结果
        upgrade_IOCHD_compatible =
        {
            func = upgrade_IOCHD_compatible_check,
            retcode = { [0] = "upgrade_IOC10GE_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_IOCHD}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验IOC10GE升级结果
        upgrade_IOC10GE_compatible =
        {
            func = upgrade_IOC10GE_compatible_check,
            retcode = { [0] = "upgrade_ACC_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_IOC10GE}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },
        --校验ACC升级结果
        upgrade_ACC_compatible =
        {
            func = upgrade_ACC_compatible_check,
            retcode = { [0] = "upgrade_PCIE_compatible", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_ACC}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_INTERFACE_CARD_COMPATIBLE",
        },

        --校验PCIE升级结果
        upgrade_PCIE_compatible =
        {
            func = upgrade_PCIE_compatible_check,
            retcode = { [0] = "CheckUltraPathAlarm", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other'] = {1, 3, upgrade_PCIE}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "UPGRADE_GET_PCIE_COMPATIBLE",
        },

        --检查多路径告警
        CheckUltraPathAlarm =
        {
            func = CheckUltraPathAlarm,
            retcode = { [0] = "CheckDiskLinkIsNormal", [1]="#FailExit", [3] = "CheckDiskLinkIsNormal", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        -- 检查硬盘链路是否正常
        CheckDiskLinkIsNormal =
        {
            func = CheckDiskLinkIsNormal,
            retcode = { [0] = "#SuccExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            nextEntry = nil,
            ownerAG = "SysCompatibleAfterReboot",
        },
    },
    ---在线升级失败后回退传包
    UploadPackageWhenOnlineRollback = g_Tbl_UploadPackageWhenRollback,

    ---在线升级失败后，回退准备
    PrepareForUpdateWhenOnlineRollback =
    {
        entry = "check_normal_when_rollback",
        check_normal_when_rollback =
        {
            func = check_normal_when_rollback,
            retcode = { [0] = "check_front_link_is_redundant", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

        check_front_link_is_redundant =
        {
            func = check_front_link_is_redundant,
            retcode = { [0] = "Check_port_drift", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        
        Check_port_drift =
        {
            func = Check_port_drift,
            retcode = { [0] = "NotifySysCtrlPrepareForOnline_when_rbk", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

        NotifySysCtrlPrepareForOnline_when_rbk =
        {
            func = NotifySysCtrlPrepareForOnline,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 10,
            stubRet = 0,
            opcode = "NOTIFY_SYS_PREPARE_FOR_ONLINE_UPDATE",
        },
    },

    --校验系统镜像是否恢复
    SysMirrorRecoveryCheck =
    {
        entry = "SysMirrorRecoveryCheck",

        --校验系统镜像是否恢复
        SysMirrorRecoveryCheck =
        {
            func = check_ctrl_normal,
            retcode = { [0] = "#SuccExit", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, [3] = {0, 0}, ['other'] = {3, 10}},
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "CHECK_NORMAL_AFTER_REBOOT",
        },
    },
    ---在线升级失败后，回退固件及系统软件
    RollbackSystemWhenOnlineUpgrade = g_Tbl_RollbackSystem,

    ---在线升级重启
    --RebootWhenOnlineRollback
    RebootWhenOnlineRollback =
    {
        entry = "RebootSysWhenOnlineUpgrade",
        RebootSysWhenOnlineUpgrade =
        {
            func = RebootSysWhenOnlineUpgrade,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
            opcode = "ONLINE_REBOOT",
        },
    },

    ---升级PCIE交换机
    UpgradePcieSw =
    {
        entry = "checkIsPCIENeedUpd",
        --检查交换机是否需要升级
        checkIsPCIENeedUpd =
        {
            func = checkIsPCIENeedUpd,
            --0：单控/双控不需要升级  1：多控 其他：未知异常
            retcode = { [0] = "#SuccExit", [1] = "checkpacket_PCIE_SW", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ",[1] = "#Succ"},
            stubRet = 1,
        },
        --检查交换机包文件
        checkpacket_PCIE_SW =
        {
            func = checkpacket_PCIE_SW,
            --0：交换机包文件存在 1：交换机包文件不存在 其他：未知异常
            retcode = { [0] = "checkstate_PCIE_SW0", [1] = "#SuccExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        ------------------------------------------------------------------------------------------------------
        ------                       升级0号PCIE交换机                                              --------
        ------------------------------------------------------------------------------------------------------

        --检查0号交换机状态
        checkstate_PCIE_SW0 =
        {
            func = checkstate_PCIE_SW0,
            --0：交换机状态OK  1：升级成功但交换机侧没有reboot，此时不再校验版本号，直接升级 2：正在升级中，需要重试90s,其他：可能通讯异常
            retcode = { [0] = "checkversion_PCIE_SW0", [1] = "Trans_PCIE_SW0_Pkg", [2] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0,0} , [2] = {3, 30} , ['other']={3, 10}},
            stubRet = 0,
        },
        --检查0号交换机版本，版本相同则检查1号PCIE交换机，版本不相同则开始升级
        checkversion_PCIE_SW0 =
        {
            func = checkversion_PCIE_SW0,
            --0：版本相同   2：版本不同     其他：通讯异常
            retcode = { [0] = "checkversion_PCIE_SW1", [2] = "Trans_PCIE_SW0_Pkg", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            retry = {[0] = {0, 0}, [2] = {0, 0}, ['other']={3, 10}},
            stubRet = 2,
        },
        --上传PCIE交换机包
        Trans_PCIE_SW0_Pkg =
        {
            func = Trans_PCIE_SW0_Pkg,
            --0：传包成功  其他：传包失败，需要重试
            retcode = { [0] = "Check_PCIE_SW0_TransPkg_State", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            stubRet = 0,
        },
         --查询传包状态
        Check_PCIE_SW0_TransPkg_State =
        {
            func = Check_PCIE_SW0_TransPkg_State,
            --0：交换机包上传完成  1：交换机包传输失败  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯失败
            retcode = { [0] = "reboot_PCIE_SW0", [2]="#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [2] ={12, 1}, ['other']={4, 21}},
            stubRet = 0,
        },

        --重启PCIE交换机
        reboot_PCIE_SW0 =
        {
            func = reboot_PCIE_SW0,
            --0：重启成功 其他：失败，需要重试
            retcode = { [0] = "Check_PCIE_SW0_reboot_State", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

        --重启后检查交换机升级状态
        Check_PCIE_SW0_reboot_State =
        {
            func = Check_PCIE_SW0_reboot_State,
            --0：升级成功  1：升级失败，需要回退，其他：通讯异常,重试6分钟
            retcode = { [0] = "checkversion_PCIE_SW0_after_upg", [1] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [1] ={0, 0}, ['other'] = {3, 1}},
            stubRet = 0,
        },

        --升级完成后检查交换机版本
        checkversion_PCIE_SW0_after_upg =
        {
            func = checkversion_PCIE_SW0,
            --0：版本相同 其他：版本异常
            retcode = { [0] = "CheckPcieLinkStateAfterUpdPcie_after_upg", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

        CheckPcieLinkStateAfterUpdPcie_after_upg =
        {
            func = CheckPcieLinkStateAfterUpdPcie,
            --0：链路状态OK 其他：链路出现问题（需要重试3次）
            retcode = { [0] = "checkstate_PCIE_SW1", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

        ------------------------------------------------------------------------------------------------------
        ----------                  升级1号PCIE交换机                                            -----------
        ------------------------------------------------------------------------------------------------------

         --检查1号交换机状态
        checkstate_PCIE_SW1 =
        {
            func = checkstate_PCIE_SW1,
            --0：交换机状态OK  1：升级成功但交换机侧没有reboot，此时不再校验版本号，直接升级 2：正在升级中，需要重试90s,其他：可能通讯异常
            retcode = { [0] = "checkversion_PCIE_SW1", [1] = "Trans_PCIE_SW1_Pkg", [2] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0,0} , [2] = {3, 30} , ['other']={3, 10}},
            stubRet = 0,
        },
        --检查1号交换机版本，版本相同直接返回升级成功  版本不相同则开始升级
        checkversion_PCIE_SW1 =
        {
            func = checkversion_PCIE_SW1,
            --0：版本相同   2：版本不同     其他：通讯失败
            retcode = { [0] = "#SuccExit", [2] = "Trans_PCIE_SW1_Pkg", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            retry = {[0] = {0, 0}, [2] = {0, 0}, ['other']={3, 10}},
            stubRet = 2,
        },
        --上传PCIE交换机包
        Trans_PCIE_SW1_Pkg =
        {
            func = Trans_PCIE_SW1_Pkg,
            --0：传包成功  其他：传包失败，需要重试
            retcode = { [0] = "Check_PCIE_SW1_TransPkg_State", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            stubRet = 0,
        },
         --查询传包状态
        Check_PCIE_SW1_TransPkg_State =
        {
            func = Check_PCIE_SW1_TransPkg_State,
            --0：交换机包上传完成 1：1号交换机包传输失败，需要回退0号交换机  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯异常
            retcode = { [0] = "reboot_PCIE_SW1", [2]="#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0},[2] ={12, 1}, ['other']={4, 21}},
            stubRet = 0,
        },

        --重启PCIE交换机
        reboot_PCIE_SW1 =
        {
            func = reboot_PCIE_SW1,
            --0：重启成功 其他：失败，需要重试
            retcode = { [0] = "Check_PCIE_SW1_reboot_State", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },

        --重启后检查交换机状态
        Check_PCIE_SW1_reboot_State =
        {
            func = Check_PCIE_SW1_reboot_State,
            --0：升级成功  1：升级失败 其他：重试（在交换机启动所需最大超时时间内（5分钟）重试）
            retcode = { [0] = "checkversion_PCIE_SW1_after_upg", [1] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [1]={0,0}, ['other'] = {3, 1}},
            stubRet = 0,
        },

        --升级完成后检查交换机版本
        checkversion_PCIE_SW1_after_upg =
        {
            func = checkversion_PCIE_SW1,
            --0：版本相同   其他：版本不同
            retcode = { [0] = "#SuccExit", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
    },

    ---回退PCIE交换机
    UpgradePcieSwRollback =
    {
        entry = "checkIsPCIENeedRbk",
        --检查交换机包文件
        checkIsPCIENeedRbk =
        {
            func = checkIsPCIENeedRbk,
            retcode = { [0] = "#SuccRbk", [1] = "checkstate_PCIE_SW0_when_rbk", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ",[1] = "#Succ"},
            stubRet = 0,
        },

        --检查0号交换机状态
        checkstate_PCIE_SW0_when_rbk =
        {
            func = checkstate_PCIE_SW0,
            --0：交换机状态OK  1：升级成功但交换机侧没有reboot，此时不再校验版本号，直接回退  2：正在升级中，需要重试90s,其他：可能通讯异常
            retcode = { [0] = "checkversion_PCIE_SW0_when_rbk", [1] = "CheckPcieLinkStateAfterUpdPcie_when_rbk", [2] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0,0} , [2] = {3, 30} , ['other']={3, 10}},
            stubRet = 0,
        },

        --检查0号交换机版本，回退时检查交换机实际版本和版本相同(0)则开始回退，版本不相同(2)则认为回退0号PCIE成功，继续检查1号PCIE交换机。
        checkversion_PCIE_SW0_when_rbk =
        {
            func = checkversion_PCIE_SW0_Rollback,
            --0：版本相同  2：版本不同  其他：异常
            retcode = { [0] = "checkversion_PCIE_SW1_when_rbk", [2] = "CheckPcieLinkStateAfterUpdPcie_when_rbk", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            retry = {[0] = {0, 0}, [2] = {0,0}, ['other']={3, 10}},
            stubRet = 2,
        },
        CheckPcieLinkStateAfterUpdPcie_when_rbk =
        {
            func = CheckPcieLinkStateAfterUpdPcie,
            --0：链路OK 其他：异常
            retcode = { [0] = "rollback_PCIE_SW0", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --回退0号PCIE交换机
        rollback_PCIE_SW0 =
        {
            func = rollback_PCIE_SW0,
            --0：回退成功  其他：回退失败，重试
            retcode = { [0] = "Check_PCIE_SW0_TransPkg_State_when_Rbk", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --查询回退的交换机包上传状态
        Check_PCIE_SW0_TransPkg_State_when_Rbk =
        {
            func = Check_PCIE_SW0_TransPkg_State,
            --0：交换机包上传完成  1：交换机包传输失败  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯失败
            retcode = { [0] = "reboot_PCIE_SW0_when_rbk", [2]="#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [2] ={12, 1}, ['other']={4, 21}},
            stubRet = 0,
        },
        --回退后重启PCIE交换机
        reboot_PCIE_SW0_when_rbk =
        {
            func = reboot_PCIE_SW0,
            retcode = { [0] = "Check_PCIE_SW0_reboot_State", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --重启后检查交换机状态
        Check_PCIE_SW0_reboot_State =
        {
            func = Check_PCIE_SW0_reboot_State,
            --0：回退成功  1：回退失败，其他：重试（在交换机启动所需最大超时时间内（5分钟）重试）
            retcode = { [0] = "checkversion_PCIE_SW0_after_rbk", [1] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0, 0}, ['other'] = {3, 1}},
            stubRet = 0,
        },
        --回退完成后检查交换机版本
        checkversion_PCIE_SW0_after_rbk =
        {
            func = checkversion_PCIE_SW0_Rollback,
            --0：版本相同  2：版本不同  其他：可能通讯异常
            retcode = { [0] = "CheckPcieLinkStateAfterUpdPcie_after_rbk", [2] = "#FailExit", ['other'] = "#FailExit" },
            retry = {[2] = {0, 0}, [0] = {0,0}, ['other']={3, 10}},
            retstate = {[2] = "#Succ"},
            stubRet = 2,
        },
        CheckPcieLinkStateAfterUpdPcie_after_rbk =
        {
            func = CheckPcieLinkStateAfterUpdPcie,
            --0：链路状态OK  其他：异常
            retcode = { [0] = "checkversion_PCIE_SW1_when_rbk", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        checkversion_PCIE_SW1_when_rbk =
        {
            func = checkversion_PCIE_SW1_Rollback,
            --0：版本相同  2：版本不同  其他：通信异常
            retcode = { [0] = "#SuccRbk", [2] = "rollback_PCIE_SW1", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, [2] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ", [2] = "#Succ"},
            stubRet = 0,
        },
        --回退1号PCIE交换机
        rollback_PCIE_SW1 =
        {
            func = rollback_PCIE_SW1,
            --0：回退成功  其他：回退失败，重试
            retcode = { [0] = "Check_PCIE_SW1_TransPkg_State_when_Rbk", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --查询回退的交换机包上传状态
        Check_PCIE_SW1_TransPkg_State_when_Rbk =
        {
            func = Check_PCIE_SW1_TransPkg_State,
            --0：交换机包上传完成  1：交换机包传输失败  2：包正在上传中，需轮询（最多2分钟）检查状态 其他：通讯失败
            retcode = { [0] = "reboot_PCIE_SW1_when_rbk", [1] = "#FailExit", [2]="#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0, 0}, [2] ={12, 1}, ['other']={4, 21}},
            stubRet = 0,
        },

        --回退后重启PCIE交换机
        reboot_PCIE_SW1_when_rbk =
        {
            func = reboot_PCIE_SW1,
            retcode = { [0] = "Check_PCIE_SW1_reboot_State", ['other'] = "#FailExit" },
            retry = {[0] = {0, 0}, ['other']={3, 10}},
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
        --重启后检查交换机状态
        Check_PCIE_SW1_reboot_State =
        {
            func = Check_PCIE_SW1_reboot_State,
            --0：回退成功  1：回退失败，其他：重试（在交换机启动所需最大超时时间内（6分钟）重试）
            retcode = { [0] = "checkversion_PCIE_SW1_after_rbk", [1] = "#FailExit", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            retry = {[0] = {0, 0}, [1] = {0, 0}, ['other'] = {3, 1}},
            stubRet = 0,
        },
        --回退完成后检查交换机版本
        checkversion_PCIE_SW1_after_rbk =
        {
            func = checkversion_PCIE_SW1_Rollback,
            --0：版本相同  2：版本不同  其他：异常
            retcode = { [0] = "#SuccRbk", ['other'] = "#FailExit" },
            retry = {[2] = {0, 0}, ['other']={3, 10}},
            retstate = {[2] = "#Succ"},
            stubRet = 2,
        },

    },
    CleanUpRollbackDir =
    {
        entry = "CleanUpBakWhenRollback",
        CleanUpBakWhenRollback =
        {
            func = CleanUpBakWhenRollback,
            retcode = { [0] = "#SuccRbk", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            stubRet = 0,
        },
    },
    --
    --安装热补丁
    InstallHotpatch=
    {
        entry = "ExecInstallHotpatch",
        ExecInstallHotpatch =
        {
            func = ExecInstallHotpatch,--os.execute("sleep " .. 10);
            retcode = { [0] = "#SuccExit",  ['other'] = "#SuccRbk" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },
    ConfirmHotPatch=
    {
        entry = "ExecConfirmHotPatch",
        ExecConfirmHotPatch =
        {
            func = ExecConfirmHotPatch,
            retcode = { [0] = "ExecResetHotPatchUpd",  ['other'] = "#SuccRbk" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        ExecResetHotPatchUpd =
        {
            func = ExecResetHotPatchUpd,
            retcode = { [0] = "#SuccExit",  ['other'] = "#SuccRbk" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },
    --安装失败后，回退补丁
    RollbackHotPatchWhenFail=
    {
        entry = "ExecIsNeedRollback",
        ExecIsNeedRollback =
        {
            func = ExecIsNeedRollback,
            retcode = { [0] = "#SuccRbk", [1] = "ExecRollbackHotPatch", ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ", [1] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        ExecRollbackHotPatch =
        {
            func = ExecRollbackHotPatch,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        ExecRollbackConfirm =
        {
            func = ExecRollbackConfirm,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },

    RollbackHotpatchCheck =
    {
        entry = "ExecRollbackHotpatchCheck",
        ExecRollbackHotpatchCheck =
        {
            func = ExecRollbackHotpatchCheck,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },
    RollbackHotpatch =
    {
        entry = "ExecRollbackHotPatchWhenRollback",
        ExecRollbackHotPatchWhenRollback =
        {
            func = ExecRollbackHotPatchWhenRollback,
            retcode = { [0] = "ExecRollbackConfirm",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        ExecRollbackConfirm =
        {
            func = ExecRollbackConfirm,
            retcode = { [0] = "#SuccRbk",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },

    DeleteHotpatchCheck =
    {
        entry = "ExecDeleteHotpatchCheck",
        ExecDeleteHotpatchCheck =
        {
            func = ExecDeleteHotpatchCheck,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },

    DeleteHotpatch =
    {
        entry = "ExecDeleteHotpatch",
        ExecDeleteHotpatch =
        {
            func = ExecDeleteHotpatch,
            retcode = { [0] = "ExecDeleteHotpatchConfirm",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
        ExecDeleteHotpatchConfirm =
        {
            func = ExecDeleteHotpatchConfirm,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },

    --拷贝异构升级包
    CopyAslPatch=
    {
        entry= "ExecDeleteInvalidAslPackage",
        ExecDeleteInvalidAslPackage=
        {
            func= ExecDeleteInvalidAslPackage,
            retcode= { [0]= "ExecCopyAslPackage",  ['other']= "#FailExit" },
            retstate= {[0]= "#Succ"},
            progress= 100,
            stubRet= 0,
        },
        ExecCopyAslPackage=
        {
            func= ExecCopyAslPackage,
            retcode= { [0]= "#SuccExit",  ['other']= "#FailExit" },
            retstate= {[0]= "#Succ"},
            progress= 100,
            stubRet= 0,
        },

    },
    --安装异构升级包
    InstallAslPatch=
    {
        entry= "ExecUnInstallAslPackage",
        ExecUnInstallAslPackage=
        {
            func= ExecUnInstallAslPackage,
            retcode= { [0]= "ExecInstallAslPatch",  ['other']= "#FailExit" },
            retstate= {[0]= "#Succ"},
            progress= 100,
            stubRet= 0,
        },
        ExecInstallAslPatch= {
            func= ExecInstallAslPatch,
            retcode= { [0]= "#SuccExit",  ['other']= "#FailExit" },
            retstate= {[0]= "#Succ"},
            progress= 100,
            stubRet= 0,
        },
    },
    --异构包修改链接
    ResetLinkToAslPatch=
    {
        entry= "ExecResetLinkToAslPatch",
         ExecResetLinkToAslPatch= {
            func= ExecResetLinkToAslPatch,
            retcode= { [0]= "#SuccExit",  ['other']= "#FailExit" },
            retstate= {[0]= "#Succ"},
            progress= 100,
            stubRet= 0,
        },
    },

    --安装异构升级包失败的回退
    RollbackAslPatchWhenFail=
    {
        entry= "ExecRbkAslPatchWhenFail",
        ExecRbkAslPatchWhenFail=
        {
            func= ExecRbkAslPatchWhenFail,
            retcode= { [0]= "#SuccRbk",  ['other']= "#FailExit" },
            retstate= {[0]= "#Succ"},
            progress= 100,
            stubRet= 0,
        },

    },
    --安装特殊补丁
    InstallSpecialPatch=
    {
        entry = "ExecInstallSpecialPatch",
        ExecInstallSpecialPatch =
        {
            func = ExecInstallSpecialPatch,
            retcode = { [0] = "#SuccExit",  ['other'] = "#FailExit" },
            retstate = {[0] = "#Succ"},
            progress = 100,
            stubRet = 0,
        },
    },
}

