Child pages
  • Automated Post-Production Tests
Skip to end of metadata
Go to start of metadata

Overview

You can create tests that EasyApache runs after each build. To do this, create an option module (opt mod) that runs the test.

Option modules are options that advanced administrators can add to the EasyApache 3 interface (Home >> Software >> EasyApache 3). For more information about opt mods, click Cpanel::Easy Framework POD on the first EasyApache 3 interface in WHM, or enter the /scripts/easyapache --perldoc command at the command line.

Warning:

It is extremely insecure to access a user's directory as the root user during tests. If you wish to access a user’s directory during an automated post-production test, assume the identity of that user. cPanel & WHM does not provide support for servers that have been successfully attacked as a result of poorly designed tests.

Getting started

To assume another user’s identity, run the following command:

su $username

For example, if you wish to test one of Apache's specific functions, you will need to use the proper Apache Cpanel::Easy::Apache::$mytest, namespace, where $mytest stands for the name of your test file. When you create your test file, make sure that you use the *.pm filename extension. You do not need to use the filename extension when you specify your namespace.

Test the functionality of PHP

If you wish to test the functionality of PHP 4 or 5, you will need to use the Cpanel::Easy::PHP$X:: $mytest namespace, where $X stands for the major version of PHP that you wish to test (4 or 5) and $mytest stands for the name of your test file. When you create your test file, make sure that you use the *.pm filename extension. You do not need to use the filename extension when you specify your namespace.

Place the test files into the directory that corresponds to the appropriate namespace:

  • For Apache — /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/Apache/$mytest.pm
  • For PHP4 — /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/PHP4/$mytest.pm
  • For PHP5 — /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/PHP5/$mytest.pm

The following sample shows how you should structure a test file:

package Cpanel::Easy::Apache::MyTestXYZ;
 our $easyconfig = {
    'name' => 'Add post restart tests for XYZ',
    'note' => 'This option does not alter anything with the build, it only adds tests to be run after a successful build and restart',
    'step'  => {
        '0' => {
            'name'    => 'Type A tests',
            'command' => sub {
                my ($easy) = @_;

                # see the post_httpd_restart_tests in Cpanel::Easy source for examples)                 push @{ $easy->{'_'}{'post_httpd_restart_tests'} }, 
                    {
                        'name'    => 'A2 support',
                        'command' => sub {
                            my ( $easy, $is_fatal_boolean_sr ) = @_;
                            
                            # do your tests for "A2 support" here  
                            # if all is well:                             return(1, 'ok');

                            # if not report it:                             # return(0, q{maketest suitable error message [_1]}, 'here'); 
                            # to abort the build (YOU PROBABLY DO NOT WANT TO USE THIS)                             # ${ $is_fatal_boolean_sr } = 1;                             # return(0, q{maketest suitable error message [_1]}, 'here');                         }, 
                    },
                    {
                        'name'  => 'A5 support',
                          ...
                    },
                ;
            },
        },
        '1' => {
            'name'    => 'Type B tests',
            'command' => sub {
                my ($easy) = @_;
                push @{ $easy->{'_'}{'post_httpd_restart_tests'} }, 
                ...
            },  
        },
    },

    # doesn't make much sense to add these tests unless we have the functionality     'depends'  => {
        'optmods' => {
            'Cpanel::Easy::Apache::XYZ' => 1, # This needs Apache's XYZ to be available         },
    },
};

1;

 

How to skip your custom option modules and post-production tests

You are able to skip your custom option modules and post-production tests before Apache is built. This can be useful if you need to troubleshoot an issue

To skip your custom option modules, perform the following steps at the command line:

  1. Run the following command before build time: 

    /scripts/easyapache --skip-custom-optmods
  2. Rebuild Apache with the /scripts/easyapache script.

If you prefer to use WHM's EasyApache 3 interface to skip these option modules, perform the following steps:

  1. Click Help on the first EasyApache 3 interface.
  2. Select the Do not build any opt mods that are not included in ea3 core box.
  3. Click Submit.
  4. Return to the previous interface and build the profile.

If the build completes successfully, you will then need to reconfigure or omit the option modules.