Skip to content

Commit acc027a

Browse files
lhaskinssykesm
authored andcommitted
[FAB-10365] Separate the Deployment from World
This separates Deployment from the World config setup and allows a dev to call multiple deployments on a channel with a designated list of peers. If one chooses to deploy to a subset of peers, this is allowed by being explicit in the call to SetupChannel. Change-Id: I074192ca607ec6f0b7362eeff35e98026c135b42 Signed-off-by: Latitia M. Haskins <latitia.haskins@gmail.com>
1 parent ff950e2 commit acc027a

File tree

6 files changed

+192
-287
lines changed

6 files changed

+192
-287
lines changed

integration/e2e/e2e_test.go

+71-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package e2e
88

99
import (
1010
"fmt"
11+
"io/ioutil"
12+
"os"
1113
"path/filepath"
1214
"syscall"
1315
"time"
@@ -23,8 +25,9 @@ import (
2325

2426
var _ = Describe("EndToEnd", func() {
2527
var (
26-
client *docker.Client
27-
w world.World
28+
client *docker.Client
29+
w world.World
30+
deployment world.Deployment
2831
)
2932

3033
BeforeEach(func() {
@@ -42,7 +45,7 @@ var _ = Describe("EndToEnd", func() {
4245

4346
// Stop the running chaincode containers
4447
filters := map[string][]string{}
45-
filters["name"] = []string{fmt.Sprintf("%s-%s", w.Deployment.Chaincode.Name, w.Deployment.Chaincode.Version)}
48+
filters["name"] = []string{fmt.Sprintf("%s-%s", deployment.Chaincode.Name, deployment.Chaincode.Version)}
4649
allContainers, _ := client.ListContainers(docker.ListContainersOptions{
4750
Filters: filters,
4851
})
@@ -57,7 +60,7 @@ var _ = Describe("EndToEnd", func() {
5760

5861
// Remove chaincode image
5962
filters = map[string][]string{}
60-
filters["label"] = []string{fmt.Sprintf("org.hyperledger.fabric.chaincode.id.name=%s", w.Deployment.Chaincode.Name)}
63+
filters["label"] = []string{fmt.Sprintf("org.hyperledger.fabric.chaincode.id.name=%s", deployment.Chaincode.Name)}
6164
images, _ := client.ListImages(docker.ListImagesOptions{
6265
Filters: filters,
6366
})
@@ -84,8 +87,21 @@ var _ = Describe("EndToEnd", func() {
8487
It("executes a basic solo network with 2 orgs", func() {
8588
w = world.GenerateBasicConfig("solo", 1, 2, testDir, components)
8689

90+
deployment = world.Deployment{
91+
Channel: "testchannel",
92+
Chaincode: world.Chaincode{
93+
Name: "mycc",
94+
Version: "0.0",
95+
Path: filepath.Join("github.com", "hyperledger", "fabric", "integration", "chaincode", "simple", "cmd"),
96+
ExecPath: os.Getenv("PATH"),
97+
},
98+
InitArgs: `{"Args":["init","a","100","b","200"]}`,
99+
Policy: `OR ('Org1MSP.member','Org2MSP.member')`,
100+
Orderer: "127.0.0.1:7050",
101+
}
102+
87103
By("generating files to bootstrap the network")
88-
w.BootstrapNetwork()
104+
w.BootstrapNetwork(deployment.Channel)
89105
Expect(filepath.Join(testDir, "configtx.yaml")).To(BeARegularFile())
90106
Expect(filepath.Join(testDir, "crypto.yaml")).To(BeARegularFile())
91107
Expect(filepath.Join(testDir, "crypto", "peerOrganizations")).To(BeADirectory())
@@ -103,48 +119,65 @@ var _ = Describe("EndToEnd", func() {
103119
w.BuildNetwork()
104120

105121
By("setting up the channel")
106-
err := w.SetupChannel()
122+
peers := []string{
123+
"peer0.org1.example.com",
124+
"peer0.org2.example.com",
125+
}
126+
err := w.SetupChannel(deployment, peers)
107127
Expect(err).NotTo(HaveOccurred())
108128

109129
By("querying the chaincode")
110130
adminPeer := components.Peer()
111131
adminPeer.LogLevel = "debug"
112-
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
132+
adminPeer.ConfigDir = filepath.Join(testDir, "peer0.org1.example.com")
113133
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
114-
adminRunner := adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
134+
adminRunner := adminPeer.QueryChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["query","a"]}`)
115135
execute(adminRunner)
116136
Eventually(adminRunner.Buffer()).Should(gbytes.Say("100"))
117137

118138
By("invoking the chaincode")
119-
adminRunner = adminPeer.InvokeChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["invoke","a","b","10"]}`, w.Deployment.Orderer)
139+
adminRunner = adminPeer.InvokeChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["invoke","a","b","10"]}`, deployment.Orderer)
120140
execute(adminRunner)
121141
Eventually(adminRunner.Err()).Should(gbytes.Say("Chaincode invoke successful. result: status:200"))
122142

123143
By("querying the chaincode again")
124-
adminRunner = adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
144+
adminRunner = adminPeer.QueryChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["query","a"]}`)
125145
execute(adminRunner)
126146
Eventually(adminRunner.Buffer()).Should(gbytes.Say("90"))
127147

128148
By("updating the channel")
129149
adminPeer = components.Peer()
130-
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
150+
adminPeer.ConfigDir = filepath.Join(testDir, "peer0.org1.example.com")
131151
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
132-
adminRunner = adminPeer.UpdateChannel(filepath.Join(testDir, "Org1_anchors_update_tx.pb"), w.Deployment.Channel, w.Deployment.Orderer)
152+
adminRunner = adminPeer.UpdateChannel(filepath.Join(testDir, "Org1_anchors_update_tx.pb"), deployment.Channel, deployment.Orderer)
133153
execute(adminRunner)
134154
Eventually(adminRunner.Err()).Should(gbytes.Say("Successfully submitted channel update"))
135155
})
136156

137157
It("executes a basic kafka network with 2 orgs", func() {
138158
By("generating files to bootstrap the network")
139159
w = world.GenerateBasicConfig("kafka", 2, 2, testDir, components)
140-
setupWorld(&w)
160+
deployment = world.Deployment{
161+
Channel: "testchannel",
162+
Chaincode: world.Chaincode{
163+
Name: "mycc",
164+
Version: "0.0",
165+
Path: filepath.Join("github.com", "hyperledger", "fabric", "integration", "chaincode", "simple", "cmd"),
166+
ExecPath: os.Getenv("PATH"),
167+
},
168+
InitArgs: `{"Args":["init","a","100","b","200"]}`,
169+
Policy: `AND ('Org1MSP.member','Org2MSP.member')`,
170+
Orderer: "127.0.0.1:7050",
171+
}
172+
173+
w.SetupWorld(deployment)
141174

142175
By("querying the chaincode")
143176
adminPeer := components.Peer()
144177
adminPeer.LogLevel = "debug"
145-
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
178+
adminPeer.ConfigDir = filepath.Join(testDir, "peer0.org1.example.com")
146179
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"]}`)
180+
adminRunner := adminPeer.QueryChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["query","a"]}`)
148181
execute(adminRunner)
149182
Eventually(adminRunner.Buffer()).Should(gbytes.Say("100"))
150183

@@ -157,3 +190,26 @@ func execute(r ifrit.Runner) (err error) {
157190
Eventually(p.Wait(), 30*time.Second).Should(Receive(&err))
158191
return err
159192
}
193+
194+
func copyFile(src, dest string) {
195+
data, err := ioutil.ReadFile(src)
196+
Expect(err).NotTo(HaveOccurred())
197+
err = ioutil.WriteFile(dest, data, 0775)
198+
Expect(err).NotTo(HaveOccurred())
199+
}
200+
201+
func copyPeerConfigs(peerOrgs []world.PeerOrgConfig, rootPath string) {
202+
for _, peerOrg := range peerOrgs {
203+
for peer := 0; peer < peerOrg.PeerCount; peer++ {
204+
peerDir := fmt.Sprintf("peer%d.%s", peer, peerOrg.Domain)
205+
if _, err := os.Stat(filepath.Join(rootPath, peerDir)); os.IsNotExist(err) {
206+
err := os.Mkdir(filepath.Join(rootPath, peerDir), 0755)
207+
Expect(err).NotTo(HaveOccurred())
208+
}
209+
copyFile(
210+
filepath.Join("testdata", fmt.Sprintf("%s_%d-core.yaml", peerOrg.Domain, peer)),
211+
filepath.Join(rootPath, peerDir, "core.yaml"),
212+
)
213+
}
214+
}
215+
}

0 commit comments

Comments
 (0)