Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
ability to control go client, closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
sveneh committed Feb 12, 2015
1 parent b746a3e commit 43279f3
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 38 deletions.
12 changes: 0 additions & 12 deletions ansible/_client-init.yml

This file was deleted.

29 changes: 29 additions & 0 deletions ansible/client-start-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# this is just for testing.
- name: Ansible-only testing scenario
hosts: tag_Name_client-01
# hosts: tag_Role_client
remote_user: ubuntu
gather_facts: false
roles:
- clients

tasks:
- include: roles/clients/tasks/start.yml
vars:

# these are normally set from the python controller
dbg_req_num_peers: 3
dbg_mining_cpu_percentage: 10

docker_container_id:
go: container_go
python: container_python

docker_run_args:
go: -loglevel=5 -seednode={{ groups['tag_Name_boot'][0] }}:30303 -maxpeer={{ dbg_req_num_peers }}
python: --logging :debug --log_json 1 --remote {{ groups['tag_Name_boot'][0] }} --port 30303 --mining {{ dbg_mining_cpu_percentage }} --peers {{ dbg_req_num_peers }}

docker_tee_args:
go: "{{ groups['tag_Name_elarch'][0]}}"
python: "{{ groups['tag_Name_elarch'][0]}}"
18 changes: 18 additions & 0 deletions ansible/client-stop-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# this is just for testing.
- name: Ansible-only testing scenario
hosts: tag_Name_client-01
# hosts: tag_Role_client
remote_user: ubuntu
gather_facts: false
roles:
- clients

tasks:
- include: roles/clients/tasks/stop.yml
vars:

# these are normally set from the python controller
docker_container_id:
go: container_go
python: container_python
20 changes: 17 additions & 3 deletions ansible/roles/clients/tasks/init.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
---
- name: initial start of ethereum go client, connection to bootstrapping node
docker:
image: "{{ docker_image['go'] }}"
name: "{{ dbg_container_id }}_go"
expose: ["8080", "30303"]
ports: ["20000:30203", "30000:30303"]

# parameters given to client
command: -loglevel=5 -seednode={{ groups['tag_Name_boot'][0] }}:30303 -maxpeer={{ dbg_req_num_peers }}
tags:
- go

- name: initial start of ethereum python client, connection to bootstrapping node
docker:
image: "{{ docker_image['python'] }}"
name: "{{ dbg_container_id }}"
name: "{{ dbg_container_id }}_python"
expose: ["30203", "30303"]
ports: ["30203:30203", "30303:30303"]
ports: ["22000:30203", "32000:30303"]

# parameters given to client
command: --logging :debug --log_json 1 --remote {{ groups['tag_Name_boot'][0] }} }} --port 30303 --mining {{ dbg_mining_cpu_percentage }} --peers {{ dbg_req_num_peers }}
command: --logging :debug --log_json 1 --remote {{ groups['tag_Name_boot'][0] }} --port 30303 --mining {{ dbg_mining_cpu_percentage }} --peers {{ dbg_req_num_peers }}
tags:
- python

- name: Log docker output to elarch
# fire and forget, don't wait to finish, run for one day
Expand Down
7 changes: 5 additions & 2 deletions ansible/roles/clients/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
- name: download latest client via docker
- name: download latest clients via docker
sudo: true
# the official ansible docker module does not have the option to just pull the image, it will also run it
shell: docker pull {{ docker_image['python'] }}
shell: docker pull {{ docker_image[item] }}
with_items:
- go
- python

- name: checkout git system-testing repo
git:
Expand Down
39 changes: 35 additions & 4 deletions ansible/roles/clients/tasks/start.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
---
# this will only work when missing parameters are injected into the inventory file.
- name: start client with parameters from inventory file
# TODO: run all clients in a loop

- name: start go client with parameters from inventory file
docker:
image: "{{ docker_image['go'] }}"
name: "{{ docker_container_id['go'] }}"
expose: ["8080", "30303"]
ports: ["20000:30203", "30000:30303"]
command: "{{ docker_run_args['go'] }}"
tags:
- go

- name: start python client with parameters from inventory file
docker:
image: "{{ docker_image['python'] }}"
name: "{{ docker_container_id['python'] }}"
expose: ["30203", "30303"]
ports: ["22000:30203", "32000:30303"]
command: "{{ docker_run_args['python'] }}"
tags:
- python

- name: Forward logfiles with parameters from inventory file
- name: Forward go logfiles with parameters from inventory file
# fire and forget, don't wait to finish, run for one day
async: 86400
poll: 0
# again, ansible docker module does not support logs
shell: docker logs --follow=true {{ docker_container_id['go'] }} 2>&1 | {{ repo_path }}/logging/teees.py {{ docker_tee_args['go'] }}
register: log_runner_go
tags:
- go

- name: verify previous task
async_status: jid={{ log_runner_go.ansible_job_id }}
tags:
- go

