Added bbsim verfication for ONU software upgrade

Change-Id: I612c6c1abf956e45b83fcdb52e387cb8d931adcc
diff --git a/libraries/bbsim.robot b/libraries/bbsim.robot
index ffcad0d..73b3f1f 100755
--- a/libraries/bbsim.robot
+++ b/libraries/bbsim.robot
@@ -98,3 +98,11 @@
     ...    bbsimctl olt restartServer ${delay}
     Log     ${res}
     Should Be Equal as Integers    ${rc}    0
+
+Verify ONU Device Image On BBSim
+    [Documentation]    Validates the state of ONU in case of Image Upgrade
+    [Arguments]    ${namespace}    ${bbsim_pod_name}    ${onu}    ${internal_state}
+    ${res}     ${rc}=    Exec Pod And Return Output And RC    ${namespace}    ${bbsim_pod_name}
+    ...    bbsimctl onu list | grep ${onu} | awk '{print $6}'
+    Should Be Equal as Integers    ${rc}    0
+    Should Be Equal    ${res}    ${internal_state}
diff --git a/tests/software-upgrades/ONU_Upgrade.robot b/tests/software-upgrades/ONU_Upgrade.robot
index 57a9450..a342d1c 100755
--- a/tests/software-upgrades/ONU_Upgrade.robot
+++ b/tests/software-upgrades/ONU_Upgrade.robot
@@ -30,6 +30,7 @@
 Resource          ../../libraries/voltha.robot
 Resource          ../../libraries/utils.robot
 Resource          ../../libraries/k8s.robot
+Resource          ../../libraries/bbsim.robot
 Resource          ../../variables/variables.robot
 
 *** Variables ***
@@ -74,6 +75,7 @@
     ...    Performs the sanity and verifies all the ONUs are authenticated/DHCP/pingable
     ...    Requirement: Pass image details in following parameters in the robot command
     ...    onu_image_name, onu_image_url, onu_image_version, onu_image_crc, onu_image_local_dir
+    ...    Note: The TC expects the image url and other parameters to be common for all ONUs on all BBSim
     ...    Check [VOL-3903] for more details
     [Tags]    functional   ONUUpgrade
     [Setup]    Start Logging    ONUUpgrade
@@ -85,9 +87,27 @@
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
     Run Keyword If    ${has_dataplane}    Clean Up Linux
     Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
+    FOR    ${J}    IN RANGE    0    ${num_olts}
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${J}][sn]
+        ${bbsim_rel}=    Catenate    SEPARATOR=    bbsim    ${J}
+        ${bbsim_pod}=    Get Pod Name By Label    ${NAMESPACE}    release     ${bbsim_rel}
+        Test ONU Upgrade Per OLT    ${bbsim_pod}    ${olt_serial_number}
+        List ONUs    ${NAMESPACE}    ${bbsim_pod}
+    END
+    # Additional Verification
+    Wait Until Keyword Succeeds    ${timeout}    2s    Delete All Devices and Verify
+    Setup
+    Run Keyword If    ${has_dataplane}    Clean Up Linux
+    Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
+
+*** Keywords ***
+Test ONU Upgrade Per OLT
+    [Documentation]    This keyword performs the ONU Upgrade test on single OLT
+    [Arguments]    ${bbsim_pod}    ${olt_serial_number}
     FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${dst}=    Set Variable    ${hosts.dst[${I}]}
+        Continue For Loop If    "${olt_serial_number}"!="${src['olt']}"
         ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
         Download ONU Device Image    ${onu_device_id}    ${onu_image_name}    ${onu_image_url}    ${onu_image_version}
         ...    ${onu_image_crc}    ${onu_image_local_dir}
@@ -105,15 +125,11 @@
         ...    ELSE    Sleep    180s
         Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image    ${onu_device_id}
         ...    DOWNLOAD_SUCCEEDED    IMAGE_ACTIVE    NO_ERROR
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image On BBSim    ${NAMESPACE}    ${bbsim_pod}
+        ...    ${src['onu']}    software_image_committed
         Wait Until Keyword Succeeds    ${timeout}    5s    Perform Sanity Test     ${suppressaddsubscriber}
     END
-    # Additional Verification
-    Wait Until Keyword Succeeds    ${timeout}    2s    Delete All Devices and Verify
-    Setup
-    Run Keyword If    ${has_dataplane}    Clean Up Linux
-    Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
 
-*** Keywords ***
 Setup Suite
     [Documentation]    Set up the test suite
     Common Test Suite Setup