This blog post will introduce tool Terraform, which we use for deploying testing environments in YSoft. We will cover following topics:

  • What is Terraform?
  • How does it work?
  • Example of use

What is Terraform?

Terraform is a command line tool for building and changing infrastructure in a safe and efficient matter. It can manage resources on most of the popular service providers. In essence, Terraform is simply a tool that takes configuration files as input and generates an execution plan describing what needs to be done to reach the desired state. Do you need to add another server to your cluster? Just add another module to your configuration. Or redeploy your production environment in a matter of minutes? Than Terraform is the right tool.

How does it work?

Infrastructure as a code

Configuration files that define infrastructure are written using high-level configuration syntax. This basically means that blueprint of your production or testing infrastructure can be versioned and treated as you would normally treat any other code. In addition, since we are talking about code, the configuration can be shared and re-used.

Execution plan

Before every Terraform execution, there is planning step, where Terraform generates an execution plan. The execution plan will show you what will happen when you run an execution (when you apply the plan). This way you avoid surprises when you manipulate with your infrastructure.

Terraform state file

How does Terraform determine the current state of infrastructure? The answer is the state file. State file keeps the information about all the resources that were created by execution of the given configuration file. To assure that the information in state file is fresh and up to date, Terraform queries our provider for any changes of our infrastructure (and modifies state file accordingly), before running any operation, meaning: for every plan and apply, Terraform will perform synchronization of a state file with a provider.

Sometimes this behavior can be problematic, for example querying large infrastructures can take a non-trivial amount of time. In this scenarios, we can turn off the synchronizing, which means the cached state will be treated as the record of truth.

Below you can see the picture of the whole execution process.

Example of use

In our example, we will be working with the azure provider. The example configuration files can be used only for the azure provider (hence the configuration files for different providers may and will differ). In our example, it is also expected, that we have set up terraform on our machine and appropriate endpoints to provider beforehand.

Step 1: Write configuration file

The presented configuration file has no expectations regarding previously created resources and it can be executed on its own, without the need to create any resources in advance.

The configuration file that we will write describes following resources:

Now we create an empty directory on the machine where we have installed terraform and within we create a file with name main.tf. The contents of the main.tf  file:

provider "azurerm" {
  subscription_id = "..."
  client_id       = "..."
  client_secret   = "..."
  tenant_id       = "..."
}

resource "azurerm_resource_group" "test" {
  name     = "test-rg"
  location = "West US 2"
}

resource "azurerm_virtual_network" "test" {
  name                = "test-vn"
  address_space       = ["10.0.0.0/16"]
  location            = "West US 2"
  resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
  name                 = "test-sbn"
  resource_group_name  = "${azurerm_resource_group.test.name}"
  virtual_network_name = "${azurerm_virtual_network.test.name}"
  address_prefix       = "10.0.2.0/24"
}

resource "azurerm_network_interface" "test" {
  name                = "test-nic"
  location            = "West US 2"
  resource_group_name = "${azurerm_resource_group.test.name}"

  ip_configuration {
    name                          = "testconfiguration1"
    subnet_id                     = "${azurerm_subnet.test.id}"
    private_ip_address_allocation = "dynamic"
  }
}

