Skip to content

Commit 05485b9

Browse files
committed
FAB-12991 kafka2raft e2e tests green path
This task focuses on testing the consensus-type migration "green" path, that was introduced in FAB-13264. The main contribution is in migration_test.go, which defines 3 test-cases that test the green path. This is not the complete test suite for migration. It is introduced in this stage to allow reviewers to get the full picture of the feature defined in FAB-13264. The tests for the abort path and failure scenarios will be added in later tasks. The three test-cases are: 1. A test that executes the migration flow on the Kafka side (from START-TX until COMMIT-TX), on the system channel only. 2. A test that executes the migration flow on the Kafka side (from START-TX, CONTEXT-TX until COMMIT-TX), on the system channel and a single application channel.  3. A test that executes the migration flow on the Raft side (from START-TX, CONTEXT-TX until COMMIT-TX, followed by restart of the orderer), on the system channel and a two application channel. The tests are somewhat overlapping but are verifying different aspects of the expected behavior. Overall, the tests verify that the flow of: - START-TX => CONTEXT-TX (x #std-channels) =>COMMIT-TX => Restart => (optional NONE-TX) results in a functional etcdraft-based ordering service. That is, normal transactions can be executed, and new channels can be created.   The task introduces some minor changes to the nwo test framework in order to support the testing of the new feature: - Add OrdererCapabilites to Config, since kafka-to-raft migration is gates by a new V2_0 capability - add the following to tests that read the network config from file orderercapabilities: v20: false - Adds method to verify failure to update the OrdererConfig - Extends the configtx template to include support for the V2_0 orderer capability - Extend the network.go to - support V2_0 orderer capability - verify channel creation is blocked - support ConsensusType.Type changes - Extend standard_networks.go to - Support V2_0 orderer capability - define a Kafka2Raft and Kafka2RaftMultiChannel configurations for migration tests Change-Id: I043b133b4c716f3bf53512f1999c7dfbc8aa67bb Signed-off-by: Yoav Tock <[email protected]>
1 parent 0504983 commit 05485b9

File tree

9 files changed

+633
-36
lines changed

9 files changed

+633
-36
lines changed

integration/discovery/testdata/network.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ orderers:
5050
- name: orderer
5151
organization: orderer-org
5252

53+
orderercapabilities:
54+
v20: false
55+
5356
channels:
5457
- name: testchannel
5558
profile: ThreeOrgsChannel

integration/e2e/migration_test.go

Lines changed: 524 additions & 0 deletions
Large diffs are not rendered by default.

integration/nwo/config.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ package nwo
99
// Config holds the basic information needed to generate
1010
// fabric configuration files.
1111
type Config struct {
12-
Organizations []*Organization `yaml:"organizations,omitempty"`
13-
Consortiums []*Consortium `yaml:"consortiums,omitempty"`
14-
SystemChannel *SystemChannel `yaml:"system_channel,omitempty"`
15-
Channels []*Channel `yaml:"channels,omitempty"`
16-
Consensus *Consensus `yaml:"consensus,omitempty"`
17-
Orderers []*Orderer `yaml:"orderers,omitempty"`
18-
Peers []*Peer `yaml:"peers,omitempty"`
19-
Profiles []*Profile `yaml:"profiles,omitempty"`
20-
Templates *Templates `yaml:"templates,omitempty"`
12+
Organizations []*Organization `yaml:"organizations,omitempty"`
13+
Consortiums []*Consortium `yaml:"consortiums,omitempty"`
14+
SystemChannel *SystemChannel `yaml:"system_channel,omitempty"`
15+
Channels []*Channel `yaml:"channels,omitempty"`
16+
Consensus *Consensus `yaml:"consensus,omitempty"`
17+
OrdererCap *OrdererCapabilities `yaml:"orderercapabilities,omitempty"`
18+
Orderers []*Orderer `yaml:"orderers,omitempty"`
19+
Peers []*Peer `yaml:"peers,omitempty"`
20+
Profiles []*Profile `yaml:"profiles,omitempty"`
21+
Templates *Templates `yaml:"templates,omitempty"`
2122
}
2223

2324
func (c *Config) RemovePeer(orgName, peerName string) {

integration/nwo/configblock.go

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,11 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated
127127
func UpdateOrdererConfig(n *Network, orderer *Orderer, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) {
128128
tempDir, err := ioutil.TempDir("", "updateConfig")
129129
Expect(err).NotTo(HaveOccurred())
130-
defer os.RemoveAll(tempDir)
131-
132-
// compute update
133-
configUpdate, err := update.Compute(current, updated)
134-
Expect(err).NotTo(HaveOccurred())
135-
configUpdate.ChannelId = channel
136-
137-
signedEnvelope, err := utils.CreateSignedEnvelope(
138-
common.HeaderType_CONFIG_UPDATE,
139-
channel,
140-
nil, // local signer
141-
&common.ConfigUpdateEnvelope{ConfigUpdate: utils.MarshalOrPanic(configUpdate)},
142-
0, // message version
143-
0, // epoch
144-
)
145-
Expect(err).NotTo(HaveOccurred())
146-
Expect(signedEnvelope).NotTo(BeNil())
147-
148130
updateFile := filepath.Join(tempDir, "update.pb")
149-
err = ioutil.WriteFile(updateFile, utils.MarshalOrPanic(signedEnvelope), 0600)
150-
Expect(err).NotTo(HaveOccurred())
131+
defer os.RemoveAll(tempDir)
151132

152-
for _, signer := range additionalSigners {
153-
sess, err := n.OrdererAdminSession(signer, submitter, commands.SignConfigTx{File: updateFile})
154-
Expect(err).NotTo(HaveOccurred())
155-
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
156-
}
133+
computeUpdateOrdererConfig(updateFile, n, channel, current, updated, submitter, additionalSigners...)
157134

158-
// get current configuration block number
159135
currentBlockNumber := CurrentConfigBlockNumber(n, submitter, orderer, channel)
160136

161137
Eventually(func() string {
@@ -207,6 +183,54 @@ func CurrentConfigBlockNumber(n *Network, peer *Peer, orderer *Orderer, channel
207183
return configBlock.Header.Number
208184
}
209185

186+
// UpdateOrdererConfigFail computes, signs, and submits a configuration update which requires orderers signature
187+
// and waits for the update to FAIL.
188+
func UpdateOrdererConfigFail(n *Network, orderer *Orderer, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) {
189+
tempDir, err := ioutil.TempDir("", "updateConfig")
190+
Expect(err).NotTo(HaveOccurred())
191+
updateFile := filepath.Join(tempDir, "update.pb")
192+
defer os.RemoveAll(tempDir)
193+
194+
computeUpdateOrdererConfig(updateFile, n, channel, current, updated, submitter, additionalSigners...)
195+
196+
//session should not return with a zero exit code nor with a success response
197+
sess, err := n.OrdererAdminSession(orderer, submitter, commands.ChannelUpdate{
198+
ChannelID: channel,
199+
Orderer: n.OrdererAddress(orderer, ListenPort),
200+
File: updateFile,
201+
})
202+
Expect(err).NotTo(HaveOccurred())
203+
Eventually(sess, n.EventuallyTimeout).ShouldNot(gexec.Exit(0))
204+
Expect(sess.Err).NotTo(gbytes.Say("Successfully submitted channel update"))
205+
}
206+
207+
func computeUpdateOrdererConfig(updateFile string, n *Network, channel string, current, updated *common.Config, submitter *Peer, additionalSigners ...*Orderer) {
208+
// compute update
209+
configUpdate, err := update.Compute(current, updated)
210+
Expect(err).NotTo(HaveOccurred())
211+
configUpdate.ChannelId = channel
212+
213+
signedEnvelope, err := utils.CreateSignedEnvelope(
214+
common.HeaderType_CONFIG_UPDATE,
215+
channel,
216+
nil, // local signer
217+
&common.ConfigUpdateEnvelope{ConfigUpdate: utils.MarshalOrPanic(configUpdate)},
218+
0, // message version
219+
0, // epoch
220+
)
221+
Expect(err).NotTo(HaveOccurred())
222+
Expect(signedEnvelope).NotTo(BeNil())
223+
224+
err = ioutil.WriteFile(updateFile, utils.MarshalOrPanic(signedEnvelope), 0600)
225+
Expect(err).NotTo(HaveOccurred())
226+
227+
for _, signer := range additionalSigners {
228+
sess, err := n.OrdererAdminSession(signer, submitter, commands.SignConfigTx{File: updateFile})
229+
Expect(err).NotTo(HaveOccurred())
230+
Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
231+
}
232+
}
233+
210234
// UnmarshalBlockFromFile unmarshals a proto encoded block from a file.
211235
func UnmarshalBlockFromFile(blockFile string) *common.Block {
212236
blockBytes, err := ioutil.ReadFile(blockFile)

integration/nwo/configtx_template.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ Profiles:{{ range .Profiles }}
8484
PreferredMaxBytes: 512 KB
8585
Capabilities:
8686
V1_1: true
87+
{{- if $w.OrdererCap.V2_0 }}
88+
V2_0: true
89+
{{- end }}
90+
8791
{{- if eq $w.Consensus.Type "kafka" }}
8892
Kafka:
8993
Brokers:{{ range $w.BrokerAddresses "HostPort" }}

integration/nwo/network.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func (o Orderer) ID() string {
8888
return fmt.Sprintf("%s.%s", o.Organization, o.Name)
8989
}
9090

91+
type OrdererCapabilities struct {
92+
V2_0 bool `yaml:"v20,omitempty"`
93+
}
94+
9195
// Peer defines a peer instance, it's owning organization, and the list of
9296
// channels that the peer shoudl be joined to.
9397
type Peer struct {
@@ -144,6 +148,7 @@ type Network struct {
144148
SystemChannel *SystemChannel
145149
Channels []*Channel
146150
Consensus *Consensus
151+
OrdererCap *OrdererCapabilities
147152
Orderers []*Orderer
148153
Peers []*Peer
149154
Profiles []*Profile
@@ -172,6 +177,7 @@ func New(c *Config, rootDir string, client *docker.Client, startPort int, compon
172177

173178
Organizations: c.Organizations,
174179
Consensus: c.Consensus,
180+
OrdererCap: c.OrdererCap,
175181
Orderers: c.Orderers,
176182
Peers: c.Peers,
177183
SystemChannel: c.SystemChannel,
@@ -732,6 +738,31 @@ func (n *Network) CreateChannel(channelName string, o *Orderer, p *Peer) {
732738
Eventually(createChannel, n.EventuallyTimeout).Should(Equal(0))
733739
}
734740

741+
// CreateChannelFail will submit an existing create channel transaction to the
742+
// specified orderer, but expect to FAIL. The channel transaction must exist
743+
// at the location returned by CreateChannelTxPath.
744+
//
745+
// The orderer must be running when this is called.
746+
func (n *Network) CreateChannelFail(o *Orderer, channelName string) {
747+
peers := n.PeersWithChannel(channelName)
748+
if len(peers) == 0 {
749+
return
750+
}
751+
752+
createChannelFail := func() int {
753+
sess, err := n.PeerAdminSession(peers[0], commands.ChannelCreate{
754+
ChannelID: channelName,
755+
Orderer: n.OrdererAddress(o, ListenPort),
756+
File: n.CreateChannelTxPath(channelName),
757+
OutputBlock: "/dev/null",
758+
})
759+
Expect(err).NotTo(HaveOccurred())
760+
return sess.Wait(n.EventuallyTimeout).ExitCode()
761+
}
762+
763+
Eventually(createChannelFail, n.EventuallyTimeout).ShouldNot(Equal(0))
764+
}
765+
735766
// JoinChannel will join peers to the specified channel. The orderer is used to
736767
// obtain the current configuration block for the channel.
737768
//
@@ -879,7 +910,8 @@ func (n *Network) OrdererRunner(o *Orderer) *ginkgomon.Runner {
879910
StartCheckTimeout: 15 * time.Second,
880911
}
881912

882-
if n.Consensus.Brokers != 0 {
913+
//After consensus-type migration, the #brokers is >0, but the type is etcdraft
914+
if n.Consensus.Type == "kafka" && n.Consensus.Brokers != 0 {
883915
config.StartCheck = "Start phase completed successfully"
884916
config.StartCheckTimeout = 30 * time.Second
885917
}

integration/nwo/solo.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ orderers:
4242
- name: orderer0
4343
organization: orderer-org
4444

45+
orderercapabilities:
46+
v20: false
47+
4548
channels:
4649
- name: testchannel
4750
profile: TwoOrgsChannel

integration/nwo/standard_networks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func BasicSolo() *Config {
4040
Consensus: &Consensus{
4141
Type: "solo",
4242
},
43+
OrdererCap: &OrdererCapabilities{
44+
V2_0: false,
45+
},
4346
SystemChannel: &SystemChannel{
4447
Name: "systemchannel",
4548
Profile: "TwoOrgsOrdererGenesis",

integration/pvtdata/testdata/network.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ orderers:
5050
- name: orderer
5151
organization: orderer-org
5252

53+
orderercapabilities:
54+
v20: false
55+
5356
channels:
5457
- name: testchannel
5558
profile: ThreeOrgsChannel

0 commit comments

Comments
 (0)