Python client for DCI Control Server
Project description
# python-dciclient
## Installation
One should retrieve the package available at
https://packages.distributed-ci.io/dci-release.el7.noarch.rpm and install it.
Then simply run `yum install python-dciclient`.
## Example
```python
#!/usr/bin/env python
import dciclient.v1.api.context as dci_context
import dciclient.v1.api.job as dci_job
import dciclient.v1.api.jobstate as dci_jobstate
import dciclient.v1.api.file as dci_file
import io
# Basic function that simulates a test run and log creation
def execute_testing(content=None):
with io.open('test.log', 'w') as f:
f.write(unicode(content))
return True
# Our DCI connection
dci_context = dci_context.build_dci_context(
'http://127.0.0.1',
'remoteci_1',
'welcome')
# RemoteCI id and Topic id -- probably better to be dynamically passed in
remoteci_id = 'fd6c285c-fa57-4aa8-a8b3-c68a4acdfa9c'
topic_id = 'fe145e49-992a-4843-a44f-b058c7a05261'
# schedule the job and pull down data
job = dci_job.schedule(dci_context, remoteci_id=remoteci_id, topic_id=topic_id).json()
job_id = job['job']['id']
job_full_data = dci_job.get_full_data(dci_context, job_id)
# create initial jobstate of pre-run
jobstate = dci_jobstate.create(dci_context, 'pre-run', 'Initializing the environment', job_id)
print "This is where we'd do some stuff to init the environment"
# update the jobstate to start the job run
dci_jobstate.create(dci_context, 'running', 'Running the test', job_id)
jobstate_id = dci_context.last_jobstate_id
print "This is where we'd run some tests"
result = execute_testing(content=job_full_data)
# read our testing log and push to the DCI control server
with io.open('test.log', encoding='utf-8') as f:
content = f.read(20 * 1024 * 1024) # default file size is 20MB
dci_file.create(dci_context, 'test.log', content, 'text/plain', jobstate_id)
# Check if our test passed successfully
print "Submit result"
if result:
final_status = 'success'
else:
final_status = 'failure'
# Set final job state based on test pass/fail
dci_jobstate.create(dci_context, final_status, "Job has been processed.", job_id)
```
## Installation
One should retrieve the package available at
https://packages.distributed-ci.io/dci-release.el7.noarch.rpm and install it.
Then simply run `yum install python-dciclient`.
## Example
```python
#!/usr/bin/env python
import dciclient.v1.api.context as dci_context
import dciclient.v1.api.job as dci_job
import dciclient.v1.api.jobstate as dci_jobstate
import dciclient.v1.api.file as dci_file
import io
# Basic function that simulates a test run and log creation
def execute_testing(content=None):
with io.open('test.log', 'w') as f:
f.write(unicode(content))
return True
# Our DCI connection
dci_context = dci_context.build_dci_context(
'http://127.0.0.1',
'remoteci_1',
'welcome')
# RemoteCI id and Topic id -- probably better to be dynamically passed in
remoteci_id = 'fd6c285c-fa57-4aa8-a8b3-c68a4acdfa9c'
topic_id = 'fe145e49-992a-4843-a44f-b058c7a05261'
# schedule the job and pull down data
job = dci_job.schedule(dci_context, remoteci_id=remoteci_id, topic_id=topic_id).json()
job_id = job['job']['id']
job_full_data = dci_job.get_full_data(dci_context, job_id)
# create initial jobstate of pre-run
jobstate = dci_jobstate.create(dci_context, 'pre-run', 'Initializing the environment', job_id)
print "This is where we'd do some stuff to init the environment"
# update the jobstate to start the job run
dci_jobstate.create(dci_context, 'running', 'Running the test', job_id)
jobstate_id = dci_context.last_jobstate_id
print "This is where we'd run some tests"
result = execute_testing(content=job_full_data)
# read our testing log and push to the DCI control server
with io.open('test.log', encoding='utf-8') as f:
content = f.read(20 * 1024 * 1024) # default file size is 20MB
dci_file.create(dci_context, 'test.log', content, 'text/plain', jobstate_id)
# Check if our test passed successfully
print "Submit result"
if result:
final_status = 'success'
else:
final_status = 'failure'
# Set final job state based on test pass/fail
dci_jobstate.create(dci_context, final_status, "Job has been processed.", job_id)
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dciclient-0.1a4.tar.gz
(24.3 kB
view details)
File details
Details for the file dciclient-0.1a4.tar.gz
.
File metadata
- Download URL: dciclient-0.1a4.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bad387d1cc38cdad5465f5630dad36567f9fe25c62ea593271b76c065320047 |
|
MD5 | 4f052fc2a21c7f8b1b9c621ab70eba78 |
|
BLAKE2b-256 | 14db89ccd018e8d79e5f7bbccde2ed7f424640dbda0ad51bdbadfbd8b8743db0 |