blob: 8f53c9b9bef5ee0b71a55e6c46358eaee807af65 [file] [log] [blame]
danielhanrahanf66694a2024-06-10 21:32:12 +01001/*
2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
19 */
20
21import http from 'k6/http';
halil.cakal1745d202024-08-06 14:02:49 +010022import { sleep } from 'k6';
23import {
24 NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES,
25 MODULE_SET_TAGS, CONTENT_TYPE_JSON_PARAM
26} from './utils.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010027import { executeCmHandleIdSearch } from './search-base.js';
danielhanrahanf66694a2024-06-10 21:32:12 +010028
halil.cakal1745d202024-08-06 14:02:49 +010029export function createCmHandles(cmHandleIds) {
danielhanrahanf66694a2024-06-10 21:32:12 +010030 const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`;
31 const payload = {
32 "dmiPlugin": DMI_PLUGIN_URL,
danielhanrahanb12d0c82024-08-15 12:42:21 +010033 "createdCmHandles": cmHandleIds.map((cmHandleId, index) => ({
danielhanrahanf66694a2024-06-10 21:32:12 +010034 "cmHandle": cmHandleId,
seanbeirne28559522024-07-19 16:55:06 +010035 "alternateId": `alt-${cmHandleId}`,
emacleef11aad92024-08-14 14:25:33 +010036 "moduleSetTag": MODULE_SET_TAGS[index % MODULE_SET_TAGS.length],
danielhanrahanf66694a2024-06-10 21:32:12 +010037 "cmHandleProperties": {"neType": "RadioNode"},
38 "publicCmHandleProperties": {
39 "Color": "yellow",
40 "Size": "small",
41 "Shape": "cube"
42 }
43 })),
44 };
danielhanrahan4e9f68c2024-06-28 13:43:35 +010045 const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM);
danielhanrahanf66694a2024-06-10 21:32:12 +010046 return response;
47}
48
halil.cakal1745d202024-08-06 14:02:49 +010049export function deleteCmHandles(cmHandleIds) {
danielhanrahanf66694a2024-06-10 21:32:12 +010050 const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`;
51 const payload = {
52 "dmiPlugin": DMI_PLUGIN_URL,
53 "removedCmHandles": cmHandleIds,
54 };
danielhanrahan4e9f68c2024-06-28 13:43:35 +010055 const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM);
danielhanrahanf66694a2024-06-10 21:32:12 +010056 return response;
57}
58
halil.cakal1745d202024-08-06 14:02:49 +010059export function waitForAllCmHandlesToBeReady() {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010060 const POLLING_INTERVAL_SECONDS = 5;
danielhanrahanf66694a2024-06-10 21:32:12 +010061 let cmHandlesReady = 0;
danielhanrahan4e9f68c2024-06-28 13:43:35 +010062 do {
63 sleep(POLLING_INTERVAL_SECONDS);
64 cmHandlesReady = getNumberOfReadyCmHandles();
65 console.log(`${cmHandlesReady}/${TOTAL_CM_HANDLES} CM handles are READY`);
66 } while (cmHandlesReady < TOTAL_CM_HANDLES);
danielhanrahanf66694a2024-06-10 21:32:12 +010067}
68
69function getNumberOfReadyCmHandles() {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010070 const response = executeCmHandleIdSearch('readyCmHandles');
71 const arrayOfCmHandleIds = JSON.parse(response.body);
72 return arrayOfCmHandleIds.length;
halil.cakal1745d202024-08-06 14:02:49 +010073}