Skip to content

Commit 4248b9e

Browse files
committed
[FAB-3750] New mspAdmin role BDD
Add new role to BDD to account for recent instantiation policy changes in peer. The mspAdmin role user's certificate will be added to the admincerts attribute of the MSPConfig used for the consortiums definition. Modify the boostrap.feature to use the mspAdmin for the instantiation related tasks. Modify dumping logs to tmp folder for run. Change-Id: I696efc1ea40451094c204b6752d95ca4d33f86a1 Signed-off-by: Jeff Garratt <[email protected]>
1 parent c140def commit 4248b9e

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

bddtests/environment.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def after_scenario(context, scenario):
4343
file_suffix = "_" + scenario.name.replace(" ", "_") + ".log"
4444
# get logs from the peer containers
4545
for containerData in context.compose_containers:
46-
with open(containerData.containerName + file_suffix, "w+") as logfile:
46+
(fileName, fileExists) = contextHelper.getTmpPathForName(name="{0}_{1}".format(containerData.containerName, scenario.name), extension="log", path_relative_to_tmp="logs")
47+
with open(fileName, "w+") as logfile:
4748
sys_rc = subprocess.call(["docker", "logs", containerData.containerName], stdout=logfile, stderr=logfile)
4849
if sys_rc !=0 :
4950
print("Cannot get logs for {0}. Docker rc = {1}".format(containerData.containerName,sys_rc))
@@ -52,7 +53,8 @@ def after_scenario(context, scenario):
5253
cli_call(["docker", "ps", "-f", "name=dev-", "--format", "{{.Names}}"], expect_success=True)
5354
for containerName in cc_output.splitlines():
5455
namePart,sep,junk = containerName.rpartition("-")
55-
with open(namePart + file_suffix, "w+") as logfile:
56+
(fileName, fileExists) = contextHelper.getTmpPathForName(name="{0}_{1}".format(namePart, scenario.name), extension="log", path_relative_to_tmp="logs")
57+
with open(fileName, "w+") as logfile:
5658
sys_rc = subprocess.call(["docker", "logs", containerName], stdout=logfile, stderr=logfile)
5759
if sys_rc !=0 :
5860
print("Cannot get logs for {0}. Docker rc = {1}".format(namepart,sys_rc))

bddtests/features/bootstrap.feature

+28-23
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,28 @@ Feature: Bootstrap
4444

4545
And the ordererBootstrapAdmin generates a GUUID to identify the orderer system chain and refer to it by name as "OrdererSystemChainId"
4646

47+
# We now have an orderer network with NO peers. Now need to configure and start the peer network
48+
# This can be currently automated through folder creation of the proper form and placing PEMs.
49+
And user requests role for peer by creating a key and csr for peer and acquires signed certificate from organization:
50+
| User | Peer | Organization |AliasSavedUnder|
51+
| peer0Signer | peer0 | peerOrg0 | |
52+
| peer1Signer | peer1 | peerOrg0 | |
53+
| peer2Signer | peer2 | peerOrg1 | |
54+
| peer3Signer | peer3 | peerOrg1 | |
55+
| peer0Admin | peer0 | peerOrg0 |peer-admin-cert|
56+
| peer1Admin | peer1 | peerOrg0 |peer-admin-cert|
57+
| peer2Admin | peer2 | peerOrg1 |peer-admin-cert|
58+
| peer3Admin | peer3 | peerOrg1 |peer-admin-cert|
59+
| mspAdminPeerOrg0| mspAdmin | peerOrg0 |msp-admin-cert |
60+
| mspAdminPeerOrg1| mspAdmin | peerOrg1 |msp-admin-cert |
61+
4762
And the ordererBootstrapAdmin creates a consortium "consortium1" (network name) for peer orgs who wish to form a network:
4863
| Organization |
4964
| peerOrg0 |
5065
| peerOrg1 |
5166
# | peerOrg2 |
5267

68+
5369
# Order info includes orderer admin/orderer information and address (host:port) from previous steps
5470
# Only the peer organizations can vary.
5571
And the ordererBootstrapAdmin using cert alias "bootstrapCertAlias" creates the genesis block "ordererGenesisBlock" for chain "OrdererSystemChainId" for network config policy "<PolicyType>" and consensus "<ConsensusType>" using consortiums:
@@ -62,20 +78,6 @@ Feature: Bootstrap
6278
# to be used for setting the orderer genesis block path parameter in composition
6379
And the orderer admins use the genesis block for chain "OrdererSystemChainId" to configure orderers
6480

