Skip to content

Commit dfd4309

Browse files
committed
Generate block fixtures in orderer/common/server UT
FAB-16704 #done Change-Id: I1e0b04ac0b0bf8f52a5966f6bd3222900fb03e8d Signed-off-by: Will Lahti <[email protected]>
1 parent 0c5f27f commit dfd4309

18 files changed

+327
-137
lines changed

orderer/common/server/etcdraft_test.go

+28-35
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ func nextPort() int32 {
2828
}
2929

3030
func TestSpawnEtcdRaft(t *testing.T) {
31-
3231
gt := NewGomegaWithT(t)
3332

34-
cwd, err := filepath.Abs(".")
35-
gt.Expect(err).NotTo(HaveOccurred())
36-
3733
// Set the fabric root folder for easy navigation to sampleconfig folder
3834
fabricRootDir, err := filepath.Abs(filepath.Join("..", "..", ".."))
3935
gt.Expect(err).NotTo(HaveOccurred())
@@ -55,7 +51,7 @@ func TestSpawnEtcdRaft(t *testing.T) {
5551
defer os.RemoveAll(tempDir)
5652

5753
t.Run("Invalid bootstrap block", func(t *testing.T) {
58-
testEtcdRaftOSNFailureInvalidBootstrapBlock(NewGomegaWithT(t), tempDir, orderer, fabricRootDir)
54+
testEtcdRaftOSNFailureInvalidBootstrapBlock(NewGomegaWithT(t), tempDir, orderer, fabricRootDir, configtxgen)
5955
})
6056

6157
t.Run("TLS disabled single listener", func(t *testing.T) {
@@ -81,17 +77,17 @@ func TestSpawnEtcdRaft(t *testing.T) {
8177
gt.Expect(err).NotTo(HaveOccurred())
8278
defer os.RemoveAll(tempDir)
8379

84-
testEtcdRaftOSNSuccess(gt, tempDir, configtxgen, cwd, orderer, fabricRootDir)
80+
testEtcdRaftOSNSuccess(gt, tempDir, configtxgen, orderer, fabricRootDir)
8581
})
8682
})
8783
}
8884

89-
func createBootstrapBlock(gt *GomegaWithT, tempDir, configtxgen, cwd string) string {
90-
// Create the genesis block for the system channel
85+
func createBootstrapBlock(gt *GomegaWithT, tempDir, configtxgen, channel, profile string) string {
86+
// create a genesis block for the specified channel and profile
9187
genesisBlockPath := filepath.Join(tempDir, "genesis.block")
92-
cmd := exec.Command(configtxgen, "-channelID", "system", "-profile", "SampleDevModeEtcdRaft",
88+
cmd := exec.Command(configtxgen, "-channelID", channel, "-profile", profile,
9389
"-outputBlock", genesisBlockPath)
94-
cmd.Env = append(cmd.Env, fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(cwd, "testdata")))
90+
cmd.Env = append(cmd.Env, "FABRIC_CFG_PATH=testdata")
9591
configtxgenProcess, err := gexec.Start(cmd, nil, nil)
9692
gt.Expect(err).NotTo(HaveOccurred())
9793
gt.Eventually(configtxgenProcess, time.Minute).Should(gexec.Exit(0))
@@ -100,8 +96,8 @@ func createBootstrapBlock(gt *GomegaWithT, tempDir, configtxgen, cwd string) str
10096
return genesisBlockPath
10197
}
10298

103-
func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, cwd, orderer, fabricRootDir string) {
104-
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, cwd)
99+
func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, orderer, fabricRootDir string) {
100+
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, "system", "SampleEtcdRaftSystemChannel")
105101

106102
// Launch the OSN
107103
ordererProcess := launchOrderer(gt, orderer, tempDir, genesisBlockPath, fabricRootDir)
@@ -126,9 +122,9 @@ func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, cwd, orderer,
126122
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("becomeLeader"))
127123
}
128124

129-
func testEtcdRaftOSNFailureInvalidBootstrapBlock(gt *GomegaWithT, tempDir, orderer, fabricRootDir string) {
130-
// Grab an application channel genesis block
131-
genesisBlockPath := filepath.Join(filepath.Join("testdata", "mychannel.block"))
125+
func testEtcdRaftOSNFailureInvalidBootstrapBlock(gt *GomegaWithT, tempDir, orderer, fabricRootDir, configtxgen string) {
126+
// create an application channel genesis block
127+
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, "mychannel", "SampleOrgChannel")
132128
genesisBlockBytes, err := ioutil.ReadFile(genesisBlockPath)
133129
gt.Expect(err).NotTo(HaveOccurred())
134130

@@ -146,10 +142,7 @@ func testEtcdRaftOSNFailureInvalidBootstrapBlock(gt *GomegaWithT, tempDir, order
146142
}
147143

148144
func testEtcdRaftOSNNoTLSSingleListener(gt *GomegaWithT, tempDir, orderer, fabricRootDir string, configtxgen string) {
149-
cwd, err := filepath.Abs(".")
150-
gt.Expect(err).NotTo(HaveOccurred())
151-
152-
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, cwd)
145+
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, "system", "SampleEtcdRaftSystemChannel")
153146

