Skip to content

Commit fddc27c

Browse files
committed
[FAB-12492] run peers session with orderer usr org
This commit adds ability to spwan peers sessions configured with orderer service admin users. In particular this is usefull if we wold like to simulate in integration test configuration update related to the ordering service where default modification policy requires signature of the orderer org admin user. Change-Id: I95f6ac57a21ca8f1dde799d5151ee203b32e7b99 Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent b54d771 commit fddc27c

File tree

2 files changed

+89
-6
lines changed

2 files changed

+89
-6
lines changed

integration/nwo/configblock.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,56 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated
110110
Eventually(ccb, n.EventuallyTimeout).Should(BeNumerically(">", currentBlockNumber))
111111
}
112112

113+
// UpdateOrdererConfig computes, signs, and submits a configuration update which requires orderers signature and waits
114+
// for the update to complete.
115+
func UpdateOrdererConfig(n *Network, orderer *Orderer, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) {
116+
tempDir, err := ioutil.TempDir("", "updateConfig")
117+
Expect(err).NotTo(HaveOccurred())
118+
defer os.RemoveAll(tempDir)
119+
120+
// compute update
121+
configUpdate, err := update.Compute(current, updated)
122+
Expect(err).NotTo(HaveOccurred())
123+
configUpdate.ChannelId = channel
124+
125+
signedEnvelope, err := utils.CreateSignedEnvelope(
126+
common.HeaderType_CONFIG_UPDATE,
127+
channel,
128+
nil, // local signer
129+
&common.ConfigUpdateEnvelope{ConfigUpdate: utils.MarshalOrPanic(configUpdate)},
130+
0, // message version
131+
0, // epoch
132+
)
133+
Expect(err).NotTo(HaveOccurred())
134+
Expect(signedEnvelope).NotTo(BeNil())
135+
136+
updateFile := filepath.Join(tempDir, "update.pb")
137+
err = ioutil.WriteFile(updateFile, utils.MarshalOrPanic(signedEnvelope), 0600)
138+
Expect(err).NotTo(HaveOccurred())
139+
140+
for _, signer := range additionalSigners {
141+
sess, err := n.OrdererAdminSession(signer, submitter, commands.SignConfigTx{File: updateFile})
142+
Expect(err).NotTo(HaveOccurred())
143+
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
144+
}
145+
146+
// get current configuration block number
147+
currentBlockNumber := CurrentConfigBlockNumber(n, submitter, orderer, channel)
148+
149+
sess, err := n.PeerAdminSession(submitter, commands.ChannelUpdate{
150+
ChannelID: channel,
151+
Orderer: n.OrdererAddress(orderer, ListenPort),
152+
File: updateFile,
153+
})
154+
Expect(err).NotTo(HaveOccurred())
155+
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
156+
Expect(sess.Err).To(gbytes.Say("Successfully submitted channel update"))
157+
158+
// wait for the block to be committed
159+
ccb := func() uint64 { return CurrentConfigBlockNumber(n, submitter, orderer, channel) }
160+
Eventually(ccb, n.EventuallyTimeout).Should(BeNumerically(">", currentBlockNumber))
161+
}
162+
113163
// CurrentConfigBlockNumber retrieves the block number from the header of the
114164
// current config block. This can be used to detect whena configuration change
115165
// has completed.

integration/nwo/network.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"text/template"
2121
"time"
2222

23-
docker "github.com/fsouza/go-dockerclient"
23+
"github.com/fsouza/go-dockerclient"
2424
"github.com/hyperledger/fabric/integration/helpers"
2525
"github.com/hyperledger/fabric/integration/nwo/commands"
2626
"github.com/hyperledger/fabric/integration/nwo/fabricconfig"
@@ -308,16 +308,31 @@ func (n *Network) WritePeerConfig(p *Peer, config *fabricconfig.Core) {
308308
Expect(err).NotTo(HaveOccurred())
309309
}
310310

