[k6] Refactoring k6 tests (#1)

This commit moves all common request logic into a common folder.
It is needed to avoid duplication before adding JVM warmup phase.

- move registration-related code into common folder
- move passthrough operations into common folder

Issue-ID: CPS-2208
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ia9ebf61d21044b43063bde153f9c526e67d607c8
diff --git a/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js b/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
index 5d54c60..cce85ab 100644
--- a/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
+++ b/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
@@ -18,9 +18,8 @@
  *  ============LICENSE_END=========================================================
  */
 
-import http from 'k6/http';
-import { sleep, fail } from 'k6';
-import { makeCustomSummaryReport, NCMP_BASE_URL, TOTAL_CM_HANDLES } from './utils.js';
+import { makeCustomSummaryReport } from './common/utils.js';
+import { waitForCmHandlesToBeReady } from './common/cmhandle-crud.js';
 
 export const options = {
     vus: 1,
@@ -32,35 +31,8 @@
 };
 
 export default function () {
-    waitForCmHandlesToBeReady(TOTAL_CM_HANDLES);
-}
-
-function waitForCmHandlesToBeReady(totalCmHandles) {
     const timeOutInSeconds = 6 * 60;
-    const pollingIntervalInSeconds = 10;
-    const maxRetries = Math.ceil(timeOutInSeconds / pollingIntervalInSeconds);
-    let cmHandlesReady = 0;
-    for (let currentTry = 0; currentTry <= maxRetries; currentTry++) {
-        sleep(pollingIntervalInSeconds);
-        try {
-            cmHandlesReady = getNumberOfReadyCmHandles();
-        } catch (error) {
-            console.error(`Attempt ${currentTry + 1} - Error fetching CM handles: ${error.message}`);
-        }
-        console.log(`Attempt ${currentTry + 1} - ${cmHandlesReady}/${totalCmHandles} CM handles are READY`);
-        if (cmHandlesReady === totalCmHandles) {
-            console.log(`All ${totalCmHandles} CM handles are READY`);
-            return;
-        }
-    }
-    fail(`Timed out after ${timeoutInSeconds} seconds waiting for ${totalCmHandles} CM handles to be READY`);
-}
-
-function getNumberOfReadyCmHandles() {
-    const endpointUrl = `${NCMP_BASE_URL}/cps/api/v2/dataspaces/NCMP-Admin/anchors/ncmp-dmi-registry/node?xpath=/dmi-registry&descendants=all`;
-    const jsonData = http.get(endpointUrl).json();
-    const cmHandles = jsonData[0]["dmi-reg:dmi-registry"]["cm-handles"];
-    return cmHandles.filter(cmhandle => cmhandle['state']['cm-handle-state'] === 'READY').length;
+    waitForCmHandlesToBeReady(timeOutInSeconds);
 }
 
 export function handleSummary(data) {