Automatic installation of the Test Suite and added Windows execution

  • Creation of scripts to automatically install the requirements (python, git, virtualenv) on MacOS, Ubuntu, and Windows.
  • Clone the repository in the local folder.
  • Generation of the Python Virtual Environment and installation of the required Python packages.
  • Generation of the run_tests file for the Windows system.
  • Correction of some initial issues in the configuration of the Test Suite.
  • Modification of the README content to be compliant with the installation process.

Merge request reports

Loading
+1 −1
Changes for resources/variables.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
url = 'localhost:8080/ngsi-ld/v1'
url = 'http://localhost:8080/ngsi-ld/v1'
ngsild_test_suite_context = 'https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld'
notification_server_host = '0.0.0.0'
notification_server_port = 8085

scripts/configure.ps1

0 → 100644
+85 −0
Changes for scripts/configure.ps1: 85 added lines, 0 removed lines.
Original line number Diff line number Diff line
$choco_version = &{choco --version} 2>&1
if ($choco_version -is [System.Management.Automation.ErrorRecord])
{
    powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"

    $env:Path += ";$env:PROGRAMDATA\Chocolatey\bin"
} else {
  echo "Chocolatey already installed"
}

$git_version = &{git --version} 2>&1
if ($git_version -is [System.Management.Automation.ErrorRecord])
{
   choco install git -y
   $env:Path += ";C:\Program Files\Git\cmd"
} else {
   echo "git already installed"
}

# - Install python if it doesn't exists - 
# Define the version of Python to install
$pythonVersion = "3.11.4"

$python_installed_version = &{python --version} 2>&1
if ($python_installed_version -is [System.Management.Automation.ErrorRecord])
{

    # Define the download URL for the Python installer
    $pythonInstallerUrl = "https://www.python.org/ftp/python/$pythonVersion/python-$pythonVersion-amd64.exe"

    # Define the path to download the Python installer
    $installerPath = "$env:TEMP\python-$pythonVersion.exe"

    # Download the Python installer
    Invoke-WebRequest -Uri $pythonInstallerUrl -OutFile $installerPath

    # Install Python silently with the necessary settings to add it to the PATH
    echo "... installing python. This takes some time."
    Start-Process -FilePath $installerPath -ArgumentList "/quiet", "InstallAllUsers=1", "PrependPath=1" -Wait

    # Remove the installer
    Remove-Item $installerPath
    #$env:Path += "C:\Python311\Scripts\;C:\Python311\"
    $env:Path = "C:\Program Files\Python311\Scripts;C:\Program Files\Python311;$env:Path"
} else {
   echo "python is already installed"
}


$python_installed_version = &{python --version} 2>&1
if ($python_installed_version -is [System.Management.Automation.ErrorRecord]) {
    sleep 60
    $python_installed_version = &{python --version} 2>&1
    if ($python_installed_version -is [System.Management.Automation.ErrorRecord]) {
	echo "Restart powershell and run this script again. Python not detected"
	exit 1
    }
}

# Install virtualenv - 
python -m pip install virtualenv

$cloned = &{Test-path .\ngsi-ld-test-suite}

echo "======================="
echo $cloned
echo "======================="

if ( $cloned -eq $false ) {
    echo "------------- doing git clone"
    # Clone the repo - somehow.
    git clone https://forge.etsi.org/rep/cim/ngsi-ld-test-suite.git >$null 2>&1
    cd ngsi-ld-test-suite                                           >$null 2>&1
} else {
    cd ngsi-ld-test-suite
    git pull
    Remove-Item -force -recurse .\.venv
}

# Create the virtualenv
virtualenv -ppython3 .venv                               >$null 2>&1

.\.venv\Scripts\activate.bat
pip install -r requirements.txt

scripts/configure.sh