65-
# We now have an orderer network with NO peers. Now need to configure and start the peer network
66-
# This can be currently automated through folder creation of the proper form and placing PEMs.
67-
And user requests role for peer by creating a key and csr for peer and acquires signed certificate from organization:
68-
| User | Peer | Organization |AliasSavedUnder|
69-
| peer0Signer | peer0 | peerOrg0 | |
70-
| peer1Signer | peer1 | peerOrg0 | |
71-
| peer2Signer | peer2 | peerOrg1 | |
72-
| peer3Signer | peer3 | peerOrg1 | |
73-
| peer0Admin | peer0 | peerOrg0 |peer-admin-cert|
74-
| peer1Admin | peer1 | peerOrg0 |peer-admin-cert|
75-
| peer2Admin | peer2 | peerOrg1 |peer-admin-cert|
76-
| peer3Admin | peer3 | peerOrg1 |peer-admin-cert|
77-
78-
7981
And we compose "<ComposeFile>"
8082

8183
# Sleep as to allow system up time
@@ -199,38 +201,41 @@ Feature: Bootstrap
199201

200202

201203
Given user "peer0Admin" gives "cc_spec" to user "dev0Org0"
204+
And user "peer0Admin" gives "cc_spec" to user "mspAdminPeerOrg0"
202205

203-
# Under the covers, create a deployment spec, etc.
204-
When user "dev0Org0" using cert alias "dev0Org0App1" creates a instantiate proposal "instantiateProposal1" for channel "com.acme.blockchain.jdoe.Channel1" using chaincode spec "cc_spec"
205206

206-
And user "dev0Org0" using cert alias "dev0Org0App1" sends proposal "instantiateProposal1" to endorsers with timeout of "90" seconds with proposal responses "instantiateProposalResponses":
207+
When user "mspAdminPeerOrg0" using cert alias "msp-admin-cert" creates a instantiate proposal "instantiateProposal1" for channel "com.acme.blockchain.jdoe.Channel1" using chaincode spec "cc_spec"
208+
209+
And user "mspAdminPeerOrg0" using cert alias "msp-admin-cert" sends proposal "instantiateProposal1" to endorsers with timeout of "90" seconds with proposal responses "instantiateProposalResponses":
207210
| Endorser |
208211
| peer0 |
209212
| peer2 |
210213

211214

212-
Then user "dev0Org0" expects proposal responses "instantiateProposalResponses" with status "200" from endorsers:
215+
Then user "mspAdminPeerOrg0" expects proposal responses "instantiateProposalResponses" with status "200" from endorsers:
213216
| Endorser |
214217
| peer0 |
215218
| peer2 |
216219

217-
And user "dev0Org0" expects proposal responses "instantiateProposalResponses" each have the same value from endorsers:
220+
And user "mspAdminPeerOrg0" expects proposal responses "instantiateProposalResponses" each have the same value from endorsers:
218221
| Endorser |
219222
| peer0 |
220223
| peer2 |
221224

222-
When the user "dev0Org0" creates transaction "instantiateTx1" from proposal "instantiateProposal1" and proposal responses "instantiateProposalResponses" for channel "com.acme.blockchain.jdoe.Channel1"
225+
When the user "mspAdminPeerOrg0" creates transaction "instantiateTx1" from proposal "instantiateProposal1" and proposal responses "instantiateProposalResponses" for channel "com.acme.blockchain.jdoe.Channel1"
223226

224-
And the user "dev0Org0" broadcasts transaction "instantiateTx1" to orderer "<orderer1>" on channel "com.acme.blockchain.jdoe.Channel1"
227+
And the user "mspAdminPeerOrg0" broadcasts transaction "instantiateTx1" to orderer "<orderer1>" on channel "com.acme.blockchain.jdoe.Channel1"
225228

226229
# Sleep as the deliver takes a bit to have the first block ready
227230
And I wait "2" seconds
228231

229-
And user "dev0Org0" sends deliver a seek request on orderer "<orderer0>" with properties:
232+
And user "mspAdminPeerOrg0" using cert alias "msp-admin-cert" connects to deliver function on orderer "<orderer0>"
233+
234+
And user "mspAdminPeerOrg0" sends deliver a seek request on orderer "<orderer0>" with properties:
230235
| ChainId | Start | End |
231236
| com.acme.blockchain.jdoe.Channel1 | 1 | 1 |
232237

233-
Then user "dev0Org0" should get a delivery "deliveredInstantiateTx1Block" from "<orderer0>" of "1" blocks with "1" messages within "1" seconds
238+
Then user "mspAdminPeerOrg0" should get a delivery "deliveredInstantiateTx1Block" from "<orderer0>" of "1" blocks with "1" messages within "1" seconds
234239

235240
# Sleep as the deliver takes a bit to have the first block ready
236241
And I wait "1" seconds

bddtests/steps/bootstrap_util.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,6 @@ def getSelfSignedCert(self):
236236
def getCertAsPEM(self):
237237
return crypto.dump_certificate(crypto.FILETYPE_PEM, self.getSelfSignedCert())
238238

