[VOL-4543] Added ONU Software Upgrade in Scale Test Suite

Change-Id: I8fdfee238b45ed3dd548700576a0c6d489e1530f
diff --git a/Makefile b/Makefile
index 539a3e4..3c1b58e 100755
--- a/Makefile
+++ b/Makefile
@@ -77,6 +77,12 @@
 voltha-scale: ROBOT_MISC_ARGS += -i activation -v NAMESPACE:voltha $(ROBOT_DEBUG_LOG_OPT)
 voltha-scale: voltha-scale-test
 
+# for onu-upgrade scale pipeline
+# Requirement: Pass ONU image details in following parameters
+# image_version, image_url, image_vendor, image_activate_on_success, image_commit_on_success, image_crc
+voltha-scale-onu-upgrade: ROBOT_MISC_ARGS += -i setup -i activation -i onu-upgrade -v NAMESPACE:voltha -v image_version:BBSM_IMG_00002 -v image_url:http://bbsim0:50074/images/software-image.img -v image_vendor:BBSM -v image_activate_on_success:false -v image_commit_on_success:false -v image_crc:0 $(ROBOT_DEBUG_LOG_OPT)
+voltha-scale-onu-upgrade: voltha-scale-test
+
 # target to invoke DT Workflow Sanity
 sanity-kind-dt: ROBOT_MISC_ARGS += -i sanityDt $(ROBOT_DEBUG_LOG_OPT)
 sanity-kind-dt: ROBOT_CONFIG_FILE := $(ROBOT_SANITY_DT_SINGLE_PON_FILE)
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index 4301379..2a85e95 100755
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -144,6 +144,14 @@
     Log    ${devices}
     Should Be Equal As Integers    ${rc1}    0
 
+Get ONUs Device IDs from Voltha
+    [Documentation]    Fetches the ONU Device Ids from Voltha
+    ${rc}    ${onus}=    Run and Return Rc and Output
+    ...    voltctl -c ${VOLTCTL_CONFIG} device list -m 32MB -f Type=brcm_openomci_onu -q
+    Should Be Equal as Integers    ${rc}    0
+    @{onuDevList}=    Split To Lines    ${onus}
+    [Return]    ${onuDevList}
+
 Get Device List from Voltha by type
     [Documentation]    Gets Device List Output from Voltha applying filtering by device type
     [Arguments]  ${type}
diff --git a/tests/scale/Voltha_Scale_Tests.robot b/tests/scale/Voltha_Scale_Tests.robot
index 93a31e4..9417038 100755
--- a/tests/scale/Voltha_Scale_Tests.robot
+++ b/tests/scale/Voltha_Scale_Tests.robot
@@ -86,6 +86,14 @@
 
 ${timeout}    10m
 
+# ONU Image to test for Upgrade needs to be passed in the following format:
+${image_version}    BBSM_IMG_00002
+${image_url}    http://bbsim0:50074/images/software-image.img
+${image_vendor}    BBSM
+${image_activate_on_success}    false
+${image_commit_on_success}    false
+${image_crc}    0
+
 *** Test Cases ***
 
 Create and Enable devices
@@ -158,6 +166,71 @@
         Wait for AAA Authentication     ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}  ${total_onus_per_olt}   ${deviceId}
     END
 
+Image Download and Validation during ONUs Software Upgrade
+    [Documentation]    Validates the Download Image step in ONU Upgrade process
+    ...    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: Expects the image url and other parameters to be common for all ONUs on all BBSim
+    [Tags]    onu-upgrade    onu-upgrade-image-download
+    ${onu_device_ids}=    Get ONUs Device IDs from Voltha
+    FOR    ${onu_device_id}    IN    @{onu_device_ids}
+        Download ONU Device Image    ${image_version}    ${image_url}    ${image_vendor}
+        ...    ${image_activate_on_success}    ${image_commit_on_success}
+        ...    ${image_crc}    ${onu_device_id}
+    END
+    ${imageState}=    Run Keyword If    '${image_activate_on_success}'=='true' and '${image_commit_on_success}'=='false'
+    ...    Set Variable    IMAGE_ACTIVE
+    ...    ELSE IF    '${image_activate_on_success}'=='true' and '${image_commit_on_success}'=='true'
+    ...    Set Variable    IMAGE_COMMITTED
+    ...    ELSE    Set Variable    IMAGE_INACTIVE
+    ${activated}=    Set Variable If    '${image_activate_on_success}'=='true'    True    False
+    ${committed}=    Set Variable If    '${image_activate_on_success}'=='true' and '${image_commit_on_success}'=='true'
+    ...    True    False
+    FOR    ${onu_device_id}    IN    @{onu_device_ids}
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image Status    ${image_version}
+        ...    ${onu_device_id}    DOWNLOAD_SUCCEEDED    NO_ERROR    ${imageState}
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image List    ${onu_device_id}
+        ...    ${image_version}    ${committed}    ${activated}    True
+    END
+
+Image Activation and Validation during ONUs Software Upgrade
+    [Documentation]    Validates the Activate Image step in ONU Upgrade process
+    ...    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: Expects the image url and other parameters to be common for all ONUs on all BBSim
+    [Tags]    onu-upgrade    onu-upgrade-image-activate
+    Pass Execution If    '${image_activate_on_success}'=='true'    Skipping test: Image activated in download stage
+    ${onu_device_ids}=    Get ONUs Device IDs from Voltha
+    FOR    ${onu_device_id}    IN    @{onu_device_ids}
+        Activate ONU Device Image    ${image_version}    ${image_commit_on_success}    ${onu_device_id}
+    END
+    ${imageState}=    Set Variable If    '${image_commit_on_success}'=='true'    IMAGE_COMMITTED    IMAGE_ACTIVE
+    ${committed}=    Set Variable If    '${image_commit_on_success}'=='true'    True    False
+    FOR    ${onu_device_id}    IN    @{onu_device_ids}
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image Status    ${image_version}
+        ...    ${onu_device_id}    DOWNLOAD_SUCCEEDED    NO_ERROR    ${imageState}
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image List    ${onu_device_id}
+        ...    ${image_version}    ${committed}    True    True
+    END
+
+Image Commit and Validation during ONUs Software Upgrade
+    [Documentation]    Validates the Commit Image step in ONU Upgrade process
+    ...    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: Expects the image url and other parameters to be common for all ONUs on all BBSim
+    [Tags]    onu-upgrade    onu-upgrade-image-commit
+    Pass Execution If    '${image_commit_on_success}'=='true'    Skipping test: Image committed in download or activate stage
+    ${onu_device_ids}=    Get ONUs Device IDs from Voltha
+    FOR    ${onu_device_id}    IN    @{onu_device_ids}
+        Commit ONU Device Image    ${image_version}    ${onu_device_id}
+    END
+    FOR    ${onu_device_id}    IN    @{onu_device_ids}
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image Status    ${image_version}
+        ...    ${onu_device_id}    DOWNLOAD_SUCCEEDED    NO_ERROR    IMAGE_COMMITTED
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image List    ${onu_device_id}
+        ...    ${image_version}    True    True    True
+    END
+
 Provision subscribers
     [Documentation]    Provision data plane flows for all the subscribers
     [Tags]      provision
@@ -311,4 +384,3 @@
     FOR    ${onu}    IN    @{onu_list}
         JoinOrLeave Igmp Rest Based    ${bbsim_rel_session}    ${onu}    ${task}    224.0.0.22
     END
-