From 144616bb94594a2b9c7402129b5968e55a2b34f3 Mon Sep 17 00:00:00 2001 From: Dariusz Kedzierski Date: Mon, 5 Nov 2018 20:11:36 +0100 Subject: [PATCH] Standard eosio.py fixing issue #1 --- cd-scripts/deploy.py | 62 +++++++++++++++++------------------- cd-scripts/eosio.py | 76 ++++++++++++++++++++++---------------------- 2 files changed, 68 insertions(+), 70 deletions(-) diff --git a/cd-scripts/deploy.py b/cd-scripts/deploy.py index 375bc492c96..1330dcbdede 100755 --- a/cd-scripts/deploy.py +++ b/cd-scripts/deploy.py @@ -508,47 +508,45 @@ def configure_genesis_json(): out_f.write(dst) def initialize_beos(): - import asyncio - import async_eosio + import eosio try: - loop = asyncio.get_event_loop() - result = loop.run_until_complete(async_eosio.run_keosd(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR)) - result = loop.run_until_complete(async_eosio.create_wallet("http://{0}:{1}".format(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT))) - result = loop.run_until_complete(async_eosio.run_nodeos(config.START_NODE_INDEX, "eosio", config.EOSIO_PUBLIC_KEY)) - - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.msig", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.names", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.saving", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.vpay", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.unregd", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.bpay", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) + eosio.run_keosd(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR) + eosio.create_wallet("http://{0}:{1}".format(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT), False) + eosio.run_nodeos(config.START_NODE_INDEX, "eosio", config.EOSIO_PUBLIC_KEY) + + eosio.create_account("eosio", "eosio.msig", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "eosio.names", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "eosio.saving", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "eosio.vpay", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "eosio.unregd", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + + eosio.create_account("eosio", "eosio.bpay", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.ram", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.ramfee", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.stake", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) + eosio.create_account("eosio", "eosio.ram", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "eosio.ramfee", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "eosio.stake", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) - result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.token", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)) - result = loop.run_until_complete(async_eosio.create_account("eosio", "beos.init", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY)) + eosio.create_account("eosio", "eosio.token", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY) + eosio.create_account("eosio", "beos.init", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY) - result = loop.run_until_complete(async_eosio.set_contract("eosio.token", config.CONTRACTS_DIR + "/eosio.token", "eosio.token")) + eosio.set_contract("eosio.token", config.CONTRACTS_DIR + "/eosio.token", "eosio.token") - result = loop.run_until_complete(async_eosio.push_action("eosio.token", "create", '[ "beos.distrib", "{0} {1}"]'.format(config.CORE_INITIAL_AMOUNT, config.CORE_SYMBOL_NAME), "eosio.token")) - result = loop.run_until_complete(async_eosio.push_action("eosio.token", "create", '[ "beos.gateway", "{0} {1}"]'.format(config.PROXY_INITIAL_AMOUNT, config.PROXY_ASSET_NAME), "eosio.token")) + eosio.push_action("eosio.token", "create", '[ "beos.distrib", "{0} {1}"]'.format(config.CORE_INITIAL_AMOUNT, config.CORE_SYMBOL_NAME), "eosio.token") + eosio.push_action("eosio.token", "create", '[ "beos.gateway", "{0} {1}"]'.format(config.PROXY_INITIAL_AMOUNT, config.PROXY_ASSET_NAME), "eosio.token") - result = loop.run_until_complete(async_eosio.set_contract("eosio", config.CONTRACTS_DIR + "eosio.system", "eosio")) - result = loop.run_until_complete(async_eosio.set_contract("beos.init", config.CONTRACTS_DIR + "eosio.init", "beos.init")) - result = loop.run_until_complete(async_eosio.set_contract("beos.gateway", config.CONTRACTS_DIR + "eosio.gateway", "beos.gateway")) - result = loop.run_until_complete(async_eosio.set_contract("beos.distrib", config.CONTRACTS_DIR + "eosio.distribution", "beos.distrib")) + eosio.set_contract("eosio", config.CONTRACTS_DIR + "eosio.system", "eosio") + eosio.set_contract("beos.init", config.CONTRACTS_DIR + "eosio.init", "beos.init") + eosio.set_contract("beos.gateway", config.CONTRACTS_DIR + "eosio.gateway", "beos.gateway") + eosio.set_contract("beos.distrib", config.CONTRACTS_DIR + "eosio.distribution", "beos.distrib") - result = loop.run_until_complete(async_eosio.push_action("eosio", "initram", '[ "beos.gateway", "{0}"]'.format(config.INIT_RAM), "eosio")) + eosio.push_action("eosio", "initram", '[ "beos.gateway", "{0}"]'.format(config.INIT_RAM), "eosio") - result = loop.run_until_complete(async_eosio.terminate_running_tasks()) - result = loop.run_until_complete(async_eosio.show_keosd_postconf(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR)) - result = loop.run_until_complete(async_eosio.show_wallet_unlock_postconf()) - result = loop.run_until_complete(async_eosio.show_nodeos_postconf(0, "eosio", config.EOSIO_PUBLIC_KEY)) + eosio.terminate_running_tasks() + eosio.show_keosd_postconf(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR) + eosio.show_wallet_unlock_postconf() + eosio.show_nodeos_postconf(0, "eosio", config.EOSIO_PUBLIC_KEY) except Exception as ex: - result = loop.run_until_complete(async_eosio.terminate_running_tasks()) + eosio.terminate_running_tasks() logger.error("Exception during initialize: {0}".format(ex)) sys.exit(1) diff --git a/cd-scripts/eosio.py b/cd-scripts/eosio.py index 8118ede10f3..6187e8ea28b 100644 --- a/cd-scripts/eosio.py +++ b/cd-scripts/eosio.py @@ -6,6 +6,11 @@ import time import sys +global KEOSD +KEOSD = None +global NODEOS +NODEOS = None + try: import config except Exception as ex: @@ -126,8 +131,6 @@ def run_keosd(ip_address, port, wallet_dir, use_https = False, forceWalletCleanu os.makedirs(config.DEFAULT_WALLET_DIR) os.makedirs(config.WALLET_PASSWORD_DIR) - time.sleep(0.5) - parameters = None if use_https: # run kleosd in https mode @@ -144,7 +147,18 @@ def run_keosd(ip_address, port, wallet_dir, use_https = False, forceWalletCleanu "--wallet-dir", wallet_dir, ] logger.info("Executing command: {0}".format(" ".join(parameters))) - subprocess.Popen(parameters, stdout=config.log_main, stderr=config.log_main) + global KEOSD + KEOSD = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + while True: + line = KEOSD.stdout.readline() + line = line.decode('utf-8').strip() + if line.startswith("error"): + raise EOSIOException("Error during KEOSD run") + else: + logger.debug(line) + if line.endswith("add api url: /v1/wallet/unlock"): + logger.info("KEOSD is up and running") + break def unlock_wallet(wallet_name, wallet_password): parameters = [config.CLEOS_EXECUTABLE, @@ -155,7 +169,6 @@ def unlock_wallet(wallet_name, wallet_password): logger.info("Executing command: {0}".format(" ".join(parameters))) ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) retcode = ret.returncode - time.sleep(1) if retcode == 0: logger.debug("Executed with ret: {0}".format(ret)) else: @@ -181,7 +194,6 @@ def import_key(wallet_name, key, wallet_url = None): logger.info("Executing command: {0}".format(" ".join(parameters))) ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) retcode = ret.returncode - time.sleep(1) if retcode == 0: logger.debug("Executed with ret: {0}".format(ret)) else: @@ -212,7 +224,6 @@ def create_wallet(wallet_url = None, unlock = False): logger.info("Executing command: {0}".format(" ".join(parameters))) ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) retcode = ret.returncode - time.sleep(1) if retcode == 0: logger.debug("Executed with ret: {0}".format(ret)) else: @@ -283,13 +294,18 @@ def run_nodeos(node_index, name, public_key, use_https = False): parameters = parameters + https_opts + plugins logger.info("Executing command: {0}".format(" ".join(parameters))) - try: - import time - subprocess.Popen(parameters, stdout=config.log_main, stderr=config.log_main) - time.sleep(2.0) - except Exception as ex: - logger.error("Exception during spawning nodeos process: {0}".format(ex)) - return 0 + global NODEOS + NODEOS = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + while True: + line = NODEOS.stdout.readline() + line = line.decode('utf-8').strip() + if line.startswith("error"): + logger.error(line) + else: + logger.debug(line) + if "] Produced block" in line: + logger.info("NODEOS is up and running") + break def create_account(creator, name, owner_key, active_key, schema = "http"): if not owner_key and not active_key: @@ -302,7 +318,6 @@ def create_account(creator, name, owner_key, active_key, schema = "http"): logger.info("Executing command: {0}".format(" ".join(parameters))) ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) retcode = ret.returncode - time.sleep(1) if retcode == 0: logger.debug("Executed with ret: {0}".format(ret)) else: @@ -318,7 +333,6 @@ def set_contract(account, contract, permission, schema = "http"): logger.info("Executing command: {0}".format(" ".join(parameters))) ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) retcode = ret.returncode - time.sleep(1) if retcode == 0: logger.debug("Executed with ret: {0}".format(ret)) else: @@ -334,7 +348,6 @@ def push_action(account, action, data, permission, schema = "http"): logger.info("Executing command: {0}".format(" ".join(parameters))) ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) retcode = ret.returncode - time.sleep(1) if retcode == 0: logger.debug("Executed with ret: {0}".format(ret)) else: @@ -343,29 +356,16 @@ def push_action(account, action, data, permission, schema = "http"): raise EOSIOException("Initialization failed on last command") def terminate_running_tasks(): - parameters = ["pkill", "nodeos"] - logger.info("Executing command: {0}".format(" ".join(parameters))) - ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) - retcode = ret.returncode - time.sleep(1) - if retcode == 0: - logger.debug("Executed with ret: {0}".format(ret)) - else: - logger.error("Executed with ret: {0}".format(ret)) - logger.error("Initialization failed on last command") - raise EOSIOException("Initialization failed on last command") + try: + if NODEOS is not None: + logger.info("Terminating NODEOS") + NODEOS.terminate() - parameters = ["pkill", "keosd"] - logger.info("Executing command: {0}".format(" ".join(parameters))) - ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main) - retcode = ret.returncode - time.sleep(1) - if retcode == 0: - logger.debug("Executed with ret: {0}".format(ret)) - else: - logger.error("Executed with ret: {0}".format(ret)) - logger.error("Initialization failed on last command") - raise EOSIOException("Initialization failed on last command") + if KEOSD is not None: + logger.info("Terminating KEOSD") + KEOSD.terminate() + except Exception as ex: + logger.error("Exception occured: {0}".format(ex)) if __name__ == '__main__': name = "eosio"