1*** Settings ***
2Documentation  Verify Auto Restart policy for set of mission critical
3...            services needed for functioning on BMC.
4
5Resource         ../../lib/resource.robot
6Resource         ../../lib/connection_client.robot
7Resource         ../../lib/openbmc_ffdc.robot
8Resource         ../../lib/utils.robot
9
10Suite Setup      Open Connection And Log In
11Suite Teardown   Close All Connections
12Test Teardown    FFDC On Test Case Fail
13
14*** Variables ***
15${LOG_SERVICE}  xyz.openbmc_project.Logging.service
16
17*** Test Cases ***
18
19Verify OpenBMC Services Auto Restart Policy
20    [Documentation]  Kill active services and expect auto restart.
21    [Tags]  Verify_OpenBMC_Services_Auto_Restart_Policy
22    # The services listed below restart policy should be "always"
23    # Command output:
24    # systemctl -p Restart show xyz.openbmc_project.Logging.service | cat
25    # Restart=always
26    @{services}=
27    ...  Create List  xyz.openbmc_project.Logging.service
28    ...               xyz.openbmc_project.ObjectMapper.service
29    ...               xyz.openbmc_project.State.BMC.service
30    ...               xyz.openbmc_project.State.Chassis.service
31    ...               xyz.openbmc_project.State.Host.service
32    : FOR  ${SERVICE}  IN  @{services}
33    \    Check Service Autorestart  ${SERVICE}
34
35
36Kill Services And Expect Service Restart
37    [Documentation]  Kill the service and it must restart.
38    [Tags]  Kill_Services_And_Expect_Service_Restart
39
40    # Get the MainPID and service state.
41    ${MainPID}=  Get Service Attribute  MainPID  ${LOG_SERVICE}
42    Should Not Be Equal  ${0}  ${MainPID}
43    ...  msg=Logging service not restarted.
44
45    ${ActiveState}=  Get Service Attribute  ActiveState  ${LOG_SERVICE}
46    Should Be Equal  active  ${ActiveState}
47    ...  msg=Logging Service not in active state.
48
49    BMC Execute Command  kill -9 ${MainPID}
50    Sleep  10s  reason=Wait for service to restart.
51
52    ${MainPID}=  Get Service Attribute  MainPID  ${LOG_SERVICE}
53    Should Not Be Equal  ${0}  ${MainPID}
54    ...  msg=Logging service not restarted.
55
56    ${ActiveState}=  Get Service Attribute  ActiveState  ${LOG_SERVICE}
57    Should Be Equal  active  ${ActiveState}
58    ...  msg=Logging service not in active state.
59
60
61*** Keywords ***
62
63Check Service Autorestart
64    [Documentation]  Check if given policy is "always".
65    [Arguments]  ${servicename}
66    # servicename  Qualified service name
67    ${restart_policy}=  Get Service Attribute  Restart  ${servicename}
68    Should Be Equal  always  ${restart_policy}
69    ...  msg=Incorrect policy for ${servicename}
70