mirror of
				https://github.com/Telecominfraproject/wlan-testing.git
				synced 2025-10-31 10:57:50 +00:00 
			
		
		
		
	make start_reservation.py take arbitrary inputs (#360)
Signed-off-by: Max Brenner <xamrennerb@gmail.com>
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/workflows/quali-advanced.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/quali-advanced.yml
									
									
									
									
										vendored
									
									
								
							| @@ -117,7 +117,7 @@ jobs: | ||||
|  | ||||
|     - name: start reservation | ||||
|       run: | | ||||
|         python wlan-testing/.quali/start_reservation.py --openwifi-version "${{ needs.vars.outputs.openwifi_revision }}" --ap-model "${{ matrix.ap_model }}" --blueprint "Advance Lab" | ||||
|         python wlan-testing/.quali/start_reservation.py --global-inputs '{"Chart Version":"${{ needs.vars.outputs.openwifi_revision }}","AP Model":"${{ matrix.ap_model }}"}' --reservation-duration 720 "Advance Lab" | ||||
|  | ||||
|     - name: set reservation outputs | ||||
|       if: always() | ||||
|   | ||||
							
								
								
									
										2
									
								
								.github/workflows/quali-basic-manual.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/quali-basic-manual.yml
									
									
									
									
										vendored
									
									
								
							| @@ -88,7 +88,7 @@ jobs: | ||||
|         CLOUDSHELL_USER: ${{ secrets.CLOUDSHELL_USER }} | ||||
|         CLOUDSHELL_PASSWORD: ${{ secrets.CLOUDSHELL_PASSWORD }} | ||||
|       run: | | ||||
|         python .quali/start_reservation.py --openwifi-version "${{ github.event.inputs.openwifi_revision }}" --ap-model "${{ github.event.inputs.ap_model }}" | ||||
|         python .quali/start_reservation.py --global-inputs '{"Chart Version":"${{ github.event.inputs.openwifi_revision }}","AP Model":"${{ github.event.inputs.ap_model }}"}' "Basic Lab" | ||||
|  | ||||
|     - name: set reservation outputs | ||||
|       if: always() | ||||
|   | ||||
							
								
								
									
										2
									
								
								.github/workflows/quali.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/quali.yml
									
									
									
									
										vendored
									
									
								
							| @@ -102,7 +102,7 @@ jobs: | ||||
|  | ||||
|     - name: start reservation | ||||
|       run: | | ||||
|         python .quali/start_reservation.py --openwifi-version "${{ needs.vars.outputs.openwifi_revision }}" --ap-model "${{ matrix.ap_model }}" | ||||
|         python .quali/start_reservation.py --global-inputs '{"Chart Version":"${{ needs.vars.outputs.openwifi_revision }}","AP Model":"${{ matrix.ap_model }}"}' "Basic Lab" | ||||
|  | ||||
|     - name: set reservation outputs | ||||
|       if: always() | ||||
|   | ||||
| @@ -12,25 +12,30 @@ def get_session() -> CloudShellAPISession: | ||||
|  | ||||
|     return CloudShellAPISession(url, user, password, "Global") | ||||
|  | ||||
| def __wait_for_status(session, res_id, field, target_status): | ||||
| def __wait_for_status(session, res_id, field, target_statuses=[], exit_statuses=[]): | ||||
|     timer = 0 | ||||
|     sleep_time = 5 | ||||
|     while True: | ||||
|         status = session.GetReservationStatus(res_id).ReservationSlimStatus.__dict__[field] | ||||
|  | ||||
|         if status == target_status: | ||||
|         if status in target_statuses: | ||||
|             print(f'reached target status: {status}') | ||||
|             break | ||||
|  | ||||
|         if status in exit_statuses: | ||||
|             print(f'reached exit status: {status}') | ||||
|             exit(1) | ||||
|  | ||||
|         print(f'current reservation status: {status}') | ||||
|  | ||||
|         if timer >= TIMEOUT: | ||||
|             raise RuntimeError(f'waiting for reservation to reach status {target_status} timed out') | ||||
|             raise RuntimeError(f'waiting for reservation to reach one of {target_statuses} or {exit_statuses} statuses timed out') | ||||
|  | ||||
|         time.sleep(sleep_time) | ||||
|         timer += sleep_time | ||||
|  | ||||
| def wait_for_provisioning_status(session, res_id, target_status): | ||||
|     __wait_for_status(session, res_id, 'ProvisioningStatus', target_status) | ||||
| def wait_for_provisioning_status(session, res_id, target_statuses, exit_statuses=[]): | ||||
|     __wait_for_status(session, res_id, 'ProvisioningStatus', target_statuses, exit_statuses) | ||||
|  | ||||
| def wait_for_reservation_status(session, res_id, target_status): | ||||
|     __wait_for_status(session, res_id, 'Status', target_status) | ||||
| def wait_for_reservation_status(session, res_id, target_statuses, exit_statuses=[]): | ||||
|     __wait_for_status(session, res_id, 'Status', target_statuses, exit_statuses) | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import json | ||||
| import os | ||||
|  | ||||
| from cloudshell.api.cloudshell_api import UpdateTopologyGlobalInputsRequest | ||||
| @@ -6,49 +7,40 @@ import argparse | ||||
|  | ||||
| from common import wait_for_provisioning_status, get_session | ||||
|  | ||||
| run_id = os.environ.get('GITHUB_RUN_NUMBER', 1) | ||||
| run_number = os.environ.get('GITHUB_RUN_NUMBER', 1) | ||||
| run_id = os.environ.get('GITHUB_RUN_ID', 1) | ||||
| workflow = os.environ.get('GITHUB_WORKFLOW', "workflow") | ||||
| marker_expression = os.environ.get('MARKER_EXPRESSION', 'sanity')  | ||||
|  | ||||
| def main(): | ||||
|     parser = argparse.ArgumentParser() | ||||
|     parser.add_argument('--openwifi-version', default='main') | ||||
|     parser.add_argument('--openwifi-gw-version', default='master') | ||||
|     parser.add_argument('--openwifi-sec-version', default='main') | ||||
|     parser.add_argument('--openwifi-fms-version', default='main') | ||||
|     parser.add_argument('--openwifi-ui-version', default='main') | ||||
|     parser.add_argument('--ap-model', default='[Any]') | ||||
|     parser.add_argument('--wifi-type', default='[Any]') | ||||
|     parser.add_argument('--blueprint', default='Basic Lab') | ||||
|     parser.add_argument('--reservation-id-file', default='./reservation_id.txt') | ||||
|     parser.add_argument('--global-inputs', help="JSON dictionary that contains global inputs that will be passed to Quali", default="{}") | ||||
|     parser.add_argument('--reservation-duration', help='duration of reservation', default=360) | ||||
|     parser.add_argument('--reservation-id-file', help='file that the reservation ID will be written to', default='./reservation_id.txt') | ||||
|     parser.add_argument('blueprint', help='name of blueprint to create reservation from') | ||||
|     args = parser.parse_args() | ||||
|  | ||||
|     session = get_session() | ||||
|  | ||||
|     if marker_expression == 'advance': | ||||
|         reservation_duration = 720 | ||||
|     else: | ||||
|         reservation_duration = 360 | ||||
|     global_inputs = {} | ||||
|     try: | ||||
|         global_inputs = json.loads(args.global_inputs) | ||||
|     except json.JSONDecodeError as e: | ||||
|         print(f'failed to decode global inputs: {e}') | ||||
|         exit(1) | ||||
|  | ||||
|     reservation = session.CreateImmediateTopologyReservation( | ||||
|         reservationName=f'{marker_expression}-{run_id}', | ||||
|         reservationName=f'{workflow}/{run_number}/{run_id}', | ||||
|         owner=session.username, | ||||
|         durationInMinutes=reservation_duration, | ||||
|         durationInMinutes=args.reservation_duration, | ||||
|         topologyFullPath=args.blueprint, | ||||
|         globalInputs=[ | ||||
|             UpdateTopologyGlobalInputsRequest('Chart Version', args.openwifi_version), | ||||
|             UpdateTopologyGlobalInputsRequest('owgw Version', args.openwifi_gw_version), | ||||
|             UpdateTopologyGlobalInputsRequest('owsec Version', args.openwifi_sec_version), | ||||
|             UpdateTopologyGlobalInputsRequest('owfms Version', args.openwifi_fms_version), | ||||
|             UpdateTopologyGlobalInputsRequest('owgwui Version', args.openwifi_ui_version), | ||||
|             UpdateTopologyGlobalInputsRequest('AP Model', args.ap_model), | ||||
|             UpdateTopologyGlobalInputsRequest('Wifi type', args.wifi_type), | ||||
|         ] | ||||
|         globalInputs=[UpdateTopologyGlobalInputsRequest(key, value) for key, value in global_inputs.items()] | ||||
|     ).Reservation | ||||
|  | ||||
|     with open(args.reservation_id_file, 'w') as f: | ||||
|         f.write(reservation.Id) | ||||
|  | ||||
|     wait_for_provisioning_status(session, reservation.Id, 'Ready') | ||||
|     wait_for_provisioning_status(session, reservation.Id, ['Ready'], ['Teardown']) | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     main() | ||||
|   | ||||
| @@ -6,7 +6,7 @@ def main(): | ||||
|     session = get_session() | ||||
|     res_id = sys.argv[1] | ||||
|     session.EndReservation(res_id) | ||||
|     wait_for_reservation_status(session, res_id, 'Completed') | ||||
|     wait_for_reservation_status(session, res_id, ['Completed']) | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     main() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Max
					Max