Deploying and Testing Configuration

When your configuration is complete it is important to ensure it works as intended. Socotra supports testing through a process which deploys configuration for quick testing. Configuration can be deployed onto empty instances to ensure that your setup works as intended.

Deploying a Configuration

  1. Make a zip file with the configuration you wish to test.

  2. Using your Socotra Sandbox credentials, authenticate with the Socotra Sandbox API using the authentication endpoint.

  3. Save the token in the API response for use in the next step.

  4. POST the zipfile to the test configuration deploy endpoint.

    • The endpoint will deploy the configuration and return the instance name and hostname to the user.

    • You may specify the tenant name, the instance’s unique identifier, in this step.

      • The first half of the instance name created by this endpoint is your username.

      • The second half may be specified in the request using the tenantNameSuffix parameter.

      • If the suffix is not specified, it will be randomly generated.

    • The users specified in your test_users.json file will be created on the instance.

  5. Log into the hostname from the API response using one of your test users’ credentials and test your configuration.

Reusing an Instance

Socotra supports deploying different configurations onto the same instance. This is useful when testing requires reusing data that already exists on a instance. When deploying configuration the instance name can be specified in the request. If the instance name has been deployed onto before then it will be deployed onto again. Note that deploying onto the same instance may cause problems when configuration changes are not backwards compatible.


See the Product Versioning topic for information on avoiding problems with updated configurations.

Example Implementation

This is a python script demonstrating the process for deploying a configuration:

$ python -z /home/socotra/ -u jsmith -p password
import argparse
import json
import requests

API_URL = ''

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('--zipfile', '-z', help='The path to the zipfile containing configuration')
    parser.add_argument('--username', '-u', help='Your Socotra username')
    parser.add_argument('--password', '-p', help='Your Socotra password')
    parser.add_argument('--hostname', '-n', help='The hostname is a combination of your account '
                                                 'name and the suffix specified here. Not Required')
    return parser.parse_args()

def main():
    args = parse_args()
    client = SocotraClient(API_URL)
    client.authenticate(args.username, args.password)
    response = client.load_configuration_for_testing(args.zipfile, args.hostname)
    if response['success']:
        print 'Tenant loaded at %s' % response['hostname']
        print 'Tenant failed to load'

class SocotraClient(object):
    def __init__(self, api_url):
        self.api_url = api_url
        self.session = requests.Session()

    def _post(self, *args, **kwargs):
        response =*args, **kwargs)
        response_json = json.loads(response.text)
        if response.status_code != 200:
            message = "POST request to %s failed with status %s and message: %s"
            message = message % (response.url, response.status_code, response_json.get('message'))
            raise Exception(message)
            return response_json

    def authenticate(self, username, password):
        endpoint = self.api_url + '/account/authenticate'
        json_body = {'username': username,
                     'password': password}
        response = self._post(endpoint, json=json_body)
        token = response['authorizationToken']
        return self.session.headers.update({'Authorization': token})

    def load_configuration_for_testing(self, zipfile_location, tenant_suffix):
        endpoint = self.api_url + '/configuration/deployTest'
        multipart_form_data = {
            'zipFile': open(zipfile_location, 'rb')
        return self._post(endpoint, files=multipart_form_data,
                          data={'tenantNameSuffix': tenant_suffix})

if __name__ == "__main__":