Add retry mechanism instead of sleep

- replaced sleeps with retry mechanism
- removed unnecessary sleeps before polling
- changed formatting

Issue-ID: CPS-1093
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I7e26570eeedea09fd36f9c9bce87c4cd45906aa9
diff --git a/csit/tests/cps-data-sync/cps-data-sync.robot b/csit/tests/cps-data-sync/cps-data-sync.robot
index 71de4be..c0ee4da 100644
--- a/csit/tests/cps-data-sync/cps-data-sync.robot
+++ b/csit/tests/cps-data-sync/cps-data-sync.robot
@@ -34,20 +34,40 @@
 ${ncmpBasePath}           /ncmp
 
 *** Test Cases ***
+
+Check if ietfYang-PNFDemo is READY
+    ${uri}=        Set Variable       ${ncmpBasePath}/v1/ch/ietfYang-PNFDemo
+    ${headers}=    Create Dictionary  Authorization=${auth}
+    Wait Until Keyword Succeeds       10sec    100ms    Is CM Handle READY    ${uri}    ${headers}    ietfYang-PNFDemo
+
 Operational state goes to UNSYNCHRONIZED when data sync (flag) is enabled
     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/ietfYang-PNFDemo/data-sync
     ${params}=           Create Dictionary  dataSyncEnabled=true
     ${headers}=          Create Dictionary  Authorization=${auth}
     ${response}=         PUT On Session     CPS_URL   ${uri}   params=${params}   headers=${headers}
     Should Be Equal As Strings              ${response.status_code}   200
-    ${verifyUri}=              Set Variable       ${ncmpBasePath}/v1/ch/ietfYang-PNFDemo/state
-    ${verifyHeaders}=          Create Dictionary  Authorization=${auth}
-    ${verifyResponse}=         GET On Session     CPS_URL   ${verifyUri}   headers=${verifyHeaders}
-    Should Be Equal As Strings                    ${verifyResponse.json()['state']['dataSyncState']['operational']['syncState']}   UNSYNCHRONIZED
-    Sleep    5
+    ${verifyUri}=        Set Variable       ${ncmpBasePath}/v1/ch/ietfYang-PNFDemo/state
+    ${verifyHeaders}=    Create Dictionary  Authorization=${auth}
+    ${verifyResponse}=   GET On Session     CPS_URL   ${verifyUri}   headers=${verifyHeaders}
+    Should Be Equal As Strings    ${verifyResponse.json()['state']['dataSyncState']['operational']['syncState']}   UNSYNCHRONIZED
 
 Operational state goes to SYNCHRONIZED after sometime when data sync (flag) is enabled
-    ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/ietfYang-PNFDemo/state
-    ${headers}=          Create Dictionary  Authorization=${auth}
-    ${response}=         GET On Session     CPS_URL   ${uri}   headers=${headers}
-    Should Be Equal As Strings              ${response.json()['state']['dataSyncState']['operational']['syncState']}   SYNCHRONIZED
\ No newline at end of file
+    ${uri}=        Set Variable       ${ncmpBasePath}/v1/ch/ietfYang-PNFDemo/state
+    ${headers}=    Create Dictionary  Authorization=${auth}
+    Wait Until Keyword Succeeds    10sec    100ms    Is CM Handle State SYNCHRONIZED    ${uri}    ${headers}
+
+*** Keywords ***
+Is CM Handle READY
+    [Arguments]    ${uri}    ${headers}    ${cmHandle}
+    ${response}=    GET On Session    CPS_URL    ${uri}    headers=${headers}
+    Should Be Equal As Strings    ${response.status_code}    200
+    FOR  ${item}  IN  ${response.json()}
+            IF  "${item['cmHandle']}" == "${cmHandle}"
+                Should Be Equal As Strings    ${item['state']['cmHandleState']}    READY
+            END
+    END
+
+Is CM Handle State SYNCHRONIZED
+    [Arguments]    ${uri}    ${headers}
+    ${response}=   GET On Session     CPS_URL    ${uri}    headers=${headers}
+    Should Be Equal As Strings        ${response.json()['state']['dataSyncState']['operational']['syncState']}    SYNCHRONIZED