go.ligato.io/vpp-agent/v3@v3.5.0/tests/robot/libraries/vat_term.robot (about)

     1  [Documentation]     Keywords for working with VAT terminal
     2  
     3  *** Settings ***
     4  Library      vat_term.py
     5  
     6  *** Variables ***
     7  ${terminal_timeout}=      30s
     8  ${bd_timeout}=            15s
     9  
    10  *** Keywords ***
    11  
    12  vat_term: Check VAT Terminal
    13      [Arguments]        ${node}
    14      [Documentation]    Check VAT terminal on node ${node}
    15      ${out}=            Write To Machine    ${node}_vat    ${DOCKER_COMMAND} exec -it ${node} /bin/bash
    16      ${command}=        Set Variable        ${VAT_START_COMMAND}
    17      ${out}=            Write To Machine    ${node}_vat    ${command}
    18      Should Contain     ${out}              ${${node}_VPP_VAT_PROMPT}
    19      [Return]           ${out}
    20  
    21  vat_term: Open VAT Terminal
    22      [Arguments]    ${node}
    23      [Documentation]    Wait for VAT terminal on node ${node} or timeout
    24      wait until keyword succeeds  ${terminal_timeout}    5s   vat_term: Check VAT Terminal    ${node}
    25  
    26  vat_term: Exit VAT Terminal
    27      [Arguments]        ${node}
    28      ${ctrl_c}          Evaluate    chr(int(3))
    29      ${command}=        Set Variable       ${ctrl_c}
    30      ${out}=            Write To Machine   ${node}_vat    ${command}
    31      [Return]           ${out}
    32  
    33  vat_term: Issue Command
    34      [Arguments]        ${node}     ${command}    ${delay}=${SSH_READ_DELAY}s
    35      ${failed_it}=     Create List
    36      :FOR    ${it_num}    IN RANGE    1    6
    37      \    ${result}    ${out}=    Run Keyword And Ignore Error    Write To Machine Until String    ${node}_vat    ${command}    ${${node}_VPP_VAT_PROMPT}    delay=${delay}
    38      \    Run Keyword If      '${result}'=='FAIL'      Append To List    ${failed_it}    ${it_num}
    39      \    Run Keyword If      '${result}'=='FAIL'      Log  Warning, no match found #vat console output!	WARN
    40      \    Exit For Loop If    '${result}'=='PASS'
    41      Run Keyword And Ignore Error  Should Be Empty  ${failed_it}  msg='Fail in this checks ${failed_it}'
    42  #    ${out}=            Write To Machine Until String    ${node}_vat    ${command}    ${${node}_VPP_VAT_PROMPT}    delay=${delay}
    43  ##    Should Contain     ${out}             ${${node}_VPP_VAT_PROMPT}
    44      [Return]           ${out}
    45  
    46  vat_term: Interfaces Dump
    47      [Arguments]        ${node}
    48      [Documentation]    Executing command sw_interface_dump
    49      ${out}=            vat_term: Issue Command  ${node}  sw_interface_dump
    50      [Return]           ${out}
    51  
    52  vat_term: Bridge Domain Dump
    53      [Arguments]        ${node}    ${bd_id}=${EMPTY}
    54      [Documentation]    Executing command bridge_domain_dump
    55      ${add_params}=     Set Variable If    '''${bd_id}'''==""    ${EMPTY}    bd_id ${bd_id}
    56      ${out}=            vat_term: Issue Command  ${node}  bridge_domain_dump ${add_params}
    57      ${out}=            Evaluate    """${out}"""["""${out}""".find('['):"""${out}""".rfind(']')+1]
    58      [Return]           ${out}
    59  
    60  vat_term: IP FIB Dump
    61      [Arguments]        ${node}
    62      [Documentation]    Executing command ip_fib_dump
    63      ${out}=            vat_term: Issue Command  ${node}  ip_fib_dump
    64      [Return]           ${out}
    65  
    66  vat_term: VXLan Tunnel Dump
    67      [Arguments]        ${node}    ${args}=${EMPTY}
    68      [Documentation]    Executing command vxlan_tunnel_dump
    69      ${out}=            vat_term: Issue Command  ${node}  vxlan_tunnel_dump ${args}
    70      ${out}=            Evaluate    """${out}"""["""${out}""".find('['):"""${out}""".rfind(']')+1]
    71      [Return]           ${out}
    72  
    73  vat_term: Check VXLan Tunnel Presence
    74      [Arguments]        ${node}     ${src}    ${dst}    ${vni}    ${status}=${TRUE}
    75      [Documentation]    Checking if specified vxlan tunnel exists
    76      ${out}=            vat_term: VXLan Tunnel Dump    ${node}
    77      ${result}  ${if_index}=    Check VXLan Tunnel Presence    ${out}    ${src}    ${dst}    ${vni}
    78      Should Be Equal    ${result}    ${status}
    79      [Return]           ${if_index}
    80  
    81  vat_term: Get Interface Name
    82      [Arguments]        ${node}     ${index}
    83      [Documentation]    Return interface with specified index name
    84      ${out}=            vat_term: Interfaces Dump    ${node}
    85      ${name}=           Get Interface Name    ${out}    ${index}
    86      [Return]           ${name}
    87  
    88  vat_term: Get Interface Index
    89      [Arguments]        ${node}     ${name}
    90      [Documentation]    Return interface index with specified name
    91      ${out}=            vat_term: Interfaces Dump    ${node}
    92      ${index}=          Get Interface Index    ${out}    ${name}
    93      [Return]           ${index}
    94  
    95  vat_term: Check VXLan Interface State
    96      [Arguments]          ${node}    ${name}    @{desired_state}
    97      ${internal_name}=    Get Interface Internal Name    ${node}    ${name}
    98      ${internal_index}=   vat_term: Get Interface Index    ${node}    ${internal_name}
    99      ${vxlan_data}=       vat_term: VXLan Tunnel Dump    ${node}    sw_if_index ${internal_index}
   100      ${vxlan_data}=       Evaluate    json.loads('''${vxlan_data}''')    json
   101      ${interfaces}=       vat_term: Interfaces Dump    ${node}
   102      ${int_state}=        Get Interface State    ${interfaces}    ${internal_index}
   103      ${src}=              Set Variable    ${vxlan_data[0]["src_address"]}
   104      ${dst}=              Set Variable    ${vxlan_data[0]["dst_address"]}
   105      ${vni}=              Set Variable    ${vxlan_data[0]["vni"]}
   106      ${enabled}=          Set Variable    ${int_state["admin_up_down"]}
   107      ${actual_state}=     Create List    src=${src}    dst=${dst}    vni=${vni}    enabled=${enabled}
   108      List Should Contain Sub List    ${actual_state}    ${desired_state}
   109      [Return]             ${actual_state}
   110  
   111  vat_term: Check Afpacket Interface State
   112      [Arguments]          ${node}    ${name}    @{desired_state}
   113      ${internal_name}=    Get Interface Internal Name    ${node}    ${name}
   114      ${internal_index}=   vat_term: Get Interface Index    ${node}    ${internal_name}
   115      ${interfaces}=       vat_term: Interfaces Dump    ${node}
   116      ${int_state}=        Get Interface State    ${interfaces}    ${internal_index}
   117      ${ipv4_list}=        vpp_term: Get Interface IPs    ${node}    ${internal_name}
   118      ${config}=           Get VPP Interface Config As Json    ${node}    ${name}
   119      ${host_int}=         Set Variable    ${config["afpacket"]["host_if_name"]}
   120      #Should Contain       ${internal_name}    ${host_int}
   121      ${enabled}=          Set Variable    ${int_state["admin_up_down"]}
   122      ${mtu}=              Set Variable    ${int_state["mtu"]}
   123      ${dec_mac}=          Set Variable    ${int_state["l2_address"]}
   124      ${mac}=              Convert Dec MAC To Hex    ${dec_mac}
   125      ${actual_state}=     Create List    enabled=${enabled}    mtu=${mtu}    mac=${mac}
   126      :FOR    ${ip}    IN    @{ipv4_list}
   127      \    Append To List    ${actual_state}    ipv4=${ip}
   128      List Should Contain Sub List    ${actual_state}    ${desired_state}
   129      [Return]             ${actual_state}
   130  
   131  vat_term: Check Physical Interface State
   132      [Arguments]          ${node}    ${name}    @{desired_state}
   133      ${internal_name}=    Get Interface Internal Name    ${node}    ${name}
   134      ${internal_index}=   vat_term: Get Interface Index    ${node}    ${internal_name}
   135      ${interfaces}=       vat_term: Interfaces Dump    ${node}
   136      ${int_state}=        Get Interface State    ${interfaces}    ${internal_index}
   137      ${ipv4_list}=        vpp_term: Get Interface IPs    ${node}    ${internal_name}
   138      ${enabled}=          Set Variable    ${int_state["admin_up_down"]}
   139      ${mtu}=              Set Variable    ${int_state["mtu"]}
   140      ${dec_mac}=          Set Variable    ${int_state["l2_address"]}
   141      ${mac}=              Convert Dec MAC To Hex    ${dec_mac}
   142      ${actual_state}=     Create List    enabled=${enabled}    mtu=${mtu}    mac=${mac}
   143      :FOR    ${ip}    IN    @{ipv4_list}
   144      \    Append To List    ${actual_state}    ipv4=${ip}
   145      List Should Contain Sub List    ${actual_state}    ${desired_state}
   146      [Return]             ${actual_state}
   147  
   148  vat_term: Check Loopback Interface State
   149      [Arguments]          ${node}    ${name}    @{desired_state}
   150      ${internal_name}=    Get Interface Internal Name    ${node}    ${name}
   151      ${internal_index}=   vat_term: Get Interface Index    ${node}    ${internal_name}
   152      ${interfaces}=       vat_term: Interfaces Dump    ${node}
   153      ${int_state}=        Get Interface State    ${interfaces}    ${internal_index}
   154      ${ipv4_list}=        vpp_term: Get Interface IPs    ${node}    ${internal_name}
   155      ${ipv6_list}=        vpp_term: Get Interface IP6 IPs    ${node}    ${internal_name}
   156      ${enabled}=          Set Variable    ${int_state["admin_up_down"]}
   157      ${mtu}=              Set Variable    ${int_state["mtu"]}
   158      ${dec_mac}=          Set Variable    ${int_state["l2_address"]}
   159      ${mac}=              Convert Dec MAC To Hex    ${dec_mac}
   160      ${actual_state}=     Create List    enabled=${enabled}    mtu=${mtu}    mac=${mac}
   161      :FOR    ${ip}    IN    @{ipv4_list}
   162      \    Append To List    ${actual_state}    ipv4=${ip}
   163      :FOR    ${ip}    IN    @{ipv6_list}
   164      \    Append To List    ${actual_state}    ipv6=${ip}
   165      List Should Contain Sub List    ${actual_state}    ${desired_state}
   166      [Return]             ${actual_state}
   167  
   168  vat_term: Check Memif Interface State
   169      [Arguments]          ${node}    ${name}    @{desired_state}
   170      ${internal_name}=    Get Interface Internal Name    ${node}    ${name}
   171      ${memif_info}=       vpp_term: Show Memif    ${node}    ${internal_name}
   172      ${memif_state}=      Parse Memif Info    ${memif_info}
   173      ${ipv4_list}=        vpp_term: Get Interface IPs    ${node}    ${internal_name}
   174      ${ipv6_list}=        vpp_term: Get Interface IP6 IPs    ${node}    ${internal_name}
   175      ${mac}=              vpp_term: Get Interface MAC    ${node}    ${internal_name}
   176      ${actual_state}=     Create List    mac=${mac}
   177      :FOR    ${ip}    IN    @{ipv4_list}
   178      \    Append To List    ${actual_state}    ipv4=${ip}
   179      :FOR    ${ip}    IN    @{ipv6_list}
   180      \    Append To List    ${actual_state}    ipv6=${ip}
   181      Append To List       ${actual_state}    @{memif_state}
   182      List Should Contain Sub List    ${actual_state}    ${desired_state}
   183      [Return]             ${actual_state}
   184  
   185  vat_term: Check Bridge Domain State
   186      [Arguments]          ${node}    ${bd}    @{desired_state}
   187      ${bd_id}=            Get Bridge Domain ID    ${node}    ${bd}
   188      ${bd_dump}=          vat_term: Bridge Domain Dump    ${node}    ${bd_id}
   189      ${bd_json}=          Evaluate    json.loads('''${bd_dump}''')    json
   190      ${flood}=            Set Variable    ${bd_json[0]["flood"]}
   191      ${forward}=          Set Variable    ${bd_json[0]["forward"]}
   192      ${learn}=            Set Variable    ${bd_json[0]["learn"]}
   193      ${bd_details}=       vpp_term: Show Bridge-Domain Detail    ${node}    ${bd_id}
   194      ${bd_state}=         Parse BD Details    ${bd_details}
   195      ${etcd_dump}=        Get ETCD Dump
   196      ${etcd_json}=        Convert_ETCD_Dump_To_JSON    ${etcd_dump}
   197      ${interfaces}=       Parse BD Interfaces    ${node}    ${bd}    ${etcd_json}    ${bd_dump}
   198      ${actual_state}=     Create List    flood=${flood}    forward=${forward}    learn=${learn}
   199      Append To List       ${actual_state}    @{bd_state}    @{interfaces}
   200      List Should Contain Sub List    ${actual_state}    ${desired_state}
   201      [Return]             ${actual_state}
   202  
   203  vat_term: Check Bridge Domain State IPv6
   204      [Arguments]          ${node}    ${bd}    @{desired_state}
   205      ${bd_id}=            Get Bridge Domain ID IPv6    ${node}    ${bd}
   206      ${bd_dump}=          vat_term: Bridge Domain Dump    ${node}    ${bd_id}
   207      ${bd_json}=          Evaluate    json.loads('''${bd_dump}''')    json
   208      ${flood}=            Set Variable    ${bd_json[0]["flood"]}
   209      ${forward}=          Set Variable    ${bd_json[0]["forward"]}
   210      ${learn}=            Set Variable    ${bd_json[0]["learn"]}
   211      ${bd_details}=       vpp_term: Show Bridge-Domain Detail    ${node}    ${bd_id}
   212      ${bd_state}=         Parse BD Details    ${bd_details}
   213      ${etcd_dump}=        Get ETCD Dump
   214      ${etcd_json}=        Convert_ETCD_Dump_To_JSON    ${etcd_dump}
   215      ${interfaces}=       Parse BD Interfaces    ${node}    ${bd}    ${etcd_json}    ${bd_dump}
   216      ${actual_state}=     Create List    flood=${flood}    forward=${forward}    learn=${learn}
   217      Append To List       ${actual_state}    @{bd_state}    @{interfaces}
   218      List Should Contain Sub List    ${actual_state}    ${desired_state}
   219      [Return]             ${actual_state}
   220  
   221  vat_term: BD Is Created
   222      [Arguments]    ${node}    @{interfaces}
   223      Wait Until Keyword Succeeds    ${bd_timeout}   3s    vat_term: Check BD Presence    ${node}    ${interfaces}
   224  
   225  vat_term: BD Is Deleted
   226      [Arguments]    ${node}    @{interfaces}
   227      Wait Until Keyword Succeeds    ${bd_timeout}   3s    vat_term: Check BD Presence    ${node}    ${interfaces}    ${FALSE}
   228  
   229  vat_term: BD Exists
   230      [Arguments]    ${node}    @{interfaces}
   231      vat_term: Check BD Presence    ${node}    ${interfaces}
   232  
   233  vat_term: BD Not Exists
   234      [Arguments]    ${node}    @{interfaces}
   235      vat_term: Check BD Presence    ${node}    ${interfaces}    ${FALSE}
   236  
   237  vat_term: Check BD Presence
   238      [Arguments]        ${node}     ${interfaces}    ${status}=${TRUE}
   239      ${indexes}=    Create List
   240      :FOR    ${int}    IN    @{interfaces}
   241      \    ${sw_if_index}=    Get Interface Sw If Index    ${node}    ${int}
   242      \    Append To List    ${indexes}    ${sw_if_index}
   243      ${bd_dump}=        vat_term: Bridge Domain Dump    ${node}
   244      ${result}=         Check BD Presence    ${bd_dump}    ${indexes}
   245      Should Be Equal    ${result}    ${status}