Useful Sandbox Operations

We often come across sandboxes for debugging and some times as proof of concept.

Summing up a few operations here.

SSH into Sandbox

  • ssh github_username@sandbox_link

Install Package on Sandbox

  • sudo su root
  • source /edx/app/edxapp/venvs/edxapp-sandbox/bin/activate (activates python virtual environment)
  • Install package
    • For example:  
      • pip install requests

Run manage.py command

  • sudo -u www-data /edx/app/edxapp/venvs/edxapp/bin/python /edx/app/edxapp/edx-platform/manage.py lms --settings production [command (shell/dbshell/migrate etc)]
    • For example: 

      • sudo -u www-data /edx/app/edxapp/venvs/edxapp/bin/python /edx/app/edxapp/edx-platform/manage.py lms --settings production dbshell
        • This command will get you in mysql> prompt.

Set Break Point (run server using manage.py runserver)

The Python debugger (pdb) requires real time interactive server daemon( as we run on local). On sandox this can be done as

  • Get into interactive supervisor console:
    • sudo /edx/bin/supervisorctl

  • Stop the lms, cms, and edxapp workers in the interactive supervisor console:
    • stop lms cms edxapp_worker:

  • Exit the interactive supervisor console:
    • exit
  • Launch the lms/cms using the debug server:
    • cd /edx/app/edxapp/edx-platform

    • LMS runs on port 8000, for lms runserver command will be:
      • sudo -u www-data LMS_CFG=/edx/etc/lms.yml /edx/bin/python.edxapp ./manage.py lms runserver 8000 --settings production
    • CMS runs on port 8010, for cms runserver command will be:
      • sudo -u www-data STUDIO_CFG=/edx/etc/studio.yml /edx/bin/python.edxapp ./manage.py cms runserver 8010 --settings production
  • Restart server normally after debugging:
    • sudo /edx/bin/supervisorctl restart lms cms edxapp_worker:

If you want to use pudb instead of pdb:

  • Get into interactive supervisor console:
    • sudo /edx/bin/supervisorctl

  • Stop the lms, cms, and edxapp workers in the interactive supervisor console:
    • stop lms cms edxapp_worker:

  • Exit the interactive supervisor console:
    • exit
  • Simulate a login shell:
    • sudo su - www-data -s /bin/bash
  • Launch the lms/cms using the debug server:
    • cd /edx/app/edxapp/edx-platform

    • LMS runs on port 8000, for cms runserver command will be:
      • /edx/bin/python.edxapp ./manage.py lms runserver 8000 --settings production
    • CMS runs on port 8010, for cms runserver command will be:
      • /edx/bin/python.edxapp ./manage.py cms runserver 8010 --settings production
  • Logout of the login shell:
    • logout
  • Restart server normally after debugging:
    • sudo /edx/bin/supervisorctl restart lms cms edxapp_worker:

Enable Social Auth (Google)

Following are steps to enable third party authentication.

First make project on google developer console and enable google+ api.

Authorized redirect URI while making credentials for your project will be as: {sandbox-link}/auth/complete/google-oauth2/

  Note down credentials (Client ID and secret)

  • sudo nano /edx/app/edxapp/lms.auth.json
    • Add following:

      • "THIRD_PARTY_AUTH":{
        "Google":{
        "SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "{client ID}",
        "SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET": "{client secret}"
        }
        },
  • sudo nano /edx/app/edxapp/lms.env.json
    • Set  "ENABLE_THIRD_PARTY_AUTH": true


  • sudo -u www-data /edx/app/edxapp/venvs/edxapp/bin/python /edx/app/edxapp/edx-platform/manage.py lms --settings production dbshell
    • This command will open mysql prompt, in this prompt

      • use edxapp;
      • INSERT INTO third_party_auth_oauth2providerconfig VALUES ('1', '2017-01-01 18:29:39.000000', '1', 'fa-google-plus', 'Google', '0', '0', '0', 'google-oauth2', '{client ID}', '{client secret}', '{}', NULL, '', '1', 'google-oauth2', '1');
  • sudo /edx/bin/supervisorctl restart edxapp:


Enable Ecommerce App

Ecommerce app needs to be enabled explicitly, following are steps.

Make sure that ecommerce was checked while creating sandbox.

Then do following:

  • sudo -H -u ecommerce bash
    • Gets into bash prompt
  • source /edx/app/ecommerce/ecommerce_env
    • Activates ecommerce environment
  • cd /edx/app/ecommerce/ecommerce/
    • Gets into ecommerce repo
  • python manage.py create_or_update_site --site-id=1 --site-domain=ecommerce-{sandbox link} --partner-code=edX --partner-name="Open edX" --lms-url-root=https://{sandbox link} --theme-scss-path=sass/themes/edx.scss --payment-processors=cybersource,paypal --client-id="ecommerce-key" --client-secret="ecommerce-secret" --from-email="{email address}"
  • Example command:
  • exit
  • sudo /edx/bin/supervisorctl restart ecommerce


  • Ecommerce app should be running now at https://ecommerce-{sandbox link} e.g https://ecommerce-credit-req.sandbox.edx.org.
  • (In case of ‘invalid_request’ error) --site-domain  in command is URL of trusted client added by default for ecommerce app use. Make sure URL and Redirect URL of trusted client is set accordingly with this command i.e 
    ecommerce-{sandbox link} and ecommerce-{sandbox link}/complete/edx-oidc/. Trusted Clients are at 
    {sandbox link}/admin/edx_oauth2_provider/trustedclient/. You will need a superuser to access admin site.
  • In this case check lms.auth.json, lms.env.json and update all the redirect uri's to the sandbox link e.g.  ecommerce-{sandbox link}.

Note: This guide assumes that sandbox was created with clients and trusted clients. Sandbox by default create clients and trusted clients.

Enable Ecommerce basket Page

By default edxapp does not uses the normal checkout flow. To enable ecommerce basket page and checkout do following steps

  • make sure staff has superuser rights
  • go to lms admin page (https://{sandbox_name}.sandbox.edx.org/admin/)
  • got to 'commerceconfiguration' in lms
  • add new configurations 
    • Check 'Enabled 
    • Check 'Checkout on ecommerce service'

Now go to lms clients (https://{sand-box-name}.sandbox.edx.org/admin/oauth2/client/)

if there is a client for ecommerce services confirm following settings else create one with following settings (Use urls according to url sandbox)

after that go to ecommerce.yml

sudo nano /edx/etc/ecommerce.yml

confirm following settings of JWT if something is missing add it.

JWT_AUTH:
    JWT_AUDIENCE: ecommerce-key  # It should be same as described in lms client.
    JWT_SECRET_KEY: ecommerce-secret  # It should be same as described in lms client.
    JWT_SECRET_KEYs:
    - ecommerce-secret
    JWT_ISSUERS:
    - ecommerce_worker
    JWT_VERIFY_EXPIRATION: False
    JWT_VERIFY_AUDIENCE: False

Now go to lms.env.json file

sudo nano /edx/app/edxapp/lms.env.json

confirm the following JWT_AUTH settings

JWT_AUTH:
    JWT_AUDIENCE: ecommerce-key  # It should be same as described in lms client.
    JWT_SECRET_KEY: ecommerce-secret  # It should be same as described in lms client.

Enable Payment Processor on Sandbox

Use the Following commands to setup the payment processor

sudo nano /edx/etc/ecommerce.yml

Search 'PayPal' in 'ecommerce.yml', Provide client_id , secret_id from your PayPal sandbox account and update mode value to 'sandbox'

Example:

client_id : 'AVhxxxxxxDm2'

secret_id : 'EMVxxxxxxGV8'

Restart the worker using the following commands:

sudo /edx/bin/supervisorctl restart edxapp: edxapp_worker: ecommerce:

*for additional paypal sandbox infromation check paypal sandbox documentation.