Skip to content

Commit 505fb6a

Browse files
committed
[FAB-11049] add {Read,Write}{Orderer,Peer}Config
Network helpers to enable config file modifications. Change-Id: I23122619c4619a1aed23aacbd95c9d1ceef46b29 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 95483dd commit 505fb6a

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

integration/nwo/network.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
docker "github.com/fsouza/go-dockerclient"
2323
"github.com/hyperledger/fabric/integration/helpers"
2424
"github.com/hyperledger/fabric/integration/nwo/commands"
25+
"github.com/hyperledger/fabric/integration/nwo/fabricconfig"
2526
"github.com/hyperledger/fabric/integration/runner"
2627
"github.com/onsi/ginkgo"
2728
. "github.com/onsi/gomega"
@@ -30,6 +31,7 @@ import (
3031
"github.com/tedsuo/ifrit"
3132
"github.com/tedsuo/ifrit/ginkgomon"
3233
"github.com/tedsuo/ifrit/grouper"
34+
yaml "gopkg.in/yaml.v2"
3335
)
3436

3537
// Organization models information about an Organization. It includes
@@ -246,6 +248,29 @@ func (n *Network) OrdererConfigPath(o *Orderer) string {
246248
return filepath.Join(n.OrdererDir(o), "orderer.yaml")
247249
}
248250

251+
// ReadOrdererConfig unmarshals an orderer's orderer.yaml and returns an
252+
// object approximating its contents.
253+
func (n *Network) ReadOrdererConfig(o *Orderer) *fabricconfig.Orderer {
254+
var orderer fabricconfig.Orderer
255+
ordererBytes, err := ioutil.ReadFile(n.OrdererConfigPath(o))
256+
Expect(err).NotTo(HaveOccurred())
257+
258+
err = yaml.Unmarshal(ordererBytes, &orderer)
259+
Expect(err).NotTo(HaveOccurred())
260+
261+
return &orderer
262+
}
263+
264+
// WriteOrdererConfig serializes the provided configuration as the specified
265+
// orderer's orderer.yaml document.
266+
func (n *Network) WriteOrdererConfig(o *Orderer, config *fabricconfig.Orderer) {
267+
ordererBytes, err := yaml.Marshal(config)
268+
Expect(err).NotTo(HaveOccurred())
269+
270+
err = ioutil.WriteFile(n.OrdererConfigPath(o), ordererBytes, 0644)
271+
Expect(err).NotTo(HaveOccurred())
272+
}
273+
249274
// PeerDir returns the path to the configuration directory for the specified
250275
// Peer.
251276
func (n *Network) PeerDir(p *Peer) string {
@@ -258,6 +283,29 @@ func (n *Network) PeerConfigPath(p *Peer) string {
258283
return filepath.Join(n.PeerDir(p), "core.yaml")
259284
}
260285

286+
// ReadPeerConfig unmarshals a peer's core.yaml and returns an object
287+
// approximating its contents.
288+
func (n *Network) ReadPeerConfig(p *Peer) *fabricconfig.Core {
289+
var core fabricconfig.Core
290+
coreBytes, err := ioutil.ReadFile(n.PeerConfigPath(p))
291+
Expect(err).NotTo(HaveOccurred())
292+
293+
err = yaml.Unmarshal(coreBytes, &core)
294+
Expect(err).NotTo(HaveOccurred())
295+
296+
return &core
297+
}
298+
299+
// WritePeerConfig serializes the provided configuration as the specified
300+
// peer's core.yaml document.
301+
func (n *Network) WritePeerConfig(p *Peer, config *fabricconfig.Core) {
302+
coreBytes, err := yaml.Marshal(config)
303+
Expect(err).NotTo(HaveOccurred())
304+
305+
err = ioutil.WriteFile(n.PeerConfigPath(p), coreBytes, 0644)
306+
Expect(err).NotTo(HaveOccurred())
307+
}
308+
261309
// PeerUserMSPDir returns the path to the MSP directory containing the
262310
// certificates and keys for the specified user of the peer.
263311
func (n *Network) PeerUserMSPDir(p *Peer, user string) string {

integration/pluggable/pluggable_test.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/onsi/gomega/gbytes"
2222
"github.com/onsi/gomega/gexec"
2323
"github.com/tedsuo/ifrit"
24-
yaml "gopkg.in/yaml.v2"
2524

2625
"github.com/hyperledger/fabric/integration/nwo"
2726
"github.com/hyperledger/fabric/integration/nwo/commands"
@@ -139,24 +138,14 @@ func compilePlugin(pluginType string) string {
139138

140139
func configurePlugins(network *nwo.Network, endorsement, validation string) {
141140
for _, p := range network.Peers {
142-
var core fabricconfig.Core
143-
coreBytes, err := ioutil.ReadFile(network.PeerConfigPath(p))
144-
Expect(err).NotTo(HaveOccurred())
145-
146-
err = yaml.Unmarshal(coreBytes, &core)
147-
Expect(err).NotTo(HaveOccurred())
141+
core := network.ReadPeerConfig(p)
148142
core.Peer.Handlers.Endorsers = fabricconfig.HandlerMap{
149143
"escc": fabricconfig.Handler{Name: "plugin-escc", Library: endorsement},
150144
}
151145
core.Peer.Handlers.Validators = fabricconfig.HandlerMap{
152146
"vscc": fabricconfig.Handler{Name: "plugin-vscc", Library: validation},
153147
}
154-
155-
coreBytes, err = yaml.Marshal(core)
156-
Expect(err).NotTo(HaveOccurred())
157-
158-
err = ioutil.WriteFile(network.PeerConfigPath(p), coreBytes, 0644)
159-
Expect(err).NotTo(HaveOccurred())
148+
network.WritePeerConfig(p, core)
160149
}
161150
}
162151

0 commit comments

Comments
 (0)