[VOL-5536] fix vgc pipeline issues

Change-Id: I6a50276a598cb5d51d54ef499ada170a9a0fc438
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/libraries/utils_vgc.robot b/libraries/utils_vgc.robot
index 5c1e181..b6ae874 100755
--- a/libraries/utils_vgc.robot
+++ b/libraries/utils_vgc.robot
@@ -78,9 +78,15 @@
     ${num_all_onus}=    Get Length    ${hosts.src}
     ${num_all_onus}=    Convert to String    ${num_all_onus}
     #send sadis file to vgc
+    ${oltconfig_file}=    Get Variable Value    ${oltconfig.file}
+    ${oltconfig1_file}=    Get Variable Value    ${oltconfig1.file}
     ${sadis_file}=    Get Variable Value    ${sadis.file}
     Log To Console    \nSadis File:${sadis_file}
-    Run Keyword Unless    '${sadis_file}' == '${None}'    Send File To VGC    ${sadis_file}   # apps/
+    Log To Console    \noltconfig File:${oltconfig_file}
+    Log To Console    \noltconfig File:${oltconfig1_file}
+    Run Keyword Unless    '${oltconfig_file}' == '${None}'    Send File To VGC    ${oltconfig_file}    olt/BBSIM_OLT_10
+    Run Keyword Unless    '${oltconfig1_file}' == '${None}'    Send File To VGC    ${oltconfig1_file}    olt/BBSIM_OLT_11
+    Run Keyword Unless    '${sadis_file}' == '${None}'    Send File To VGC    ${sadis_file}    network-configurations   #apps/
     Set Suite Variable    ${num_all_onus}
     Set Suite Variable    ${num_olts}
     Set Suite Variable    ${list_olts}
diff --git a/libraries/vgc.robot b/libraries/vgc.robot
index b1bee31..8f116b3 100755
--- a/libraries/vgc.robot
+++ b/libraries/vgc.robot
@@ -64,6 +64,18 @@
     Should Be True    ${matched}    No match for ${serial_number} found
     [Return]    ${of_id}
 
+Verify meters response
+    [Arguments]    ${meter_json_resp}    ${us_cir}    ${us_cbs}
+     ${meter_json_Length}    Get Length    ${meter_json_resp['bands']}
+     FOR    ${I}    IN RANGE    0     ${meter_json_Length}
+         ${burst_size}=    Get From Dictionary    ${meter_json_resp['bands'][${I}]}    burstSize
+         ${rate}=        Get From Dictionary    ${meter_json_resp['bands'][${I}]}    rate
+         Log    ${rate}
+         Log    ${burst_size}
+         ${matched}=    Evaluate    '${rate}' == '${us_cir}' and '${burst_size}' == '${us_cbs}'
+         Exit For Loop If    ${matched}
+     END
+    [Return]    ${matched}
 
 
 Validate Deleted Device Cleanup In VGC
@@ -447,13 +459,13 @@
 Send File To VGC
     [Documentation]    Send the content of the file to VGC to selected section of configuration
     ...   using Post Request
-    [Arguments]    ${CONFIG_FILE}    #${section}=${EMPTY}
+    [Arguments]    ${CONFIG_FILE}    ${dest}    #${section}=${EMPTY}
     ${Headers}=    Create Dictionary    Content-Type    application/json
     ${File_Data}=    OperatingSystem.Get File    ${CONFIG_FILE}
     Log    ${Headers}
     Log    ${File_Data}
     ${resp}=    Post Request    VGC
-    ...    network-configurations    headers=${Headers}    data=${File_Data}
+    ...    ${dest}    headers=${Headers}    data=${File_Data}
     Should Be Equal As Strings    ${resp.status_code}    200
 
 Verify No Pending Flows For ONU
@@ -698,74 +710,46 @@
     Log    ${meters}
     ${meter_length}    Get Length    ${meters}
     FOR    ${i}    IN RANGE    ${meter_length}
