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

     1  *** Settings ***
     2  Library    OperatingSystem
     3  Library       SSHLibrary            timeout=15s        loglevel=TRACE
     4  Resource    ../setup-teardown.robot
     5  Resource    ../SshCommons.robot
     6  Documentation     Contains keywords used to setup and teardown Kubernetes tests.
     7  
     8  *** Variables ***
     9  
    10  
    11  *** Keywords ***
    12  Kubernetes Suite Setup
    13      [Arguments]    ${cluster_id}
    14      [Documentation]    Perform actions common for setup of every suite.
    15      BuiltIn.Log    ${cluster_id}
    16      setup-teardown.Discard Old Results
    17      Create_Connections_To_Kube_Cluster      ${cluster_id}
    18      BuiltIn.Set_Suite_Variable    ${testbed_connection}    vm_1
    19  
    20  Kubernetes Suite Teardown
    21      [Arguments]    ${cluster_id}
    22      [Documentation]    Perform actions common for teardown of every suite.
    23      BuiltIn.Log    ${cluster_id}
    24      Kubernetes Log SSH Output    ${cluster_id}
    25      SSHLibrary.Get_Connections
    26      SSHLibrary.Close_All_Connections
    27  
    28  Kubernetes Log SSH Output
    29      [Arguments]    ${cluster_id}
    30      [Documentation]    Call Log_\${vm}_Output for every cluster node.
    31      [Timeout]    ${SSH_LOG_OUTPUTS_TIMEOUT}
    32      BuiltIn.Log    ${cluster_id}
    33      : FOR    ${index}    IN RANGE    1    ${K8_CLUSTER_${cluster_id}_NODES}+1
    34      \    Kubernetes Log ${VM_SSH_ALIAS_PREFIX}${index} Output
    35  
    36  Kubernetes Log ${vm} Output
    37      [Documentation]    Switch to \${vm} SSH connection, read with delay of ${SSH_READ_DELAY}, Log and append to log file.
    38      BuiltIn.Log_Many    ${vm}
    39      BuiltIn.Comment    TODO: Rewrite this keyword with ${vm} being explicit argument.
    40      SSHLibrary.Switch_Connection    ${vm}
    41      ${out} =    SSHLibrary.Read    delay=${SSH_READ_DELAY}s
    42      BuiltIn.Log    ${out}
    43      OperatingSystem.Append_To_File    ${RESULTS_FOLDER}/output_${vm}.log    ${out}
    44  
    45  Get Kubernetes VM Status
    46      [Arguments]    ${vm}
    47      [Documentation]    Execute df, free, ifconfig -a, ps -aux... on vm, assuming ssh connection there is active.
    48      BuiltIn.Log_Many    ${vm}
    49      SshCommons.Execute_Command_And_Log    whoami
    50      SshCommons.Execute_Command_And_Log    pwd
    51      SshCommons.Execute_Command_And_Log    df
    52      SshCommons.Execute_Command_And_Log    free
    53      SshCommons.Execute_Command_And_Log    ip address
    54      SshCommons.Execute_Command_And_Log    ps aux
    55      SshCommons.Execute_Command_And_Log    export
    56      SshCommons.Execute_Command_And_Log    docker images
    57      SshCommons.Execute_Command_And_Log    docker ps -as
    58      BuiltIn.Return_From_Keyword_If    """${vm}""" != """${VM_SSH_ALIAS_PREFIX}1"""
    59      SshCommons.Execute_Command_And_Log    kubectl get nodes    ignore_stderr=True    ignore_rc=True
    60      SshCommons.Execute_Command_And_Log    kubectl get pods    ignore_stderr=True    ignore_rc=True
    61      
    62  Create Connections To Kube Cluster
    63      [Arguments]    ${cluster_id}
    64      [Documentation]    Create connection and log machine status for each node.
    65      BuiltIn.Log    ${cluster_id}
    66      : FOR    ${index}    IN RANGE    1    ${K8_CLUSTER_${cluster_id}_NODES}+1
    67      \    SshCommons.Open_Ssh_Connection_Kube    ${VM_SSH_ALIAS_PREFIX}${index}    ${K8_CLUSTER_${cluster_id}_VM_${index}_PUBLIC_IP}    ${K8_CLUSTER_${cluster_id}_VM_${index}_USER}    ${K8_CLUSTER_${cluster_id}_VM_${index}_PSWD}
    68      \    SSHLibrary.Set_Client_Configuration    prompt=${K8_CLUSTER_${cluster_id}_VM_${index}_PROMPT}
    69      \    Get_Machine_Status    ${VM_SSH_ALIAS_PREFIX}${index}
    70      BuiltIn.Set_Suite_Variable    ${testbed_connection}    ${VM_SSH_ALIAS_PREFIX}1
    71      SSHLibrary.Switch_Connection  ${testbed_connection}
    72  
    73  Make K8 ETCD Snapshots
    74      [Arguments]    ${tag}=notag
    75      [Documentation]    Log ${tag}, compute next prefix and log ETCD status with the prefix.
    76      BuiltIn.Log_Many    ${tag}
    77      ${prefix} =    Create_K8_Next_Snapshot_Prefix
    78      setup-teardown.Take ETCD Snapshots    ${prefix}_${tag}    ${testbed_connection}
    79  
    80  Create_K8_Next_Snapshot_Prefix
    81      [Documentation]    Contruct new prefix, store next snapshot num. Return the prefix.
    82      ${prefix} =    BuiltIn.Evaluate    str(${snapshot_num}).zfill(3)
    83      ${snapshot_num} =    BuiltIn.Evaluate    ${snapshot_num}+1
    84      BuiltIn.Set_Global_Variable    ${snapshot_num}
    85      [Return]    ${prefix}