Skip to content

Commit 686461d

Browse files
committed
[FAB-10282] Refactor the building of test config
This CR allows a test to be configured by using the World struct to be generated for them instead of copying and pasting the original test. More work is need to generate the peer and orderer yaml files. This CR does not cover that work. Change-Id: I027f0651173df54ed6b8801c8f0e96a4b1831a0f Signed-off-by: Latitia M Haskins <latitia.haskins@gmail.com>
1 parent cccce48 commit 686461d

File tree

7 files changed

+266
-201
lines changed

7 files changed

+266
-201
lines changed

integration/e2e/e2e_suite_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ var _ = SynchronizedBeforeSuite(func() []byte {
3939
}, func(payload []byte) {
4040
err := json.Unmarshal(payload, &components)
4141
Expect(err).NotTo(HaveOccurred())
42+
})
4243

44+
var _ = BeforeEach(func() {
45+
var err error
4346
testDir, err = ioutil.TempDir("", "e2e-suite")
4447
Expect(err).NotTo(HaveOccurred())
4548
})
4649

47-
var _ = SynchronizedAfterSuite(func() {
50+
var _ = AfterEach(func() {
4851
os.RemoveAll(testDir)
52+
})
53+
54+
var _ = SynchronizedAfterSuite(func() {
4955
}, func() {
5056
components.Cleanup()
5157
})

integration/e2e/e2e_test.go

+25-190
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ package e2e
88

99
import (
1010
"fmt"
11-
"io/ioutil"
12-
"os"
1311
"path/filepath"
1412
"syscall"
1513
"time"
1614

1715
docker "github.com/fsouza/go-dockerclient"
18-
"github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
19-
"github.com/hyperledger/fabric/integration/runner"
2016
"github.com/hyperledger/fabric/integration/world"
2117
. "github.com/onsi/ginkgo"
2218
. "github.com/onsi/gomega"
@@ -27,161 +23,15 @@ import (
2723

2824
var _ = Describe("EndToEnd", func() {
2925
var (
30-
client *docker.Client
31-
network *docker.Network
32-
w world.World
26+
client *docker.Client
27+
w world.World
3328
)
3429

3530
BeforeEach(func() {
3631
var err error
3732

3833
client, err = docker.NewClientFromEnv()
3934
Expect(err).NotTo(HaveOccurred())
40-
41-
pOrg := []*localconfig.Organization{{
42-
Name: "Org1",
43-
ID: "Org1MSP",
44-
MSPDir: "crypto/peerOrganizations/org1.example.com/msp",
45-
AnchorPeers: []*localconfig.AnchorPeer{{
46-
Host: "0.0.0.0",
47-
Port: 7051,
48-
}},
49-
}, {
50-
Name: "Org2",
51-
ID: "Org2MSP",
52-
MSPDir: "crypto/peerOrganizations/org2.example.com/msp",
53-
AnchorPeers: []*localconfig.AnchorPeer{{
54-
Host: "0.0.0.0",
55-
Port: 14051,
56-
}},
57-
}}
58-
59-
ordererOrgs := world.OrdererConfig{
60-
OrganizationName: "OrdererOrg",
61-
Domain: "example.com",
62-
OrdererNames: []string{"orderer"},
63-
BrokerCount: 2,
64-
ZookeeperCount: 1,
65-
}
66-
67-
peerOrgs := []world.PeerOrgConfig{{
68-
OrganizationName: pOrg[0].Name,
69-
Domain: "org1.example.com",
70-
EnableNodeOUs: false,
71-
UserCount: 1,
72-
PeerCount: 1,
73-
}, {
74-
OrganizationName: pOrg[1].Name,
75-
Domain: "org2.example.com",
76-
EnableNodeOUs: false,
77-
UserCount: 1,
78-
PeerCount: 1,
79-
}}
80-
81-
oOrg := []*localconfig.Organization{{
82-
Name: ordererOrgs.OrganizationName,
83-
ID: "OrdererMSP",
84-
MSPDir: filepath.Join("crypto", "ordererOrganizations", "example.com", "orderers", "orderer.example.com", "msp"),
85-
}}
86-
87-
deployment := world.Deployment{
88-
SystemChannel: "systestchannel",
89-
Channel: "testchannel",
90-
Chaincode: world.Chaincode{
91-
Name: "mycc",
92-
Version: "1.0",
93-
Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd",
94-
ExecPath: os.Getenv("PATH"),
95-
},
96-
InitArgs: `{"Args":["init","a","100","b","200"]}`,
97-
Peers: []string{"peer0.org1.example.com", "peer0.org2.example.com"},
98-
Policy: `OR ('Org1MSP.member','Org2MSP.member')`,
99-
Orderer: "127.0.0.1:7050",
100-
}
101-
102-
peerProfile := localconfig.Profile{
103-
Consortium: "SampleConsortium",
104-
Application: &localconfig.Application{
105-
Organizations: pOrg,
106-
Capabilities: map[string]bool{
107-
"V1_2": true,
108-
},
109-
},
110-
Capabilities: map[string]bool{
111-
"V1_1": true,
112-
},
113-
}
114-
115-
orderer := &localconfig.Orderer{
116-
BatchTimeout: 1 * time.Second,
117-
BatchSize: localconfig.BatchSize{
118-
MaxMessageCount: 1,
119-
AbsoluteMaxBytes: (uint32)(98 * 1024 * 1024),
120-
PreferredMaxBytes: (uint32)(512 * 1024),
121-
},
122-
Kafka: localconfig.Kafka{
123-
Brokers: []string{
124-
"127.0.0.1:9092",
125-
"127.0.0.1:8092",
126-
},
127-
},
128-
Organizations: oOrg,
129-
OrdererType: "kafka",
130-
Addresses: []string{"0.0.0.0:7050"},
131-
Capabilities: map[string]bool{
132-
"V1_1": true,
133-
},
134-
}
135-
136-
ordererProfile := localconfig.Profile{
137-
Application: &localconfig.Application{
138-
Organizations: oOrg,
139-
Capabilities: map[string]bool{
140-
"V1_2": true,
141-
},
142-
},
143-
Orderer: orderer,
144-
Consortiums: map[string]*localconfig.Consortium{
145-
"SampleConsortium": &localconfig.Consortium{
146-
Organizations: append(oOrg, pOrg...),
147-
},
148-
},
149-
Capabilities: map[string]bool{
150-
"V1_1": true,
151-
},
152-
}
153-
154-
profiles := map[string]localconfig.Profile{
155-
"TwoOrgsOrdererGenesis": ordererProfile,
156-
"TwoOrgsChannel": peerProfile,
157-
}
158-
159-
// Create a network
160-
network, err = client.CreateNetwork(
161-
docker.CreateNetworkOptions{
162-
Name: runner.UniqueName(),
163-
Driver: "bridge",
164-
},
165-
)
166-
Expect(err).NotTo(HaveOccurred())
167-
168-
crypto := runner.Cryptogen{
169-
Config: filepath.Join(testDir, "crypto.yaml"),
170-
Output: filepath.Join(testDir, "crypto"),
171-
}
172-
173-
w = world.World{
174-
Rootpath: testDir,
175-
Components: components,
176-
Cryptogen: crypto,
177-
Network: network,
178-
Deployment: deployment,
179-
OrdererOrgs: []world.OrdererConfig{ordererOrgs},
180-
PeerOrgs: peerOrgs,
181-
OrdererProfileName: "TwoOrgsOrdererGenesis",
182-
ChannelProfileName: "TwoOrgsChannel",
183-
Profiles: profiles,
184-
}
18535
})
18636

18737
AfterEach(func() {
@@ -220,15 +70,20 @@ var _ = Describe("EndToEnd", func() {
22070
// Stop the orderers and peers
22171
for _, localProc := range w.LocalProcess {
22272
localProc.Signal(syscall.SIGTERM)
73+
Eventually(localProc.Wait(), 5*time.Second).Should(Receive())
74+
localProc.Signal(syscall.SIGKILL)
75+
Eventually(localProc.Wait(), 5*time.Second).Should(Receive())
22376
}
22477

22578
// Remove any started networks
226-
if network != nil {
227-
client.RemoveNetwork(network.Name)
79+
if w.Network != nil {
80+
client.RemoveNetwork(w.Network.Name)
22881
}
22982
})
23083

231-
It("executes a basic kafka network with 2 orgs", func() {
84+
It("executes a basic solo network with 2 orgs", func() {
85+
w = world.GenerateBasicConfig("solo", 1, 2, testDir, components)
86+
23287
By("generating files to bootstrap the network")
23388
w.BootstrapNetwork()
23489
Expect(filepath.Join(testDir, "configtx.yaml")).To(BeARegularFile())
@@ -278,47 +133,27 @@ var _ = Describe("EndToEnd", func() {
278133
execute(adminRunner)
279134
Eventually(adminRunner.Err()).Should(gbytes.Say("Successfully submitted channel update"))
280135
})
281-
})
282136

283-
func copyFile(src, dest string) {
284-
data, err := ioutil.ReadFile(src)
285-
Expect(err).NotTo(HaveOccurred())
286-
err = ioutil.WriteFile(dest, data, 0775)
287-
Expect(err).NotTo(HaveOccurred())
288-
}
137+
It("executes a basic kafka network with 2 orgs", func() {
138+
By("generating files to bootstrap the network")
139+
w = world.GenerateBasicConfig("kafka", 2, 2, testDir, components)
140+
setupWorld(&w)
289141

290-
func copyDir(src, dest string) {
291-
os.MkdirAll(dest, 0755)
292-
objects, err := ioutil.ReadDir(src)
293-
for _, obj := range objects {
294-
srcfileptr := src + "/" + obj.Name()
295-
destfileptr := dest + "/" + obj.Name()
296-
if obj.IsDir() {
297-
copyDir(srcfileptr, destfileptr)
298-
} else {
299-
copyFile(srcfileptr, destfileptr)
300-
}
301-
}
302-
Expect(err).NotTo(HaveOccurred())
303-
}
142+
By("querying the chaincode")
143+
adminPeer := components.Peer()
144+
adminPeer.LogLevel = "debug"
145+
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
146+
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
147+
adminRunner := adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
148+
execute(adminRunner)
149+
Eventually(adminRunner.Buffer()).Should(gbytes.Say("100"))
150+
151+
})
152+
})
304153

305154
func execute(r ifrit.Runner) (err error) {
306155
p := ifrit.Invoke(r)
307156
Eventually(p.Ready()).Should(BeClosed())
308157
Eventually(p.Wait(), 30*time.Second).Should(Receive(&err))
309158
return err
310159
}
311-
312-
func copyPeerConfigs(peerOrgs []world.PeerOrgConfig, rootPath string) {
313-
for _, peerOrg := range peerOrgs {
314-
for peer := 0; peer < peerOrg.PeerCount; peer++ {
315-
peerDir := fmt.Sprintf("%s_%d", peerOrg.Domain, peer)
316-
if _, err := os.Stat(filepath.Join(rootPath, peerDir)); os.IsNotExist(err) {
317-
err := os.Mkdir(filepath.Join(rootPath, peerDir), 0755)
318-
Expect(err).NotTo(HaveOccurred())
319-
}
320-
copyFile(filepath.Join("testdata", fmt.Sprintf("%s-core.yaml", peerDir)),
321-
filepath.Join(rootPath, peerDir, "core.yaml"))
322-
}
323-
}
324-
}

integration/e2e/setup.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package e2e
8+
9+
import (
10+
"fmt"
11+
"io/ioutil"
12+
"os"
13+
"path/filepath"
14+
15+
"github.com/hyperledger/fabric/integration/world"
16+
17+
. "github.com/onsi/gomega"
18+
)
19+
20+
func setupWorld(w *world.World) {
21+
w.BootstrapNetwork()
22+
copyFile(filepath.Join("testdata", "orderer.yaml"), filepath.Join(testDir, "orderer.yaml"))
23+
copyPeerConfigs(w.PeerOrgs, w.Rootpath)
24+
w.BuildNetwork()
25+
err := w.SetupChannel()
26+
Expect(err).NotTo(HaveOccurred())
27+
}
28+
29+
func copyFile(src, dest string) {
30+
data, err := ioutil.ReadFile(src)
31+
Expect(err).NotTo(HaveOccurred())
32+
err = ioutil.WriteFile(dest, data, 0775)
33+
Expect(err).NotTo(HaveOccurred())
34+
}
35+
36+
func copyDir(src, dest string) {
37+
os.MkdirAll(dest, 0755)
38+
objects, err := ioutil.ReadDir(src)
39+
for _, obj := range objects {
40+
srcfileptr := src + "/" + obj.Name()
41+
destfileptr := dest + "/" + obj.Name()
42+
if obj.IsDir() {
43+
copyDir(srcfileptr, destfileptr)
44+
} else {
45+
copyFile(srcfileptr, destfileptr)
46+
}
47+
}
48+
Expect(err).NotTo(HaveOccurred())
49+
}
50+
51+
func copyPeerConfigs(peerOrgs []world.PeerOrgConfig, rootPath string) {
52+
for _, peerOrg := range peerOrgs {
53+
for peer := 0; peer < peerOrg.PeerCount; peer++ {
54+
peerDir := fmt.Sprintf("%s_%d", peerOrg.Domain, peer)
55+
if _, err := os.Stat(filepath.Join(rootPath, peerDir)); os.IsNotExist(err) {
56+
err := os.Mkdir(filepath.Join(rootPath, peerDir), 0755)
57+
Expect(err).NotTo(HaveOccurred())
58+
}
59+
copyFile(filepath.Join("testdata", fmt.Sprintf("%s-core.yaml", peerDir)),
60+
filepath.Join(rootPath, peerDir, "core.yaml"))
61+
}
62+
}
63+
}

integration/e2e/testdata/org2.example.com_0-core.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ logging:
1818
peer:
1919
id: peer0.org2.example.com
2020
networkId: mytestnet
21-
listenAddress: 0.0.0.0:14051
22-
chaincodeListenAddress: 0.0.0.0:14052
21+
listenAddress: 0.0.0.0:8051
22+
chaincodeListenAddress: 0.0.0.0:8052
2323
# chaincodeAddress: 0.0.0.0:7052
24-
address: 0.0.0.0:14051
24+
address: 0.0.0.0:8051
2525
addressAutoDetect: false
2626
gomaxprocs: -1
2727
keepalive:
@@ -33,7 +33,7 @@ peer:
3333
interval: 60s
3434
timeout: 20s
3535
gossip:
36-
bootstrap: 127.0.0.1:14051
36+
bootstrap: 127.0.0.1:8051
3737
useLeaderElection: true
3838
orgLeader: false
3939
endpoint:
@@ -59,7 +59,7 @@ peer:
5959
aliveTimeInterval: 5s
6060
aliveExpirationTimeout: 25s
6161
reconnectInterval: 25s
62-
externalEndpoint: 0.0.0.0:14051
62+
externalEndpoint: 0.0.0.0:8051
6363
election:
6464
startupGracePeriod: 15s
6565
membershipSampleInterval: 1s
@@ -70,7 +70,7 @@ peer:
7070
transientstoreMaxBlockRetention: 1000
7171
pushAckTimeout: 3s
7272
events:
73-
address: 0.0.0.0:14053
73+
address: 0.0.0.0:8053
7474
buffersize: 100
7575
timeout: 10ms
7676
timewindow: 15m

0 commit comments

Comments
 (0)