# Copyright 2017-present Radisys Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


*** Settings ***
Documentation     Test suite for checking results collected by various commands on the soak server
Library           OperatingSystem
Library           ../cord-api/Framework/utils/onosUtils.py
Library           ../cord-api/Framework/utils/utils.py

*** Variables ***
${FILE_PATH}       /home/cord/SoakTest_Logs

*** Test Cases ***
Verify Docker Containers Restart Status
    [Documentation]    Verify  that no containers have been restarted
    [Tags]      Restart_Status
    ${command_output}=  Run     docker inspect --format "ID: {{.ID}} RESTARTS: {{.RestartCount}} NAME: {{.Name}}" $(docker ps -aq) | grep -v ": 0" > /tmp/count_log
    Log To Console      ${command_output}
    ${file_output}=     Run     cat /tmp/count_log
    ${count}=   Run     cat /tmp/count_log | wc -l
    Log ${file_output}
    ${command_output1}= Run     sudo mv /tmp/count_log ${FILE_PATH}/container_restarts$(date "+%Y.%m.%d-%H.%M.%S")
    Should Be Empty     ${count}

Verify Memory Utilization on the Containers
    [Documentation]     Display the memory utilization for the containers
    [Tags]      Container_Memory_Usage
    ${command_output}=  Run     docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" $(docker ps -a --format '{{.Names}}') > /tmp/mem_log
    ${cat_output}=      Run     cat /tmp/mem_log
    ${count}=   Run     cat /tmp/mem_log | wc -l
    ${command_output1}= Run     sudo mv /tmp/mem_log ${FILE_PATH}/container_mem_usage_$(date "+%Y.%m.%d-%H.%M.%S")
    Should Not Be Empty ${count}