- name: Forward python logfiles with parameters from inventory file
async: 86400
poll: 0
shell: docker logs --follow=true {{ docker_container_id['python'] }} 2>&1 | {{ repo_path }}/logging/teees.py {{ docker_tee_args['python'] }}
register: log_runner
register: log_runner_python
tags:
- python

- name: verify previous task
async_status: jid={{ log_runner.ansible_job_id }}
async_status: jid={{ log_runner_python.ansible_job_id }}
tags:
- python
40 changes: 32 additions & 8 deletions ansible/roles/clients/tasks/stop.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
---
# this will only work when missing parameters are injected into the inventory file.
- name: Stop client docker instances
# TODO do all in a loop

- name: Stop go client docker instances
# ansible docker does not support stop by container name, only by image name. Stupid.
shell: docker stop {{ docker_container_id['go'] }}
tags:
- go

- name: Persist state of stopped go client
# ansible docker module does not support this ...
shell: docker commit {{ docker_container_id['go'] }} {{ docker_image['go'] }}
tags:
- go

- name: Stop go docker log forwarding
# there is no Ansible API to stop async tasks, unfortunately.
shell: pkill --parent $(pgrep --full "docker logs.*{{ docker_container_id['go'] }}.*teees")
# pkill gives -15 return code, don't know why. Ignore it
failed_when: false
tags:
- go

- name: Stop python client docker instances
# ansible docker does not support stop by container name, only by image name. Stupid.
shell: docker stop {{ docker_container_id['python'] }}
tags:
- python

- name: Persist state of stopped client
- name: Persist state of stopped python client
# ansible docker module does not support this ...
shell: docker commit {{ docker_container_id['python'] }} {{ docker_image['python'] }}
tags:
- python


- name: Stop docker log forwarding
- name: Stop python docker log forwarding
# there is no Ansible API to stop async tasks, unfortunately.
shell: "{{ item }}"
with_items:
- pkill --full teees
- pkill --full "docker logs"
shell: pkill --parent $(pgrep --full "docker logs.*{{ docker_container_id['python'] }}.*teees")
# pkill gives -15 return code, don't know why. Ignore it
failed_when: false
tags:
- python
8 changes: 2 additions & 6 deletions ansible/roles/clients/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
repo_path: /home/ubuntu/git

docker_image:
python : sveneh/pyethereum-develop

# client configuration details - only valid for ansible testing,
dbg_container_id: container_id
dbg_req_num_peers: 3
dbg_mining_cpu_percentage: 10
go: sveneh/go-ethereum
python: sveneh/pyethereum-develop
20 changes: 17 additions & 3 deletions scenarios/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

key_file = '../ansible/system-testing.pem'

# needs some for go, too
docker_run_args = '--logging :debug --log_json 1 --remote {bootstrap_ip} --port 30303 ' \
'--mining {mining_cpu_percentage} --peers {req_num_peers} --address {coinbase}'
teees_args = '{elarch_ip} guid,{pubkey_hex}'
Expand All @@ -37,7 +38,8 @@ def mk_inventory_executable(inventory):

def exec_playbook(inventory, playbook):
fn = mk_inventory_executable(inventory)
args = ['ansible-playbook', '../ansible/%s' % playbook, '-i', fn] + ansible_args
# replace for go with --tags=go or delete to address both
args = ['ansible-playbook', '../ansible/%s' % playbook, '-i', fn, '--tags=python'] + ansible_args
print 'executing', ' '.join(args)
result = subprocess.call(args)
if result:
Expand Down Expand Up @@ -65,22 +67,34 @@ def start_clients(clients=[]):
mining_cpu_percentage=mining_cpu_percentage,
req_num_peers=req_num_peers,
coinbase=coinbase)
# add here go parmeters
d['vars']['docker_run_args'] = {}
d['vars']['docker_run_args']['python'] = dra
d['vars']['docker_container_id'] = {}
d['vars']['docker_container_id']['python'] = client
d['vars']['docker_tee_args'] = {}
d['vars']['docker_tee_args']['python'] = teees_args.format(elarch_ip=inventory.es, pubkey_hex=pubkey)
inventory.inventory[client] = d
print json.dumps(inventory.inventory, indent=2)
# exec_playbook(inventory.inventory, playbook='client-start.yml')
# print json.dumps(inventory.inventory, indent=2)
exec_playbook(inventory.inventory, playbook='client-start.yml')


def stop_clients(clients=[]):
# create group in inventory
inventory = Inventory()
clients = clients or list(inventory.clients)
inventory.inventory['client_stop_group'] = dict(children=clients, hosts=[])
assert inventory.es
assert inventory.boot
for client in clients:
assert client
d = dict(hosts=inventory.inventory[client], vars=dict())
# add the same for go
d['vars']['docker_container_id'] = {}
d['vars']['docker_container_id']['python'] = client
# add the same container id for go
inventory.inventory[client] = d
# print json.dumps(inventory.inventory, indent=2)
exec_playbook(inventory.inventory, playbook='client-stop.yml')


Expand Down

0 comments on commit 43279f3

Please sign in to comment.