This library contains various functions that help finding and connecting openQA job to the correct deployment VM. Deployment VM is recognized from other VMs by being tagged with deployment_id tag. Deployment ID is an unique identifier which is an OpenQA job ID of a job that created this VM. In single machine test Deployment ID equals test ID. This is not always true in case of multi-machine jobs. Deployment ID might be an ID of the parent job which executed the deployment itself.
Example: Job: 123456 - deployment module - created deployer VM tagged with "deployment_id=123456", Job: 123457 (child of 123456) - some test module Deployment ID returned from both jobs: 123456 - because it matches with existing VM tagged with "deployment_id=123456"
check_ssh_availability($deployer_ip_addr [, ssh_port=>42 ,$wait_started=>'true', wait_timeout=>'42']);
Checks if deployer VM is running and listening on ssh port. Returns found state. Optionally function can wait till VM reaches requested state until timeout. Function dies only with internal errors, VM status should be evaluated and handled by caller.
deployer_ip_addr: Deployer VM IP address
wait_started: Probe SSH port in loop until it is available or wait_timeout is reached.
wait_timeout: Time in sec to stop probing SSH port.
ssh_port: Specify custom SSH port number. Default: 22
get_deployer_ip(deployer_resource_group=>$deployer_resource_group, deployer_vm_name=>$deployer_vm_name);
Returns first public IP of deployer VM that is reachable and can be used for SDAF deployment connection.
deployer_resource_group: Deployer resource group. Default: get_required_var('SDAF_DEPLOYER_RESOURCE_GROUP')
deployer_vm_name: Deployer VM resource name
get_deployer_vm_name(deployer_resource_group=>$deployer_resource_group, deployment_id=>'123456');
Returns deployer VM name which is tagged with deployment_id specified in parameter. This means that the VM was used to deploy the infrastructure under this ID and contains whole SDAF setup. Function returns VM name or undef if no VM was found. Function dies if there is more than one VM found, because two VM's must not have same ID.
deployer_resource_group: Deployer resource group. Default: get_required_var('SDAF_DEPLOYER_RESOURCE_GROUP')
deployment_id: Deployment ID
get_parent_ids();
Returns ARRAYREF of all parent job IDs acquired from current job data.
find_deployment_id(deployer_resource_group=>$deployer_resource_group);
Finds deployment ID for currently running test. Deployment ID is ID of an OpenQA test which created deployer VM. In case of multi-machine test this can be either parent test ID or current job id as well. This function collects all OpenQA job IDs related to current test run and checks if any of them match an existing deployer VM tagged with this ID.
Using OpenQA parameter SDAF_DEPLOYMENT_ID it is possible to override this value. It is mostly intended for development purposes where it allows you to run test code on already existing deployment. Use it with caution and override the value only with ID of the infrastructure that belongs to you.
Example: Job: 123456 - deployment module - created deployer VM tagged with "deployment_id=123456", Job: 123457 (child of 123456) - some test module Deployment ID returned from both jobs: 123456 - because it matches with existing VM tagged with "deployment_id=123456"
deployer_resource_group: Deployer resource group. Default: get_required_var('SDAF_DEPLOYER_RESOURCE_GROUP')
get_deployer_resources(deployer_resource_group=>$deployer_resource_group [, deployment_id=>'123456', return_ids=1]);
Returns ARRAYREF of all resources belonging to deployer_resource_group tagged with deployment_id.
deployer_resource_group: Deployer resource group. Default: get_required_var('SDAF_DEPLOYER_RESOURCE_GROUP')
deployment_id: Deployment ID
return_value: Control the content of the returned array. It can either return array of resource IDs or resource names. Values allowed: id, name Default: name
destroy_resources(resource_cleanup_list=>['resource_A', 'resource_B'] [, timeout=>900]);
Destroys all resources specified by resources argument in ARRAYREF format.
timeout Timeout for AZ command to destroy resources. Default: 800
resource_cleanup_list ARRAYREF specifying resources to be deleted. If empty, function will just return.
destroy_deployer_vm([timeout=>900]);
Collects resource id of all resources belonging to the deployer VM and deletes them. Cleanup deployer VM resources only, deployer resource group itself will stay intact.
timeout: Timeout for destroy command. Default: 800
destroy_orphaned_deployers([timeout=>9999]);
Destroys orphaned deployer VM resources existing inside permanent deployer resource group. Function lists all resources and their creation time belonging to deployer RG which are tagged with 'deployment_id'. Resource being tagged with 'deployment_id' means it was created by an OpenQA test. Resource names are as well checked against OpenQA naming convention as another prevention from unwanted resource deletion. Resources older than 'SDAF_DEPLOYER_VM_RETENTION_SEC' seconds (Default 7H) are considered as orphans and deleted. Be very careful with changes here (especially with regexes and az cli filters) as mistakes can lead to damage on permanent SDAF infrastructure.
timeout: Timeout for az destroy command. Default: 1200