Code support to check CPU and OCC count match check

Changes:
    - Get CPU functional count
    - Get OCC active count
    - Match CPU and OCC count

Change-Id: Ie1f1fd1e0b058c4cec6c06da5291ce89ee5a8a76
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/open_power_utils.robot b/lib/open_power_utils.robot
index bcc37bd..d6c05e7 100644
--- a/lib/open_power_utils.robot
+++ b/lib/open_power_utils.robot
@@ -5,6 +5,10 @@
 Resource       ../lib/utils.robot
 Resource       ../lib/connection_client.robot
 
+*** Variables ***
+${functional_cpu_count}       ${0}
+${active_occ_count}           ${0}
+
 *** Keywords ***
 
 Get OCC Objects
@@ -74,6 +78,49 @@
     [Return]  ${content["data"]}
 
 
+Get Functional Processor Count
+    [Documentation]  Get functional processor count.
+
+    ${cpu_list}=  Redfish.Get Members List  /redfish/v1/Systems/system/Processors/  *cpu*
+
+    FOR  ${endpoint_path}  IN  @{cpu_list}
+       # {'Health': 'OK', 'State': 'Enabled'} get only matching status good.
+       ${cpu_status}=  Redfish.Get Attribute  ${endpoint_path}  Status
+       Continue For Loop If  '${cpu_status['Health']}' != 'OK' or '${cpu_status['State']}' != 'Enabled'
+       ${functional_cpu_count} =  Evaluate   ${functional_cpu_count} + 1
+    END
+
+    [Return]  ${functional_cpu_count}
+
+
+Get Active OCC State Count
+    [Documentation]  Get active OCC state count.
+
+    ${cpu_list}=  Redfish.Get Members List  /redfish/v1/Systems/system/Processors/  *cpu*
+
+    FOR  ${endpoint_path}  IN  @{cpu_list}
+       ${num}=  Set Variable  ${endpoint_path[-1]}
+       ${cmd}=  Catenate  busctl get-property org.open_power.OCC.Control
+       ...   /org/open_power/control/occ${num} org.open_power.OCC.Status OccActive
+
+       ${cmd_output}  ${stderr}  ${rc} =  BMC Execute Command  ${cmd}
+       ...  print_out=1  print_err=1  ignore_err=1
+
+       # The command returns format  'b true'
+       Continue For Loop If   '${cmd_output.split(' ')[-1]}' != 'true'
+       ${active_occ_count} =  Evaluate   ${active_occ_count} + 1
+    END
+
+    [Return]  ${active_occ_count}
+
+
+Match OCC And CPU State Count
+    ${cpu_count}=  Get Functional Processor Count
+    ${occ_count}=  Get Active OCC State Count
+    Should Be Equal  ${occ_count}  ${cpu_count}
+    ...  msg=OCC count ${occ_count} and CPU Count ${cpu_count} mismatched.
+
+
 Verify OCC State
     [Documentation]  Check OCC active state.
     [Arguments]  ${expected_occ_active}=${1}