nephos icon indicating copy to clipboard operation
nephos copied to clipboard

Pre Multi-Org nephos version failing when no MSP is defined

Open dbandin opened this issue 6 years ago • 0 comments

Composer install and setup scripts are calling the function get_namespace with a direct access to a dictionary subkey that may not be present in older versions of nephos deployments.

This makes the upgrade of older deployments to fail when trying to get the namespace passing the "msp" parameter to get_namespace function.

Traceback (most recent call last):
  File "./donate/setup_da.py", line 215, in <module>
    main()
  File "/tools/deployer/venv/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/tools/deployer/venv/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/tools/deployer/venv/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tools/deployer/venv/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "./donate/setup_da.py", line 208, in main
    install_api(env, opts, upgrade=upgrade, verbose=verbose)
  File "./donate/setup_da.py", line 108, in install_api
    env_vars = get_api_vars(env, opts, verbose=verbose)
  File "./donate/setup_da.py", line 32, in get_api_vars
    composer_data = get_composer_data(opts, verbose=verbose)
  File "/tools/deployer/venv/lib/python3.7/site-packages/nephos/composer/install.py", line 41, in get_composer_data
    peer_namespace = get_namespace(opts, opts["peers"]["msp"])
KeyError: 'msp'

The problem is not in the get_namespace function, this will allow None for the msp parameter.

https://github.com/hyperledger-labs/nephos/blob/master/nephos/fabric/settings.py#L51 It's gracefully handled in get_namespace if the value is 'None' if it's None it falls back to get the namespace defined in the core config of the nephos_config.yaml file.

def get_namespace(opts, msp=None, ca=None):
    """Get relevant namespace where MSP or CA should be located.
    Args:
        opts (dict): Nephos options dict.
        msp (str): Name of Membership Service Provider (MSP).
        ca (str): Name of Certificate Authority (CA).
    Returns:
        str: Namespace relating to either an MSP or a CA.
    """

It fails when is calling with the following code: https://github.com/hyperledger-labs/nephos/blob/master/nephos/composer/install.py#L47 https://github.com/hyperledger-labs/nephos/blob/master/nephos/composer/upgrade.py#L34

    peer_namespace = get_namespace(opts, opts["peers"]["msp"])

If the key/value doesn't exist in the dictionary. The dictionary is populated with the nephos_config.yaml file.

In the previous version of Nephos I could work it around using a simple workaround:

diff --git a/nephos/composer/install.py b/nephos/composer/install.py
index 40ddd52..e6dde03 100644
--- a/nephos/composer/install.py
+++ b/nephos/composer/install.py
@@ -44,7 +44,12 @@ def get_composer_data(opts, verbose=False):
     Returns:
         dict: Data related to the Composer deployment (URI & API key)
     """
-    peer_namespace = get_namespace(opts, opts["peers"]["msp"])
+    try:
+        msp = opts["peers"]["msp"]
+    except KeyError:
+        msp = None
+
+    peer_namespace = get_namespace(opts, msp)
     composer_name = opts["composer"]["name"] + "-hl-composer-rest"
     data = get_app_info(
         peer_namespace,

For new versions with multi-org, we should check what's the best wat to go ahead.

dbandin avatar Jul 18 '19 10:07 dbandin