Skip to content

Commit

Permalink
Document Fabric v1.4.3 requirement and enforce binary versions (resolves
Browse files Browse the repository at this point in the history
 #265) (#266)

Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
  • Loading branch information
Simon Stone authored Jun 2, 2020
1 parent 306d5c9 commit bd157b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ In order to use this Ansible collection, you must have the following pre-requisi

pip install ansible

**Hyperledger Fabric v1.4.x binaries**
**Hyperledger Fabric v1.4.3+ binaries**

This Ansible collection uses the Hyperledger Fabric v1.4 binaries to interact with the peers and ordering services in your Hyperledger Fabric networks. These binaries include ``configtxgen``, ``peer``, and ``fabric-ca-client``.
This Ansible collection requires use of the binaries from Hyperledger Fabric v1.4.3 or later to interact with the peers and ordering services in your Hyperledger Fabric networks. These binaries include ``configtxlator`` and ``peer``.

You can install these binaries by following the Hyperledger Fabric documentation: https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html

Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---
namespace: ibm
name: blockchain_platform
version: 0.0.23
version: 0.0.24
readme: README.md
authors:
- Simon Stone
Expand Down
22 changes: 22 additions & 0 deletions plugins/module_utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils._text import to_native
from distutils.version import LooseVersion

import os
import platform
import re
import subprocess

HFC_IMPORT_ERR = None
Expand Down Expand Up @@ -40,6 +42,19 @@ def missing_required_bin(binary, reason=None, url=None):
return msg


def wrong_version_bin(binary, actual_version, expected_version, reason=None, url=None):
hostname = platform.node()
msg = "Required binary (%s) on %s has wrong version, expected version %s but version is %s." % (binary, hostname, expected_version, actual_version)
if reason:
msg += " This is required %s." % reason
if url:
msg += " See %s for more info." % url

msg += (" Please read module documentation and install in the appropriate location."
" If the required binary is installed, then the install directory may not be present in the PATH environment variable (%s)." % os.environ['PATH'])
return msg


class BlockchainModule(AnsibleModule):

def __init__(self, *args, **kwargs):
Expand All @@ -63,3 +78,10 @@ def check_for_missing_bins(self):
self.fail_json(msg=missing_required_bin(binary, url=url), exception=to_native(e), cmd=f'{binary} version')
if process.returncode != 0:
self.fail_json(msg=missing_required_bin(binary, url=url), rc=process.returncode, stdout=process.stdout, stderr=process.stderr, cmd=f'{binary} version')
p = re.compile('Version: (.+)$', re.MULTILINE)
m = p.search(process.stdout)
if m is None:
self.fail_json(msg=wrong_version_bin(binary, '<unknown>', '>= 1.4.3', url=url), rc=process.returncode, stdout=process.stdout, stderr=process.stderr, cmd=f'{binary} version')
version = m.group(1)
if not LooseVersion(version) >= LooseVersion('1.4.3'):
self.fail_json(msg=wrong_version_bin(binary, version, '>= 1.4.3', url=url), rc=process.returncode, stdout=process.stdout, stderr=process.stderr, cmd=f'{binary} version')

0 comments on commit bd157b7

Please sign in to comment.