From 44bd76e32ba3dea0ccf2cd04436d4d463c0ad7a9 Mon Sep 17 00:00:00 2001 From: zhangwenqing Date: Tue, 14 Apr 2020 15:42:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(Cli)=EF=BC=9A1=E3=80=81=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9B=B4=E6=94=B9=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E8=A1=A5=E5=85=85=E7=AD=96=E7=95=A5=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=EF=BC=8C2=E3=80=81=E7=AD=96=E7=95=A5=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E8=BF=AD=E4=BB=A3=EF=BC=8C3=E3=80=81=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AF=B9=E5=90=84cli=E5=91=BD=E4=BB=A4help=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=BF=94=E5=9B=9E=E5=80=BC=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01-TestCase/tsg_cli/EnDisablePolicy.robot | 26 ++--- 01-TestCase/tsg_cli/OtherCommand.robot | 6 +- .../tsg_cli/QueryManipulationPolicy.robot | 38 ++----- 01-TestCase/tsg_cli/QueryObject.robot | 107 +----------------- 01-TestCase/tsg_cli/QuerySecurityPolicy.robot | 38 ++----- 02-Keyword/tsg_cli/Interface.robot | 38 ++++++- 05-Other/cli_files/tsg_policy_help.txt | 5 + 05-Other/cli_files/tsg_policy_object_help.txt | 5 + 05-Other/cli_files/tsg_record_help.txt | 4 + 05-Other/cli_files/tsg_show_help.txt | 9 ++ 10 files changed, 100 insertions(+), 176 deletions(-) create mode 100644 05-Other/cli_files/tsg_policy_help.txt create mode 100644 05-Other/cli_files/tsg_policy_object_help.txt create mode 100644 05-Other/cli_files/tsg_record_help.txt create mode 100644 05-Other/cli_files/tsg_show_help.txt diff --git a/01-TestCase/tsg_cli/EnDisablePolicy.robot b/01-TestCase/tsg_cli/EnDisablePolicy.robot index 5de173f..5f828a7 100644 --- a/01-TestCase/tsg_cli/EnDisablePolicy.robot +++ b/01-TestCase/tsg_cli/EnDisablePolicy.robot @@ -3,20 +3,14 @@ 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] - - - - +Policy_EnDisable_TestCase + # 操作不同类型策略 + FOR ${policyType} IN @{PolicyTypes} + ${obj} Get_Policy_Object3 ${policyType} + # 更改策略状态 + Tsg_Policy_EnDisable ${obj}[policyId] ${policyType} ${obj}[commandType1] + # 复原策略状态 + Tsg_Policy_EnDisable ${obj}[policyId] ${policyType} ${obj}[commandType2] + END + \ No newline at end of file diff --git a/01-TestCase/tsg_cli/OtherCommand.robot b/01-TestCase/tsg_cli/OtherCommand.robot index 8d7bfc9..fc45645 100644 --- a/01-TestCase/tsg_cli/OtherCommand.robot +++ b/01-TestCase/tsg_cli/OtherCommand.robot @@ -6,7 +6,11 @@ Resource ../../02-Keyword/tsg_cli/interface.robot Tsg_Help_TestCase [Tags] tsg-cli TsgHelp Tsg_Help_Keyword - + Tsg_Command_Help tsg_policy + Tsg_Command_Help tsg_policy_object + Tsg_Command_Help tsg_record + Tsg_Command_Help tsg_show + Tsg_Diagnose_TestCase [Tags] tsg-cli TsgDiagnose Tsg_Diagnose_Keyword diff --git a/01-TestCase/tsg_cli/QueryManipulationPolicy.robot b/01-TestCase/tsg_cli/QueryManipulationPolicy.robot index 174ec72..766ff77 100644 --- a/01-TestCase/tsg_cli/QueryManipulationPolicy.robot +++ b/01-TestCase/tsg_cli/QueryManipulationPolicy.robot @@ -3,31 +3,17 @@ 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} +PxyManipulation_Policy_Query_TestCase + # 取最多10条策略数据,分别做条件查询 + ${list} Get_Policy_Object2 pxy_manipulation + FOR ${obj} IN @{list} + Tsg_Policy_Query pxy_manipulation ${obj}[policyId] ${None} ${None} ${True} + Tsg_Policy_Query pxy_manipulation ${None} ${obj}[policyName] ${None} ${True} + Tsg_Policy_Query pxy_manipulation ${None} ${None} ${obj}[policyDesc] ${True} + Tsg_Policy_Query pxy_manipulation ${obj}[policyId] ${obj}[policyName] ${None} ${True} + Tsg_Policy_Query pxy_manipulation ${obj}[policyId] ${None} ${obj}[policyDesc] ${True} + Tsg_Policy_Query pxy_manipulation ${None} ${obj}[policyName] ${obj}[policyDesc] ${True} + END + -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 index 606a806..58357f9 100644 --- a/01-TestCase/tsg_cli/QueryObject.robot +++ b/01-TestCase/tsg_cli/QueryObject.robot @@ -3,109 +3,12 @@ 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 +Objects_Query_TestCase + # 无条件查询 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} + FOR ${objectType} IN @{ObjectTypes} + QueryObjectInnerForEach ${objectType} + END -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 index 739c5df..833ef68 100644 --- a/01-TestCase/tsg_cli/QuerySecurityPolicy.robot +++ b/01-TestCase/tsg_cli/QuerySecurityPolicy.robot @@ -3,31 +3,15 @@ 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} - - - +Security_Policy_Query_TestCase + # 取最多10条策略数据,分别做条件查询 + ${list} Get_Policy_Object2 tsg_security + FOR ${obj} IN @{list} + Tsg_Policy_Query tsg_security ${obj}[policyId] ${None} ${None} ${True} + Tsg_Policy_Query tsg_security ${None} ${obj}[policyName] ${None} ${True} + Tsg_Policy_Query tsg_security ${None} ${None} ${obj}[policyDesc] ${True} + Tsg_Policy_Query tsg_security ${obj}[policyId] ${obj}[policyName] ${None} ${True} + Tsg_Policy_Query tsg_security ${obj}[policyId] ${None} ${obj}[policyDesc] ${True} + Tsg_Policy_Query tsg_security ${None} ${obj}[policyName] ${obj}[policyDesc] ${True} + END diff --git a/02-Keyword/tsg_cli/Interface.robot b/02-Keyword/tsg_cli/Interface.robot index 1aa2b18..3cc501a 100644 --- a/02-Keyword/tsg_cli/Interface.robot +++ b/02-Keyword/tsg_cli/Interface.robot @@ -32,7 +32,8 @@ Get_Policy_Object1 [Arguments] ${type} ${dict} Tsg_Policy_Query ${type} ${None} ${None} ${None} ${True} Should Be True ${dict}[data][total] > 1 - [Return] ${dict}[data][list][1] + ${list} Evaluate list(${dict}[data][list])[1:11] + [Return] ${list} Get_Policy_Object2 [Documentation] @@ -41,7 +42,8 @@ Get_Policy_Object2 ... 返回:任意单条策略 [Arguments] ${type} ${dict} Tsg_Policy_Query ${type} ${None} ${None} ${None} ${True} - [Return] ${dict}[data][list][0] + ${list} Evaluate list(${dict}[data][list])[:10] + [Return] ${list} Get_Policy_Object3 [Documentation] @@ -49,7 +51,11 @@ Get_Policy_Object3 ... 参数:type(策略类型) ... 返回:policyId(策略ID)、commandType1(enable/disable,修改)、commandType2(enable/disable,还原) [Arguments] ${type} - ${obj} Get_Policy_Object1 ${type} + #${obj} Get_Policy_Object1 ${type} + ${dict} Tsg_Policy_Query ${type} ${None} ${None} ${None} ${True} + Should Be True ${dict}[data][total] > 1 + ${obj} Set Variable ${dict}[data][list][1] + ${commandType1} Run Keyword If ${obj}[isValid]==0 Set Variable enable ... ELSE Set Variable disable ${commandType2} Run Keyword If ${obj}[isValid]==1 Set Variable enable @@ -64,7 +70,8 @@ Get_Policy_Object4 ... 返回:任意单条对象 [Arguments] ${type} ${dict} Tsg_Policy_Object_Query ${type} ${None} ${True} - [Return] ${dict}[data][list][0] + ${list} Evaluate list(${dict}[data][list])[:10] + [Return] ${list} Get_File_Name [Documentation] @@ -209,6 +216,17 @@ Tsg_Diagnose_Keyword # 执行'text'指令,在'timeout'时间内每隔'retry_interval'时间重试,直至返回值出现'expected'时或超时结束 Write Until Expected Output tsg_diagnose\n Success ${timeout} ${retryInterval} +Tsg_Command_Help + [Documentation] + ... 描述:执行'* --help'指令,并验证返回值 + ... 参数:无 + ... 返回:无 + [Arguments] ${cmd} + ${str} Set Variable ${cmd} --help + ${r} Run9 ${str} + ${data} Evaluate open(r"${path}/cli_files/${cmd}_help.txt",'rb').read() + Should Be Equal ${r} ${data} + Tsg_Show_Chassis-ip [Documentation] ... 描述:执行'tsg_show --chassis-ip'指令,并验证返回值 @@ -464,3 +482,15 @@ Run9 ${r} Read delay=10s Should Not Be Empty ${r} [Return] ${r} + +QueryObjectInnerForEach + # 循环嵌套 + [Arguments] ${objectType} + ${list} Get_Policy_Object4 ${objectType} + # 取最多10条策略对象数据,分别做条件查询 + FOR ${obj} IN @{list} + Tsg_Policy_Object_Query ${None} ${obj}[objectName] ${True} + Tsg_Policy_Object_Query ${obj}[objectType] ${None} ${True} + Tsg_Policy_Object_Query ${obj}[objectType] ${obj}[objectName] ${True} + END + diff --git a/05-Other/cli_files/tsg_policy_help.txt b/05-Other/cli_files/tsg_policy_help.txt new file mode 100644 index 0000000..1196fe3 --- /dev/null +++ b/05-Other/cli_files/tsg_policy_help.txt @@ -0,0 +1,5 @@ +Policy query +tsg_policy [--query --policyType(tsg_security|pxy_manipulation|pxy_cache) --policyId --policyName --policyDesc --all] Query strategy: policyType is required, policyId, policyName, policyDesc is not. +tsg_policy [--enable --policyId --policyType] Enable the strategy +tsg_policy [--disable --policyId --policyType] Stop using strategy +tsgcli > \ No newline at end of file diff --git a/05-Other/cli_files/tsg_policy_object_help.txt b/05-Other/cli_files/tsg_policy_object_help.txt new file mode 100644 index 0000000..3da3b07 --- /dev/null +++ b/05-Other/cli_files/tsg_policy_object_help.txt @@ -0,0 +1,5 @@ +Strategy object query +tsg_policy_object [--query --objectType(ip|url|fqdn|keywords|subscriberid|fqdn_category|account|http_signature) --all --objectName] Query strategy object +tsg_policy_object [--import --objectType --file --objectName] Import the policy object by file: enter objectType/file are required, objectName is optional +tsg_policy_object [--export --objectType --file --exportFormat(txt|csv)] Export the policy object to a local file:export objectType/file are required, exportFormat is optional +tsgcli > \ No newline at end of file diff --git a/05-Other/cli_files/tsg_record_help.txt b/05-Other/cli_files/tsg_record_help.txt new file mode 100644 index 0000000..7ac04b7 --- /dev/null +++ b/05-Other/cli_files/tsg_record_help.txt @@ -0,0 +1,4 @@ +Display the most recently run command history: you can view the command history of all users +tsg_record [--username] Specifies the user's history is to be viewed +tsg_record [--userlist] View all current CLI user names +tsgcli > \ No newline at end of file diff --git a/05-Other/cli_files/tsg_show_help.txt b/05-Other/cli_files/tsg_show_help.txt new file mode 100644 index 0000000..103119b --- /dev/null +++ b/05-Other/cli_files/tsg_show_help.txt @@ -0,0 +1,9 @@ +Used to view the running status of devices and applications, network traffic, and related statistics +tsg_show [--interface -- "where PhyRXBits > 60"] Display all available ports of the current device (network card name),where support, format : -- "where PhyRXBits > 60" +tsg_show [--app -- "where RxBits > 3000"] Displays traffic information processed by the application,where support, format : -- "where RxBits > 3000" +tsg_show [--protocol -- "where Ipv4_Bit > 3000"] Show Eth,Ipv4, and IPv6 statistics for each layer of network traffic,where support, format : -- "where Ipv4_Bit > 3000" +tsg_show [--stream -- "where Tcp_Concurrent > 0"] TCP stream related information, including the number of concurrent streams, C2S, S2C, etc,where support, format : -- "where Tcp_Concurrent > 0" +tsg_show [--chassis-ip] Output all board card IP information of TSG device +tsg_show [--chassis-port] Output all board card port information of TSG device +tsg_show [--intercept -- "where intcp_rdy_bits > 0"] Show intercept information,where support, format : -- "where intcp_rdy_bits > 0" +tsgcli > \ No newline at end of file