Skip to content

Commit

Permalink
Make the ccf ping_test.py more useful for connection debugging
Browse files Browse the repository at this point in the history
Several changes to ping test to make it a little more useful:
* Removed the dependencies on PDO configuration including configuration
files and environment variables; everything gets specified as command
line parameters:
    ping_test.py --url ${PDO_LEDGER_URL} --cert ${PDO_LEDGER_KEY_ROOT}/networkcert.pem

* Allow for "quiet" mode operation so that the result code can be used
in other scripts.

* Change behavior on failure to print the root cause message for
an exception that occurs; CCF was hiding the useful messages

Signed-off-by: Mic Bowman <mic.bowman@intel.com>
  • Loading branch information
cmickeyb authored and prakashngit committed Jan 17, 2024
1 parent e62be5e commit 0b4ed7c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 66 deletions.
2 changes: 1 addition & 1 deletion ledgers/ccf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $(PYTHON_DIR) :
install : install-pdo-tp

PDO_BASH_SCRIPTS=start_ccf_network.sh stop_cchost.sh
PDO_PYTHON_SCRIPTS=configure_ccf_network.py generate_ledger_authority.py fetch_ledger_authority.py register_enclave_attestation_verification_policy.py utils.py
PDO_PYTHON_SCRIPTS=configure_ccf_network.py generate_ledger_authority.py fetch_ledger_authority.py register_enclave_attestation_verification_policy.py

install-pdo-tp : build-pdo-tp
@ cd $(BLDDIR) && $(NINJA) install
Expand Down
2 changes: 1 addition & 1 deletion ledgers/ccf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ at the end of the test.

```bash
source $PDO_HOME/ccf/bin/activate
${PDO_SOURCE_ROOT}/ledgers/ccf/scripts/ping_test.py
${PDO_SOURCE_ROOT}/ledgers/ccf/scripts/ping_test.py --url ${PDO_LEDGER_URL} --cert ${PDO_LEDGER_KEY_ROOT}/networkcert.pem
```

While invoking the test from a remote machine, be sure to 1) copy the
Expand Down
55 changes: 29 additions & 26 deletions ledgers/ccf/scripts/ping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@
import os
import sys
import time
import toml
from urllib.parse import urlparse

from ccf.clients import CCFClient

from utils import parse_ledger_url
# pick up the logger used by the rest of CCF
from loguru import logger as LOG

## -----------------------------------------------------------------
ContractHome = os.environ.get("PDO_HOME") or os.path.realpath("/opt/pdo")
CCF_Etc = os.path.join(ContractHome, "ccf", "etc")
CCF_Keys = os.environ.get("PDO_LEDGER_KEY_ROOT") or os.path.join(ContractHome, "ccf", "keys")

# -----------------------------------------------------------------
def ping_test(client, options):
num_pings = options.num_pings
Expand All @@ -47,38 +38,50 @@ def ping_test(client, options):
total_time = end_time - start_time
txn_throuput = num_pings/total_time

LOG.info("Performed {0} pings. Average txn_throuput is {1} pings per second".format(num_pings, txn_throuput))
if options.verbose :
LOG.warning("Performed {0} pings. Average throughput is {1} pings per second".format(num_pings, txn_throuput))

# -----------------------------------------------------------------
def Main() :
parser = argparse.ArgumentParser(description='Script to enable the CCF network')

parser.add_argument('--logfile', help='Name of the log file, __screen__ for standard output', type=str)
parser.add_argument('--loglevel', help='Logging level', default='INFO', type=str)
parser.add_argument('--user-name', help="Name of the user being added", default = "userccf", type=str)
parser.add_argument("--num-pings", help="Number of ping operations to do", default = 100, type=int)

parser = argparse.ArgumentParser(description='Test the connection to a CCF server')

parser.add_argument('--loglevel', help='Logging level', default='WARNING', type=str)
parser.add_argument("--num-pings", help="Number of ping operations to do", default = 1, type=int)
parser.add_argument('--url', type=str, required=True)
parser.add_argument('--cert', type=str, required=True)
group = parser.add_mutually_exclusive_group()
group.add_argument('--verbose', action='store_true', default=True)
group.add_argument('--quiet', action='store_false', dest='verbose')
options = parser.parse_args()

# -----------------------------------------------------------------
LOG.remove()
LOG.add(sys.stderr, level=options.loglevel)

# -----------------------------------------------------------------
network_cert = os.path.join(CCF_Keys, "networkcert.pem")

host, port = parse_ledger_url()
try :
(host, port) = urlparse(options.url).netloc.split(':')
except Exception as e:
if options.verbose :
LOG.error('failed to parse ledger URL: {}'.format(str(e)))
sys.exit(-1)

try :
user_client = CCFClient(
host,
port,
network_cert)
user_client = CCFClient(host, port, options.cert)
except Exception as e:
LOG.error('failed to connect to CCF service: {}'.format(str(e)))
if options.verbose :
LOG.error('failed to connect to CCF service: {}'.format(str(e)))
sys.exit(-1)

ping_test(user_client, options)
try :
ping_test(user_client, options)
except Exception as e:
# this just lets the script get back to the original error
# that caused the execption
if options.verbose :
while e.__context__ : e = e.__context__
LOG.error('ping test failed: {}', str(e))
sys.exit(-1)

sys.exit(0)

Expand Down
38 changes: 0 additions & 38 deletions ledgers/ccf/scripts/utils.py

This file was deleted.

0 comments on commit 0b4ed7c

Please sign in to comment.