[#issue-330] cmdlinelib implement of lifecycle_check_commit_readiness
cmdlinelib implement of lifecycle_check_commit_readiness&lifecycle_commit functions
Close #issue-330
@@ -109,6 +109,7 @@ class ChainCode(BasicEnv):
:param sequence: The channel chain code defines the serial number. The default value is 1
:return:
"""
+ try:
res, installed = self.lifecycle_query_installed("3s")
cc_label = cc_name+"_"+chaincode_version
package_id = ""
@@ -139,6 +140,9 @@ class ChainCode(BasicEnv):
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
+ except Exception as e:
+ err_msg = "lifecycle_approve_for_my_org failed for {}!".format(e)
+ raise Exception(err_msg)
return return_code, content
def lifecycle_query_approved(self, channel_name, cc_name):
@@ -149,6 +153,7 @@ class ChainCode(BasicEnv):
:return:
"""
+ try:
res = subprocess.Popen("{} lifecycle chaincode queryapproved --output json --channelID {}"
" --name {}".format(self.peer, channel_name, cc_name),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -160,6 +165,9 @@ class ChainCode(BasicEnv):
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
+ except Exception as e:
+ err_msg = "lifecycle_query_approved failed for {}!".format(e)
+ raise Exception(err_msg)
return return_code, chaincodes_info
@@ -176,6 +184,7 @@ class ChainCode(BasicEnv):
:param sequence:The channel chain code defines the serial number. The default value is 1
:return:
"""
+ try:
if os.getenv("CORE_PEER_TLS_ENABLED") == "false" or os.getenv("CORE_PEER_TLS_ENABLED") is None:
res = subprocess.Popen("{} lifecycle chaincode checkcommitreadiness --output json "
" --channelID {} --name {} --version {} --init-required --sequence {} "
@@ -207,6 +216,9 @@ class ChainCode(BasicEnv):
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
+ except Exception as e:
+ err_msg = "lifecycle_check_commit_readiness failed for {}!".format(e)
+ raise Exception(err_msg)
def lifecycle_commit(self, orderer_url, orderer_tls_rootcert, channel_name, cc_name, chaincode_version,
policy, peerlist, peer_root_certs, sequency=1):
@@ -224,6 +236,7 @@ class ChainCode(BasicEnv):
:param sequency:The channel chain code defines the serial number. The default value is 1
:return:
"""
+ try:
peer_addresses_format = " --peerAddresses {} --tlsRootCertFiles {}"
command_str_with_tls = "{} lifecycle chaincode commit -o {} --tls --cafile {} " \
"--channelID {} --name {} --version {} --init-required --sequence {} " \
@@ -245,5 +258,8 @@ class ChainCode(BasicEnv):
command_str_with_tls = command_str_with_tls + peer_addresses_format
res = os.system(command_str_with_tls.format(self.peer, orderer_url, orderer_tls_rootcert, channel_name,
cc_name, chaincode_version, sequency, policy, *peer_addressed))
+ except Exception as e:
+ err_msg = "lifecycle_commit failed for {}!".format(e)
+ raise Exception(err_msg)
res = res >> 8
return res
