lib/sles4sap/sap_deployment_automation_framework/networking.pm

SYNOPSIS

Library with common functions for Microsoft SDAF deployment automation related to networking setup.

calculate_net_addr_space

calculate_net_addr_space();

Calculate network IP space that will be reserved to contain all underlying subnets: 'admin', 'db', 'app', 'web'. Each network space will reserve 64 IP addresses. This splits last IP octet into 4 network spaces. First 64 address spaces are used from third octet, making 256 network spaces available for all OpenQA tests at any point in time. (256 tests can run at the same time using one control plane.)

Random network space pick is only performance related. If the pick was in orderly manner it would mean that from for example 5 parallel tests, one test will spend 5 loops to get a free network.

calculate_subnets

calculate_subnets([network_space=>'192.168.0.0']);
network_space: Define network space to calculate subnets for. Will be generated if left undefined.

Calculates 4 subnets required by SDAF within a network space. If network space is not specified, it will be generated by calculate_net_addr_space. Check mentioned function for details. Network space is set to reserve 64 IP addresses which will be split into 4 subnets: 'db', 'app', 'web', 'admin' This leaves 16 IP addresses for each subnet. (only 14 are usable).

list_expired_files

list_expired_files($check_older_than_sec);
$check_older_than_sec: Check only files with modification time older than parameter value in seconds

Returns names of lease blob files within 'network-spaces' container which are older than retention time. Test will search network spaces which were reserved more than $check_older_than_sec seconds ago. Default 7h should be plenty for not triggering race condition between network assignment and actual infrastructure creation.

list_network_lease_files

list_network_lease_files();

Returns names of all lease blob files within 'network-spaces' container.

acquire_network_file_lease

acquire_network_file_lease(network_lease_file=>'192.168.1.0' [, storage_account=>'some account']);
storage_account: Storage account containing lease file. Default: 'SDAF_TFSTATE_STORAGE_ACCOUNT'
network_lease_file: Name of the lease file

Acquire network lease for a blob. Returns blob lease UUID which is later required for getting permission to modify blob file.

deployer_peering_exists

deployer_peering_exists(addr_space=>'192.168.0.0', deployer_vnet_name=>'SHODAN-vnet');
addr_space: Address space to check for. Must include subnet prefix.
deployer_vnet_name: Deployer virtual network name

Checks if there is already a network peering established between deployer virtual network and address space specified by addr_space.

assign_defined_network

assign_defined_network(deployer_vnet_name=>'SHODAN-vnet' [, networks_older_than=>3600]);
networks_older_than: Check for networks older than parameter value in seconds.
deployer_vnet_name: Deployer virtual network name

Assign network that has already lease file present in storage account. Lists existing network files which were modified more than $args{networks_older_than} seconds in the past and picks one of the files at random. A check is performed if the network space is already peered to deployer virtual network deployer_vnet_name. Last step is to attempt to assign a blob lease for the network file associated. Blob file lease serves as a locking mechanism to prevent multiple tests assign same network space, causing collisions.

For a successful network assignment three criteria must be met: - there is blob file that represents a network space in storage account (check list_expired_files()) - network peering between network space and deployer virtual network does not exist - function is able to assign a 60s blob file lease to reserve exclusive network rights

Argument networks_older_than value should be greater than time between the start of this function and lib/sles4sap/sap_deployment_automation_framework sdaf_execute_deployment() creating network resources. This serves to prevent a race condition where a test picks network space which another test already assigned but haven't created network resources yet.

There are multiple ways to handle this: A. set networks_older_than to larger value than (timeout + retry) arguments set for sdaf_execute_deployment(timeout=>$timeout, retry=>$retry). This means test won't search for networks which are still possibly being created by terraform. Check tests/sles4sap/sap_deployment_automation_framework/deploy_workload_zone.pm for example.

B. Set it to some arbitrarily high but acceptable value like default 7 hours. This should be enough for any terraform deployment either to finish or fail.

create_lease_file

create_lease_file(network_space=>'192.168.1.0' [, storage_account=>'SHODAN-storage']);
storage_account: Storage account containing lease file
network_space: Network space to create the lease file for

Creates an uploads new network lease file

create_new_address_space

create_new_address_space(deployer_vnet_name=>'SHODAN-vnet' [, timeout=>9001]);
deployer_vnet_name: Deployer virtual network
timeout: Timeout for creating new lease file

Used to assign network space which does not yet have blob file created in 'SDAF_TFSTATE_STORAGE_ACCOUNT' storage account. Function generates random address space and checks for an existing lease file in storage account. If file does not exist it will be created, otherwise function searches again for network space without existing file. Before assigning network space there is a check for an existing peering between this network and deployer vnet. This is to avoid assigning network which was created without a lease file.

assign_address_space

assign_address_space([networks_older_than=>3600]);
networks_older_than: Check for networks older than parameter value in seconds.

Assigns an unused address space either by leasing existing network file inside storage account or creates a new file in case there are no free existing lease files. Check functions assign_defined_network and create_new_address_space for details about the process.