📜 ⬆️ ⬇️

Using Acronis products in test automation

Hello! In this article I will tell you how you can use our products to prepare the environment for testing your programs. In most software testing scenarios, in order to achieve repeatable results, it is necessary that the environment on which it is conducted is identical. The preparation of this environment before the test will be called deployment (“deployment”).

The whole complex of automated testing is as follows: the starting point is the server with Jenkins installed on it; through it we set the parameters of the automatic test run:

- on which server or machine we will run our test;
- how to configure a raid controller on it; how, in what sequence and with what parameters to break the disks;
- what operating system to install
- what products need to be installed on this server to run the test script.

Jenkins via SSH connects to another server, which contains all the necessary deployment scripts, and executes these scripts with the parameters passed to it. The server, which directly performs all the actions, prepares the configuration for booting the selected computer through PXE .
')
As what will be loaded by PXE, we have chosen our Acronis Bootable Media, since with its help you can do everything we need. Acronis Bootable Media is a stripped-down version of Linux (BusyBox) with executable files of our product, packed in ramdisk . The ramdisk of our media can be obtained by installing the Agent For Windows component from the Acronis Backup distribution. Ramdisk will be in the folder with the installed product:

C:\Program Files (x86)\Common Files\Acronis\BackupAndRecoveryAgent\

and will be called agent_ramdisk.dat for 32-bit media and agent_ramdisk64.dat for 64-bit media.

image
Appearance loaded from ramdisk media

In the loaded media, we will execute all the scripts for preparing the raid controller, and through it we will restore the image of this or that operating system - on top of the newly configured hardware. The first step is to configure the raid controller. For disk configuration, we use the storcli utility, which we pre-pack into ramdisk.

Here is an example of a shell script that packs the files we need in ramdisk:

 #  ramdisk. extract_ramdisk() { rm -rf .ramdisk mkdir .ramdisk pushd .ramdisk gzip -dc < $1 | cpio -i -d --no-absolute-filenames popd } #     Acronis Media. copy_extra_files() { mkdir -p .ramdisk/tmp/root/.ssh cp -f files/id_rsa .ramdisk/tmp/root/.ssh cp -f files/autostart.sh .ramdisk/bin/autostart_dbg cp -f files/libstorelibir-2.so.14.07-0 .ramdisk/bin cp -f files/storcli64 .ramdisk/bin } #  ramdisk'a. pack_ramdisk() { mkdir -p out pushd .ramdisk /cygdrive/c/cygwin/bin/find . | cpio -H newc -o > ../out/agent_ramdisk_echo.dat.initrd popd gzip -c9 out/agent_ramdisk_echo.dat.initrd > out/ramdisk.dat rm -f out/agent_ramdisk_echo.dat.initrd rm -rf .ramdisk } #  . echo Extracting ramdisk... extract_ramdisk $1 echo Copying extra files... copy_extra_files echo Packing ramdisk... pack_ramdisk 

Once we have packed the utility into ramdisk, it can be used in the loaded Acronis media. To load via custom ramdisk from under PXE, you need to create the correct configuration file for the loading machine. As a PXE server, we use the same machine that Jenkins passes control to. We also have a DHCP server on it. We keep all test machines in our own virtual network in order not to interfere with other employees of the company.

The deployment process begins with the preparation of a configuration file for PXE: which is generated by the name of the machine. Since the same server also performs the DHCP function, the name is enough for us to find out its mac-address, create the correct configuration file and put it in / var / lib / tftpboot. An example of the boot configuration file is shown below. After that, we reboot the machine via IPMI (if the machine has one).

After the machine boots from ramdisk, the autostart.sh script will run in the media. First, we prescribe in it how to configure disks through storcli, and then we set the parameters for restoring one or another operating system image to the machine through our product. These images are made by our Acronis product.

Backup are * .tib files and lie on the ball in the same network.

