1a7327ea8SSushil Singh*** Settings *** 2a7327ea8SSushil SinghDocumentation Verify Auto Restart policy for set of mission critical 3a7327ea8SSushil Singh... services needed for functioning on BMC. 4a7327ea8SSushil Singh 54422e2b2SGeorge KeishingResource ../../lib/resource.robot 64422e2b2SGeorge KeishingResource ../../lib/connection_client.robot 74422e2b2SGeorge KeishingResource ../../lib/openbmc_ffdc.robot 84422e2b2SGeorge KeishingResource ../../lib/utils.robot 932d55427SganesanbLibrary ../../data/platform_variables.py 10a7327ea8SSushil Singh 11a7327ea8SSushil SinghSuite Setup Open Connection And Log In 12a7327ea8SSushil SinghSuite Teardown Close All Connections 13a7327ea8SSushil SinghTest Teardown FFDC On Test Case Fail 14a7327ea8SSushil Singh 15a7327ea8SSushil Singh*** Variables *** 16a7327ea8SSushil Singh${LOG_SERVICE} xyz.openbmc_project.Logging.service 17a7327ea8SSushil Singh 18a7327ea8SSushil Singh*** Test Cases *** 19a7327ea8SSushil Singh 20a7327ea8SSushil SinghVerify OpenBMC Services Auto Restart Policy 21a7327ea8SSushil Singh [Documentation] Kill active services and expect auto restart. 22a7327ea8SSushil Singh [Tags] Verify_OpenBMC_Services_Auto_Restart_Policy 23a7327ea8SSushil Singh # The services listed below restart policy should be "always" 24a7327ea8SSushil Singh # Command output: 25a7327ea8SSushil Singh # systemctl -p Restart show xyz.openbmc_project.Logging.service | cat 26a7327ea8SSushil Singh # Restart=always 27a7327ea8SSushil Singh @{services}= 28a7327ea8SSushil Singh ... Create List xyz.openbmc_project.Logging.service 29a7327ea8SSushil Singh ... xyz.openbmc_project.ObjectMapper.service 30a7327ea8SSushil Singh ... xyz.openbmc_project.State.BMC.service 31*d26c0643SAndrew Geissler ... xyz.openbmc_project.State.Chassis@0.service 32*d26c0643SAndrew Geissler ... xyz.openbmc_project.State.Host@0.service 33a125de8eSSushil Singh FOR ${SERVICE} IN @{services} 34a125de8eSSushil Singh Check Service Autorestart ${SERVICE} 35a125de8eSSushil Singh END 36a7327ea8SSushil Singh 37a7327ea8SSushil Singh 38a7327ea8SSushil SinghKill Services And Expect Service Restart 39a7327ea8SSushil Singh [Documentation] Kill the service and it must restart. 40a7327ea8SSushil Singh [Tags] Kill_Services_And_Expect_Service_Restart 41a7327ea8SSushil Singh 42a7327ea8SSushil Singh # Get the MainPID and service state. 43a7327ea8SSushil Singh ${MainPID}= Get Service Attribute MainPID ${LOG_SERVICE} 44a7327ea8SSushil Singh Should Not Be Equal ${0} ${MainPID} 45a7327ea8SSushil Singh ... msg=Logging service not restarted. 46a7327ea8SSushil Singh 47a7327ea8SSushil Singh ${ActiveState}= Get Service Attribute ActiveState ${LOG_SERVICE} 48a7327ea8SSushil Singh Should Be Equal active ${ActiveState} 49a7327ea8SSushil Singh ... msg=Logging Service not in active state. 50a7327ea8SSushil Singh 51a7327ea8SSushil Singh BMC Execute Command kill -9 ${MainPID} 52a7327ea8SSushil Singh Sleep 10s reason=Wait for service to restart. 53a7327ea8SSushil Singh 54a7327ea8SSushil Singh ${MainPID}= Get Service Attribute MainPID ${LOG_SERVICE} 55a7327ea8SSushil Singh Should Not Be Equal ${0} ${MainPID} 56a7327ea8SSushil Singh ... msg=Logging service not restarted. 57a7327ea8SSushil Singh 58a7327ea8SSushil Singh ${ActiveState}= Get Service Attribute ActiveState ${LOG_SERVICE} 59a7327ea8SSushil Singh Should Be Equal active ${ActiveState} 60a7327ea8SSushil Singh ... msg=Logging service not in active state. 61a7327ea8SSushil Singh 6286d85f4cSGeorge KeishingKill The List Of Services And Expect Killed Service Gets Restarted 6332d55427Sganesanb [Documentation] Kill the given services and expect again services get restarted automatically. 6432d55427Sganesanb [Tags] Kill_The_List_Of_Services_And_Expect_Killed_Service_Gets_Restarted 6532d55427Sganesanb 6632d55427Sganesanb # Create a list of services in respective server model python file 6732d55427Sganesanb # like romulus.py, witherspoon.py on openbmc-test-automation/data directory etc. 6832d55427Sganesanb # Example of creating a list of services in their respective server model python file 6932d55427Sganesanb # SERVICES = { 7032d55427Sganesanb # "BMC_SERVICES": ['xyz.openbmc_project.Logging.service', 'xyz.openbmc_project.ObjectMapper.service', 7132d55427Sganesanb # 'xyz.openbmc_project.State.BMC.service', 'xyz.openbmc_project.State.Chassis.service', 7232d55427Sganesanb # 'xyz.openbmc_project.State.Host.service'] 7332d55427Sganesanb 7432d55427Sganesanb @{auto_restart_policy_always_services}= Create List 7532d55427Sganesanb @{incorrect_auto_restart_policy_services}= Create List 7632d55427Sganesanb @{service_not_started}= Create List 7732d55427Sganesanb 7832d55427Sganesanb # Creating an list of services which needs to be validated. 7932d55427Sganesanb 8032d55427Sganesanb ${services}= Get Service Restart Policy Services ${OPENBMC_MODEL} 8132d55427Sganesanb ${service_list}= Get From Dictionary ${services} BMC_SERVICES 8232d55427Sganesanb ${length_services}= Get Length ${service_list} 8332d55427Sganesanb 8432d55427Sganesanb # From service list it will check service auto-restart policy 8532d55427Sganesanb # If incorrect those services will be appended to incorrect_auto_restart_policy_services list 8632d55427Sganesanb # Proper restart policy services will be appended to auto_restart_policy_always_services list. 8732d55427Sganesanb 8832d55427Sganesanb FOR ${service} IN @{service_list} 8932d55427Sganesanb ${service_status}= Run Keyword And Return Status Check Service Autorestart ${service} 9032d55427Sganesanb Run Keyword If ${service_status} == False 9132d55427Sganesanb ... Append To List ${incorrect_auto_restart_policy_services} ${service} 9232d55427Sganesanb ... ELSE 9332d55427Sganesanb ... Append To List ${auto_restart_policy_always_services} ${service} 9432d55427Sganesanb END 9532d55427Sganesanb 9632d55427Sganesanb ${length_incorrect_autorestart_policy}= Get Length ${incorrect_auto_restart_policy_services} 9732d55427Sganesanb Run Keyword If ${length_incorrect_autorestart_policy} != 0 and ${length_incorrect_autorestart_policy} == ${length_services} 9832d55427Sganesanb ... Run Keywords Log ${incorrect_auto_restart_policy_services} AND 9932d55427Sganesanb ... Fail msg=All the given services have incorrect auto-restart policy. 10032d55427Sganesanb ... ELSE IF ${length_incorrect_autorestart_policy} != 0 and ${length_incorrect_autorestart_policy} != ${length_services} 10132d55427Sganesanb ... Run Keywords Log ${incorrect_auto_restart_policy_services} AND 10232d55427Sganesanb ... Run Keyword And Continue On Failure Fail msg=Listed services are having incorrect auto-restart policy. 10332d55427Sganesanb 10432d55427Sganesanb # This will get process id and check the service active state before killing the services. 10532d55427Sganesanb # If service process id was 0 or service was not in active state then those services will get 10632d55427Sganesanb # appended to service_not_started list. 10732d55427Sganesanb # Only services with process ID and in active state get killed and checked whether 10832d55427Sganesanb # they automatically restart and put into active state. 10932d55427Sganesanb 11032d55427Sganesanb FOR ${service} IN @{auto_restart_policy_always_services} 11132d55427Sganesanb ${Old_MainPID}= Get Service Attribute MainPID ${service} 11232d55427Sganesanb ${ActiveState}= Get Service Attribute ActiveState ${service} 11332d55427Sganesanb ${main_pid_status}= Run Keyword And Return Status Should Not Be Equal ${0} ${Old_MainPID} 11432d55427Sganesanb ${active_state_status}= Run Keyword And Return Status Should Be Equal active ${ActiveState} 11532d55427Sganesanb Run Keyword If ${main_pid_status} == False or ${active_state_status} == False 11632d55427Sganesanb ... Run Keywords Append To List ${service_not_started} ${service} AND Continue For Loop 11732d55427Sganesanb 11832d55427Sganesanb BMC Execute Command kill -9 ${Old_MainPID} 11932d55427Sganesanb Sleep 10s reason=Wait for service to restart. 12032d55427Sganesanb 12132d55427Sganesanb ${New_MainPID}= Get Service Attribute MainPID ${service} 12232d55427Sganesanb Run Keyword And Continue On Failure Should Not Be Equal ${0} ${New_MainPID} 12332d55427Sganesanb ... msg=${service} service not restarted. 12432d55427Sganesanb Run Keyword And Continue On Failure Should Not Be Equal ${Old_MainPID} ${New_MainPID} 12532d55427Sganesanb ... msg=Old process ID is mapped to ${service} service after service restart.. 12632d55427Sganesanb 12732d55427Sganesanb ${ActiveState}= Get Service Attribute ActiveState ${service} 12832d55427Sganesanb Run Keyword And Continue On Failure Should Be Equal active ${ActiveState} 12932d55427Sganesanb ... msg=${service} service not in active state. 13032d55427Sganesanb END 13132d55427Sganesanb 13232d55427Sganesanb ${length_service_not_started}= Get Length ${service_not_started} 13332d55427Sganesanb ${incorrect_services}= Evaluate ${length_incorrect_autorestart_policy} + ${length_service_not_started} 13432d55427Sganesanb 13532d55427Sganesanb Run Keyword If ${incorrect_services} == ${length_services} and ${length_service_not_started} != 0 13632d55427Sganesanb ... Run Keywords Log ${service_not_started} AND Fail msg=All the services were either not started or not in active state by default. 13732d55427Sganesanb ... ELSE IF ${incorrect_services} != ${length_services} and ${length_service_not_started} != 0 13832d55427Sganesanb ... Run Keywords Log ${service_not_started} AND Fail msg=Few listed services were either not started or not in active state by default. 139a7327ea8SSushil Singh 140a7327ea8SSushil Singh*** Keywords *** 141a7327ea8SSushil Singh 142a7327ea8SSushil SinghCheck Service Autorestart 143a7327ea8SSushil Singh [Documentation] Check if given policy is "always". 144a7327ea8SSushil Singh [Arguments] ${servicename} 145a7327ea8SSushil Singh # servicename Qualified service name 146a7327ea8SSushil Singh ${restart_policy}= Get Service Attribute Restart ${servicename} 147a7327ea8SSushil Singh Should Be Equal always ${restart_policy} 148a7327ea8SSushil Singh ... msg=Incorrect policy for ${servicename} 149