1*** Settings ***
2Documentation   Find services and service agents on the system.
3Library         OperatingSystem
4Library         Collections
5Library         String
6
7Resource        ../lib/utils.robot
8
9# Get the SLP services available, make it suite global.
10Suite Setup     Suite Setup Execution
11
12Test Tags  SLP_Service_Test
13
14*** Variables ***
15${service_types}    findsrvtypes
16${service_agents}   findsrvs
17${service_path}     /etc/slp/services
18# SLP_SERVICES  Services listed by slptool, by default Empty.
19${SLP_SERVICES}       ${EMPTY}
20
21*** Test Cases ***
22
23Verify SLP Service Types
24    [Documentation]  Find services supported by system.
25    [Tags]  Verify_SLP_Service_Types
26    Verify Service Types
27
28Verify Service Agents For Service Types
29    [Documentation]  Find And verify service agents.
30    [Tags]  Verify_Service_Agents_For_Service_Types
31
32    @{parameters}=  Split String  ${SLP_SERVICES}  ${\n}
33
34    FOR  ${parameter}  IN  @{parameters}
35      ${output}=  Run SLP command  ${service_agents}  ${parameter}
36      Verify Service Agents  ${output}  ${parameter}
37    END
38
39*** Keywords ***
40
41Suite Setup Execution
42    [Documentation]  Get SLP services.
43    ${output}=  Run  which slptool
44    Should Not Be Empty  ${output}
45    ...  msg=slptool not installed.
46    ${SLP_SERVICES}=  Run SLP command  ${service_types}
47    Set Suite Variable  ${SLP_SERVICES}
48
49Run SLP Command
50    [Documentation]  Run SLPTool command and return output.
51    [Arguments]      ${cmd}  ${param}=${EMPTY}
52    # cmd    The SLP command to be run.
53    # param  The SLP command parameters.
54
55    ${rc}  ${output}=  Run And Return Rc And Output
56    ...   slptool -u ${OPENBMC_HOST} ${cmd} ${param}
57    Should Be Equal As Integers  ${rc}  0
58    RETURN  ${output}
59
60Verify Service Types
61    [Documentation]  Verifies the output of service types.
62
63    ${remove_prefix}=  Remove String  ${SLP_SERVICES}  service:
64    @{services}=  Split String  ${remove_prefix}  ${\n}
65    ${service_count}=  Get Length  ${services}
66    Open Connection And Log In
67    ${stdout}  ${stderr}=  Execute Command  ls ${service_path}
68    ...  return_stderr=True
69    Should Be Empty  ${stderr}
70    ${file_count}=  Get Line Count  ${stdout}
71    Should Be Equal  ${service_count}  ${file_count}
72    ...  msg=Number of services on system & command are not equal.
73
74    FOR  ${service}  IN  @{services}
75      Should Contain  ${stdout}  ${service}  msg=Services on system & command are not same.
76    END
77
78Verify Service Agents
79    [Documentation]  Verifies the output of srvs.
80    [Arguments]      ${output}  ${service_agent}
81    # Example of output
82    # <service:service_name:tcp//xxx.xxx.xxx.xxx,2200>
83
84    Run Keywords  Should Contain  ${output}  ${service_agent}  AND
85    ...  Should Contain  ${output}  ${OPENBMC_HOST},
86    ...  msg=Expected process info missing.
87
88