Commit 505fb6a0 authored by Matthew Sykes's avatar Matthew Sykes
Browse files

[FAB-11049] add {Read,Write}{Orderer,Peer}Config



Network helpers to enable config file modifications.

Change-Id: I23122619c4619a1aed23aacbd95c9d1ceef46b29
Signed-off-by: default avatarMatthew Sykes <sykesmat@us.ibm.com>
parent 95483dd8
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
docker "github.com/fsouza/go-dockerclient" docker "github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/integration/helpers" "github.com/hyperledger/fabric/integration/helpers"
"github.com/hyperledger/fabric/integration/nwo/commands" "github.com/hyperledger/fabric/integration/nwo/commands"
"github.com/hyperledger/fabric/integration/nwo/fabricconfig"
"github.com/hyperledger/fabric/integration/runner" "github.com/hyperledger/fabric/integration/runner"
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
...@@ -30,6 +31,7 @@ import ( ...@@ -30,6 +31,7 @@ import (
"github.com/tedsuo/ifrit" "github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/ginkgomon" "github.com/tedsuo/ifrit/ginkgomon"
"github.com/tedsuo/ifrit/grouper" "github.com/tedsuo/ifrit/grouper"
yaml "gopkg.in/yaml.v2"
) )
// Organization models information about an Organization. It includes // Organization models information about an Organization. It includes
...@@ -246,6 +248,29 @@ func (n *Network) OrdererConfigPath(o *Orderer) string { ...@@ -246,6 +248,29 @@ func (n *Network) OrdererConfigPath(o *Orderer) string {
return filepath.Join(n.OrdererDir(o), "orderer.yaml") return filepath.Join(n.OrdererDir(o), "orderer.yaml")
} }
// ReadOrdererConfig unmarshals an orderer's orderer.yaml and returns an
// object approximating its contents.
func (n *Network) ReadOrdererConfig(o *Orderer) *fabricconfig.Orderer {
var orderer fabricconfig.Orderer
ordererBytes, err := ioutil.ReadFile(n.OrdererConfigPath(o))
Expect(err).NotTo(HaveOccurred())
err = yaml.Unmarshal(ordererBytes, &orderer)
Expect(err).NotTo(HaveOccurred())
return &orderer
}
// WriteOrdererConfig serializes the provided configuration as the specified
// orderer's orderer.yaml document.
func (n *Network) WriteOrdererConfig(o *Orderer, config *fabricconfig.Orderer) {
ordererBytes, err := yaml.Marshal(config)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile(n.OrdererConfigPath(o), ordererBytes, 0644)
Expect(err).NotTo(HaveOccurred())
}
// PeerDir returns the path to the configuration directory for the specified // PeerDir returns the path to the configuration directory for the specified
// Peer. // Peer.
func (n *Network) PeerDir(p *Peer) string { func (n *Network) PeerDir(p *Peer) string {
...@@ -258,6 +283,29 @@ func (n *Network) PeerConfigPath(p *Peer) string { ...@@ -258,6 +283,29 @@ func (n *Network) PeerConfigPath(p *Peer) string {
return filepath.Join(n.PeerDir(p), "core.yaml") return filepath.Join(n.PeerDir(p), "core.yaml")
} }
// ReadPeerConfig unmarshals a peer's core.yaml and returns an object
// approximating its contents.
func (n *Network) ReadPeerConfig(p *Peer) *fabricconfig.Core {
var core fabricconfig.Core
coreBytes, err := ioutil.ReadFile(n.PeerConfigPath(p))
Expect(err).NotTo(HaveOccurred())
err = yaml.Unmarshal(coreBytes, &core)
Expect(err).NotTo(HaveOccurred())
return &core
}
// WritePeerConfig serializes the provided configuration as the specified
// peer's core.yaml document.
func (n *Network) WritePeerConfig(p *Peer, config *fabricconfig.Core) {
coreBytes, err := yaml.Marshal(config)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile(n.PeerConfigPath(p), coreBytes, 0644)
Expect(err).NotTo(HaveOccurred())
}
// PeerUserMSPDir returns the path to the MSP directory containing the // PeerUserMSPDir returns the path to the MSP directory containing the
// certificates and keys for the specified user of the peer. // certificates and keys for the specified user of the peer.
func (n *Network) PeerUserMSPDir(p *Peer, user string) string { func (n *Network) PeerUserMSPDir(p *Peer, user string) string {
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec" "github.com/onsi/gomega/gexec"
"github.com/tedsuo/ifrit" "github.com/tedsuo/ifrit"
yaml "gopkg.in/yaml.v2"
"github.com/hyperledger/fabric/integration/nwo" "github.com/hyperledger/fabric/integration/nwo"
"github.com/hyperledger/fabric/integration/nwo/commands" "github.com/hyperledger/fabric/integration/nwo/commands"
...@@ -139,24 +138,14 @@ func compilePlugin(pluginType string) string { ...@@ -139,24 +138,14 @@ func compilePlugin(pluginType string) string {
func configurePlugins(network *nwo.Network, endorsement, validation string) { func configurePlugins(network *nwo.Network, endorsement, validation string) {
for _, p := range network.Peers { for _, p := range network.Peers {
var core fabricconfig.Core core := network.ReadPeerConfig(p)
coreBytes, err := ioutil.ReadFile(network.PeerConfigPath(p))
Expect(err).NotTo(HaveOccurred())
err = yaml.Unmarshal(coreBytes, &core)
Expect(err).NotTo(HaveOccurred())
core.Peer.Handlers.Endorsers = fabricconfig.HandlerMap{ core.Peer.Handlers.Endorsers = fabricconfig.HandlerMap{
"escc": fabricconfig.Handler{Name: "plugin-escc", Library: endorsement}, "escc": fabricconfig.Handler{Name: "plugin-escc", Library: endorsement},
} }
core.Peer.Handlers.Validators = fabricconfig.HandlerMap{ core.Peer.Handlers.Validators = fabricconfig.HandlerMap{
"vscc": fabricconfig.Handler{Name: "plugin-vscc", Library: validation}, "vscc": fabricconfig.Handler{Name: "plugin-vscc", Library: validation},
} }
network.WritePeerConfig(p, core)
coreBytes, err = yaml.Marshal(core)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile(network.PeerConfigPath(p), coreBytes, 0644)
Expect(err).NotTo(HaveOccurred())
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment