Installation

How to automate init of depths, locations, location_addresses?

How to automate init of depths, locations, location_addresses?

by Allan Metts -
Number of replies: 4

I've automated the installation of Georgia Tech's WeBWork on AWS using Terraform and Ansible.  We're re-deploying it from scratch each semester to keep things clean with respect to content, patching, and user access.  

All authentication happens via the Canvas LTI, and courses are added via command line.  With this setup, the admin course and non-LTI-based logins are not necessary.  Except...

Unfortunately, the "depths", "locations", and "location_addresses" tables created on the first access of the admin course. 

Is there an alternative way to properly initialize these tables?  As it stands now, I have to...

  1. Set up the admin course when I don't need it
  2. Log into a server and disable external-only authentication
  3. Log into the admin course via a browser to trigger the table creation
  4. Re-enable external-only authentication

This is not at all compatible with an automated deployment!  Thanks in advance for any guidance or suggestions.

Allan Metts, Georgia Tech

In reply to Allan Metts

Re: How to automate init of depths, locations, location_addresses?

by Michael Gage -

This initialization is done in the subroutine:  InitNonNativeTables()

(searching for that term in the webwork2 directory I get:

~/webwork-docker2/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm:37:                                         listArchivedCourses unarchiveCourse initNonNativeTables);
~/webwork-docker2/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm:70:     my $table_update_result = initNonNativeTables($ce, $ce->{dbLayoutName});
~/webwork-docker2/webwork2/lib/WeBWorK/Utils/CourseManagement.pm:52:     initNonNativeTables
~/webwork-docker2/webwork2/lib/WeBWorK/Utils/CourseManagement.pm:1143: =item initNonNativeTables($ce, $db, $dbLayoutName, %options)
~/webwork-docker2/webwork2/lib/WeBWorK/Utils/CourseManagement.pm:1152: sub initNonNativeTables {

so the function is define on line 1152 of .../Utils/CourseManagement.pm and called on line 70 of CourseAdmin.pm (which is the admin course front page)

You should be able to write a short script fragment which you can use with wwsh.  one example of such a fragment is addadmin which is called from the bin directory via    wwsh admin ./addadmin 

You comments in wwsh may be enough to tell you how you could access the initNonNativeTables() function and run it from the command line.

I've not tried it, but it seems like it might work. Let us know how it goes.

-- Mike

In reply to Michael Gage

Re: How to automate init of depths, locations, location_addresses?

by Allan Metts -
Thanks, Mike. I gave it a whirl, but punted in the end and added these tables with a manual login to the Admin course. Looking at intNonNativeTables, it appears that it's doing quite a bit more than addAdmin. If I'm interpreting things correctly, it's consulting a reference DB layout and deciding for itself what represents a "non-native table". I was hoping to find three simple "create table" statements somewhere.

Unfortunately, I'm not fluent at all in PERL -- and even less familiar with WebWork's design and implementation. I pasted the entire subroutine into a fresh file, added a command at the bottom of the file to run that subroutine, and executed the file with wwsh. I got complaints of uninitialized variables and decided I'd reached the end of my competency. :)

I'll post this into GitHub issues in case someone else considers this a worthwhile improvement to the application. Thanks for helping me out!
In reply to Allan Metts

Re: How to automate init of depths, locations, location_addresses?

by Andrew Parker -

instead of copying the subroutine verbatim, import the function itself. It's defined in CourseManagement, so our wwsh script only actually needs two lines.

# tell WeBWorK to import 'initNonNativeTables' from WeBWorK/Utils/CourseManagement.pm
use WeBWorK::Utils::CourseManagement 'initNonNativeTables';

# execute the subroutine as called in CourseAdmin.pm
my $table_update_result = initNonNativeTables($ce, $ce->{dbLayoutName});

# see what's in the return value
warn Dumper($table_update_result);
exit;


In reply to Andrew Parker

Re: How to automate init of depths, locations, location_addresses?

by Allan Metts -

Thanks for posting this, Andrew.  I haven't had a chance to try it on an un-initialized system yet, but it looks like it's exactly what I need.  I'll update the GitHub issue I created previously with your suggestion.