Skip to content

Robottelo Setup

Ondřej Gajdušek edited this page Aug 16, 2024 · 11 revisions

How to setup Robottelo

Install system dependencies

dnf -y install gcc python3-devel libxml2-devel

Set up Python Virtual Environment

To ensure a clean and isolated environment for robottelo, it's highly recommended to use a Python virtual environment (venv). This prevents conflicts with system-wide Python packages and allows you to manage project dependencies independently.

There are multiple tools that you can use to create venv with. For example uv, virtualenvwrapper, venv, and many more.

Create a virtual environment

Use tool of your choice to create a venv. This guide demonstrates how to set it up using virtualenvwrapper.

Install (Fedora/RHEL)

dnf install python-virtualenvwrapper
# or using pip
pip install virtualenvwrapper

or install it using brew if you use MacOS

brew install virtualenvwrapper

Reload shell to get access to virtualenvwrapper scripts or run

source /etc/profile

Create and activate the venv

mkvirtualenv robottelo

After running the command, new directory containing the virtual environment gets created in $HOME/.virtualenvs. This is where virtualenvwrapper stores venvs.

Essential virtualenvwrapper commands for venv management are:

  • mkvirtualenv to create the venv
  • workon <venv-name> to activate the venv or to show what venv is currently activated
  • rmvirtualenv to remove the virtualenv.
  • lsvirtualenv list all virtual environments See the documentation for more.

Clone the repository

Clone the upstream repository from GitHub and enter the robottelo directory.

git clone --origin upstream [email protected]:SatelliteQE/robottelo.git
cd robottelo/

Optional: Fork the repository if you haven't done already and add it as a remote.

git remote add origin [email protected]:<your-github-username>/robottelo.git

Install dependencies

Tip

Optional: Install uv package manager which is blazingly fast - 10-100x faster than pip.

pip install uv

Install requirements. If you do not want to use uv, start the command with pip. Make sure the virtual environment is activated.

uv pip install -r requirements.txt -r requirements-optional.txt

Robottelo is using broker to perform remote execution on the remote hosts. First, we need to ensure that broker_settings.yaml exists and contains the correct credentials for remote execution. To do that, run broker --version to generate it and to display the path where the config file is stored. Once the config file is obtained, an editor is opened.

broker --version
Broker settings file not found at /home/franta/.broker/broker_settings.yaml.
Get example file from
https://raw.githubusercontent.com/SatelliteQE/broker/master/broker_settings.yaml.example?
https://raw.githubusercontent.com/SatelliteQE/broker/master/broker_settings.yaml.example
(y, n) [y]:
Downloading example file from:
https://raw.githubusercontent.com/SatelliteQE/broker/master/broker_settings.yaml.example
Version: 0.5.3
Broker Directory: /home/franta/.broker
Settings File: /home/franta/.broker/broker_settings.yaml
Inventory File: /home/franta/.broker/inventory.yaml
Log File: /home/franta/.broker/logs/broker.log

That let's you modify the settings. It is recommended to change the following settings to have remote execution set up correctly.

host_username: <remote-user-you-want-to-use-for-remote-exec>
host_password: "<password>"
# IMPORTATNT: keep the following setting only if you want to use key-based
# authentication, comment/remove it otherwise
host_ssh_key_filename: "</path/to/the/ssh-key>"

Configuration

Robottelo uses Dynaconf configuration engine which is set to load configuration files from the conf/ directory.

Transform the template configuration files shipped with robottelo into an actual configuration files.

for conffile in conf/*.yaml.template; do
  cp -- "$conffile" "${conffile%.yaml.template}.yaml"
done;

You can either modify config files in conf/ or create settings.local.yaml file in the root of the repository to override the settings from conf/.

cp settings.sample.yaml settings.local.yaml

To test the initial setup of robottelo, it is recommended to run a test. Robottelo spins Satellite instances dynamically, to suppress this behavior, a hostname of an existing Satellite/Foreman instance needs to be specified. To do that put the following into your settings.local.yaml or similarly edit conf/server.yaml.

dynaconf_merge: true
server:
  hostnames: ['the.fqdn.of.your.satellite.acme.com']
  ssh_username: <remote-user-name>
  ssh_password: <remote-user-password>

Additional configuration

Please keep in mind that the above setup is a minimal one. If you or your organization has an existing robottelo configuration stored elsewhere, it might be desired to not copy the template configuration files, but copy the existing one into conf/. Depending on what is desired, configuration can be also symbolically linked to robottelo's conf/ directory and these settings can be overridden by settings.local.yaml.

Run tests

Run one of our simplest tests - the test to test hammer ping.

pytest tests/foreman/api/test_ping.py

The test should pass without errors.

UI testing setup

This section describes how to set up robottelo for UI testing.

There are multiple ways to run UI tests - different browsers and webdrivers. The default browser used by robottelo is chrome and the webdriver_kaifuku driver. This guide walks you through the setup using the default settings. They contain a minimal setting that should quickly get you started with UI testing.

A prerequisite is having a Selenium Grid running. You can spin it up in a container if you do not have one.

podman run -d -p 4444:4444 -p 5900:5900 --shm-size="2g" -e SE_VNC_NO_PASSWORD=1 docker.io/selenium/standalone-chrome:latest

If you do not have Grid running on localhost on port 4444, change the ui.grid_url setting. You could use the settings.local.yaml for that.

# settings.local.yaml
---
ui:
  grid_url: http://<fqdn-of-your-grid>:<grid-hub-listen-port>

Try to run a UI test

pytest tests/foreman/ui/test_operatingsystem.py::test_positive_verify_os_name

While the test is running, you should see an active session on your Selenium Grid in the Sessions section.

Advanced setup - airgun development

make robottelo env

git clone --origin upstream [email protected]:SatelliteQE/airgun.git

In robottelo venv, remove the existing installation of airgun.

uv pip uninstall airgun

And install airgun in the development mode - -e, --editable, passing the path to the airgun directory as an argument.

uv pip install --editable ~/airgun

Warning

Keep in mind that every time you run pip install -r requirements.txt, airgun is updated to the latest version, overriding the editable install.

Let's do a simple patch in airgun, add sleep to give us more time to investigate what is on the Operating Systems page.

diff --git a/airgun/entities/os.py b/airgun/entities/os.py
index 827c46a..2752044 100644
--- a/airgun/entities/os.py
+++ b/airgun/entities/os.py
@@ -33,6 +33,8 @@ class OperatingSystemEntity(BaseEntity):
     def search(self, value):
         """Search for operating system entity"""
         view = self.navigate_to(self, 'All')
+        import time
+        time.sleep(200)
         return view.search(value)
 
     def read(self, entity_name, widget_names=None):

Apply the patch:

git apply /tmp/the.patch

From robottelo directory, run the test:

pytest tests/foreman/ui/test_operatingsystem.py::test_positive_verify_os_name