154147
cmd := exec.Command(orderer)
155148
cmd.Env = []string{
@@ -169,10 +162,10 @@ func testEtcdRaftOSNNoTLSSingleListener(gt *GomegaWithT, tempDir, orderer, fabri
169162
}
170163

171164
func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, tempDir, orderer, fabricRootDir string, configtxgen string) {
172-
cwd, err := filepath.Abs(".")
165+
cwd, err := os.Getwd()
173166
gt.Expect(err).NotTo(HaveOccurred())
174167

175-
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, cwd)
168+
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, "system", "SampleEtcdRaftSystemChannel")
176169

177170
cmd := exec.Command(orderer)
178171
cmd.Env = []string{
@@ -185,11 +178,11 @@ func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, tempDir, orderer, fabricR
185178
fmt.Sprintf("ORDERER_GENERAL_GENESISFILE=%s", genesisBlockPath),
186179
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_LISTENPORT=%d", nextPort()),
187180
"ORDERER_GENERAL_CLUSTER_LISTENADDRESS=127.0.0.1",
188-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s", filepath.Join(cwd, "testdata", "tls", "server.crt")),
189-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "tls", "server.key")),
190-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s", filepath.Join(cwd, "testdata", "tls", "server.crt")),
191-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "tls", "server.key")),
192-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "tls", "ca.crt")),
181+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")),
182+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.key")),
183+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")),
184+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.key")),
185+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "example.com", "tls", "ca.crt")),
193186
fmt.Sprintf("ORDERER_CONSENSUS_WALDIR=%s", filepath.Join(tempDir, "wal")),
194187
fmt.Sprintf("ORDERER_CONSENSUS_SNAPDIR=%s", filepath.Join(tempDir, "snapshot")),
195188
fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(fabricRootDir, "sampleconfig")),
@@ -204,7 +197,7 @@ func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, tempDir, orderer, fabricR
204197
}
205198

206199
func launchOrderer(gt *GomegaWithT, orderer, tempDir, genesisBlockPath, fabricRootDir string) *gexec.Session {
207-
cwd, err := filepath.Abs(".")
200+
cwd, err := os.Getwd()
208201
gt.Expect(err).NotTo(HaveOccurred())
209202

210203
// Launch the orderer process
@@ -220,14 +213,14 @@ func launchOrderer(gt *GomegaWithT, orderer, tempDir, genesisBlockPath, fabricRo
220213
fmt.Sprintf("ORDERER_GENERAL_GENESISFILE=%s", genesisBlockPath),
221214
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_LISTENPORT=%d", nextPort()),
222215
"ORDERER_GENERAL_CLUSTER_LISTENADDRESS=127.0.0.1",
223-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s", filepath.Join(cwd, "testdata", "tls", "server.crt")),
224-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "tls", "server.key")),
225-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s", filepath.Join(cwd, "testdata", "tls", "server.crt")),
226-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "tls", "server.key")),
227-
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "tls", "ca.crt")),
228-
fmt.Sprintf("ORDERER_GENERAL_TLS_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "tls", "ca.crt")),
229-
fmt.Sprintf("ORDERER_GENERAL_TLS_CERTIFICATE=%s", filepath.Join(cwd, "testdata", "tls", "server.crt")),
230-
fmt.Sprintf("ORDERER_GENERAL_TLS_PRIVATEKEY=%s", filepath.Join(cwd, "testdata", "tls", "server.key")),
216+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")),
217+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.key")),
218+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")),
219+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.key")),
220+
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "example.com", "tls", "ca.crt")),
221+
fmt.Sprintf("ORDERER_GENERAL_TLS_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "example.com", "tls", "ca.crt")),
222+
fmt.Sprintf("ORDERER_GENERAL_TLS_CERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")),
223+
fmt.Sprintf("ORDERER_GENERAL_TLS_PRIVATEKEY=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.key")),
231224
fmt.Sprintf("ORDERER_CONSENSUS_WALDIR=%s", filepath.Join(tempDir, "wal")),
232225
fmt.Sprintf("ORDERER_CONSENSUS_SNAPDIR=%s", filepath.Join(tempDir, "snapshot")),
233226
fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(fabricRootDir, "sampleconfig")),

orderer/common/server/main_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ func TestUpdateTrustedRoots(t *testing.T) {
498498
TLS: localconfig.TLS{
499499
Enabled: true,
500500
ClientAuthRequired: true,
501-
PrivateKey: filepath.Join(".", "testdata", "tls", "server.key"),
502-
Certificate: filepath.Join(".", "testdata", "tls", "server.crt"),
501+
PrivateKey: filepath.Join(".", "testdata", "example.com", "tls", "server.key"),
502+
Certificate: filepath.Join(".", "testdata", "example.com", "tls", "server.crt"),
503503
},
504504
},
505505
}

0 commit comments

Comments
 (0)