danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
halil.cakal | 1745d20 | 2024-08-06 14:02:49 +0100 | [diff] [blame] | 21 | import { sleep } from 'k6'; |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 22 | import { performPostRequest, NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES, MODULE_SET_TAGS |
halil.cakal | 1745d20 | 2024-08-06 14:02:49 +0100 | [diff] [blame] | 23 | } from './utils.js'; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 24 | import { executeCmHandleIdSearch } from './search-base.js'; |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 25 | |
halil.cakal | 1745d20 | 2024-08-06 14:02:49 +0100 | [diff] [blame] | 26 | export function createCmHandles(cmHandleIds) { |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 27 | const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 28 | const payload = JSON.stringify(createCmHandlePayload(cmHandleIds)); |
| 29 | return performPostRequest(url, payload, 'createCmHandles'); |
| 30 | } |
| 31 | |
| 32 | export function deleteCmHandles(cmHandleIds) { |
| 33 | const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; |
| 34 | const payload = JSON.stringify({ |
| 35 | "dmiPlugin": DMI_PLUGIN_URL, |
| 36 | "removedCmHandles": cmHandleIds, |
| 37 | }); |
| 38 | return performPostRequest(url, payload, 'deleteCmHandles'); |
| 39 | } |
| 40 | |
| 41 | export function waitForAllCmHandlesToBeReady() { |
| 42 | const POLLING_INTERVAL_SECONDS = 5; |
| 43 | let cmHandlesReady = 0; |
| 44 | do { |
| 45 | sleep(POLLING_INTERVAL_SECONDS); |
| 46 | cmHandlesReady = getNumberOfReadyCmHandles(); |
| 47 | console.log(`${cmHandlesReady}/${TOTAL_CM_HANDLES} CM handles are READY`); |
| 48 | } while (cmHandlesReady < TOTAL_CM_HANDLES); |
| 49 | } |
| 50 | |
| 51 | function createCmHandlePayload(cmHandleIds) { |
| 52 | return { |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 53 | "dmiPlugin": DMI_PLUGIN_URL, |
danielhanrahan | b12d0c8 | 2024-08-15 12:42:21 +0100 | [diff] [blame] | 54 | "createdCmHandles": cmHandleIds.map((cmHandleId, index) => ({ |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 55 | "cmHandle": cmHandleId, |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 56 | "alternateId": cmHandleId.replace('ch-', 'alt-'), |
emaclee | f11aad9 | 2024-08-14 14:25:33 +0100 | [diff] [blame] | 57 | "moduleSetTag": MODULE_SET_TAGS[index % MODULE_SET_TAGS.length], |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 58 | "cmHandleProperties": {"neType": "RadioNode"}, |
| 59 | "publicCmHandleProperties": { |
| 60 | "Color": "yellow", |
| 61 | "Size": "small", |
| 62 | "Shape": "cube" |
| 63 | } |
| 64 | })), |
| 65 | }; |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | function getNumberOfReadyCmHandles() { |
danielhanrahan | a9de166 | 2024-09-21 16:47:43 +0100 | [diff] [blame] | 69 | const response = executeCmHandleIdSearch('cps-path-for-ready-cm-handles'); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 70 | const arrayOfCmHandleIds = JSON.parse(response.body); |
| 71 | return arrayOfCmHandleIds.length; |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 72 | } |