fix etcd data check - part III
- delete onu etcd data in suite setup to ensure clean etcd data
- validate etcd in both teardown, test as well suite with Wait Until Keyword Succeeds
- add a flag to decide etcd check is executed in test or suite teardown
- some small further improvements

Change-Id: If323a0ce85e46fda46ed5aaa229788260df27c83
diff --git a/libraries/onu_utilities.robot b/libraries/onu_utilities.robot
index 2db750c..b19a9c4 100755
--- a/libraries/onu_utilities.robot
+++ b/libraries/onu_utilities.robot
@@ -234,6 +234,7 @@
         ${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
         ${oltpononuuniid}=    Read Pon Onu Uni String    ${tp_path}
         ${list_id}=    Get Index From List    ${oltpononuuniidlist}   ${oltpononuuniid}
@@ -368,6 +369,20 @@
     Should Be Equal As Integers    ${uni}    ${uni_id}
     ...    msg=Uni-Id (${uni_id}) does not match onu (${uni}) from tp_path in etcd data!
 
+Delete ONU Go Adapter ETCD Data
+    [Documentation]    This keyword deletes openonu-go-adapter Data stored in etcd
+    [Arguments]    ${defaultkvstoreprefix}=voltha_voltha    ${validate}=False
+    ${namespace}=    Set Variable    default
+    ${podname}=    Set Variable    etcd
+    ${kvstoreprefix}=    Get Kv Store Prefix    ${defaultkvstoreprefix}
+    ${commandget}=    Catenate
+    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/${kvstoreprefix}/openonu'
+    ${result}=    Exec Pod In Kube    ${namespace}    ${podname}    ${commandget}
+    log    ${result}
+    Run Keyword If    ${validate}    Wait Until Keyword Succeeds    ${timeout}    1s
+    ...    Validate Onu Data In Etcd    0    without_pm_data=False
+    [Return]    ${result}
+
 Wait for Ports in ONOS for all OLTs
     [Documentation]    Waits untill a certain number of ports are enabled in all OLTs
     [Arguments]    ${onos_ssh_connection}    ${count}    ${filter}    ${max_wait_time}=10m