0 → 100644
+246 −0
Changes for scripts/configure.sh: 246 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash
#
#  Command Line Interface to configure the ETSI NGSI-LD Test Suite (https://forge.etsi.org/rep/cim/ngsi-ld-test-suite)
#  For this repository, the commands are merely a convenience script to install the needed services (Python3.11,
#  Virtualenv, Pip, and Git. Additionally, the script clones the repository of the tests and create the proper Python
#  Virtual Environment for the python project based on the requirements.txt file.
#
#  The script will check the OS (MacOS or Ub Ubuntu Linux) and based on it execute the steps to configure the ETSI Test
#  Suite. You can start up with the following command:
#
#  ./configure.sh
#
#  The final steps is the configuration of the ./ngsi-ld-test-suite/resources/variables.py
#  (https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/blob/windows11/resources/variables.py) following the README.md
#  content (https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/tree/windows11?ref_type=heads), activate the Virtual
#  Environment and execute the Robot Tests.


# Function to check if a command is available
command_exists() {
  command -v "$1" >/dev/null 2>&1
}


# Install Homebrew (macOS)
install_homebrew() {
  echo "  - Installing Homebrew..."
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  if command_exists brew; then
    echo "    - Brew was installed successfully."
  else
    echo "    - Failed to install Brew."
    exit 1
  fi
}


# Function to prompt for yes/no confirmation
confirm() {
  local prompt="${1:-Are you sure? [Y/n]} "
  local default_value="${2:-Y}"

  read -r -p "$prompt" response
  response=${response:-$default_value}
  response=$(echo "$response" | tr '[:upper:]' '[:lower:]')

  if [[ $response == "y" || $response == "yes" ]]; then
    return 1
  elif [[ $response == "n" || $response == "no" ]]; then
    return 0
  else
    echo "Invalid response. Please enter 'Y' or 'N'."
    confirm "$prompt" "$default_value"
  fi
}

# Create the virtualenv .venv, activate, and install python requirements
configure_virtualenv() {
  echo "Configuring Python Virtual Environment"
  echo "  - Cloning the ETSI repository in the current folder"
  git clone https://forge.etsi.org/rep/cim/ngsi-ld-test-suite.git              >/dev/null 2>/dev/null

  cd ngsi-ld-test-suite || {
      echo "Failure, unable to change to the ngsi-ld-test-suite directory, maybe the git clone operation failed...";
      exit 1;
  }

  echo "  - Creating Python Virtual Environment"

  if [ -d "./.venv" ]; then
    echo "    - .venv directory already exists"

    # Prompt for confirmation
    confirm "      Do you want to delete and generate it again? [Y/n]? " "Y"

    # Check the return value
    if [ $? -eq 1 ]; then
      echo "      Deleting previous .venv folder..."
      rm -rf -y .venv                                                          >/dev/null 2>/dev/null
      virtualenv -ppython3.11 .venv                                            >/dev/null 2>/dev/null
    else
      echo "      You declined. Aborting..."
    fi
  else
    virtualenv -ppython3.11 .venv                                              >/dev/null 2>/dev/null
  fi

  # Activate the .venv
  echo "  - Activating .venv"
  source .venv/bin/activate                                                    >/dev/null 2>/dev/null

  # Install the requirements
  echo "  - Installing the python requirements from the project"
  pip3 install -r requirements.txt                                             >/dev/null 2>/dev/null
}


# Configuration script for macOS
execute_macos() {
  echo "macOS operating system, installing requirements..."

  # Check if Homebrew is already installed
  if ! command_exists brew; then
    install_homebrew
  else
    echo "  - Homebrew is already installed."
  fi

  # Check if git is already installed
  if ! command_exists git; then
    echo "  - Installing git..."
    brew install git --quiet                                                   >/dev/null 2>/dev/null

    # Check that git was successfully installed
    if command_exists git; then
      echo "    - Git installed successfully"
    else
      echo "      - Failed to install Git."
      exit 1
    fi
  else
    echo "  - Git is already installed."
  fi

  # Check if Python 3.11 is already installed
  if command_exists python3.11; then
    echo "  - Python 3.11 is already installed."
  else
    # Install Python 3.11 for macOS, it includes also the installation of pip3
    echo "  - Installing Python 3.11 (with pip) and Virtualenv for macOS..."
    brew install python@3.11 virtualenv --quiet                                >/dev/null 2>/dev/null

    # Check if Python 3.11 was installed successfully
    if command_exists python3.11; then
      echo "    - Python 3.11 was installed successfully on macOS."
    else
      echo "    - Failed to install Python 3.11 on macOS."
      exit 1
    fi

    # Check if Pip was installed successfully
    if command_exists pip3; then
      echo "    - Pip3 was installed successfully."
    else
      echo "    - Failed to install Pip3."
      exit 1
    fi

    # Check if Virtualenv was installed successfully
    if command_exists virtualenv; then
      echo "    - Virtualenv was installed successfully."
    else
      echo "    - Failed to install Virtualenv."
      exit 1
    fi
  fi

  echo

  # Create the virtualenv .venv, activate, and install python requirements
  configure_virtualenv
}

