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