Welcome to the ELL PiClusterService. This is a simple Node.js web application that runs in Azure providing a simple way to manage a list of raspberry pi machines that are being used for testing.
This service provides a central place for the machines to register themselves when they reboot and for remote jobs to "lock" and "unlock" those machines to coordinate the usage of them so different test runs don't clobber each other.
The node.js service runs in memory so it is quick, but has limited scalability as a result. You can also integrate this with an Azure Dev Ops Build configuration to automate testing of your code on a raspberry pi cluster.
See also http://cluster.bitscope.com/
Install Node.js.
For local testing all you need to do is run npm install
.
Set the following environment variables:
Variable | Value |
---|---|
RPI_CLUSTER |
The URL of the cluster |
RPI_APIKEY |
The API key to use |
RPI_PASSWORD |
The login password for the cluster machines |
For local testing you can set RPI_CLUSTER to http://localhost:1337/
. Set the RPI_APIKEY to your own new unique guid.
Then simply load the folder into Visual Studio Code, then press F5 and select node.js
debugging and you should see this message:
Server running at http://localhost:1337
So point your web browser at this address to see the result.
You can also use npm start
from the command line.
See Node.js App Service Getting Started, to create your Node.js Azure Web App (but ignore all the steps about deploying with Zip). You will be deploying using git.
Once you follow all these steps you should have a service URL which should look
something like this: <app_name>.azurewebsites.net
. Replace all instances of
<app_name>.azurewebsites.net
you see below with your service URL.
Once your service is running you can choose how you want to deploy your updated bits. See App Service Deployment.
The web app also needs to set the RPI_APIKEY
environment, index.js
expects this to be set and you can configure that using
the Azure Portal under Application Settings.
If you use Github deployment from "local git" then once you have configured the upstream azure git repo using the URL provided in the Deployment Trigger URL in the Azure Management Portal Properties for your App Service you can push new bits by simply pushing to the upstream repo:
git push azure master
Once you have a service URL you can now set your local RPI_CLUSTER environment variable to point to your new service, see that you append "/api/" to the end of that URL, and yes that final "/" is important.
Variable | Value |
---|---|
RPI_CLUSTER |
<app_name>.azurewebsites.net/api/ |
Follow the instructions at ELL-PiDataCenter which show how to setup a Raspberry Pi machine so that it automatically registers itself with this service.
Once the above environment variables are configured you can test the service manually by running these scripts:
list.py
to list all available machines and see their status.lock.py ipaddress
to lock a machine listed as free on the website.unlock.py ipaddress
to unlock the machine when you are finished.
This is handy if you want to login using SSH and do long running work on a given machine, perhaps you need to install some new stuff and so on.
But if you want to automate a short job you can import picluster.py
into your app and do the following:
import picluster
cluster = picluster.PiBoardTable("<app_name>.azurewebsites.net/api/")
machine = self.cluster.wait_for_free_machine("some descriptive job name")
This will wait until a machine becomes available, lock it for your job, then you can do what drivetest does to send the job to the machine using SCP and SSH libraries. When the job is finished run this:
cluster.unlock(machine.ip_address)
This is picking up your user name as well and it ensures you are the only one that can free this machine that you locked. It is convenient to see who has locked the machine anyway, in case we need to follow up with that person to see if they are done in the event that something goes wrong and they accidentally forgot to free the machine.
The pitestfolder in the ELL repo shows how to create a fully automated test that uses this cluster service to get a free raspberry pi, then use SSH and SCP to copy bits over to that machine and run tests on it, get the results back, then unlock the machine.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.