
THE WIKIPEDIA ZERO AUTOMATION TEST SCRIPT

The Wikipedia Zero automation test script is housed within the ZeroRatedMobileAccess Gerrit/Git project under the directory maintenance/phantom. The script is named zero_automated_tests.js and it has an accompanying job.sh execution and mailer script and diskusage.sh mailer script.

$ crontab -l

PATH=/bin:/usr/bin

# every hour:
20 * * * * /home/user/job.sh minor
# twice daily:
45 16 * * * /home/user/job.sh tech
45 22 * * * /home/user/job.sh tech
# once weekly on Wednesday:
05 21 * * 3 /home/user/job.sh major
# need to make the following more useful
50 23 * * * /home/user/diskusage.sh

Be sure to establish appropriate permissions:

$ chmod 740 job.sh
$ chmod 740 diskusage.sh

You'll need to get some dependencies setup to avoid unnecessary errors when job.sh runs. See the following.

Note that security patches are applied to the server regularly and the server is rebooted upon patch.

$ sudo crontab -l

PATH=/usr/sbin:/usr/bin:/sbin:/bin

01 07 * * * /usr/bin/apt-get update && /usr/bin/unattended-upgrade && /usr/bin/mailx -s "Applied Security Patches" SOMEBODY+HERE@wikimedia.org && /sbin/shutdown -r 5


job.sh runs casperjs zero_automated_tests.js to look at Wikipedia Zero banners, and emails results:
* Hourly to the email(s) in minor
* Twice daily to the email(s) in tech
* Once per week to the email(s) in major. major also gets emails anytime the status is FAILED.

CasperJS and its dependency PhantomJS constitute a "headless WebKit browser" solution allowing for accessing webpages, and then doing interesting things like simulating real user behavior and taking screenshots, while providing introspection of browser requests and responses if wanted.

Currently, CasperJS and PhantomJS are installed from the latest stable compiled packages at http://docs.casperjs.org/en/latest/installation.html and http://casperjs.org/ http://phantomjs.org/download.html. To setup on an Ubuntu machine, for example:

$ cd
$ wget https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
$ sudo mv phantomjs-1.9.1-linux-x86_64.tar.bz2 /opt
$ cd /opt
$ sudo tar xvjf phantomjs-1.9.1-linux-x86_64.tar.bz2
$ sudo rm phantomjs-1.9.1-linux-x86_64.tar.bz2
$ sudo ln -s /opt/phantomjs-1.9.1-linux-x86_64/bin/phantomjs /bin/phantomjs
$ phantomjs
phantomjs>

If you get an error about libfontconfig.so.1, just run the following:

$ sudo apt-get install libfontconfig
$ phantomjs
phantomjs>

Now enter Ctrl+C to get out of the phantomjs prompt.

Then:

$ cd
$ curl -o casper.tar.gz -L https://github.com/n1k0/casperjs/tarball/1.0.3
$ sudo mv casper.tar.gz /opt
$ cd /opt
$ sudo tar xvzf casper.tar.gz
$ sudo rm casper.tar.gz
$ sudo ln -s /opt/n1k0-casperjs-76fc831/bin/casperjs /bin/casperjs
$ casperjs

That should print a help message, and if there aren't any errors, then you'll want to install some other stuff now.

job.sh does some zipping of files. Install zip:

$ sudo apt-get update
$ sudo apt-get install zip

FINALLY!

More detail on job.sh:

It runs a CasperJS script that:

1. Logs in with the username 'zerobdd' and the password stored an access controlled configuration file.
1. Gets operator configurations.
2. Screen captures a bunch of URLs under access simulated from each operator network.
3. Barks if it sees Wikipedia Zero banners when it shouldn't, or doesn't see Wikipedia Zero banners when it should.

It then emails the screen captures in case of encountering a FAILED status. okay or UNKNOWN statuses at the moment don't need attachments.

WHAT diskusage.sh DOES:

A disk usage email is also sent daily to the user in the file 'duemail'.


SOME NOTES:

The scripts do not attempt to perform elegant try-catch logic for unexpected errors. Such errors should be investigated by an engineer.