-        ${id}=    Get From Dictionary    ${meters[${i}]}    id
-        Run Keyword If    '${id}' == '2'    Set Suite Variable    ${meter_json_resp}    ${meters[${i}]}
-    END
-    ${meter_json_Length}    Get Length    ${meter_json_resp['bands']}
-    FOR    ${I}    IN RANGE    0     ${meter_json_Length}
-        ${burst_size}=    Get From Dictionary    ${meter_json_resp['bands'][${I}]}    burstSize
-        ${rate}=        Get From Dictionary    ${meter_json_resp['bands'][${I}]}    rate
-        Log    ${rate}
-        Log    ${burst_size}
-        # for cir & cbs
-        ${matched}=    Set Variable If    '${rate}' == '${us_cir}' and '${burst_size}' == '${us_cbs}'   True    False
-        ${res1}=    Evaluate    '${rate}' == '${us_cir}' and '${burst_size}' == '${us_cbs}'
-        Exit For Loop If    ${matched}
+       ${matched}=    Verify meters response    ${meters[${i}]}    ${us_cir}    ${us_cbs}
+       Exit For Loop If    ${matched}
     END
     Should Be True    ${matched}
     #for pir & pbs
-    FOR    ${I}    IN RANGE    0     3
-        ${burst_size}=    Get From Dictionary    ${meter_json_resp['bands'][${I}]}    burstSize
-        ${rate}=        Get From Dictionary    ${meter_json_resp['bands'][${I}]}    rate
-        ${matched}=    Set Variable If    '${rate}' == '${us_pir}' and '${burst_size}' == '${us_pbs}'   True    False
-        ${res2}=    Evaluate    '${rate}' == '${us_pir}' and '${burst_size}' == '${us_pbs}'
-        Exit For Loop If    ${matched}
+    FOR    ${i}    IN RANGE    ${meter_length}
+       ${matched}=    Verify meters response    ${meters[${i}]}    ${us_pir}    ${us_pbs}
+       Exit For Loop If    ${matched}
     END
     Should Be True    ${matched}
     #for gir
-    Run Keyword if  ${us_gir} != 0    Validate Guarenteed Information Rate For FTTB    ${us_gir}  ${meter_json_resp}
-    # Get downstream bandwidth profile details
+    FOR    ${i}    IN RANGE    ${meter_length}
+        ${matched}=    Run Keyword if  ${us_gir} != 0    Validate Guarenteed Information Rate For FTTB    ${us_gir}  ${meters[${i}]}
+        Exit For Loop If    ${matched}
+    END
+    Should Be True    ${matched}
     ${ds_cir}    ${ds_cbs}    ${ds_pir}    ${ds_pbs}    ${ds_gir}    Get Bandwidth Profile Details Ietf Rest
     ...    ${ds_bw_profile}
     ${meter}=      Get Request    VGC    meters
     ${meter_json_resp}=    To Json   ${meter.content}
     Log    ${meter_json_resp}
-    Log    ${rate}
-    Log    ${burst_size}
-     ${meters}=    Get From Dictionary    ${meter_json_resp}    meters
-     Log    ${meter_json_resp}
-     Log    ${meters}
-     FOR    ${i}    IN RANGE    2
-         ${id}=    Get From Dictionary    ${meters[${i}]}    id
-         Run Keyword If    '${id}' == '2'    Set Suite Variable    ${meter_json_resp}    ${meters[${i}]}
-     END
-     FOR    ${I}    IN RANGE    0     3
-         ${burst_size}=    Get From Dictionary    ${meter_json_resp['bands'][${I}]}    burstSize
-         ${rate}=        Get From Dictionary    ${meter_json_resp['bands'][${I}]}    rate
-         Log    ${rate}
-         Log    ${burst_size}
-         # for cir & cbs
-         ${matched}=    Set Variable If    '${rate}' == '${ds_cir}' and '${burst_size}' == '${ds_cbs}'   True    False
-         ${res1}=    Evaluate    '${rate}' == '${ds_cir}' and '${burst_size}' == '${ds_cbs}'
-         Exit For Loop If    ${matched}
+    ${meters}=    Get From Dictionary    ${meter_json_resp}    meters
+    Log    ${meter_json_resp}
+    Log    ${meters}
+    FOR    ${i}    IN RANGE    ${meter_length}
+        ${matched}=    Verify meters response    ${meters[${i}]}    ${ds_cir}    ${ds_cbs}
+        Exit For Loop If    ${matched}
     END
     Should Be True    ${matched}
