Sync Reports to Central Database
Sahi reports can be synced from one machine to another using Sync functionality.This document describes the various ways in which reports can be synced from Machine A to Machine B. Both machines need to be running Sahi.
Sync can be performed manually or it can be set to automatic mode.
The source and destination database types can be different. For example, you can sync from h2.db to mysql.
Sync to a Central Database
While sync can be performed from any machine to any other machine, the real power lies in having Machine B as a Central machine and syncing reports from various other machines to Machine B.This is especially useful in a continuous integration setup where one wants to aggregate the reports of each build's run at a central location.
Manual Sync
To sync the reports from machine A to machine B, follow these steps (in essence, we are pushing logs from machine A to machine B):
- Open logs on machine A and select the scripts/suites that you want to Sync with machine B.
- Click on Sync button, which will open Sync Database dialog.
- Enter Sync Database details and click on Sync button. Following fields are available in the dialog:
- Host: Host name or IP address of machine B
- Port: The port on which Sahi is running. Unless changed, it should be 9999
- Your Machine Name: A user given machine name. This will be used as a reference to show which machine pushed the logs. In this case, it can be machine A.
- Sync Script Steps: Check this to Sync with all the steps in the scripts
- Sync Steps Images: Check this to Sync Images, if your script logs has images
- Number of Images at one request: Number of images you want to Sync in one request(in case of slow network speed, reduce the number. By default, this is 20.)
- After the sync is performed, Sahi shows a notification about success or failure.
- Refer to Trigger Email After Sync section for details on how to send emails after sync.
infoNote: Sahi should be running on both the machines for sync to be performed.
Auto Sync
In a typical continuous integration setup, the Sync needs to be done between the Sahi Master machine (Machine A) and Central database machine(Machine B). You can configure this as follows:
Sahi Master Machine
Configure the following in Sahi Master Machine.- Click on
Configure
link from Sahi Dashboard, and opensync_db.properties
. - Uncomment the below statements and enter the appropriate values.
syncdb.autosync.enable=true syncdb.autosync.host=centralDBHostIP syncdb.autosync.port=9999 syncdb.autosync.machineName=UserMachineName syncdb.autosync.syncSteps.enable=true syncdb.autosync.syncSteps.syncImages=true syncdb.autosync.syncSteps.imagesPerBatch=20 syncdb.autosync.syncSteps.artifactsPerBatch=20
infoNote that these values are indicative. You need to modify these values as appropriate.info- syncdb.autosync.host and syncdb.autosync.port refer to the host and port of the Central DB machine. syncdb.autosync.host can be IP address or machine name of the Central DB machine. syncdb.autosync.port is the port at which Sahi is running on the Central DB machine
- syncdb.autosync.machineName refers to the source machine from which reports are being synced. Give a unique name that distinguishes this machine from other machines in the Central DB.
- syncdb.autosync.syncSteps.enable - Setting this to false will not sync the steps in a script. Leave this as true.
- syncdb.autosync.syncSteps.syncImages - Setting this to true means that if a step has images (_takeScreenShot etc), it will get synced too. If you do not want images, set this to false.
- syncdb.autosync.syncSteps.imagesPerBatch - This controls how many images should be zipped and transferred at a time. Leave this as 20. Reduce this, if your network is slow.
- syncdb.autosync.syncSteps.artifactsPerBatch - This controls how many artifacts should be zipped and transferred at a time. This may need to be adjusted based on artifact sizes. Reduce this, if your network is slow.
- If you want to ignore some tests from Auto Sync, you can provide the regular expression using
syncdb.autosync.ignoreTests
. For example, to ignore all individual scripts (.sah files), you can use the following regular expression. This is a Java Regular Expression.syncdb.autosync.ignoreTests=.*[.]sah$
You can also ignore select suites from getting auto synced. - Refer to Trigger Email After Sync section for details on how to send emails after sync.
infoNote: Sahi should be running on both the machines for sync to be performed.
Whenever playback is completed for a sync unit (as decided by the ignoreTests parameter), Sahi will automatically Sync Reports to your Central Database Machine.
Trigger Email After Sync
To trigger email after manual sync or auto sync, follow the below steps.Destination Machine (Central Database Machine)
Configure the following on the Destination machine (Central Database Machine) to which reports are synced.info
NOTE: The configuration spans multiple configuration files.
- Click on
Configure
link from Sahi Dashboard, and opensync_db.properties
. Uncomment the statement below. - Click on
Configure
link from Sahi Dashboard, and opensync_db.properties
- To configure email.properties, refer to Email.properties section.
- Comment
"mail.to"
property (address of the receiver's) statement from email.properties file. - Click on
Configure
link from Sahi Dashboard, and opensync_email_trigger.txt
. When using a Central DB to sync all reports, emails can be sent to multiple people based on which machine(s) triggered the sync. Eg.machine1,machine2,projectx_.*=manager1@example.com,boss2@example.com machine3=email1@example.com, email2@example.com When reports are synced from machine1, machine2 or any machine starting with projectx_, emails will be sent to manager1@example.com and boss2@example.com. When reports are synced from machine3, emails will be sent to email1@example.com and email2@example.com.
The left hand side of the expression specifies the source machines (corresponding tosyncdb.autosync.machineName
insync_db.properties
) from where the reports were synced. You can specify multiple machine patterns separated by comma. Each machine pattern can be a Java Regular Expression that matchessyncdb.autosync.machineName
of a source machine. -
The email contains a
View Logs
link that points to the logs. Sometimes the IP address of the link does not come out correct - this can happen in case of a VM. In such cases, you can configure the machine and port details explicitly, by updating the following properties in userdata.properties.
By default, these values are not specified, and the machine's IP address and port will be taken.mail.centralDB.host= mail.centralDB.port=
syncdb.autosync.triggerEmail.enable=true
infoNOTE: Email address of the receivers need to be configured in
userdata/config/sync_email_trigger.txt
. Other properties should get defined in email.properties
.