[VOL-4198] Validate for presence of resource instance now that tech profile instance does not exist

Change-Id: I6e8a0ab8bf0c3909b0afb9c89f6a0265cbc96de4
diff --git a/libraries/onu_utilities.robot b/libraries/onu_utilities.robot
index 5a7fdfb..8b9586d 100755
--- a/libraries/onu_utilities.robot
+++ b/libraries/onu_utilities.robot
@@ -14,6 +14,7 @@
 
 *** Settings ***
 Documentation     Library for various openonu-go-adpter utilities
+Library           grpc_robot.VolthaTools     WITH NAME    volthatools
 
 
 *** Keywords ***
@@ -215,6 +216,47 @@
     ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/technology_profiles/XGS-PON/64'
     Exec Pod In Kube    ${namespace}    ${podname}    ${commandget}
 
+Validate Resource Instances Used Gem Ports
+    [Documentation]    This keyword validates resource instances data stored in etcd.
+    ...                It checks checks the number of gemport-ids which has matched with used Tech Profile
+    [Arguments]    ${nbofgemports}    ${defaultkvstoreprefix}=voltha_voltha
+    ${kvstoreprefix}=    Get Kv Store Prefix    ${defaultkvstoreprefix}
+    ${etcddata}=    Get ONU Go Adapter ETCD Data    ${kvstoreprefix}
+    #prepare result for json convert
+    ${result}=    Prepare ONU Go Adapter ETCD Data For Json    ${etcddata}
+    ${jsondata}=    To Json    ${result}
+    ${length}=    Get Length    ${jsondata}
+    log    ${jsondata}
+    FOR    ${INDEX}    IN RANGE    0    ${length}
+        ${value}=    Get From List    ${jsondata}    ${INDEX}
+        # TODO: The TP ID is hardcoded to 64 below. It is fine when testing single-tcont workflow.
+        # When testing multi-tcont this may need some adjustment.
+        Exit For Loop If    not ('uni_config' in $value)
+        ${tp_path}=    Get From Dictionary    ${value['uni_config'][0]['PersTpPathMap']}    64
+        ${resourcedata}=    Get Resource Instances ETCD Data    ${tp_path}    ${kvstoreprefix}
+        log    ${resourcedata}
+        ${decoderesult}=    volthatools.Tech Profile Decode Resource Instance    ${resourcedata}    return_default=true
+        log    ${decoderesult}
+        ${gemportids}=    Get From Dictionary    ${decoderesult}    gemport_ids
+        ${length}=    Get Length    ${gemportids}
+        Should Be Equal As Integers    ${nbofgemports}    ${length}
+        ...    msg=Number of gem ports (${length}) does not match with techprofile ${techprofile}/${nbofgemports}
+    END
+
+Get Resource Instances ETCD Data
+    [Documentation]    This keyword delivers Resource Instances Data stored in etcd
+    [Arguments]    ${tppath}    ${defaultkvstoreprefix}=voltha_voltha
+    ${namespace}=    Set Variable    default
+    ${podname}=    Set Variable    etcd
+    ${kvstoreprefix}=    Get Kv Store Prefix    ${defaultkvstoreprefix}
+    ${commandget}=    Catenate
+    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/${kvstoreprefix}/resource_instances/${tppath}
+    ...    --print-value-only --hex'
+    ${result}=    Exec Pod In Kube    ${namespace}    ${podname}    ${commandget}
+    log    ${result}
+    [Return]    ${result}
+
+
 Validate Onu Data In Etcd
     [Documentation]    This keyword validates openonu-go-adapter Data stored in etcd.
     ...                It checks unique of  serial_number and combination of pon, onu and uni in tp_path.
diff --git a/requirements.txt b/requirements.txt
index f51b693..f24cad4 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,9 +13,9 @@
 virtualenv
 matplotlib>=3.0.3
 requests==2.24.0
-grpc-robot>=2.7.0
+grpc-robot>=2.9.3
 kafka-robot>=2.3.2
-voltha-protos>=4.0.16
+voltha-protos>=4.2.0
 protobuf>=3.15.7
 protobuf3-to-dict>=0.1.5
 device-management-interface>=0.13.0
\ No newline at end of file
diff --git a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
index 938f27d..ba3c207 100755
--- a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
@@ -445,6 +445,7 @@
     ${num_of_expected_matches}=    Set Variable If    "${techprofile}"!="default" or ${length}>0    1    0
     Should Be Equal As Integers    ${num_of_expected_matches}    ${num_of_count_matches}
     ...    TechProfile (${TechProfile}) not loaded correctly: found(${num_of_count_matches}) expected(${num_of_expected_matches})
+    Validate Resource Instances Used Gem Ports    ${num_gem_ports}    defaultkvstoreprefix=${kvstoreprefix}
 
 Do Disable Enable Onu Test
     [Documentation]    This keyword disables/enables all onus and checks the states.