From 32c05bd1881ffb0e04f95c6c6840b3f73eb3b779 Mon Sep 17 00:00:00 2001 From: nirro <nirro@il.ibm.com> Date: Mon, 18 Jun 2018 14:46:16 +0300 Subject: [PATCH] [FAB-10689] add collection config to peer runner this change set adds the collection config path to peer structs, and adds the collection config in instantiate and upgrade functions. Change-Id: I5338485c7e0e7a9cf27b221428f5e2623b950175 Signed-off-by: nirro <nirro@il.ibm.com> --- integration/runner/discovery_service_test.go | 2 +- integration/runner/peer.go | 21 ++++++++++++++--- integration/runner/peer_test.go | 2 +- integration/world/config.go | 24 +++++++------------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/integration/runner/discovery_service_test.go b/integration/runner/discovery_service_test.go index 4cfbecfd0..dd750ece3 100644 --- a/integration/runner/discovery_service_test.go +++ b/integration/runner/discovery_service_test.go @@ -225,7 +225,7 @@ var _ bool = Describe("DiscoveryService", func() { instantiateCC := components.Peer() instantiateCC.ConfigDir = tempDir instantiateCC.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp") - instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "") + instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "", "") By("list instantiated chaincode") listInstan := components.Peer() diff --git a/integration/runner/peer.go b/integration/runner/peer.go index 83c31d0da..60a0fecb9 100644 --- a/integration/runner/peer.go +++ b/integration/runner/peer.go @@ -189,14 +189,29 @@ func (p *Peer) InstallChaincode(name, version, path string) { Expect(sess).To(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version))) } -func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, policy string) { - cmd := exec.Command(p.Path, "chaincode", "instantiate", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy) +func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, policy string, collectionsConfigPath string) { + cmd := exec.Command(p.Path, "chaincode", "instantiate", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy, "--collections-config", collectionsConfigPath) p.setupEnvironment(cmd) sess, err := helpers.StartSession(cmd, "instantiate", "4;35m") ExpectWithOffset(1, err).NotTo(HaveOccurred()) EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0)) + p.VerifyChaincodeIsInstantiated(name, version, channel, time.Minute) +} + +func (p *Peer) UpgradeChaincode(name string, version string, orderer string, channel string, args string, policy string, collectionsConfigPath string) { + cmd := exec.Command(p.Path, "chaincode", "upgrade", "-n", name, "-v", version, "-o", orderer, "-C", channel, "-c", args, "-P", policy, "--collections-config", collectionsConfigPath) + p.setupEnvironment(cmd) + + sess, err := helpers.StartSession(cmd, "upgrade", "4;35m") + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0)) + + p.VerifyChaincodeIsInstantiated(name, version, channel, time.Minute) +} + +func (p *Peer) VerifyChaincodeIsInstantiated(chaincodeName string, version string, channel string, timeout time.Duration) { listInstantiated := func() *gbytes.Buffer { cmd := exec.Command(p.Path, "chaincode", "list", "--instantiated", "-C", channel) p.setupEnvironment(cmd) @@ -206,7 +221,7 @@ func (p *Peer) InstantiateChaincode(name, version, orderer, channel, args, polic EventuallyWithOffset(1, sess, 10*time.Second).Should(gexec.Exit(0)) return sess.Buffer() } - EventuallyWithOffset(1, listInstantiated, time.Minute).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version))) + EventuallyWithOffset(1, listInstantiated, timeout).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", chaincodeName, version))) } func (p *Peer) QueryChaincode(name string, channel string, args string) *ginkgomon.Runner { diff --git a/integration/runner/peer_test.go b/integration/runner/peer_test.go index 5a8514309..a887d5183 100644 --- a/integration/runner/peer_test.go +++ b/integration/runner/peer_test.go @@ -199,7 +199,7 @@ var _ = Describe("Peer", func() { instantiateCC := components.Peer() instantiateCC.ConfigDir = tempDir instantiateCC.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp") - instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "") + instantiateCC.InstantiateChaincode("mytest", "1.0", "127.0.0.1:8050", "mychan", `{"Args":["init","a","100","b","200"]}`, "", "") By("list instantiated chaincode") listInstan := components.Peer() diff --git a/integration/world/config.go b/integration/world/config.go index b01398c2f..b5079d6f8 100644 --- a/integration/world/config.go +++ b/integration/world/config.go @@ -25,7 +25,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" - "github.com/onsi/gomega/gexec" "github.com/tedsuo/ifrit" yaml "gopkg.in/yaml.v2" ) @@ -75,11 +74,12 @@ type World struct { } type Chaincode struct { - Name string - Path string - Version string - GoPath string - ExecPath string + Name string + Path string + Version string + GoPath string + ExecPath string + CollectionsConfigPath string } type Deployment struct { @@ -428,19 +428,11 @@ func (w *World) SetupChannel(d Deployment, peers []string) { } p = setupPeerRunner(peers[0]) - p.InstantiateChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Orderer, d.Channel, d.InitArgs, d.Policy) + p.InstantiateChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Orderer, d.Channel, d.InitArgs, d.Policy, d.Chaincode.CollectionsConfigPath) for _, peer := range peers[1:] { p = setupPeerRunner(peer) - listInstantiated := func() *gbytes.Buffer { - adminRunner = p.ChaincodeListInstantiated(d.Channel) - - sess, err := helpers.StartSession(adminRunner.Command, "list instantiated", "4;34m") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - EventuallyWithOffset(1, sess, 10*time.Second).Should(gexec.Exit(0)) - return sess.Buffer() - } - EventuallyWithOffset(1, listInstantiated, time.Minute).Should(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", d.Chaincode.Name, d.Chaincode.Version))) + p.VerifyChaincodeIsInstantiated(d.Chaincode.Name, d.Chaincode.Version, d.Channel, time.Minute) } } -- GitLab