# Configuration script for Linux
execute_linux() {
  echo "Linux operating system, installing requirements..."

  # Check if git is already installed
  if ! command_exists git; then
    echo "  - Installing Git."
    sudo apt-get install -y -qq git                                            >/dev/null 2>/dev/null

    # Check that git was successfully installed
    if command_exists git; then
      echo "    - Git installed successfully."
    else
      echo "    - Failed to install Git."
      exit 1
    fi
  else
    echo "  - Git is already installed."
  fi

  # Check if Python 3.11 is already installed
  if command_exists python3.11; then
    echo "  - Python 3.11 is already installed."
  else
    # Install Python 3.11 for Ubuntu
    echo "  - Installing Python 3.11, Pip, and Virtualenv for Ubuntu..."
    sudo add-apt-repository -y ppa:deadsnakes/ppa                              >/dev/null 2>/dev/null
    sudo apt-get update     -y -qq                                             >/dev/null 2>/dev/null
    sudo apt-get install    -y -qq python3.11 python3-pip python3-virtualenv   >/dev/null 2>/dev/null

    # Check if Python 3.11 was installed successfully
    if command_exists python3.11; then
      echo "    - Python 3.11 was installed successfully."
    else
      echo "    - Failed to install Python 3.11."
      exit 1
    fi

    # Check if Pip was installed successfully
    if command_exists pip3; then
      echo "    - Pip3 was installed successfully."
    else
      echo "    - Failed to install Pip3."
      exit 1
    fi

    # Check if Virtualenv was installed successfully
    if command_exists virtualenv; then
      echo "    - Virtualenv was installed successfully."
    else
      echo "    - Failed to install Virtualenv."
      exit 1
    fi

  fi

  echo

  # Create the virtualenv .venv, activate, and install python requirements
  configure_virtualenv
}



# Determine the operating system
os=$(uname -s)

# Execute the script based in the OS
if [[ $os == "Darwin" ]]; then
  execute_macos
  echo
  echo "Ready to use..."
elif [[ $os == "Linux" ]]; then
  execute_linux
  echo
  echo "Ready to use..."
else
  echo "Unsupported operating system: $os"
  exit 1
fi

exit 1

scripts/run_tests.ps1

0 → 100644
+25 −0
Changes for scripts/run_tests.ps1: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
# run all tests
robot --outputdir .\results .\TP\NGSI-LD

# run all tests with base url overriden
robot --variable url:"URL_HERE" --outputdir .\results .

# run by specific tag(s)
robot --include mandatory --outputdir .\results .

# run all the tests for context information
robot --outputdir .\results .\TP\NGSI-LD\ContextInformation

# run a specific test case
robot --outputdir .\results .\TP\NGSI-LD\ContextInformation\Provision\Entities\CreateEntity\001_01.robot
robot --outputdir .\results --suite 001_01 .

# run specific test case
robot --outputdir .\results -t "SuccessCases_MinimalEntity"
robot --outputdir .\results -t "SuccessCases_MinimalEntity" .\TP\NGSI-LD\ContextInformation\Provision\Entities\CreateEntity\SuccessCases.robot

# rerun failed tests
robot --rerunfailedsuites .\results\output.xml  --outputdir .\results .

# stop the suite after a failed test
robot --exitonfailure --outputdir .\results . 
+1 −0
Changes for .gitignore: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,3 +3,4 @@ results
*.pyc
*.http
.vscode/
.idea
Loading
Loading