-
     # for cir & cbs
-      FOR    ${I}    IN RANGE    0     3
-          ${burst_size}=    Get From Dictionary    ${meter_json_resp['bands'][${I}]}    burstSize
-          ${rate}=        Get From Dictionary    ${meter_json_resp['bands'][${I}]}    rate
-          Log    ${rate}
-          Log    ${burst_size}
-          ${matched}=    Set Variable If    '${rate}' == '${ds_cir}' and '${burst_size}' == '${ds_cbs}'   True    False
-          ${res1}=    Evaluate    '${rate}' == '${ds_pir}' and '${burst_size}' == '${ds_pbs}'
-          Exit For Loop If    ${matched}
-     END
-     Should Be True    ${matched}
-    #for pir & pbs
-    #for gir
-    Run Keyword If    ${ds_gir} != 0
-    ...    Validate Guarenteed Information Rate For FTTB    ${ds_gir}  ${meter_json_resp}
+    FOR    ${i}    IN RANGE    ${meter_length}
+        ${matched}=    Verify meters response    ${meters[${i}]}    ${ds_pir}    ${ds_pbs}
+        Exit For Loop If    ${matched}
+    END
+    Should Be True    ${matched}
+    FOR    ${i}    IN RANGE    ${meter_length}
+        ${matched}=    Run Keyword if  ${us_gir} != 0    Validate Guarenteed Information Rate For FTTB    ${ds_gir}  ${meters[${i}]}
+        Exit For Loop If    ${matched}
+    END
+    Should Be True    ${matched}
 
 Validate Guarenteed Information Rate
      [Documentation]    Validate gir for both upstream and downstream meters
@@ -781,8 +765,9 @@
     [Arguments]    ${gir}    ${meter_json_resp}
     ${burst_size}=    Get From Dictionary    ${meter_json_resp['bands'][2]}    burstSize
     ${rate}=    Get From Dictionary    ${meter_json_resp['bands'][2]}    rate
-    ${matched}=    Set Variable If    '${rate}' == '${gir}' and '${burst_size}' == '0'  True    False
-    Should Be True    ${matched}
+#    ${matched}=    Set Variable If    '${rate}' == '${gir}' and '${burst_size}' == '0'  True    False
+    ${matched}=    Evaluate    ${rate} == ${gir} and ${burst_size} == 0
+#    Should Be True    ${matched}
     [Return]    ${matched}
 
 Get Bandwidth Profile Details Ietf Rest
diff --git a/tests/data/bbsim-kind-2OLTx2ONUx2PON_VGC.yaml b/tests/data/bbsim-kind-2OLTx2ONUx2PON_VGC.yaml
index a5fd993..7e99924 100755
--- a/tests/data/bbsim-kind-2OLTx2ONUx2PON_VGC.yaml
+++ b/tests/data/bbsim-kind-2OLTx2ONUx2PON_VGC.yaml
@@ -27,7 +27,8 @@
 
 # Actual Unused sadis.file but ready to future implementation
 sadis.file: ../data/dt-sadis-multiolt-config-vgc.json
-
+oltconfig.file: ../data/oltdeviceconfig.json
+oltconfig1.file: ../data/oltdeviceconfig_1.json
 
 nodes:
   -
diff --git a/tests/data/bbsim-kind-dt-fttb-1OLTx1PONx2ONUx2UNI.yaml b/tests/data/bbsim-kind-dt-fttb-1OLTx1PONx2ONUx2UNI.yaml
index d257a1e7..25e4b53 100644
--- a/tests/data/bbsim-kind-dt-fttb-1OLTx1PONx2ONUx2UNI.yaml
+++ b/tests/data/bbsim-kind-dt-fttb-1OLTx1PONx2ONUx2UNI.yaml
@@ -28,6 +28,7 @@
 
 # Actual Unused sadis.file but ready to future implementation
 sadis.file: ../data/dt-sadis-config-fttb-vgc.json
+oltconfig.file: ../data/oltdeviceconfig.json
 
 nodes:
   -
