Creating Automated Post-Production Tests

You can add your own tests that EasyApache will run after each build. Simply create an option module (or “opt mod”) that runs the test.

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

ALERT! Warning: During tests, accessing a user’s directory as the root user is extremely insecure. If you wish to access a user’s directory during an automated post-production test, you’ll need to assume the identity of that user. cPanel will not provide support for servers that have been successfully attacked as a result of poorly designed tests.

To assume another user’s identity, you may use the following command:

  • su $username

If, for example, you wanted to test one of Apache’s specific functions, you will need to use the proper Apache namespace: Cpanel::Easy::Apache::$mytest, where $mytest is meant to stand for the name of your test file. When you create your test file, make sure that you use the filename extension *.pm. You do not need to use the filename extension when specifying your namespace.

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

Once you have created the test file(s), you will ned to place the file 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

This sample shows how a test file should be structured:

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;

Skipping your custom option modules/post-production tests

If need be, you are able to skip your custom option modules, including post-production tests, before build time. This can be useful for troubleshooting purposes.

To skip your custom option modules:

  1. Type the following command before build time:
    • /scripts/easyapache --skip-custom-optmods
  2. Rebuild Apache using the /scripts/easyapache script.

If you would prefer to use the WHM interface to skip these option modules:

  1. Click the Help link on the first EasyApache (Apache Update) screen.
  2. Check the Do not build any opt mods that are not included in ea3 core checkbox.
  3. Click Submit.
  4. Return to the previous screen and build the profile.

If the build completes successfully, the option modules need to be reconfigured or omitted.

Topic revision: r10 - 26 Nov 2010 - 17:31:46 - Main.MelanieSeibert
EasyApache3.CreatingTests moved from Sandbox.CreatingTests on 08 Jun 2009 - 14:47 by Main.JustinSchaefer - put it back
 

Copyright © cPanel 2000–2011.