In the following, these files are assumed to be available at /tmp/install_python.tar.gz and /tmp/nw_measurer.tar.gz
Developing the Script
This project consists of one script, available at ~/measure_test_experiment.py. Simply create an empty file for this. Since we use the CLI, we can access all API calls as global variables
You should keep in mind that this script has to completely function on its own. If you are unsure about an API and its effects, you can look it up in the API reference, or you can try it out via the CLI.
In the following, we will develop a single script. If not stated otherwise, the final script will be a concatenation of all snippets in this tutorial.
It may be useful to have a sandbox topology when developing scripts.
Step 0: Set-Up
This step is optional since we just define some constants. However, it is easier to change if we do it at the beginning of the script.
Step 1 and 2: Topology Creation and Start
The following code will generate our desired topology:
Step 3 and 4: Install Software
To install Python, we can simply upload the respective archive. However, our software is not in an executable archive yet, so we should also pack it.
Step 5: Start the Experiment
To start the experiment, we create two executable archives, one starting the server, and one starting the client.
We upload these to their respective elements, making sure that the server is started before the client.
The server start script opens the server in a separate process. The client start script shall pipe the standard output of the client to the custom status.
Step 6: Collect and Print Data
We know that the client has finished. We can simple access the element’s custom status and print it as the result:
Step 7: Clean Up
Now, we should to tear down the topology and remove the temporary directory as well.
Now, we have a script. To execute it, we run the CLI with the respective parameters:
You will be prompted for your login, and the experiment will be conducted. Congratulations!
You have just run an automated experiment using the CLI’s scripting capabilities. Of course, you can test more complex software and more complex topologies with it, and use a more closed feedback loop. Now, you know almost everything you need to know to conduct automated tests with ToMaTo.
If you need more ideas, you can check out our examples!
You may also want to catch errors and repeat some things if they fail, but this is rather difficult for CLI scripts. For more advanced scripts, you should use ToMaTo as a library for your own Python program.
The full script is available for download here. Remember to update the first two lines to the correct paths!
In the next tutorial, you will learn how to connect your independent Python app to the ToMaTo API.