resource "azurerm_virtual_machine" "test" {
  name                  = "test-vm"
  location              = "West US 2"
  resource_group_name   = "${azurerm_resource_group.test.name}"
  network_interface_ids = ["${azurerm_network_interface.test.id}"]
  vm_size               = "Standard_DS1_v2"

  delete_os_disk_on_termination = true

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  storage_os_disk {
    name              = "myosdisk1"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  os_profile {
    computer_name  = "hostname"
    admin_username = "testadmin"
    admin_password = "Password1234!"
  }

  os_profile_linux_config {
    disable_password_authentication = false
  }
}

 

Step 2: Planning the execution

Now we browse into a directory with our main.tf  file and we run command terraform init, which initializes various local settings and data that will be used by subsequent commands.

Secondly, we run command terraform plan, which will output the execution plan, describing which actions Terraform will take in order to change real infrastructure to match the configuration. The output format is similar to the diff format generated by tools such as Git. If terraform plan failed with an error, read the error message and fix the error that occurred. At this stage, it is likely to be a syntax error in the configuration.

Step 3: Applying the plan

If terraform plan ran successfully we are safe to execute terraform apply. Throughout the whole “apply” process terraform will inform us of progress. Once the terraform is done, our environment is ready and we can easily check by logging in to our virtual machine. Also, our directory now contains file terraform.tfstate file, which is state file that corresponds to our newly created infrastructure.

Conclusion

This example was only a very simple one to show how configuration file might look. Terraform offers more on top of that. Configurations can be packed into modules, self-contained packages that are managed as a group. This way we can create reusable parametrizable components and treat these pieces of infrastructure as a black box. Besides that, Terraform can also perform a provisioning of VM and much more.

Reaction time measurement is a process of acquiring timespan for how long it takes for the tested device to change its state after clicking on action element. The most common scenario is the measuring of time needed to load new screen after clicking on the button that invokes screen change. This measurement directly testifies about user experience with the tested system.

So how does our robotic system do it?

The algorithm of reaction time measurement is based on calculation of pixel-wise differences between two consecutive frames. That simply subtracts values of pixels of one image from another. Let’s have two frames labeled as fr1 and fr2, there are three main types of difference computation:

  • Changes in fr1 according to fr2: diff = fr1 – fr2
  • Changes in fr2 according to fr1: diff = fr2 – fr1
  • Changes in both directions: diff = | fr1 – fr2 |

The last mentioned computation of differences is called Absolute difference and is used in our algorithm for reaction time measurements. In general, the input frames are grayscale 8-bit images of the same size. Computation of differences for color images is possible however it would only deliver more errors in RGB color spectrum due to more variables being dependent on surrounding lighting conditions. The final computed difference is just a number indicating the amount of changes between two frames, therefore, it is perfect for detecting the change of screen in the sequence of images.

Enough of theory, let’s make it work!

First of all, we need two images indicating the change of screen. For this purpose, I choose the following two pictures.

Imagine those are the two consecutive frames in the sequence of all frames we talked about earlier.

Next step is to change them into grayscale and make sure they are of the same height and width.

After those necessary adjustments, we are ready to calculate the difference between them. As was told before, it is computed as an absolute subtraction of one image from another. In about every computer vision library there is a method implemented for this purpose, i.e. in opencv it is called AbsDiff. The following image shows the result of subtraction of two images above. As you can see there is a visible representation of both images. That is completely fine because every non zero pixel tells us how much given pixel is distinct from the same pixel in the second image. If result image would be black it would mean that difference is zero and images are identical, vice versa for white image.

Next step is to sum values of all pixels in the result image. Remember that each pixel value for grayscale 8-bit image is in a range from 0 to 255. The difference for this image:

diff = 68964041

This value itself is not very descriptive of the change between the two images, therefore normalization needs to be applied. The form of normalization we use is to transform that computed difference number into a percentual representation of change in the screen with a defined threshold. Threshold specifies what value of a pixel is high enough to be classified as changed so rather than computing sum of all pixels in result image we find how many of pixels are above the defined threshold. The normalized difference for this image:

diffnormed =96.714% (with threshold =10)

This result compared to the previous one very precisely tells us how much change happened between the two images. The algorithm to detect the amount of change between two images was just the first part of the whole time measurement process. In our robotic system, we have implemented two modes of reaction measurement, Forward and Backward reaction time evaluation.

 

Forward reaction time evaluation

Forward RTE is based on real-time-ish evaluation meaning that algorithm procedurally obtains data from an image source and process them as they arrive. The algorithm does not have the ambition to find desired screen immediately but it rather searches for screen changes, evaluates them and then compares them to desired one.

Forward RTE diagram shows the process flow of the algorithm. At the start, it sets the first frame as the reference image. Differences against this reference are then computed with incoming frames. If the computed difference is above the threshold then the frame is identified and the result is compared to desired screen. If this does not match, the frame is set as new reference and differences are then calculated against it. If that does match then timestamp of image acquirement is saved and the algorithm ends. In theory, every screen change during measuring is identified only once, however it strongly depends on the threshold value that user needs to set. Even if this algorithm tries to be real-time the identification algorithms take so much time that it is not possible yet.

 

 

Backward reaction time evaluation

Backward RTE works pretty much the other way. Rather than searching desired image from the start, it waits for all images to be acquired, identifies the last frame and sets it as a reference, after that looks for the first appearance of given reference in sequence.

Backward RTE diagram shows the process flow of the algorithm. First of all, it waits for all frames from the subsequence of frames. After all frames are acquired, the last frame is identified and if the last frame is the actual desired screen then the reference is set and the algorithm proceeds. If the last frame was not desired screen it would mean that desired screen did not load yet or some other error happened. For this case, algorithm records backup sequences to provide additional consecutive frames. If there is no desired screen in those sequences then the algorithm is aborted.

After reference is set the actual algorithm starts. It looks for the first frame which is very similar to the reference one using difference algorithms described earlier. Found image is identified and compared to desired. If identified and desired screens match then the time of acquirement is saved and the algorithm ends. However, if they do not match then the sequence is shortened to start at the index of falsely identified frame and then the algorithm searches further. The furthest index is the actual end of sequence because image at the end sequence was at the start of RTE identified as desired.

Summary

This article contains information about difference based measurement of reaction time. It guides you through computation of differences between two images. Also, this article describes our very own two reaction time evaluation modes which we use in practice.

 

Additional notes

To keep the description of algorithms as readable as possible few adjustments are missing. Preprocessing of the images is the essential part where elimination of noise has high impact on the stability of the whole algorithm. We have also implemented few optimization procedures that reduce the amount of data that needs to be processed, e.i. bisection.

 

ARUR_logoY Soft Applied Research and University Relations (ARUR) is a program under which we ysofters:

  • Supervise and consult students working on their theses
  • Support student research positions at research laboratories
  • Offer student internships
  • Give lectures at universities
  • Organize and support student events

This post provides statistics (collected for the last six years) about some of the Y Soft ARUR activities mentioned above.

Theses supervision

During the last six years, 46 bachelor and master theses realized in collaboration with Y Soft were successfully defended. See Figure 1 for a number of theses defended per each year. In 2015, for example, 6 bachelor and 8 master theses were successfully defended. Most of all the theses came from Y Soft R&D in collaboration with the Faculty of Informatics, Masaryk University.

Figure 1

Figure 1. Number of defended theses

More than 75% of all theses defended during the last six years received “A” or “B” grade. See Figure 2 for grades statistics per each year. In 2015, for example, 14 theses were successfully defended and received eight “A” and six “B” grades (i.e., 100% of the theses defended in 2015 received “A” or “B” grade).

Figure 2

Figure 2. Grades of defended theses

Since 2012, five of the students received awards for their theses (see Figure 3).

Figure 3

Figure 3. Number of awards

Part-time positions at Y Soft

14 students were given part-time jobs within the scope of ARUR during the last six years. Some of these part-timers have been working in Y Soft on their bachelor or master thesis for more than a year. There were ten students from the Faculty of Informatics (Masaryk University), two from the Faculty of Electrical Engineering and Communication (Brno University of Technology), and two from the Faculty of Information Technology (Brno University of Technology).

Student positions at research laboratories

Every year, in cooperation with the Faculty of Informatics, Masaryk University, we participate in organizing a competition for talented students who are in the first or the second year of their bachelor studies. During the last six years, we have supported nine students who were winners of the competition. Some students were funded for more than one year. In 2015, six student positions at research laboratories have been funded.

Thanks to all already participating in our ARUR program and we are looking forward for new participants!

We are more than happy to discuss any suggestions and ideas for cooperation you might have.

Contact us: uni-rel@ysoft.com

I spent winter semester of academic year 2014/2015 on Malta studying on local university. As a student of FIT BUT. I had an opportunity to participate in Erasmus+ student exchange program. In Y Soft Corporation I work as a QA Engineer in Jakub Pavlák’s team in R&D Department. During study period I was still part-time employed in Y Soft corp. I would like to express big thanks to my supervisors who allowed me to work from abroad. It was not easy to manage it but I tried to do my best.

Erasmus+

University of Malta was founded in 1769 and has 14 faculties. There are more than 11000 students at the university and around 1000 students are foreigners. I studied at Faculty of information and communication technologies that is the newest one and was built in 2007. I took study units that involved programming, object oriented design and business intelligence. Partly I revised my knowledge from previous study program but I also got new experience in neural networks or cryptography basics.

Faculty - Malta

During semester no more than 100 students attend classes, but mostly in higher classes there are mostly 40 students maximally so there is very calm atmosphere during lessons. Teacher approach to the students is much more personal than that is at my home university. Every study unit contains an assignment – home work which helps to get deeper knowledge of subject. In the end semester there was an examination session. Unlike from BUT FIT the session is very short – only two weeks and for every study unit students have only one attempt. At my home university we have three attempts for each study unit.

It took more than month to get all the results from University of Malta – but it was worth waiting for it – I passed all my exams.

There is one interesting thing about UoM especially about one of its teacher. Dr. Vitezslav Nezval works at the Faculty of information and communication technologies. He is an alumnus of BUT and what is more he is a nephew of one famous Czech poet – Vitezslav Nezval.

At UoM there are also some student organizations that organized different types of activities. During whole visit I participated in many activities with other international students. Very often we travelled throughout Malta and also we visited the smaller island Gozo. There were also organized student parties in Paceville and in other places at least twice a week – it was sometimes quite difficult to get up next day for next lesson or work.

Malta – places, nature, local specialties

Maltese islands can be found south from Sicily. They consist of three islands Malta, Gozo and Comino. Whole area of islands is no more than 400 km2 and population counts around 400 000 inhabitants. But this number grows at least three times during tourist season. The capital of Malta is Valletta. There are the most important administrative building amongst many beautiful sights also with restaurants, theaters and shops.

Paceville

There two languages officially spoken on Malta, Maltese and English. Maltese is a very strange language. It is a kind of mixture of Arabic, Italian and English and also quite difficult to pronounce. Most of Maltese people speak English so there are no problems with understanding. Very exciting place to visit is Paceville. It is a center of many fun activities and social life; there are shopping centers, many hotels, bars, pubs, cinemas and casinos. Most student parties took place here. In this part of Malta there is the highest building of Malta – The Portomaso Tower. It is 98 meters tall and on its top floor a club called Twenty Two. It offers very nice view on the island and very luxury and expensive drinks.

Prices of common foods and drinks in shops are a bit higher than in the Czech republic. But prices for services, dishes and drinks in restaurants, bars etc. are two or three times higher. Living costs on Malta are higher but if you don’t go every week to casino or high society bar, it is affordable. Malta has really exciting nature. There are many places to visits. You can start with cliffs, megalithic temples, churches and cathedrals with big domes. There is one interesting point about churches – on Malta there are around 360 of them and almost all native Maltese people are believers – Roman Catholic. Also there are plenty of beaches on Maltese island – Golden bay, St. Peter’s pool, Ramla beach on Gozo with orange sand or Blue lagoon on Comino.

BlueGrotto

Very interesting place is city of Mdina. It is former capital of Malta and it is called “Silent city”. Mdina is medieval fortress with cathedrals inside.

There are also other places like Azure window on Gozo or Blue Grotto where you can do scuba diving.

AzureWindow

Because I am a beer lover I had to taste local beers but I was really disappointed. Local beer is a very poor taste. I don’t recommend to move to Malta, if you are beer lovers. Even if you can buy some better tasting beers, the variety is very little. From middle of Europe almost no beers are imported, I think, if a Maltese tastes good Czech beer, he will never drink the local one 😉 There are also sold liqueurs made of prickly pear and other tropical fruit are very typical drinks. They are often very sweet.

Maltese wine is worth tasting, there are not many places where to make wine but final product is quite good. Typical Maltese dishes contain mostly seafood and fish. But there are also cooked little snacks called pastizzi with big variety of tastes. Fried rabbit with garlic and wine is also one the typical Maltese dish. The weather on Malta is for almost 8 months in the year really nice, no raining, mostly sunny with tropical temperatures. Only in the winter the temperature is between 10 and 15°C but of course without any snow. Sometimes there are hailstorms. Maltese people are very kind, always willing to help but they have plenty of time for doing everything, they never hurry. I had to adapt to this.

Conclusion

I had a great chance to meet a lot of new people and students from countries all over the world. I learned about different culture and about different style of teaching. I think I also improved my English communication skills and learned new interesting information about information technologies. I gained lots of exciting experience and the whole visit left me with many unforgettable memories.

Boat