diff --git a/01-TestCase/tsg_cli/EnDisablePolicy.robot b/01-TestCase/tsg_cli/EnDisablePolicy.robot new file mode 100644 index 0000000..5de173f --- /dev/null +++ b/01-TestCase/tsg_cli/EnDisablePolicy.robot @@ -0,0 +1,22 @@ +*** Settings *** +Force Tags tsg-cli Policy EnDisable +Resource ../../03-Variable/bifangapivariable.txt +Resource ../../02-Keyword/tsg_cli/interface.robot + +*** Variables *** +${PolicyType} tsg_security + +*** Test Cases *** +init + ${data} Get_Policy_Object3 ${PolicyType} + Set Suite Variable ${obj} ${data} + +Policy_Update01 + Tsg_Policy_EnDisable ${obj}[policyId] ${PolicyType} ${obj}[commandType1] + +Policy_Update02 + Tsg_Policy_EnDisable ${obj}[policyId] ${PolicyType} ${obj}[commandType2] + + + + diff --git a/01-TestCase/tsg_cli/ImExportObject.robot b/01-TestCase/tsg_cli/ImExportObject.robot new file mode 100644 index 0000000..67a3dcf --- /dev/null +++ b/01-TestCase/tsg_cli/ImExportObject.robot @@ -0,0 +1,30 @@ +*** Settings *** +Test Teardown Clear_Test_Data +Force Tags tsg-cli Object ExImport +Resource ../../03-Variable/bifangapivariable.txt +Resource ../../02-Keyword/tsg_cli/interface.robot + +*** Test Cases *** +Object_Export_And_Import_TestCase + FOR ${type} IN @{ObjectTypes} + # export 01 + ${FileName1} Get_File_Name ${type} txt + Tsg_Policy_Object_Export ${type} ${FileName1} txt + # export 02 + ${FileName2} Get_File_Name ${type} csv + Tsg_Policy_Object_Export ${type} ${FileName2} csv + # # export 03 + ${FileName3} Get_File_Name ${type} txt + Tsg_Policy_Object_Export ${type} ${FileName3} ${None} + # export 04 + ${FileName4} Get_File_Name ${type} csv + Tsg_Policy_Object_Export ${type} ${FileName4} ${None} + + # # import 01 + ${name1} Get_Import_Info ${type} + Tsg_Policy_Object_Import ${type} ${FileName3} ${name1} + # import 02 + ${name2} Get_Import_Info ${type} + Tsg_Policy_Object_Import ${type} ${FileName4} ${name2} + END + diff --git a/01-TestCase/tsg_cli/OtherCommand.robot b/01-TestCase/tsg_cli/OtherCommand.robot new file mode 100644 index 0000000..8d7bfc9 --- /dev/null +++ b/01-TestCase/tsg_cli/OtherCommand.robot @@ -0,0 +1,34 @@ +*** Settings *** +Resource ../../03-Variable/bifangapivariable.txt +Resource ../../02-Keyword/tsg_cli/interface.robot + +*** Test Cases *** +Tsg_Help_TestCase + [Tags] tsg-cli TsgHelp + Tsg_Help_Keyword + +Tsg_Diagnose_TestCase + [Tags] tsg-cli TsgDiagnose + Tsg_Diagnose_Keyword + +Tsg_Record_Userlist_TestCase + [Tags] tsg-cli TsgRecordUserlist + Tsg_Record_UserList + +Tsg_Record_Username_TestCase + [Tags] tsg-cli TsgRecordUsername + Tsg_Record_Query + +Tsg_Show_TestCase + [Tags] tsg-cli TsgShow + Tsg_Show_Chassis-ip + Tsg_Show_Chassis-port + Tsg_Show_Interface + Tsg_Show_APP + Tsg_Show_Protocol + Tsg_Show_Stream + Tsg_Show_Intercept + +Tsg_Passwd_TestCase + [Tags] tsg-cli TsgPasswd + Tsg_Passwd_Keyword diff --git a/01-TestCase/tsg_cli/QueryManipulationPolicy.robot b/01-TestCase/tsg_cli/QueryManipulationPolicy.robot new file mode 100644 index 0000000..174ec72 --- /dev/null +++ b/01-TestCase/tsg_cli/QueryManipulationPolicy.robot @@ -0,0 +1,33 @@ +*** Settings *** +Force Tags tsg-cli ManipulationPolicy Query +Resource ../../03-Variable/bifangapivariable.txt +Resource ../../02-Keyword/tsg_cli/interface.robot + +*** Variables *** +${PolicyType} pxy_manipulation + +*** Test Cases *** +init + ${data} Get_Policy_Object2 ${PolicyType} + Set Suite Variable ${obj} ${data} + +Policy_Query01 + Tsg_Policy_Query ${PolicyType} ${obj}[policyId] ${None} ${None} ${True} + +Policy_Query02 + Tsg_Policy_Query ${PolicyType} ${None} ${obj}[policyName] ${None} ${True} + +Policy_Query03 + Tsg_Policy_Query ${PolicyType} ${None} ${None} ${obj}[policyDesc] ${True} + +Policy_Query04 + Tsg_Policy_Query ${PolicyType} ${obj}[policyId] ${obj}[policyName] ${None} ${True} + +Policy_Query05 + Tsg_Policy_Query ${PolicyType} ${obj}[policyId] ${None} ${obj}[policyDesc] ${True} + +Policy_Query06 + Tsg_Policy_Query ${PolicyType} ${None} ${obj}[policyName] ${obj}[policyDesc] ${True} + + + diff --git a/01-TestCase/tsg_cli/QueryObject.robot b/01-TestCase/tsg_cli/QueryObject.robot new file mode 100644 index 0000000..606a806 --- /dev/null +++ b/01-TestCase/tsg_cli/QueryObject.robot @@ -0,0 +1,111 @@ +*** Settings *** +Force Tags tsg-cli Object Query +Resource ../../03-Variable/bifangapivariable.txt +Resource ../../02-Keyword/tsg_cli/interface.robot + +*** Variables *** +${ObjectType1} ip +${ObjectType2} url +${ObjectType3} fqdn +${ObjectType4} keywords +${ObjectType5} subscriberid +${ObjectType6} fqdn_category +${ObjectType7} account +${ObjectType8} http_signature + +*** Test Cases *** +init + ${data1} Get_Policy_Object4 ${ObjectType1} + Set Suite Variable ${obj1} ${data1} + ${data2} Get_Policy_Object4 ${ObjectType2} + Set Suite Variable ${obj2} ${data2} + ${data3} Get_Policy_Object4 ${ObjectType3} + Set Suite Variable ${obj3} ${data3} + ${data4} Get_Policy_Object4 ${ObjectType4} + Set Suite Variable ${obj4} ${data4} + ${data5} Get_Policy_Object4 ${ObjectType5} + Set Suite Variable ${obj5} ${data5} + ${data6} Get_Policy_Object4 ${ObjectType6} + Set Suite Variable ${obj6} ${data6} + ${data7} Get_Policy_Object4 ${ObjectType7} + Set Suite Variable ${obj7} ${data7} + ${data8} Get_Policy_Object4 ${ObjectType8} + Set Suite Variable ${obj8} ${data8} + + +Object_Query01 + Tsg_Policy_Object_Query ${None} ${None} ${True} + +Object_Query_IP_01 + Tsg_Policy_Object_Query ${None} ${obj1}[objectName] ${True} + +Object_Query_IP_02 + Tsg_Policy_Object_Query ${obj1}[objectType] ${None} ${True} + +Object_Query_IP_03 + Tsg_Policy_Object_Query ${obj1}[objectType] ${obj1}[objectName] ${True} + +Object_Query_URL_01 + Tsg_Policy_Object_Query ${None} ${obj2}[objectName] ${True} + +Object_Query_URL_02 + Tsg_Policy_Object_Query ${obj2}[objectType] ${None} ${True} + +Object_Query_URL_03 + Tsg_Policy_Object_Query ${obj2}[objectType] ${obj2}[objectName] ${True} + +Object_Query_FQDN_01 + Tsg_Policy_Object_Query ${None} ${obj3}[objectName] ${True} + +Object_Query_FQDN_02 + Tsg_Policy_Object_Query ${obj3}[objectType] ${None} ${True} + +Object_Query_FQDN_03 + Tsg_Policy_Object_Query ${obj3}[objectType] ${obj3}[objectName] ${True} + +Object_Query_KEYWORDS_01 + Tsg_Policy_Object_Query ${None} ${obj4}[objectName] ${True} + +Object_Query_KEYWORDS_02 + Tsg_Policy_Object_Query ${obj4}[objectType] ${None} ${True} + +Object_Query_KEYWORDS_03 + Tsg_Policy_Object_Query ${obj4}[objectType] ${obj4}[objectName] ${True} + +Object_Query_SUBSCRIBERID_01 + Tsg_Policy_Object_Query ${None} ${obj5}[objectName] ${True} + +Object_Query_SUBSCRIBERID_02 + Tsg_Policy_Object_Query ${obj5}[objectType] ${None} ${True} + +Object_Query_SUBSCRIBERID_03 + Tsg_Policy_Object_Query ${obj5}[objectType] ${obj5}[objectName] ${True} + +Object_Query_FQDN_CATEGORY_01 + Tsg_Policy_Object_Query ${None} ${obj6}[objectName] ${True} + +Object_Query_FQDN_CATEGORY_02 + Tsg_Policy_Object_Query ${obj6}[objectType] ${None} ${True} + +Object_Query_FQDN_CATEGORY_03 + Tsg_Policy_Object_Query ${obj6}[objectType] ${obj6}[objectName] ${True} + +Object_Query_ACCOUNT_01 + Tsg_Policy_Object_Query ${None} ${obj7}[objectName] ${True} + +Object_Query_ACCOUNT_02 + Tsg_Policy_Object_Query ${obj7}[objectType] ${None} ${True} + +Object_Query_ACCOUNT_03 + Tsg_Policy_Object_Query ${obj7}[objectType] ${obj7}[objectName] ${True} + +Object_Query_HTTP_SIGNATURE_01 + Tsg_Policy_Object_Query ${None} ${obj8}[objectName] ${True} + +Object_Query_HTTP_SIGNATURE_02 + Tsg_Policy_Object_Query ${obj8}[objectType] ${None} ${True} + +Object_Query_HTTP_SIGNATURE_03 + Tsg_Policy_Object_Query ${obj8}[objectType] ${obj8}[objectName] ${True} + + diff --git a/01-TestCase/tsg_cli/QuerySecurityPolicy.robot b/01-TestCase/tsg_cli/QuerySecurityPolicy.robot new file mode 100644 index 0000000..739c5df --- /dev/null +++ b/01-TestCase/tsg_cli/QuerySecurityPolicy.robot @@ -0,0 +1,33 @@ +*** Settings *** +Force Tags tsg-cli SecurityPolicy Query +Resource ../../03-Variable/bifangapivariable.txt +Resource ../../02-Keyword/tsg_cli/interface.robot + +*** Variables *** +${PolicyType} tsg_security + +*** Test Cases *** +init + ${data} Get_Policy_Object1 ${PolicyType} + Set Suite Variable ${obj} ${data} + +Policy_Query01 + Tsg_Policy_Query ${PolicyType} ${obj}[policyId] ${None} ${None} ${True} + +Policy_Query02 + Tsg_Policy_Query ${PolicyType} ${None} ${obj}[policyName] ${None} ${True} + +Policy_Query03 + Tsg_Policy_Query ${PolicyType} ${None} ${None} ${obj}[policyDesc] ${True} + +Policy_Query04 + Tsg_Policy_Query ${PolicyType} ${obj}[policyId] ${obj}[policyName] ${None} ${True} + +Policy_Query05 + Tsg_Policy_Query ${PolicyType} ${obj}[policyId] ${None} ${obj}[policyDesc] ${True} + +Policy_Query06 + Tsg_Policy_Query ${PolicyType} ${None} ${obj}[policyName] ${obj}[policyDesc] ${True} + + + diff --git a/02-Keyword/tsg_cli/Interface.robot b/02-Keyword/tsg_cli/Interface.robot index 9fd6237..d21799b 100644 --- a/02-Keyword/tsg_cli/Interface.robot +++ b/02-Keyword/tsg_cli/Interface.robot @@ -9,26 +9,45 @@ Library Selenium2Library Resource ../../03-Variable/bifangapivariable.txt *** Variables *** +# 指令前缀 ${Tsg_Policy} tsg_policy ${Tsg_Policy_Object} tsg_policy_object ${Tsg_Record} tsg_record ${Tsg_Show} tsg_show ${Tsg_Passwd} tsg_passwd +# tsg_help指令返回值对比文件路径 ${Tsg_Help_file_Path} cli_files/tsg_help.txt +# tsg_show指令查询时附加sql条件 +${Tsg_Show_Added_Sql} "order by time desc limit 20" +# tsg_show指令返回数据flowType和sled参数值 +${Tsg_Show_FlowType_Values} inline|intercomm|mirror +${Tsg_Show_Sled_Values} mcn0|mcn1|mcn2|mcn3 *** Keywords *** Get_Policy_Object1 + [Documentation] + ... 描述:获取SecurityPolicy数据 + ... 参数:type(策略类型) + ... 返回:除默认策略外的任意单条策略 [Arguments] ${type} ${dict} Tsg_Policy_Query ${type} ${None} ${None} ${None} ${True} Should Be True ${dict}[data][total] > 1 [Return] ${dict}[data][list][1] Get_Policy_Object2 + [Documentation] + ... 描述:获取ProxyManipulationPolicy数据 + ... 参数:type(策略类型) + ... 返回:任意单条策略 [Arguments] ${type} ${dict} Tsg_Policy_Query ${type} ${None} ${None} ${None} ${True} [Return] ${dict}[data][list][0] -Get_Policy_Object3 +Get_Policy_Object3 + [Documentation] + ... 描述:用于执行'tsg_policy --enable/disable ...'指令前的数据获取 + ... 参数:type(策略类型) + ... 返回:policyId(策略ID)、commandType1(enable/disable,修改)、commandType2(enable/disable,还原) [Arguments] ${type} ${obj} Get_Policy_Object1 ${type} ${commandType1} Run Keyword If ${obj}[isValid]==0 Set Variable enable @@ -39,19 +58,31 @@ Get_Policy_Object3 [Return] ${obj} Get_Policy_Object4 + [Documentation] + ... 描述:获取Object数据 + ... 参数:type(对象类型) + ... 返回:任意单条对象 [Arguments] ${type} ${dict} Tsg_Policy_Object_Query ${type} ${None} ${True} [Return] ${dict}[data][list][0] Get_File_Name + [Documentation] + ... 描述:拼接对象数据导出时的文件名 + ... 参数:ObjectType(对象类型) FileType(txt|csv) + ... 返回:文件名称 [Arguments] ${ObjectType} ${FileType} - ${date} Get Current Date + ${date} Get Current Date ${date_stamp} Convert Date ${date} epoch ${time} Evaluate int(round(${date_stamp} * 1000)) ${filename} Set Variable ${ObjectType}_export_${time}.${FileType} [Return] ${filename} Get_Import_Info + [Documentation] + ... 描述:随机生成对象数据导入时的对象名称 + ... 参数:type(对象类型) + ... 返回:对象名称 [Arguments] ${type} ${date} Get Current Date ${date_stamp} Convert Date ${date} epoch @@ -60,7 +91,10 @@ Get_Import_Info [Return] ${name} Tsg_Policy_Query - # ${type}:必传 @{param}:非必传,最大参数数量为四位。依次顺序为'policyId'、'policyName'、'policyDesc'和'allFlag',中间存在为空参数可用'${None}'占位 + [Documentation] + ... 描述:执行'tsg_policy --query ...'指令 + ... 参数:type(策略类型) param(非必传,最大参数数量为四位,依次顺序为'policyId'、'policyName'、'policyDesc'和'allFlag',中间存在为空参数可用'None'占位) + ... 返回:查询响应数据 [Arguments] ${type} @{params} ${str} Evaluate '${Tsg_Policy} --query --policyType %s ' % ('${type}') ${str} Run Keyword If '${params}[0]' != '${None}' Evaluate '${str}--policyId %s ' % ('${params}[0]') @@ -76,13 +110,24 @@ Tsg_Policy_Query [Return] ${r} Tsg_Policy_EnDisable - # ${id}:必传 ${type}:必传 ${commandType}:必传'enable'|'disable' + [Documentation] + ... 描述:执行'tsg_policy --enable/disable ...'指令 + ... 参数:id(策略ID) type(策略类型) commandType(enable|disable) + ... 返回:无 [Arguments] ${id} ${type} ${commandType} ${str} Evaluate '${Tsg_Policy} --%s --policyId %s --policyType %s' % ('${commandType}', '${id}', '${type}') - Run2 ${str} + Run2 ${str} + # 数据更改后做查询验证 + ${r} Tsg_Policy_Query ${type} ${id} ${None} ${None} ${True} + ${value} Run Keyword If '${commandType}'=='disable' Convert To Integer 0 + ... ELSE Convert To Integer 1 + Should Be Equal ${r}[data][list][0][isValid] ${value} Tsg_Policy_Object_Query - # @{param}:非必传,最大参数数量为三位。依次顺序为'objectName'、'objectType'和'allFlag',中间存在为空参数可用'${None}'占位 + [Documentation] + ... 描述:执行'tsg_policy_object --query ...'指令 + ... 参数:param(非必传,最大参数数量为三位,依次顺序为'objectName'、'objectType'和'allFlag',中间存在为空参数可用'None'占位) + ... 返回:查询响应数据 [Arguments] @{params} ${str} Set Variable ${Tsg_Policy_Object} --query ${str} Run Keyword If '${params}[0]' != '${None}' Evaluate '${str} --objectType "%s" ' % ('${params}[0]') @@ -95,7 +140,10 @@ Tsg_Policy_Object_Query [Return] ${r} Tsg_Policy_Object_Import - # ${type}:必传 ${file}:必传 @{params}:非必传,含义'objectName' + [Documentation] + ... 描述:执行'tsg_policy_object --import ...'指令 + ... 参数:type(对象类型) file(导入文件名称) params(对象名称) + ... 返回:无 [Arguments] ${type} ${file} @{params} ${newFile} Replace String ${file} export import ${command} Set Variable head -n 2 files/${file} > files/${newFile} @@ -103,10 +151,15 @@ Tsg_Policy_Object_Import ${str} Evaluate '${Tsg_Policy_Object} --import --objectType %s --file files/%s ' % ('${type}','${newFile}') ${str} Run Keyword If '${params}[0]' != '${None}' Evaluate '${str}--objectName %s ' % ('${params}[0]') ... ELSE Set Variable ${str} - Run3 ${str} + Run3 ${str} + # 数据导入后做查询验证 + Tsg_Policy_Object_Query ${type} ${params}[0] ${True} Tsg_Policy_Object_Export - # ${type}:必传 ${file}:必传 @{params}:非必传,含义'exportFormat'(txt|csv) + [Documentation] + ... 描述:执行'tsg_policy_object --export ...'指令 + ... 参数:type(对象类型) file(导出文件名称) params(txt|csv) + ... 返回:无 [Arguments] ${type} ${file} @{params} ${str} Evaluate '${Tsg_Policy_Object} --export --objectType %s --file files/%s ' % ('${type}','${file}') ${str} Run Keyword If '${params}[0]' != '${None}' Evaluate '${str}--exportFormat %s ' % ('${params}[0]') @@ -114,106 +167,184 @@ Tsg_Policy_Object_Export Run3 ${str} Tsg_Record_UserList + [Documentation] + ... 描述:执行'tsg_record --userlist'指令 + ... 参数:无 + ... 返回:无 ${str} Set Variable ${Tsg_Record} --userlist Run6 ${str} ${cliUsername} Tsg_Record_Query + [Documentation] + ... 描述:执行'tsg_record --username'指令 + ... 参数:无 + ... 返回:无 ${str} Evaluate '${Tsg_Record} --username %s ' % ('${cliUsername}') ${param} Set Variable ${Tsg_Record} --userlist Run6 ${str} ${param} Clear_Test_Data + [Documentation] + ... 描述:清除测试对象导出功能时的文件 + ... 参数:无 + ... 返回:无 ${str} Set Variable rm -rf /home/${cliUsername}/files/* Run4 ${str} Tsg_Help_Keyword - ${r} Run5 tsg_help + [Documentation] + ... 描述:执行'tsg_help'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + ${r} Run9 tsg_help ${data} Evaluate open(r"${path}/${Tsg_Help_file_Path}",'rb').read() Should Be Equal As Strings ${r} ${data} Tsg_Diagnose_Keyword - Write Until Expected Output tsg_diagnose\n Success ${timeout} ${timeout} + [Documentation] + ... 描述:执行'tsg_diagnose'指令 + ... 参数:无 + ... 返回:无 + # 执行'text'指令,在'timeout'时间内每隔'retry_interval'时间重试,直至返回值出现'expected'时或超时结束 + Write Until Expected Output tsg_diagnose\n Success ${timeout} ${retryInterval} Tsg_Show_Chassis-ip + [Documentation] + ... 描述:执行'tsg_show --chassis-ip'指令,并验证返回值 + ... 参数:无 + ... 返回:无 ${str} Set Variable ${Tsg_Show} --chassis-ip - ${r} Run5 ${str} - Should Contain ${r} Name - Should Contain ${r} IP + ${r} Run9 ${str} + Should Contain ${r} mxn + Should Contain ${r} mcn0 + Should Contain ${r} mcn1 + Should Contain ${r} mcn2 + Should Contain ${r} mcn3 Tsg_Show_Chassis-port + [Documentation] + ... 描述:执行'tsg_show --chassis-port'指令,并验证返回值 + ... 参数:无 + ... 返回:无 ${str} Set Variable ${Tsg_Show} --chassis-port - ${r} Run5 ${str} - Should Contain ${r} PortId - Should Contain ${r} Type - Should Contain ${r} Function - Should Contain ${r} Description - + ${r} Run9 ${str} + Should Contain Any ${r} physical backplane + Should Contain Any ${r} inline mirror business intercomm + +Time_Check + [Documentation] + ... 描述:验证时间是否正确 + ... 参数:str(时间列值) start(起始时间,用于验证) end(结束时间,用于验证) + ... 返回:无 + [Arguments] ${str} ${start} ${end} + # 处理'time'返回值,例2020-03-31T09:19:05.445123Z + ${str} Get Substring ${str} 0 -4 + ${date} Add Time To Date ${str} 08:00:00 + ${time} Evaluate int(time.mktime(time.strptime('${date}', '%Y-%m-%d %H:%M:%S.%f'))) time + # 处理时间范围 + ${start} Add Time To Date ${start} -00:10:00 + ${end} Add Time To Date ${end} 00:10:00 + ${minTime} Convert Date ${start} epoch + ${maxTime} Convert Date ${end} epoch + Should Be True ${minTime} < ${time} < ${maxTime} + Tsg_Show_Interface - ${str} Set Variable ${Tsg_Show} --interface - ${r} Run5 ${str} - Should Contain ${r} time - Should Contain ${r} PhyRXBits - Should Contain ${r} PhyRXFrame - Should Contain ${r} PhyTXBits - Should Contain ${r} PhyTXFrame - Should Contain ${r} flow_type - Should Contain ${r} sled + [Documentation] + ... 描述:执行'tsg_show --interface'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + ${str} Set Variable ${Tsg_Show} --interface -- ${Tsg_Show_Added_Sql} + ${stime} Get Time + @{list} Run5 ${str} + ${etime} Get Time + FOR ${obj} IN @{list} + Time_Check ${obj}[time] ${stime} ${etime} + Should Contain ${Tsg_Show_FlowType_Values} ${obj}[flow_type] + Should Contain ${Tsg_Show_Sled_Values} ${obj}[sled] + END Tsg_Show_APP - ${str} Set Variable ${Tsg_Show} --app - ${r} Run5 ${str} - Should Contain ${r} time - Should Contain ${r} RxBits - Should Contain ${r} RxPkts - Should Contain ${r} TxBits - Should Contain ${r} TxPkts - Should Contain ${r} device - Should Contain ${r} flow_type - Should Contain ${r} sled - + [Documentation] + ... 描述:执行'tsg_show --app'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + ${str} Set Variable ${Tsg_Show} --app -- ${Tsg_Show_Added_Sql} + ${stime} Get Time + @{list} Run5 ${str} + ${etime} Get Time + FOR ${obj} IN @{list} + Time_Check ${obj}[time] ${stime} ${etime} + Should Contain ${Tsg_Show_FlowType_Values} ${obj}[flow_type] + Should Contain ${Tsg_Show_Sled_Values} ${obj}[sled] + END + Tsg_Show_Protocol - ${str} Set Variable ${Tsg_Show} --protocol - ${r} Run5 ${str} - Should Contain ${r} time - Should Contain ${r} Eth_Bit - Should Contain ${r} Ipv4_Bit - Should Contain ${r} Ipv6_Bit - Should Contain ${r} Tcp_Bit - Should Contain ${r} Udp_Bit - Should Contain ${r} device - Should Contain ${r} flow_type - Should Contain ${r} sled + [Documentation] + ... 描述:执行'tsg_show --protocol'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + ${str} Set Variable ${Tsg_Show} --protocol -- ${Tsg_Show_Added_Sql} + ${stime} Get Time + @{list} Run5 ${str} + ${etime} Get Time + FOR ${obj} IN @{list} + Time_Check ${obj}[time] ${stime} ${etime} + Should Contain ${Tsg_Show_FlowType_Values} ${obj}[flow_type] + Should Contain ${Tsg_Show_Sled_Values} ${obj}[sled] + END Tsg_Show_Stream - ${str} Set Variable ${Tsg_Show} --stream - ${r} Run5 ${str} - Should Contain ${r} time - Should Contain ${r} Tcp_Link_New - Should Contain ${r} Tcp_Concurrent - Should Contain ${r} Tcp_Link_Double - Should Contain ${r} device - Should Contain ${r} flow_type - Should Contain ${r} sled + [Documentation] + ... 描述:执行'tsg_show --stream'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + ${str} Set Variable ${Tsg_Show} --stream -- ${Tsg_Show_Added_Sql} + ${stime} Get Time + @{list} Run5 ${str} + ${etime} Get Time + FOR ${obj} IN @{list} + Time_Check ${obj}[time] ${stime} ${etime} + Should Contain ${Tsg_Show_FlowType_Values} ${obj}[flow_type] + Should Contain ${Tsg_Show_Sled_Values} ${obj}[sled] + END Tsg_Show_Intercept - ${str} Set Variable ${Tsg_Show} --intercept - ${r} Run5 ${str} - Should Contain ${r} time - Should Contain ${r} intcp_rdy_bits - Should Contain ${r} intcp_rdy_stm - Should Contain ${r} intcped_bits - Should Contain ${r} intcped_stm - Should Contain ${r} sled + [Documentation] + ... 描述:执行'tsg_show --intercept'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + ${str} Set Variable ${Tsg_Show} --intercept -- ${Tsg_Show_Added_Sql} + ${stime} Get Time + @{list} Run5 ${str} + ${etime} Get Time + FOR ${obj} IN @{list} + Time_Check ${obj}[time] ${stime} ${etime} + Should Contain ${Tsg_Show_Sled_Values} ${obj}[sled] + END Tsg_Passwd_Keyword + [Documentation] + ... 描述:执行'tsg_show --passwd'指令,更改密码并验证 + ... 参数:无 + ... 返回:无 + # 修改密码 ${str1} Evaluate '${Tsg_Passwd} --password %s' % ('${cliPassword}x') Run7 ${str1} ${str2} Evaluate '${Tsg_Passwd} --password %s --username %s' % ('${cliPassword}y','${cliUsername}') - Run7 ${str2} + Run7 ${str2} + Close Connection + # 登录验证 + Open Connection ${cliHost} + SSHLibrary.Login ${cliUsername} ${cliPassword}y + # 复原密码 ${str3} Evaluate '${Tsg_Passwd} --password %s' % ('${cliPassword}') - Run7 ${str3} + Run8 ${str3} Run1 + [Documentation] + ... 描述:运行指令,将返回值处理后返回 + ... 参数:command(具体指令内容) + ... 返回:响应数据,字典 [Arguments] ${command} Write ${command} ${r} Read delay=10s @@ -240,6 +371,10 @@ Run1_B [Return] ${dict} Run2 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:无 [Arguments] ${command} Write ${command} ${r} Read delay=10s @@ -247,12 +382,22 @@ Run2 ... ELSE Should Contain ${r} Success Run3 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:无 [Arguments] ${command} ${flag} Run Keyword If '${cliUsername}'!='tsgadmin' Set Variable Permission denied ... ELSE Set Variable Success - Write Until Expected Output ${command}\n ${flag} ${timeout} ${timeout} - + # 执行'text'指令,在'timeout'时间内每隔'retry_interval'时间重试,直至返回值出现'expected'时或超时结束 + Write Until Expected Output ${command}\n ${flag} ${timeout} ${retryInterval} + Read delay=5s + Run4 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:无 [Arguments] ${command} Write ${command} ${r} Read delay=10s @@ -260,13 +405,27 @@ Run4 ... ELSE Should Not Contain ${r} head: Run5 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:响应数据,列表 [Arguments] ${command} Write ${command} ${r} Read delay=10s Should Not Be Empty ${r} - [Return] ${r} + ${str} Replace String ${r} ${\n} - + ${index} Evaluate '${str}'.rindex('-') + ${len} Convert To Integer ${index} + ${json} Evaluate '${str}'[0:${len}] + ${dict} json.Loads ${json} + ${list} Convert To List ${dict} + [Return] ${list} Run6 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) param(预期内容,用于验证) + ... 返回:无 [Arguments] ${command} ${param} Write ${command} ${r} Read delay=10s @@ -275,7 +434,32 @@ Run6 ... ELSE Should Contain ${r} ${param} Run7 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:无 [Arguments] ${command} Write ${command} ${r} Read delay=10s Should Contain ${r} Success + +Run8 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:无 + [Arguments] ${command} + # 执行'text'指令,在'timeout'时间内每隔'retry_interval'时间重试,直至返回值出现'expected'时或超时结束 + Write Until Expected Output ${command}\n Success ${timeout} ${retryInterval} + Read delay=5s + +Run9 + [Documentation] + ... 描述:运行指令,并验证返回值 + ... 参数:command(具体指令内容) + ... 返回:无 + [Arguments] ${command} + Write ${command} + ${r} Read delay=10s + Should Not Be Empty ${r} + [Return] ${r} diff --git a/03-Variable/BifangApiVariable.txt b/03-Variable/BifangApiVariable.txt index 7f042e0..3fb2d32 100644 --- a/03-Variable/BifangApiVariable.txt +++ b/03-Variable/BifangApiVariable.txt @@ -42,4 +42,6 @@ ${cliHost} 192.168.40.165 ${cliUsername} tsgadmin ${cliPassword} Cli2019 ${timeout} 600s +${retryInterval} 300s +@{ObjectTypes} ip url fqdn keywords subscriberid fqdn_category account http_signature # Cli自动化测试变量[end]