@@ -63,9 +63,15 @@ def lifecycle_query_installed(self, timeout):
6363 """
6464
6565 try :
66- res = subprocess .Popen ("{} lifecycle chaincode queryinstalled --output json --connTimeout {}"
67- .format (self .peer , timeout ), shell = True ,
68- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
66+ command = [
67+ self .peer ,
68+ "lifecycle" , "chaincode" , "queryinstalled" ,
69+ "--output" , "json" ,
70+ "--connTimeout" , timeout
71+ ]
72+ LOG .info (" " .join (command ))
73+ res = subprocess .Popen (command , shell = False ,
74+ stdout = subprocess .PIPE , stderr = subprocess .PIPE )
6975
7076 stdout , stderr = res .communicate ()
7177 return_code = res .returncode
@@ -106,8 +112,8 @@ def lifecycle_get_installed_package(self, timeout):
106112 raise Exception (err_msg )
107113 return res_return
108114
109- def lifecycle_approve_for_my_org (self , orderer_url , orderer_tls_rootcert , channel_name , cc_name ,
110- chaincode_version , policy , sequence = 1 ):
115+ def lifecycle_approve_for_my_org (self , orderer_url , channel_name , cc_name ,
116+ chaincode_version , sequence , policy , init_flag ):
111117 """
112118 The administrator can use the peer lifecycle chaincode approveformyorg subcommand to approve the chain code on
113119 behalf of the organization.
@@ -116,8 +122,9 @@ def lifecycle_approve_for_my_org(self, orderer_url, orderer_tls_rootcert, channe
116122 :param channel_name: channel name
117123 :param cc_name: chaincode name
118124 :param chaincode_version: chaincode version
119- :param policy: chaincode policy
120125 :param sequence: The channel chain code defines the serial number. The default value is 1
126+ :param policy: chaincode policy
127+ :param init_flag: if the chaincode is first init.
121128 :return:
122129 """
123130 try :
@@ -131,18 +138,43 @@ def lifecycle_approve_for_my_org(self, orderer_url, orderer_tls_rootcert, channe
131138 if package_id == "" :
132139 return 1 , "not exist the chaincode, please check chaincode_name and chaincode_version"
133140
141+ command = []
134142 if os .getenv ("CORE_PEER_TLS_ENABLED" ) == "false" or os .getenv ("CORE_PEER_TLS_ENABLED" ) is None :
135- res = subprocess .Popen ("{} lifecycle chaincode approveformyorg -o {} - --channelID {} --name {} "
136- "--version {} --init-required --package-id {} --sequence {} --signature-policy {}"
137- .format (self .peer , orderer_url , channel_name , cc_name , chaincode_version , package_id ,
138- sequence , policy ), shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
143+ command = [
144+ self .peer ,
145+ "lifecycle" , "chaincode" , "approveformyorg" ,
146+ "-o" , orderer_url ,
147+ "--channelID" , channel_name ,
148+ "--name" , cc_name ,
149+ "--version" , chaincode_version ,
150+ "--package-id" , package_id ,
151+ "--sequence" , str (sequence )
152+ ]
139153 else :
140- res = subprocess .Popen ("{} lifecycle chaincode approveformyorg -o {} --tls --cafile {} --channelID {} "
141- "--name {} --version {} --init-required --package-id {} --sequence {} "
142- "--signature-policy {}"
143- .format (self .peer , orderer_url , orderer_tls_rootcert , channel_name ,
144- cc_name , chaincode_version , package_id , sequence , policy ), shell = True ,
145- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
154+ ORDERER_CA = os .getenv ("ORDERER_CA" )
155+ command = [
156+ self .peer ,
157+ "lifecycle" , "chaincode" , "approveformyorg" ,
158+ "-o" , orderer_url ,
159+ "--ordererTLSHostnameOverride" , orderer_url .split (":" )[0 ],
160+ "--channelID" , channel_name ,
161+ "--name" , cc_name ,
162+ "--version" , chaincode_version ,
163+ "--package-id" , package_id ,
164+ "--sequence" , str (sequence ),
165+ "--tls" ,
166+ "--cafile" , ORDERER_CA
167+ ]
168+
169+ if init_flag :
170+ command .append ("--init-required" )
171+ if policy :
172+ command .append ("--signature-policy" )
173+ command .append (policy )
174+
175+ LOG .info (" " .join (command ))
176+ res = subprocess .Popen (command , shell = False ,
177+ stdout = subprocess .PIPE , stderr = subprocess .PIPE )
146178 stdout , stderr = res .communicate ()
147179 return_code = res .returncode
148180
0 commit comments