311-
// peerUserCrpytoDir returns the path to the directory containing the
311+
// peerUserCryptoDir returns the path to the directory containing the
312312
// certificates and keys for the specified user of the peer.
313-
func (n *Network) peerUserCrpytoDir(p *Peer, user, cryptoMaterialType string) string {
313+
func (n *Network) peerUserCryptoDir(p *Peer, user, cryptoMaterialType string) string {
314314
org := n.Organization(p.Organization)
315315
Expect(org).NotTo(BeNil())
316316

317+
return n.userCryptoDir(org, "peerOrganizations", user, cryptoMaterialType)
318+
}
319+
320+
// ordererUserCryptoDir returns the path to the directory containing the
321+
// certificates and keys for the specified user of the orderer.
322+
func (n *Network) ordererUserCryptoDir(o *Orderer, user, cryptoMaterialType string) string {
323+
org := n.Organization(o.Organization)
324+
Expect(org).NotTo(BeNil())
325+
326+
return n.userCryptoDir(org, "ordererOrganizations", user, cryptoMaterialType)
327+
}
328+
329+
// userCryptoDir returns the path to the folder with crypto materials for either peers or orderer organizations
330+
// specific user
331+
func (n *Network) userCryptoDir(org *Organization, nodeOrganizationType, user, cryptoMaterialType string) string {
317332
return filepath.Join(
318333
n.RootDir,
319334
"crypto",
320-
"peerOrganizations",
335+
nodeOrganizationType,
321336
org.Domain,
322337
"users",
323338
fmt.Sprintf("%s@%s", user, org.Domain),
@@ -328,13 +343,19 @@ func (n *Network) peerUserCrpytoDir(p *Peer, user, cryptoMaterialType string) st
328343
// PeerUserMSPDir returns the path to the MSP directory containing the
329344
// certificates and keys for the specified user of the peer.
330345
func (n *Network) PeerUserMSPDir(p *Peer, user string) string {
331-
return n.peerUserCrpytoDir(p, user, "msp")
346+
return n.peerUserCryptoDir(p, user, "msp")
347+
}
348+
349+
// OrdererUserMSPDir returns the path to the MSP directory containing the
350+
// certificates and keys for the specified user of the peer.
351+
func (n *Network) OrdererUserMSPDir(o *Orderer, user string) string {
352+
return n.ordererUserCryptoDir(o, user, "msp")
332353
}
333354

334355
// PeerUserTLSDir returns the path to the TLS directory containing the
335356
// certificates and keys for the specified user of the peer.
336357
func (n *Network) PeerUserTLSDir(p *Peer, user string) string {
337-
return n.peerUserCrpytoDir(p, user, "tls")
358+
return n.peerUserCryptoDir(p, user, "tls")
338359
}
339360

340361
// PeerUserCert returns the path to the certificate for the specified user in
@@ -960,6 +981,18 @@ func (n *Network) PeerUserSession(p *Peer, user string, command Command) (*gexec
960981
return n.StartSession(cmd, command.SessionName())
961982
}
962983

984+
// OrdererAdminSession execute a gexec.Session as an orderer node admin user. This is used primarily
985+
// to generate orderer configuration updates
986+
func (n *Network) OrdererAdminSession(o *Orderer, p *Peer, command Command) (*gexec.Session, error) {
987+
cmd := n.peerCommand(
988+
command,
989+
"CORE_PEER_LOCALMSPID=OrdererMSP",
990+
fmt.Sprintf("FABRIC_CFG_PATH=%s", n.PeerDir(p)),
991+
fmt.Sprintf("CORE_PEER_MSPCONFIGPATH=%s", n.OrdererUserMSPDir(o, "Admin")),
992+
)
993+
return n.StartSession(cmd, command.SessionName())
994+
}
995+
963996
// Peer returns the information about the named Peer in the named organization.
964997
func (n *Network) Peer(orgName, peerName string) *Peer {
965998
for _, p := range n.PeersInOrg(orgName) {

0 commit comments

Comments
 (0)