Skip to content

Commit

Permalink
ADD: Molecule test merge support (#600)
Browse files Browse the repository at this point in the history
* ADD: Besu + Teku beacon merge support

* ADD: Nethermind + Teku-beacon merge support

* UPDATE: docker images for merge
  • Loading branch information
gbayasgalan authored Aug 3, 2022
1 parent e4a7213 commit 82a64ef
Show file tree
Hide file tree
Showing 15 changed files with 686 additions and 4 deletions.
8 changes: 4 additions & 4 deletions controls/defaults/stereum_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ stereum_static:
# consensus clients
lighthouse: v2.3.1
nimbus: multiarch-v22.6.1
teku: "22.6.1"
teku: "22.7.0"
prysm: v2.1.3

# execution clients
geth: v1.10.20
besu: "22.4.4"
nethermind: "1.13.4"
geth: v1.10.21
besu: "22.7.0-RC2"
nethermind: "1.13.5"

# ssv
blox_ssv: v0.2.1-rc.5
Expand Down
109 changes: 109 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
- name: Converge
hosts: all
vars_files:
- ../../../../defaults/stereum_defaults.yaml
vars:
teku_service: 1929168e-e0d6-11ec-9183-97daacc21ea6
besu_service: 9c52bfc6-ee3f-11ec-8841-fff909f62b80

tasks:
# besu service
- block:
- set_fact:
stereum: "{{ stereum_static | combine(stereum_args, recursive=True) }}"
- name: "Include manage-service"
include_role:
name: "manage-service"
vars:
stereum_args:
manage_service:
save: true
state: started
configuration:
service: BesuService
id: "{{ besu_service }}"
image: "hyperledger/besu:{{ stereum_static.defaults.versions.besu }}"
ports:
- 0.0.0.0:30303:30303/tcp
- 0.0.0.0:30303:30303/udp
- 127.0.0.1:8551:8551/tcp
entrypoint: ["besu"]
env:
JAVA_OPTS: -Xmx4g
command:
- --network=goerli
- --data-path=/opt/app/data
- --data-storage-format=BONSAI
- --sync-mode=X_SNAP
- --p2p-port=30303
- --p2p-host=0.0.0.0
- --rpc-http-enabled=true
- --rpc-http-host=0.0.0.0
- --rpc-http-cors-origins=*
- --rpc-ws-enabled=true
- --rpc-ws-host=0.0.0.0
- --host-allowlist=*
- --metrics-enabled
- --metrics-host=0.0.0.0
- --logging=INFO
- --engine-rpc-enabled=true
- --engine-host-allowlist=*
- --engine-rpc-port=8551
- --engine-jwt-enabled=true
- --engine-jwt-secret=/engine.jwt
- --Xmerge-support=true
user: "2000"
volumes:
- "/opt/app/services/{{ besu_service }}/data:/opt/app/data"
- "/opt/app/services/{{ besu_service }}/engine.jwt:/engine.jwt"

# teku beacon service
- block:
- set_fact:
stereum: "{{ stereum_static | combine(stereum_args, recursive=True) }}"
- name: "Include manage-service"
include_role:
name: "manage-service"
vars:
stereum_args:
manage_service:
save: true
state: started
configuration:
service: TekuBeaconService
id: "{{ teku_service }}"
image: "consensys/teku:{{ stereum_static.defaults.versions.teku }}"
ports:
- 0.0.0.0:9001:9001/tcp
- 0.0.0.0:9001:9001/udp
env:
JAVA_OPTS: -Xmx4g
entrypoint: ["/opt/teku/bin/teku"]
command:
- --network=prater
- --logging=INFO
- --p2p-enabled=true
- --p2p-port=9001
- --ee-endpoint=http://stereum-{{ besu_service }}:8551
- --ee-jwt-secret-file=/engine.jwt
- --metrics-enabled=true
- --metrics-categories=BEACON,LIBP2P,NETWORK,PROCESS
- --metrics-port=8008
- --metrics-interface=0.0.0.0
- --metrics-host-allowlist="*"
- --metrics-publish-interval=10
- --rest-api-port=5051
- --rest-api-host-allowlist="*"
- --rest-api-interface=0.0.0.0
- --rest-api-docs-enabled=true
- --rest-api-enabled=true
- --data-path=/opt/app/data
- --data-storage-mode=prune
- --log-destination=CONSOLE
user: "2000"
volumes:
- "/opt/app/services/{{ teku_service }}/data:/opt/app/data"
- "/opt/app/services/{{ besu_service }}/engine.jwt:/engine.jwt"

# EOF
96 changes: 96 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
ssh_port: 22
ssh_user: root
ssh_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
tasks:
- name: Create SSH key
user:
name: "{{ lookup('env', 'USER') }}"
generate_ssh_key: true
ssh_key_file: "{{ ssh_path }}"
force: true
register: generated_ssh_key

- name: Register the SSH key name
set_fact:
ssh_key_name: "molecule-generated-{{ 12345 | random | to_uuid }}"

- name: Register SSH key for test instance(s)
hcloud_ssh_key:
name: "{{ ssh_key_name }}"
public_key: "{{ generated_ssh_key.ssh_public_key }}"
state: present

- name: Create molecule instance(s)
hcloud_server:
name: "{{ item.name }}"
server_type: "{{ item.server_type }}"
ssh_keys:
- "{{ ssh_key_name }}"
volumes: "{{ item.volumes | default(omit) }}"
image: "{{ item.image }}"
location: "hel1"
datacenter: "{{ item.datacenter | default(omit) }}"
user_data: "{{ item.user_data | default(omit) }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: present
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0

- name: Wait for instance(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_jobs
until: hetzner_jobs.finished
retries: 300
with_items: "{{ server.results }}"

- name: Attach Server to Subnetwork(s)
hcloud_server_network:
network: "{{ item.network.name }}"
server: "{{ item.name }}"
ip: "{{ item.network.ip }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: "present"
loop: "{{ molecule_yml.platforms }}"
when: molecule_yml.platforms is search('network')

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.hcloud_server.name }}",
'ssh_key_name': "{{ ssh_key_name }}",
'address': "{{ item.hcloud_server.ipv4_address }}",
'user': "{{ ssh_user }}",
'port': "{{ ssh_port }}",
'identity_file': "{{ ssh_path }}", }
with_items: "{{ hetzner_jobs.results }}"
register: instance_config_dict
when: server.changed | bool

- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server.changed | bool

- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | to_yaml }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool

- name: Wait for SSH
wait_for:
port: "{{ ssh_port }}"
host: "{{ item.address }}"
search_regex: SSH
delay: 10
with_items: "{{ lookup('file', molecule_instance_config) | from_yaml }}"
55 changes: 55 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
- name: Populate the instance config
block:
- name: Populate instance config from file
set_fact:
instance_conf: "{{ lookup('file', molecule_instance_config) | from_yaml }}"
skip_instances: false
rescue:
- name: Populate instance config when file missing
set_fact:
instance_conf: {}
skip_instances: true

- name: Destroy molecule instance(s)
hcloud_server:
name: "{{ item.instance }}"
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
state: absent
register: server
with_items: "{{ instance_conf }}"
when: not skip_instances
async: 7200
poll: 0

- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: hetzner_jobs
until: hetzner_jobs.finished
retries: 300
with_items: "{{ server.results }}"

- name: Remove registered SSH key
hcloud_ssh_key:
name: "{{ instance_conf[0].ssh_key_name }}"
state: absent
when:
- not skip_instances
- instance_conf | length # must contain at least one instance

- name: Populate instance config
set_fact:
instance_conf: {}

- name: Dump instance config
copy:
content: "{{ instance_conf | to_yaml }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
33 changes: 33 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
dependency:
name: galaxy
driver:
name: hetznercloud
platforms:
- name: "manage-service--besu-teku--ubuntu-22.04"
hostname: ubuntu
server_type: cpx31
image: ubuntu-22.04
# - name: "manage-service--besu-teku--centos-stream-8"
# hostname: "centos"
# server_type: cpx31
# image: centos-stream-8
provisioner:
name: ansible
config_options:
ssh_connection:
ssh_args: -o ServerAliveInterval=30 -o ControlMaster=auto -o ControlPersist=60s
lint: |
set -e
yamllint .
ansible-lint .
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
#- idempotence
- lint
- verify
- destroy
7 changes: 7 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include manage-service"
include_role:
name: "manage-service"
30 changes: 30 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Prepare
hosts: all
roles:
- role: '../'
vars_files:
- ../../../../defaults/stereum_defaults.yaml

tasks:
- name: Install python for Ansible (Ubuntu)
apt:
update_cache: yes
name: pip
become: true
changed_when: false
when: ansible_distribution == "Ubuntu"

- name: Install python for Ansible (CentOS 8)
raw: yum install -y python38 tar && yum remove -y python36
become: true
changed_when: false
when: ansible_distribution == "CentOS"

- include_role:
name: "setup"

- include_role:
name: "configure-firewall"

# EOF
16 changes: 16 additions & 0 deletions controls/roles/manage-service/molecule/besu-teku/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
# teku beacon logs
- name: Teku beacon
command: "docker logs --tail=20 stereum-1929168e-e0d6-11ec-9183-97daacc21ea6"
register: teku_beacon
until:
- teku_beacon.stdout is search("Endpoint http://stereum-9c52bfc6-ee3f-11ec-8841-fff909f62b80:8551 is INVALID | Connection refused")
- teku_beacon.stdout is search("Eth1 service down or still syncing for")
retries: 60
delay: 10

# EOF
Loading

0 comments on commit 82a64ef

Please sign in to comment.