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

Commit

Permalink
adjusted to support Go networking poc-8, using the automatic Docker
Browse files Browse the repository at this point in the history
build from gitub go-ethereum, refactored global variables into separate
file. Closes #30 , again.
  • Loading branch information
sveneh committed Feb 18, 2015
1 parent 522d277 commit 32a0006
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
system-testing.pem
ping.yml
testing.yml
test.yml
venv/
*.pyc
*.sw?
*.bak
*~
roles/aws/tasks/add_host.yml
roles/aws/tasks/check_ssh.yml
Expand Down
18 changes: 18 additions & 0 deletions ansible/client-reset-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/reset.yml
vars:

# these are normally set from the python controller
docker_container_id:
go: container_go
python: container_python
2 changes: 1 addition & 1 deletion ansible/client-start-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
python: container_python

docker_run_args:
go: -loglevel=5 -seednode={{ groups['tag_Name_boot'][0] }}:30303 -maxpeer={{ dbg_req_num_peers }}
go: -loglevel=5 -port=30000 -bootnodes=enode://{{ g_boot_public_key }}@{{ 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:
Expand Down
2 changes: 1 addition & 1 deletion ansible/client-stop-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- clients

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

# these are normally set from the python controller
Expand Down
10 changes: 10 additions & 0 deletions ansible/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# these are variables needed in multiple places in the playbooks. They are all name-space'd with g_lobal

# the docker images we use for client
g_docker_image:
go: ethereum/client-go
python: sveneh/pyethereum-develop

# the private key of the bootstrap node is defined in roles/boot/vars/main.yml, this is only the public key
g_boot_public_key: 829bb728a1b38d2e3bb8288d750502f7dce2ee329aaebf48ddc54e0cfc8003b3068fe57e20277ba50e42826c4d2bfcb172699e108d9e90b3339f8b6589449faf
9 changes: 9 additions & 0 deletions ansible/roles/boot/files/docker-go-boot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ethereum go bootnode
FROM ethereum/client-go

WORKDIR $GOPATH/src/github.com/ethereum/go-ethereum
RUN git checkout develop
RUN godep restore
RUN go install -v ./cmd/bootnode

ENTRYPOINT ["bootnode"]
39 changes: 34 additions & 5 deletions ansible/roles/boot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,41 @@
# ports: 30303:30303
# command: --client-name bootstrap --mining off

- name: download / updates latest Go clients base 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 {{ g_docker_image['go'] }}
register: docker_pull_out
changed_when: '"Downloaded newer image" in docker_pull_out.stdout'


- name: Start bootstrapping node (python client)
- name: Prepare building go bootstrap image
copy: src=../files/docker-go-boot dest=/tmp

- name: Build go bootstrap image locally
sudo: yes
docker_image:
path: /tmp/docker-go-boot
name: local/eth-go-boot
state: build


- name: Start bootstrapping node (go)
sudo: yes
docker:
image: sveneh/pyethereum-develop
expose: 30303
ports: 30303:30303
command: --peers 0 --mining 0
image: local/eth-go-boot
expose:
- 30303/tcp
- 30303/udp
ports:
- 30303:30303/tcp
- 30303:30303/udp
command: -nodekeyhex={{ boot_private_key }} -addr=:30303

#- name: Start bootstrapping node (python client)
# sudo: yes
# docker:
# image: sveneh/pyethereum-develop
# expose: 30303
# ports: 30303:30303
# command: --peers 0 --mining 0
2 changes: 2 additions & 0 deletions ansible/roles/boot/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
boot_private_key: 4742e32d05c9f8b7016db3444664f4cf82c3362e002d09429cad411569b07763
4 changes: 2 additions & 2 deletions ansible/roles/clients/tasks/init.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: initial start of ethereum go client, connection to bootstrapping node
docker:
image: "{{ docker_image['go'] }}"
image: "{{ g_docker_image['go'] }}"
name: "{{ dbg_container_id }}_go"
expose: ["8080", "30303"]
ports: ["20000:30203", "30000:30303"]
Expand All @@ -13,7 +13,7 @@

- name: initial start of ethereum python client, connection to bootstrapping node
docker:
image: "{{ docker_image['python'] }}"
image: "{{ g_docker_image['python'] }}"
name: "{{ dbg_container_id }}_python"
expose: ["30203", "30303"]
ports: ["22000:30203", "32000:30303"]
Expand Down
4 changes: 3 additions & 1 deletion ansible/roles/clients/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
- 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[item] }}
shell: docker pull {{ g_docker_image[item] }}
with_items:
- go
- python
register: docker_pull_out
changed_when: '"Downloaded newer image" in docker_pull_out.stdout'

- name: checkout git system-testing repo
git:
Expand Down
30 changes: 26 additions & 4 deletions ansible/roles/clients/tasks/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,46 @@

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

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


- name: ensure the go clients runs, check cmd-line parameters if this fails
shell: docker ps
register: docker_ps_out
failed_when: not docker_container_id['go'] in docker_ps_out.stdout
tags:
- go


- name: ensure the python clients runs, check cmd-line parameters if this fails
shell: docker ps
register: docker_ps_out
failed_when: not docker_container_id['python'] in docker_ps_out.stdout
tags:
- python

- name: Forward go logfiles with parameters from inventory file
# fire and forget, don't wait to finish, run for one day
async: 86400
Expand Down
4 changes: 2 additions & 2 deletions ansible/roles/clients/tasks/stop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

- name: Persist state of stopped go client
# ansible docker module does not support this ...
shell: docker commit {{ docker_container_id['go'] }} {{ docker_image['go'] }}
shell: docker commit {{ docker_container_id['go'] }} {{ g_docker_image['go'] }}
ignore_errors: true
tags:
- go
Expand All @@ -33,7 +33,7 @@