Here is an example autostart.sh script:

 configureRaidDisk() { conf_id=$(cat /proc/cmdline | grep -o 'raid_configuration_number=[^ ]*' | sed 's/\(^raid_configuration_number=\)\(.*\)/\2/') echo Raid configuration: $conf_id # Default value not to reconfigure raid controller disk state. if [ "$conf_id" == "0" ]; then return elif [ "$conf_id" == "1" ]; then (/bin/storcli64 /c1/vall delete force && echo Delete all virtual drives.) || exit 1 (/bin/storcli64 /c1 add vd type=raid0 drives=252:3 wt nora direct strip=64 && echo Create system partition.) || exit 1 (/bin/storcli64 /c1 add vd type=raid0 drives=252:0,252:1,252:2 wt nora direct strip=64 && echo Create first virtual drive.) || exit 1 (/bin/storcli64 /c1 add vd type=raid0 drives=252:4,252:5,252:6 wt nora direct strip=64 && echo Create second virtual drive.) || exit 1 (/bin/storcli64 /c1 add vd type=raid0 drives=252:7 wt nora direct strip=64 && echo Create third virtual drive.) || exit 1 (/bin/storcli64 /c1/v0 set bootdrive=on && echo Set system disk as bootable.) || exit 1 fi } execCmd() { tmp=$(cat /proc/cmdline | grep -oe acrocmd.*\) ) cmd=${tmp%%\)} echo Recovering OS image... ($cmd >> /dev/null && echo Done.) || exit 1 } configureRaidDisk startProduct execCmd reboot now 

We pass the parameters for this script via / proc / cmdline, which we take from the PXE configuration file. We review which raid configuration we should take, and call directly storcli with the parameters we need. Now we are all set up for certain pieces of hardware, in the future there is a desire to make these operations more intelligent.

After the raid configuration, we start the operation of restoring the operating system. To do this, we again extract from the command sent to us in / proc / cmdline for recovery and execute it.

Here is an example of a configuration file generated for booting a machine via PXE:

 timeout=1 default=media image=kernel64.dat label=media initrd=ramdisk64.dat append="ramdisk_size=100000 quiet vga=791 recover=(acrocmd recover disk --loc=smb://10.250.114.44/raid/images --credentials=image,qweqweqwe --arc=win7_64srv --disk=1 --target_disk=1) bootfile=root@10.250.114.101:/tmp/uefi/0AFA7218.conf#end raid_configuration_number=1" 

From it, we ask which archive to restore - just that, in the append parameter, then gets into the proc / cmdline inside the media.

The ramdisk should be in / var / lib / tftpboot / on the PXE server. In our case, it is called ramdisk64.dat. After our media has worked and the system is restored, we can face a problem: after configuring the raid using storcli, no volumes are created on the raid virtual disks. Therefore, in the highest level script that prepares the configuration for PXE boot, reboots the machine and waits for the recovery system to boot, we added the following script:

  echo list disk > list.txt for /f "usebackq tokens=1,2" %%a in (`diskpart /s list.txt ^| findstr /r /c:"Disk [1-99]"`) do ( echo sel %%a %%b>script.txt echo clean>>script.txt echo create part primary>>script.txt echo format FS=NTFS quick>>script.txt echo assign>>script.txt echo rescan>>script.txt diskpart /s script.txt ) del list.txt, del script.txt 

It creates NTFS volumes on each found disk (except the first). Since diskpart cannot accept parameters as input, but can only use a script, we generate a file with the command for listing disks on the fly and after formatting the file system using the disks from the listing.

After restoring the OS, you can install the products. Running scripts and other actions on a test machine is performed from the management server via an SSH connection. To do this, there is an SSH server on the test machine, which is already installed in the image, so after restoring the machine, we simply connect to it via SSH. We implement the installation of the product by copying the msi files of our product that we need, which we simply install via msiexec. Now you can proceed to the testing itself.

Tests are "wrappers" on Python that perform certain operations through the Acrocmd command line utility. Acrocmd allows us to perform all the same operations as through the main product GUI.

The launch of these files (implemented in Python) on the machine under test is handled by a special system installed on another control server. The managing server over the SSH connection uploads all the scripts to the machine and runs them, collects their output and combines the results of all tests into one final report. In the future, it is possible to build a beautiful report on the test script run. To do this, we use a simple web server written in Python, which converts the results into beautiful html pages.

image

Here is an example of a report that we end up with. Comparison of backup speed in three different versions of the product. The abscissa axis is the iteration number in the run, and the ordinate axis is the backup speed.

The task of automation of deployment, each decides in its own way. We have chosen the path with the use of our own products, since according to their capabilities they fully fit our goals.

How do you automate the testing and preparation of the environment for it?

Source: https://habr.com/ru/post/229417/


All Articles