From d5bf357c8010bb1219d04ede14ce699b409e93c5 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 30 Aug 2020 00:15:08 -0400 Subject: fix the connection issue with --notls flag on; WIP: deployment example --- scripts/deploy/app/_setup.yml | 34 +++++++++++++ scripts/deploy/app/build.yml | 27 +++++++++++ scripts/deploy/app/hotstuff_app.py | 93 ++++++++++++++++++++++++++++++++++++ scripts/deploy/app/hotstuff_cli.py | 97 ++++++++++++++++++++++++++++++++++++++ scripts/deploy/app/reset.yml | 21 +++++++++ scripts/deploy/app/run.yml | 40 ++++++++++++++++ scripts/deploy/app/run_cli.yml | 36 ++++++++++++++ 7 files changed, 348 insertions(+) create mode 100644 scripts/deploy/app/_setup.yml create mode 100644 scripts/deploy/app/build.yml create mode 100644 scripts/deploy/app/hotstuff_app.py create mode 100644 scripts/deploy/app/hotstuff_cli.py create mode 100644 scripts/deploy/app/reset.yml create mode 100644 scripts/deploy/app/run.yml create mode 100644 scripts/deploy/app/run_cli.yml (limited to 'scripts/deploy/app') diff --git a/scripts/deploy/app/_setup.yml b/scripts/deploy/app/_setup.yml new file mode 100644 index 0000000..7a9ba28 --- /dev/null +++ b/scripts/deploy/app/_setup.yml @@ -0,0 +1,34 @@ +--- +# available vars: +# workdir -- the local directory of run_id + +- name: setup libhotstuff example binaries + block: + - apt: + pkg: + - g++ + - libssl-dev + - libuv1-dev + - cmake + - make + - dh-autoreconf + state: + latest + become: true + become_user: root + - file: + path: "{{ hs_repo_dir }}" + state: directory + - synchronize: + archive: true + delete: true + src: "{{ (workdir, hs_local_repo_dir, '') | path_join }}" + dest: "{{ hs_repo_dir }}" + mode: push + rsync_opts: + - "--exclude=.git" + - "--exclude=scripts/" + - "--exclude=CMakeCache.txt" + - "--exclude=CMakeFiles" + - "--exclude=libsecp256k1-prefix" + - "--delete-excluded" diff --git a/scripts/deploy/app/build.yml b/scripts/deploy/app/build.yml new file mode 100644 index 0000000..2a0c24c --- /dev/null +++ b/scripts/deploy/app/build.yml @@ -0,0 +1,27 @@ +--- +# available vars: +# last_state -- the content of state.json +# nid -- host_idx (with 0 as default) +# ngroup -- the group of nodes involved in the build +# testbed -- the remote path of run_id + +- name: build hotstuff example binaries + block: + - file: + path: "{{ (hs_repo_dir, 'build') | path_join }}" + state: absent + - command: cmake -DCMAKE_BUID_TYPE=Release -DHOTSTUFF_PROTO_LOG=OFF -DCMAKE_CXX_FLAGS={{ hs_flags | default('') }} + args: + chdir: "{{ hs_repo_dir }}" + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + - command: make clean + args: + chdir: "{{ hs_repo_dir }}" + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + - command: make -j4 + args: + chdir: "{{ hs_repo_dir }}" + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin diff --git a/scripts/deploy/app/hotstuff_app.py b/scripts/deploy/app/hotstuff_app.py new file mode 100644 index 0000000..2a21e65 --- /dev/null +++ b/scripts/deploy/app/hotstuff_app.py @@ -0,0 +1,93 @@ +#!/usr/bin/python3 + +import os +import subprocess + +ANSIBLE_METADATA = { + 'metadata_version': '0.1', + 'status': ['preview'], + 'supported_by': 'Ted Yin' +} + +DOCUMENTATION = ''' +--- +module: hotstuff_app + +short_description: Ansible module for hotstuff-app + +author: + - Ted Yin (@Tederminant) +''' + +EXAMPLES = ''' +''' + +RETURN = ''' +''' + +from ansible.module_utils.basic import AnsibleModule + +def run_module(): + # define available arguments/parameters a user can pass to the module + module_args = dict( + bin=dict(type='str', required=True), + cwd=dict(type='str', required=True), + conf=dict(type='str', required=True), + log_dir=dict(type='str', required=True), + tls=dict(type='bool', default=True, required=False), + ) + + module = AnsibleModule( + argument_spec=module_args, + supports_check_mode=False + ) + + expanduser = [ + 'bin', + 'cwd', + 'conf', + 'log_dir', + ] + + for arg in expanduser: + module.params[arg] = os.path.expanduser(module.params[arg]) + + try: + cmd = [*(module.params['bin'].split())] + cmd += ['--conf', module.params['conf']] + if not module.params['tls']: + cmd += ['--notls'] + + logdir = module.params['log_dir'] + if not (logdir is None): + stdout = open(os.path.expanduser( + os.path.join(logdir, 'stdout')), "w") + stderr = open(os.path.expanduser( + os.path.join(logdir, 'stderr')), "w") + nullsrc = open("/dev/null", "r") + else: + (stdout, stderr) = None, None + + cwd = module.params['cwd'] + + pid = subprocess.Popen( + cmd, + cwd=cwd, + stdin=nullsrc, + stdout=stdout, stderr=stderr, + env=os.environ, + shell=False, + start_new_session=True).pid + module.exit_json( + changed=False, + status=0, pid=pid, cmd=" ".join(cmd), cwd=cwd) + except (OSError, subprocess.SubprocessError) as e: + module.fail_json(msg=str(e), changed=False, status=1) + + +def main(): + run_module() + + +if __name__ == '__main__': + main() diff --git a/scripts/deploy/app/hotstuff_cli.py b/scripts/deploy/app/hotstuff_cli.py new file mode 100644 index 0000000..0d4b57a --- /dev/null +++ b/scripts/deploy/app/hotstuff_cli.py @@ -0,0 +1,97 @@ +#!/usr/bin/python3 + +import os +import subprocess + +ANSIBLE_METADATA = { + 'metadata_version': '0.1', + 'status': ['preview'], + 'supported_by': 'Ted Yin' +} + +DOCUMENTATION = ''' +--- +module: hotstuff_cli + +short_description: Ansible module for hotstuff-client + +author: + - Ted Yin (@Tederminant) +''' + +EXAMPLES = ''' +''' + +RETURN = ''' +''' + +from ansible.module_utils.basic import AnsibleModule + +def run_module(): + # define available arguments/parameters a user can pass to the module + module_args = dict( + bin=dict(type='str', required=True), + cwd=dict(type='str', required=True), + idx=dict(type='int', required=True), + cid=dict(type='int', required=True), + iter=dict(type='int', required=True), + max_async=dict(type='int', required=True), + log_dir=dict(type='str', required=True), + ) + + module = AnsibleModule( + argument_spec=module_args, + supports_check_mode=False + ) + + expanduser = [ + 'bin', + 'cwd', + 'log_dir', + ] + + for arg in expanduser: + module.params[arg] = os.path.expanduser(module.params[arg]) + + try: + cmd = [*(module.params['bin'].split())] + cmd += [ + '--idx', str(module.params['idx']), + '--cid', str(module.params['cid']), + '--iter', str(module.params['iter']), + '--max-async', str(module.params['max_async']), + ] + + logdir = module.params['log_dir'] + if not (logdir is None): + stdout = open(os.path.expanduser( + os.path.join(logdir, 'stdout')), "w") + stderr = open(os.path.expanduser( + os.path.join(logdir, 'stderr')), "w") + nullsrc = open("/dev/null", "r") + else: + (stdout, stderr) = None, None + + cwd = module.params['cwd'] + + pid = subprocess.Popen( + cmd, + cwd=cwd, + stdin=nullsrc, + stdout=stdout, stderr=stderr, + env=os.environ, + shell=False, + start_new_session=True).pid + module.exit_json( + changed=False, + status=0, pid=pid, cmd=" ".join(cmd), cwd=cwd) + except (OSError, subprocess.SubprocessError) as e: + module.fail_json(msg=str(e), changed=False, status=1) + + +def main(): + run_module() + + +if __name__ == '__main__': + main() diff --git a/scripts/deploy/app/reset.yml b/scripts/deploy/app/reset.yml new file mode 100644 index 0000000..1b80b27 --- /dev/null +++ b/scripts/deploy/app/reset.yml @@ -0,0 +1,21 @@ +--- +# available vars: +# last_state -- the content of state.json +# nid -- host_idx (with 0 as default) +# ngroup -- the group of nodes involved in the build +# testbed -- the remote path of run_id + +- name: reset hotstuff + vars: + log_dir: "{{ (testbed, hs_log_dir) | path_join }}" + block: + - name: remove confs + file: + path: "{{ conf_dir }}" + state: absent + when: "hs_no_reset_conf is not defined or (hs_no_reset_conf == False)" + - name: remove old logs + file: + path: "{{ log_dir }}" + state: absent + when: "hs_no_reset_log is not defined or (hs_no_reset_log == False)" diff --git a/scripts/deploy/app/run.yml b/scripts/deploy/app/run.yml new file mode 100644 index 0000000..260d611 --- /dev/null +++ b/scripts/deploy/app/run.yml @@ -0,0 +1,40 @@ +--- +# available vars: +# last_state -- the content of state.json +# nid -- host_idx (with 0 as default) +# ngroup -- the group of nodes involved in the build +# testbed -- the remote path of run_id + +- vars: + conf_dir: "{{ (testbed, hs_conf_dir) | path_join }}" + log_dir: "{{ (testbed, hs_log_dir) | path_join }}" + block: + - name: create testbed dirs + block: + - file: + path: "{{ conf_dir }}" + state: directory + - file: + path: "{{ log_dir }}" + state: directory + - name: copy the base conf file + copy: + src: "{{ (lookup('env','run_path'), hs_base_conf) | path_join }}" + dest: "{{ (conf_dir, 'hotstuff.conf') | path_join }}" + mode: '0644' + - name: copy per node conf files + copy: + src: "{{ (lookup('env','run_path'), extra_conf) | path_join }}" + dest: "{{ (conf_dir, (extra_conf | basename)) | path_join }}" + mode: '0644' + when: extra_conf | default('') | length > 0 + - name: start the hotstuff replica + hotstuff_app: + bin: "{{ replica_bin | default('~/libhotstuff/examples/hotstuff_app') }}" + log_dir: "{{ log_dir }}" + cwd: "{{ conf_dir }}" + conf: "{{ extra_conf | basename }}" + tls: false + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + register: spawn_results diff --git a/scripts/deploy/app/run_cli.yml b/scripts/deploy/app/run_cli.yml new file mode 100644 index 0000000..c882a13 --- /dev/null +++ b/scripts/deploy/app/run_cli.yml @@ -0,0 +1,36 @@ +--- +# available vars: +# last_state -- the content of state.json +# nid -- host_idx (with 0 as default) +# ngroup -- the group of nodes involved in the build +# testbed -- the remote path of run_id + +- vars: + conf_dir: "{{ (testbed, hs_conf_dir) | path_join }}" + log_dir: "{{ (testbed, hs_log_dir) | path_join }}" + block: + - name: create testbed dirs + block: + - file: + path: "{{ conf_dir }}" + state: directory + - file: + path: "{{ log_dir }}" + state: directory + - name: copy the base conf file + copy: + src: "{{ (lookup('env','run_path'), hs_base_conf) | path_join }}" + dest: "{{ (conf_dir, 'hotstuff.conf') | path_join }}" + mode: '0644' + - name: start the hotstuff client + hotstuff_cli: + bin: "{{ client_bin | default('~/libhotstuff/examples/hotstuff_client') }}" + log_dir: "{{ log_dir }}" + cwd: "{{ conf_dir }}" + idx: "{{ client_idx | default(1) }}" + cid: "{{ cid }}" + iter: "{{ max_iter | default(100000) }}" + max_async: "{{ max_async }}" + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin + register: spawn_results -- cgit v1.2.3