diff --git a/tests/data/bbsim-kind-dt-vgc.yaml b/tests/data/bbsim-kind-dt-vgc.yaml
index c28e98c..397db20 100755
--- a/tests/data/bbsim-kind-dt-vgc.yaml
+++ b/tests/data/bbsim-kind-dt-vgc.yaml
@@ -27,6 +27,7 @@
 
 # Actual Unused sadis.file but ready to future implementation
 sadis.file: ../data/dt-sadis-config.json
+oltconfig.file: ../data/oltdeviceconfig.json
 
 
 nodes:
diff --git a/tests/data/oltdeviceconfig.json b/tests/data/oltdeviceconfig.json
new file mode 100644
index 0000000..6cfd9b3
--- /dev/null
+++ b/tests/data/oltdeviceconfig.json
@@ -0,0 +1,9 @@
+{
+  "id": "BBSIM_OLT_10",
+  "nasId": "BBSIM_OLT_10",
+  "hardwareIdentifier": "28:b9:d9:e2:93:d6",
+  "uplinkPort": "16777216",
+  "nniDhcpTrapVid": 4,
+  "nniPorts":["16777216","16777217"]
+}
+
diff --git a/tests/data/oltdeviceconfig_1.json b/tests/data/oltdeviceconfig_1.json
new file mode 100755
index 0000000..a46d3da
--- /dev/null
+++ b/tests/data/oltdeviceconfig_1.json
@@ -0,0 +1,9 @@
+{
+  "id": "BBSIM_OLT_11",
+  "nasId": "BBSIM_OLT_11",
+  "hardwareIdentifier": "28:b9:d9:e2:93:d6",
+  "uplinkPort": "16777216",
+  "nniDhcpTrapVid": 4,
+  "nniPorts":["16777216","16777217"]
+}
+
diff --git a/tests/dt-workflow/Voltha_DT_FailureScenarios_VGC.robot b/tests/dt-workflow/Voltha_DT_FailureScenarios_VGC.robot
index f9bf40c..88f9b0a 100644
--- a/tests/dt-workflow/Voltha_DT_FailureScenarios_VGC.robot
+++ b/tests/dt-workflow/Voltha_DT_FailureScenarios_VGC.robot
@@ -284,8 +284,10 @@
         ...    ${dst['dp_iface_name']}    ${dst['ip']}    ${dst['user']}    ${dst['pass']}    ${dst['container_type']}
         ...    ${dst['container_name']}
     END
-    Restart VOLTHA Port Forward    voltha-api
-    ${port_fwd}    Start Process    kubectl -n voltha port-forward svc/${kafka} ${KAFKA_PORT}:${KAFKA_PORT} --address 0.0.0.0 &    shell=true
+    Restart VOLTHA Port Forward    voltha-api 55555:55555\
+    ${cmd}    Set Variable    ps -ef | grep -E "[k]ubectl.*-n[[:space:]]*voltha.*port-forward.*voltha-voltha-api.*55555:55555" | awk '{print $2}' | xargs -r kill -9
+    ${rc}    ${pid}    Run And Return Rc And Output    ${cmd}
+    ${port_fwd}    Start Process    kubectl -n voltha port-forward svc/${kafka} ${KAFKA_PORT}:${KAFKA_PORT} &    shell=true
 
 Verify OLT Soft Reboot for DT
     [Documentation]    Test soft reboot of the OLT using voltctl command
@@ -516,7 +518,9 @@
     # of now. And there is no other to check if the reconcile has happened for all the OLTs. Due to this limitations a
     # sleep of 60s is introduced to give enough time for rw core to reconcile the OLTs."
     Sleep   60s
-    ${port_fwd}    Start Process    kubectl -n voltha port-forward svc/${kafka} ${KAFKA_PORT}:${KAFKA_PORT} --address 0.0.0.0 &    shell=true
+    ${cmd}    Set Variable    ps -ef | grep -E "[k]ubectl.*-n[[:space:]]*voltha.*port-forward.*voltha-voltha-api.*55555:55555" | awk '{print $2}' | xargs -r kill -9
+    ${rc}    ${pid}    Run And Return Rc And Output    ${cmd}
+    ${port_fwd}    Start Process    kubectl -n voltha port-forward svc/${kafka} ${KAFKA_PORT}:${KAFKA_PORT} &    shell=true
     Verify Control Plane After Pod Restart DT
 
 *** Keywords ***