239-
def getMSPConfig(self):
240-
certPemsList = [crypto.dump_certificate(crypto.FILETYPE_PEM, self.getSelfSignedCert())]
241-
# For now, admin certs and CA certs are the same per @ASO
242-
adminCerts = certPemsList
243-
cacerts = adminCerts
244-
# Currently only 1 component, CN=<orgName>
245-
# name = self.getSelfSignedCert().get_subject().getComponents()[0][1]
246-
name = self.name
247-
fabricMSPConfig = msp_config_pb2.FabricMSPConfig(admins=adminCerts, root_certs=cacerts, name=name)
248-
mspConfig = msp_config_pb2.MSPConfig(config=fabricMSPConfig.SerializeToString(), type=0)
249-
return mspConfig
250-
251239
def isInNetwork(self, network):
252240
for n in self.networks:
253241
if str(n)==str(network):
@@ -657,7 +645,7 @@ def createChannelConfigGroup(directory, hashingAlgoName="SHA256", consensusType=
657645
# Add the orderer org groups MSPConfig info
658646
for ordererOrg in [org for org in directory.getOrganizations().values() if Network.Orderer in org.networks]:
659647
channel.groups[OrdererGroup].groups[ordererOrg.name].values[BootstrapHelper.KEY_MSP_INFO].value = toValue(
660-
ordererOrg.getMSPConfig())
648+
getMSPConfig(org=ordererOrg, directory=directory))
661649
channel.groups[OrdererGroup].groups[ordererOrg.name].values[BootstrapHelper.KEY_MSP_INFO].mod_policy=BootstrapHelper.KEY_POLICY_ADMINS
662650
# #Kafka specific
663651
# matchingNATs = [nat for nat in directory.getNamedCtxTuples() if (("orderer" in nat.user) and ("Signer" in nat.user) and ((compose_service in nat.nodeName)))]
@@ -808,6 +796,20 @@ class PathType(Enum):
808796
Container = 2
809797

810798

799+
def getMSPConfig(org, directory):
800+
adminCerts = [org.getCertAsPEM()]
801+
# Find the mspAdmin Tuple for org and add to admincerts folder
802+
for pnt, cert in [(nat, cert) for nat, cert in directory.ordererAdminTuples.items() if
803+
org.name == nat.organization and "mspadmin" in nat.nodeName.lower()]:
804+
adminCerts.append(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
805+
cacerts = [org.getCertAsPEM()]
806+
# Currently only 1 component, CN=<orgName>
807+
# name = self.getSelfSignedCert().get_subject().getComponents()[0][1]
808+
fabricMSPConfig = msp_config_pb2.FabricMSPConfig(admins=adminCerts, root_certs=cacerts, name=org.name)
809+
mspConfig = msp_config_pb2.MSPConfig(config=fabricMSPConfig.SerializeToString(), type=0)
810+
return mspConfig
811+
812+
811813
class CallbackHelper:
812814
def __init__(self, discriminator, volumeRootPathInContainer = "/var/hyperledger/bddtests"):
813815
self.volumeRootPathInContainer = volumeRootPathInContainer
@@ -1012,7 +1014,7 @@ def createConsortium(context, consortium_name, org_names):
10121014
for consortium_org in [org for org in directory.getOrganizations().values() if org.name in org_names]:
10131015
# channel.groups[ConsortiumsGroup].groups[consortium_name].groups[consortium_org.name].mod_policy = BootstrapHelper.KEY_POLICY_ADMINS
10141016
channel.groups[ConsortiumsGroup].groups[consortium_name].groups[consortium_org.name].values[BootstrapHelper.KEY_MSP_INFO].value = toValue(
1015-
consortium_org.getMSPConfig())
1017+
getMSPConfig(org=consortium_org, directory=directory))
10161018
channel.groups[ConsortiumsGroup].groups[consortium_name].groups[consortium_org.name].values[BootstrapHelper.KEY_MSP_INFO].mod_policy=BootstrapHelper.KEY_POLICY_ADMINS
10171019
typeImplicitMeta = common_dot_policies_pb2.Policy.PolicyType.Value("IMPLICIT_META")
10181020
Policy = common_dot_policies_pb2.Policy

bddtests/steps/contexthelper.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ def getTmpProjectPath(self):
4242
os.makedirs(pathToReturn)
4343
return pathToReturn
4444

45-
def getTmpPathForName(self, name, extension=None, copyFromCache=False):
45+
def getTmpPathForName(self, name, extension=None, copyFromCache=False, path_relative_to_tmp=''):
4646
'Returns the tmp path for a file, and a flag indicating if the file exists. Will also check in the cache and copy to tmp if copyFromCache==True'
4747
unicodeName = unicode(name)
48+
dir_path = os.path.join(self.getTmpProjectPath(), path_relative_to_tmp)
49+
if not os.path.isdir(dir_path):
50+
os.makedirs(dir_path)
4851
slugifiedName = ".".join([slugify(unicodeName), extension]) if extension else slugify(unicodeName)
49-
tmpPath = os.path.join(self.getTmpProjectPath(), slugifiedName)
52+
tmpPath = os.path.join(dir_path, slugifiedName)
5053
fileExists = False
5154
if os.path.isfile(tmpPath):
5255
# file already exists in tmp path, return path and exists flag

0 commit comments

Comments
 (0)