Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Send LUV test results to an HTTP server

meghadey edited this page Mar 13, 2019 · 27 revisions

DISCLAIMER: This Wiki just serves as a reference implementation of an HTTP server which could be used to send the LUV test results.

The default behavior of a LUV Live Test is to store the results of the tests in a directory called luv-results directly on the disk where you created the original LUV image. This is all done automatically when booting via diskboot, and was designed to be simple and easy for users.

However, what if there is a situation where writing back to the USB (or other) media isn't feasible? It is indeed possible to boot the LUV test suite with network boot (netboot) and to collect the results in a centralized location where they can be stored and reviewed entirely independent from your client machine.

One way to do this is to set up an HTTP server to collect test results. This would be especially convenient in a situation with multiple machines running LUV; all of the test results get sent to the server automatically!

Example

Here we'll provide an example of a basic webserver setup that was tested to successfully collect the LUV test results when booted with netboot. Beyond this bonus documentation example, the LUV team does not provide support for setting up webservers.

For the sake of simplicity, the LUV team tested this on Ubuntu 14.04 machine and used the Apache2 webserver. Of course, any server (that is set up to be able to receive file uploads via POST method) running on any Linux distribution can work just as well.

Server side

  1. We presume sudo privileges and that Apache2 has already been installed on the Ubuntu machine. If it isn't run:

    $ sudo apt-get install apache2
    
  2. Check under http://localhost/ to confirm you see the default page. Now we are ready to customize it to suit our needs.

  3. The default location of the server files when installing Apache is /var/www/; this is where the uploads will be saved. Create a directory here:

    $ sudo su
    # cd /var/www
    # mkdir luv-storage
  4. Install the necessary modules to allow the web server to accept our POST requests from the PHP file we are going to create.

    $ sudo apt-get install php7.0
    $ sudo apt-get install libapache2-mod-php7.0
  5. So far we've created a directory for storing the results and installed the required module. Now we let the web server know that luv-storage is the directory where the results should be posted. So we configure apache2.conf (located under /etc/apache2/apache2.conf) as follows with the following blocks:

    <Directory "/var/www/">
       Options Indexes FollowSymLinks Includes ExecCGI
       AllowOverride None
       Allow from all
       Require all granted
    </Directory>
    
    <Directory /var/www/luv-storage/>
      AddDescription "<span class='description'> tarball </span>" .tgz .tar.gz
    </Directory>
    

    AddDescription is a directive that specifies the format of the uploaded file. Add other formats, if needed.

  6. Create upload.php under /usr/lib/cgi-bin/:

    <?php
    //
    // Copyright 2016 Intel Corporation; author Gayatri Kammela
    //
    // This script enables the HTTP POST method and allows the user to upload the
    // file to specified location/directory
    //
    // Specify the directory where all the uploads should go to
    
    $uploads_dir = "/var/www/luv-storage/";
    
    $my_file = $uploads_dir . basename( $_FILES['uploadedfile']['name']);
    
    $date = date('_Y-m-d--H:i:s');
    
    // check whether size exceeds the limit set
    
    if (($_FILES['uploadedfile']['size']) > 500000)
    {
        echo "The file is too large to upload, upload failed!<br>";
    }
    
    else
    {
        // Rename the file if already exists by appending the timestamp to it.
        if(file_exists($my_file))
        {
            $_FILES['uploadedfile']['name'] = $_FILES['uploadedfile']['name'].$date;
            $my_file = $my_file .$date;
        }
    
        // check if the file has been uploaded
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $my_file))
        {
            echo "Success! Your file " . basename( $_FILES['uploadedfile']['name']).
                 " has been uploaded!";
        }
        else
        {
            echo "Oops! We didn't receive your file! Try again!";
        }
    
    }
    
    ?>
  7. Set the correct permission on the script we just created:

    $ sudo chmod +x upload.php

    The script checks for the size of the uploading file and, if it is more than 500 KB, it will not upload the file. For files less than 500 KB, it checks for an existing file with the same name; and if it exists, renames it and uploads it to the luv-storage directory.

  8. Include the path where the uploaded PHP script resides This script is responsible for file upload using POST method as Apache2 doesn't support POST method by default.

  9. Now go to the sites-available directory and edit 000-default.conf to be sure DocumentRoot points to /var/www/ (this setting may be different if you have previously customized Apache2).

    Right below the ServerAdmin webmaster@localhost add/ edit as follows:

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
     <Directory "/usr/lib/cgi-bin">
         AllowOverride All
         Options +ExecCGI -MultiViews
         Require all granted
     </Directory>
    
  10. Enable the default site with a2enmod:

    $ sudo a2enmod default
    
  11. Lastly, restart the server:

    $ sudo service apache2 restart
    

Client side

Following the above steps will give you a working web server that's able to accept the results of the test suite. So how do we actually get the results sent there?

  1. Download the LUV Live image from here.
  2. Download the script modify_luv_netboot_efi.py from the github repo.

Now we'll use the Python script to customize the binary image. This script will enable a feature in the EFI binary that allows the results to be sent to a centralized location, such as a webserver, when booting LUV via netboot.

Modifying the binary with a script can be tricky; there is a high chance of making it unreadable while modifying it. So care has been taken to ensure that the script allows for modification of the luv_storage parameter only when it is of a certain size. Read more about the usage of this script in the link.

Now we simply run the script:

$ ./modify_luv_netboot_efi.py -f /path/to/luv-netboot-image.efi -n 10.20.30.40,64001 -u http://ipaddress/cgi-bin/upload.php

We're passing the IP address instead of the domain name because LUV doesn't resolve the domain hostname to an IP address. So for the sake of simplicity, IP address is used. You can also run the script with the :option:`--verbose` option.