From 2d6594f79c8f6d35a05e93f74c9a1308ce0ec725 Mon Sep 17 00:00:00 2001 From: BulatSaif Date: Tue, 8 Aug 2023 14:21:14 +0300 Subject: [PATCH 1/4] Add support for separate_binary --- galaxy.yml | 2 +- roles/key_inject/tasks/inject.yml | 2 +- roles/node/defaults/main.yml | 10 ++++ roles/node/tasks/100-tests.yml | 7 +++ roles/node/tasks/400-binary.yml | 90 ++++++++++++++++++++++++++++--- 5 files changed, 103 insertions(+), 8 deletions(-) diff --git a/galaxy.yml b/galaxy.yml index b9d3971..255d3ec 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: parity name: chain # The version of the collection. Must be compatible with semantic versioning -version: 1.4.0 +version: 1.5.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/roles/key_inject/tasks/inject.yml b/roles/key_inject/tasks/inject.yml index 9b2ba59..35ed021 100644 --- a/roles/key_inject/tasks/inject.yml +++ b/roles/key_inject/tasks/inject.yml @@ -28,7 +28,7 @@ - name: Inject | Check {{ item.type }} key results ansible.builtin.debug: - msg: "Key {{ key_inject_pub_key }} ({{ item.type }}, {{ tem.scheme | default('sr25519') }}) is {{ 'NOT ' if not key_inject_uri.json.result else '' }}present in keystore" + msg: "Key {{ key_inject_pub_key }} ({{ item.type }}, {{ item.scheme | default('sr25519') }}) is {{ 'NOT ' if not key_inject_uri.json.result else '' }}present in keystore" changed_when: not key_inject_uri.json.result - name: Inject | Inject {{ item.type }} keys diff --git a/roles/node/defaults/main.yml b/roles/node/defaults/main.yml index b9c9d4d..18b27de 100644 --- a/roles/node/defaults/main.yml +++ b/roles/node/defaults/main.yml @@ -20,6 +20,16 @@ node_binary_release_key_id: 9D4B2B6EB8F97156D19669A9FF0812D491B96798 # GPG signature URL. When left empty, binary verification will not be executed node_binary_signature: "" +# Set it to true if Polkadot uses separate binaries: https://github.com/paritytech/polkadot/pull/7337 +node_separate_binary: false +# List of binders to download if node_separate_binary is True. +# The first element is the main binary, and the rest are auxiliary binaries. +node_separate_binary_list: + - polkadot + - polkadot-prepare-worker + - polkadot-execute-worker + + ### Node preferences # You can redefine any variables from playbooks directly # Values from the "_node_profiles" are used by default diff --git a/roles/node/tasks/100-tests.yml b/roles/node/tasks/100-tests.yml index 3487e46..0c53e28 100644 --- a/roles/node/tasks/100-tests.yml +++ b/roles/node/tasks/100-tests.yml @@ -5,6 +5,13 @@ msg: "The 'node_binary' variable can't be empty!" when: node_binary == '' +- name: Test | Check if separate binary + ansible.builtin.fail: + msg: "If 'node_separate_binary' is True, 'node_binary' and 'node_binary_signature' should end with '/'" + when: + - node_separate_binary + - not node_binary.endswith('/') + - name: Test | Check if node_binary_signature is a URL ansible.builtin.fail: msg: "The 'node_binary_signature' variable must be a URL!" diff --git a/roles/node/tasks/400-binary.yml b/roles/node/tasks/400-binary.yml index 2df9b23..90937c5 100644 --- a/roles/node/tasks/400-binary.yml +++ b/roles/node/tasks/400-binary.yml @@ -12,9 +12,9 @@ ansible.builtin.set_fact: _node_temp_binary_file: "{{ _node_temp_dir.path }}/{{ node_app_name }}" -- name: Binary | Download binary +- name: Binary | Download main binary ansible.builtin.get_url: - url: "{{ node_binary }}" + url: "{{ node_binary }}{{ node_separate_binary_list[0] if node_separate_binary else ''}}" dest: "{{ _node_temp_binary_file }}" mode: 0755 owner: "root" @@ -25,16 +25,40 @@ check_mode: false changed_when: false +- name: Binary | Download auxiliary binaries + ansible.builtin.get_url: + url: "{{ node_binary }}{{ item }}" + dest: "{{ _node_temp_dir.path }}" + mode: 0755 + owner: "root" + group: "root" + timeout: 30 + headers: + PRIVATE-TOKEN: "{{ node_binary_download_private_token }}" + check_mode: false + changed_when: false + when: node_separate_binary + loop: "{{ node_separate_binary_list[1:] }}" + - name: Binary | GPG signature verification block: - - name: Binary | Download GPG signature + - name: Binary | Download GPG signature for main binary ansible.builtin.get_url: - url: "{{ node_binary_signature }}" + url: "{{ node_binary_signature }}{{ node_separate_binary_list[0] + '.asc' if node_separate_binary else ''}}" dest: "{{ _node_temp_dir.path }}/{{ node_app_name }}.asc" check_mode: false changed_when: false + - name: Binary | Download GPG signature for auxiliary binaries + ansible.builtin.get_url: + url: "{{ node_binary_signature }}{{ item }}.asc" + dest: "{{ _node_temp_dir.path }}/{{ item }}.asc" + check_mode: false + changed_when: false + when: node_separate_binary + loop: "{{ node_separate_binary_list[1:] }}" + - name: Binary | Import release GPG public key ansible.builtin.command: | {{ _node_binary_gpg_binary }} --keyserver hkps://keyserver.ubuntu.com --receive-keys {{ node_binary_release_key_id }} @@ -43,7 +67,7 @@ failed_when: _node_keyout.rc != 0 check_mode: false - - name: Binary | Verify GPG signature + - name: Binary | Verify GPG signature for main binary ansible.builtin.command: | {{ _node_binary_gpg_binary }} --verify {{ _node_temp_dir.path }}/{{ node_app_name }}.asc register: _node_verifyout @@ -51,6 +75,16 @@ changed_when: false failed_when: _node_verifyout.rc != 0 + - name: Binary | Verify GPG signature for auxiliary binaries + ansible.builtin.command: | + {{ _node_binary_gpg_binary }} --verify {{ _node_temp_dir.path }}/{{ item }}.asc + register: _node_verifyout + check_mode: false + changed_when: false + failed_when: _node_verifyout.rc != 0 + when: node_separate_binary + loop: "{{ node_separate_binary_list[1:] }}" + when: node_binary_signature != '' - name: Binary | Check new version @@ -93,9 +127,40 @@ path: "{{ _node_binary_file | dirname }}" register: _node_binary_path_stat +- name: Binary | Migration between versions + block: + - name: Binary | Check new version + ansible.builtin.command: "{{ _node_temp_binary_file }} --help" + register: _node_new_help + check_mode: false + changed_when: false + - name: Binary | Setup supported flags + ansible.builtin.set_fact: + _node_legacy_rpc_flags_supported: "{{ '--ws-port' in _node_new_help }}" + _node_separate_binary_supported: "{{ '--workers-path' in _node_new_help }}" + + - name: Binary | Check new rpc flags + ansible.builtin.fail: + msg: "ERROR: RPC flag --ws-port {{ 'IS' if _node_legacy_rpc_flags_supported else 'NOT' }} supported. 'node_legacy_rpc_flags' should be set to {{ _node_legacy_rpc_flags_supported }}" + when: + # XOR (skip fail if both true or both false) + - node_legacy_rpc_flags or _node_legacy_rpc_flags_supported + - not (node_legacy_rpc_flags and _node_legacy_rpc_flags_supported) + + - name: Binary | Check new rpc flags + ansible.builtin.fail: + msg: > + ERROR: RPC flag --workers-path {{ 'IS' if _node_separate_binary_supported else 'NOT' }} supported. + 'node_separate_binary' should be set to {{ _node_separate_binary_supported }, + you may also need to update the 'node_binary' and 'node_separate_binary_list' variables. + when: + # XOR (skip fail if both true or both false) + - node_separate_binary or _node_separate_binary_supported + - not (node_separate_binary and _node_separate_binary_supported) + # We don't need checking of hashes. The copy module does it itself. # If you have the same binary file you will see a green check in the check mode. -- name: Binary | Copy new binary +- name: Binary | Copy new main binary ansible.builtin.copy: src: "{{ _node_temp_binary_file }}" dest: "{{ _node_binary_file }}" @@ -106,6 +171,19 @@ notify: restart service {{ node_handler_id }} ignore_errors: "{{ not _node_binary_path_stat.stat.exists }}" +- name: Binary | Copy new auxiliary binaries + ansible.builtin.copy: + src: "{{ _node_temp_dir.path }}/{{ item }}" + dest: {{ _node_binary_path }}/{{ item }}" + remote_src: yes + mode: 0755 + owner: "{{ node_user }}" + group: "{{ node_user }}" + notify: restart service {{ node_handler_id }} + ignore_errors: "{{ not _node_binary_path_stat.stat.exists }}" + when: node_separate_binary + loop: "{{ node_separate_binary_list[1:] }}" + - name: Binary | Block block: From db5371b890e8df9c48f98441c49cb56d4951fca7 Mon Sep 17 00:00:00 2001 From: BulatSaif Date: Tue, 8 Aug 2023 14:45:39 +0300 Subject: [PATCH 2/4] fix ci --- .github/workflows/molecule.yml | 2 +- roles/node/tasks/400-binary.yml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index 678d99a..e4f5e58 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -30,7 +30,7 @@ jobs: with: channel: latest/stable - name: Setup Python modules - run: pip3 install yamllint ansible ansible-lint molecule molecule-plugins[docker] molecule-lxd docker + run: pip3 install PyYAML==5.3.1 yamllint ansible ansible-lint molecule molecule-plugins[docker] molecule-lxd docker - name: Run molecule run: molecule test --all working-directory: "${{ github.repository }}/${{ inputs.role-path }}" diff --git a/roles/node/tasks/400-binary.yml b/roles/node/tasks/400-binary.yml index 90937c5..eec6eba 100644 --- a/roles/node/tasks/400-binary.yml +++ b/roles/node/tasks/400-binary.yml @@ -136,9 +136,8 @@ changed_when: false - name: Binary | Setup supported flags ansible.builtin.set_fact: - _node_legacy_rpc_flags_supported: "{{ '--ws-port' in _node_new_help }}" - _node_separate_binary_supported: "{{ '--workers-path' in _node_new_help }}" - + _node_legacy_rpc_flags_supported: "{{ '--ws-port' in _node_new_help.stdout }}" + _node_separate_binary_supported: "{{ '--workers-path' in _node_new_help.stdout }}" - name: Binary | Check new rpc flags ansible.builtin.fail: msg: "ERROR: RPC flag --ws-port {{ 'IS' if _node_legacy_rpc_flags_supported else 'NOT' }} supported. 'node_legacy_rpc_flags' should be set to {{ _node_legacy_rpc_flags_supported }}" @@ -174,7 +173,7 @@ - name: Binary | Copy new auxiliary binaries ansible.builtin.copy: src: "{{ _node_temp_dir.path }}/{{ item }}" - dest: {{ _node_binary_path }}/{{ item }}" + dest: "{{ _node_binary_path }}/{{ item }}" remote_src: yes mode: 0755 owner: "{{ node_user }}" From 5a35ff95b7a908108e0389d5d5d36aeb7c6aa19a Mon Sep 17 00:00:00 2001 From: BulatSaif Date: Tue, 8 Aug 2023 19:37:08 +0300 Subject: [PATCH 3/4] fix typo --- roles/node/tasks/400-binary.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/node/tasks/400-binary.yml b/roles/node/tasks/400-binary.yml index eec6eba..85674bc 100644 --- a/roles/node/tasks/400-binary.yml +++ b/roles/node/tasks/400-binary.yml @@ -146,11 +146,11 @@ - node_legacy_rpc_flags or _node_legacy_rpc_flags_supported - not (node_legacy_rpc_flags and _node_legacy_rpc_flags_supported) - - name: Binary | Check new rpc flags + - name: Binary | Check new worker flags ansible.builtin.fail: msg: > - ERROR: RPC flag --workers-path {{ 'IS' if _node_separate_binary_supported else 'NOT' }} supported. - 'node_separate_binary' should be set to {{ _node_separate_binary_supported }, + ERROR: node flag --workers-path {{ 'IS' if _node_separate_binary_supported else 'NOT' }} supported. + 'node_separate_binary' should be set to {{ _node_separate_binary_supported }}, you may also need to update the 'node_binary' and 'node_separate_binary_list' variables. when: # XOR (skip fail if both true or both false) From 6897e73a93ce70be4059b7d7c500272267588888 Mon Sep 17 00:00:00 2001 From: Bulat Saifullin Date: Wed, 9 Aug 2023 12:09:23 +0300 Subject: [PATCH 4/4] Update roles/node/defaults/main.yml Co-authored-by: Pierre Besson --- roles/node/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/node/defaults/main.yml b/roles/node/defaults/main.yml index 18b27de..81dd6c0 100644 --- a/roles/node/defaults/main.yml +++ b/roles/node/defaults/main.yml @@ -22,7 +22,7 @@ node_binary_signature: "" # Set it to true if Polkadot uses separate binaries: https://github.com/paritytech/polkadot/pull/7337 node_separate_binary: false -# List of binders to download if node_separate_binary is True. +# List of binaries to download if node_separate_binary is True. # The first element is the main binary, and the rest are auxiliary binaries. node_separate_binary_list: - polkadot