- name: Persist state of stopped python client
# ansible docker module does not support this ...
shell: docker commit {{ docker_container_id['python'] }} {{ docker_image['python'] }}
shell: docker commit {{ docker_container_id['python'] }} {{ g_docker_image['python'] }}
ignore_errors: true
tags:
- python
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/clients/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
repo_path: /home/ubuntu/git

docker_image:
go: sveneh/go-ethereum
go: ethereum/client-go
python: sveneh/pyethereum-develop
8 changes: 6 additions & 2 deletions ansible/roles/ec2/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
from_port: 20000
to_port: 22999
cidr_ip: "{{ ec2_ip_access_range }}"
# ethereum incoming connection port
# ethereum incoming connection ports
- proto: udp
from_port: 30000
to_port: 32999
cidr_ip: "{{ ec2_ip_access_range }}"
- proto: tcp
from_port: 30000
to_port: 33303
to_port: 32999
cidr_ip: "{{ ec2_ip_access_range }}"
rules_egress:
- proto: all
Expand Down
46 changes: 0 additions & 46 deletions docker-go/Dockerfile

This file was deleted.

42 changes: 27 additions & 15 deletions scenarios/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
ansible --overwrite
http://docs.ansible.com/developing_inventory.html
http://docs.ansible.com/playbooks_variables.html#passing-variables-on-the-command-line
docker_run_args = []
"""

from base import Inventory
import nodeid_tool
import json
Expand All @@ -16,15 +15,21 @@

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

# needs some for go, too
docker_run_args = '--logging :debug --log_json 1 --remote {bootstrap_ip} --port 30303 ' \
use_impls = ['go']

# this must be the same as in ../ansible/group_vars/all
g_boot_public_key = '829bb728a1b38d2e3bb8288d750502f7dce2ee329aaebf48ddc54e0cfc8003b3068fe57e20277ba50e42826c4d2bfcb172699e108d9e90b3339f8b6589449faf'

docker_run_args = {}
docker_run_args['go'] = '-port=30000 -loglevel=5 -bootnodes=enode://{bootstrap_public_key}@{bootstrap_ip}:30303 -maxpeer={req_num_peers}'
docker_run_args['python'] = '--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}'

mining_cpu_percentage = 50
req_num_peers = 4

ansible_args = ['-u', 'ubuntu', '--private-key=../ansible/system-testing.pem']
ansible_args = ['-u', 'ubuntu', '--private-key=../ansible/system-testing.pem', '-vv']


def mk_inventory_executable(inventory):
Expand All @@ -39,7 +44,8 @@ def mk_inventory_executable(inventory):
def exec_playbook(inventory, playbook):
fn = mk_inventory_executable(inventory)
# replace for go with --tags=go or delete to address both
args = ['ansible-playbook', '../ansible/%s' % playbook, '-i', fn, '--tags=python'] + ansible_args
impls = ','.join(use_impls)
args = ['ansible-playbook', '../ansible/%s' % playbook, '-i', fn, '--tags=%s' % impls] + ansible_args
print 'executing', ' '.join(args)
result = subprocess.call(args)
if result:
Expand All @@ -55,6 +61,8 @@ def start_clients(clients=[]):
inventory = Inventory()
clients = clients or list(inventory.clients)
inventory.inventory['client_start_group'] = dict(children=clients, hosts=[])
# print clients
# quit()
assert inventory.es
assert inventory.boot
for client in clients:
Expand All @@ -63,19 +71,23 @@ def start_clients(clients=[]):
pubkey = nodeid_tool.topub(ext_id)
coinbase = nodeid_tool.coinbase(ext_id)
d = dict(hosts=inventory.inventory[client], vars=dict())
dra = docker_run_args.format(bootstrap_ip=inventory.boot,
dra_go = docker_run_args['go'].format(bootstrap_public_key=g_boot_public_key, bootstrap_ip=inventory.boot,
req_num_peers=req_num_peers)
dra_python = docker_run_args['python'].format(bootstrap_ip=inventory.boot,
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_run_args']['go'] = dra_go
d['vars']['docker_run_args']['python'] = dra_python
d['vars']['docker_container_id'] = {}
d['vars']['docker_container_id']['python'] = client
d['vars']['docker_container_id']['go'] = 'docker_go'
d['vars']['docker_container_id']['python'] = 'docker_python'
d['vars']['docker_tee_args'] = {}
d['vars']['docker_tee_args']['go'] = teees_args.format(elarch_ip=inventory.es, pubkey_hex=pubkey)
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)
print json.dumps(inventory.inventory, indent=2)
exec_playbook(inventory.inventory, playbook='client-start.yml')


Expand All @@ -89,10 +101,9 @@ def stop_clients(clients=[]):
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
d['vars']['docker_container_id']['go'] = 'docker_go'
d['vars']['docker_container_id']['python'] = 'docker_python'
inventory.inventory[client] = d
# print json.dumps(inventory.inventory, indent=2)
exec_playbook(inventory.inventory, playbook='client-stop.yml')
Expand All @@ -103,7 +114,8 @@ def stop_clients(clients=[]):
args = sys.argv[1:]
sys.argv = sys.argv[:1] # ec2.py peeks into args, so delete passing-variables-on-the-command-line
if 'start' in args:
start_clients()
start_clients()
# start_clients([u'tag_Name_client-01'])
elif 'stop' in args:
stop_clients()
else:
Expand Down

0 comments on commit 32a0006

Please sign in to comment.