Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'osnadmin channel info' subcommand and update tests #4892

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cmd/osnadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func executeForArgs(args []string) (output string, exit int, err error) {
configBlockPath := join.Flag("config-block", "Path to the file containing an up-to-date config block for the channel").Short('b').Required().String()

list := channel.Command("list", "List channel information for an Ordering Service Node (OSN). If the channelID flag is set, more detailed information will be provided for that channel.")
listChannelID := list.Flag("channelID", "Channel ID").Short('c').String()
info := channel.Command("info", "Get detailed information about a specific channel.")
infoChannelID := info.Flag("channelID", "Channel ID").Short('c').Required().String()
Comment on lines +55 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we can do this in a backward compatible way.
Keep the support for passing channel id to list with this line:
listChannelID := list.Flag("channelID", "Channel ID").Short('c').String()

Then add an entirely new "info" command.

Change the function osnadmin.ListSingleChannel() to osnadmin.Info() and have both of them call it.

The help text doesn't need to mention that you can pass channel id to list command anymore, but keep the functionality there so that any existing users that depend on it don't break.


remove := channel.Command("remove", "Remove a channel from an Ordering Service Node (OSN).")
removeChannelID := remove.Flag("channelID", "Channel ID").Short('c').Required().String()
Expand Down Expand Up @@ -113,11 +114,13 @@ func executeForArgs(args []string) (output string, exit int, err error) {
case join.FullCommand():
resp, err = osnadmin.Join(osnURL, marshaledConfigBlock, caCertPool, tlsClientCert)
case list.FullCommand():
if *listChannelID != "" {
resp, err = osnadmin.ListSingleChannel(osnURL, *listChannelID, caCertPool, tlsClientCert)
break
}
// if *listChannelID != "" {
// resp, err = osnadmin.ListSingleChannel(osnURL, *listChannelID, caCertPool, tlsClientCert)
// break
// }
resp, err = osnadmin.ListAllChannels(osnURL, caCertPool, tlsClientCert)
case info.FullCommand():
resp, err = osnadmin.ListSingleChannel(osnURL, *infoChannelID, caCertPool, tlsClientCert)
case remove.FullCommand():
resp, err = osnadmin.Remove(osnURL, *removeChannelID, caCertPool, tlsClientCert)
}
Expand Down
172 changes: 133 additions & 39 deletions cmd/osnadmin/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ var _ = Describe("osnadmin", func() {
Name: "fight-the-system",
},
})

mockChannelManagement.ChannelInfoReturns(types.ChannelInfo{
Name: "asparagus",
ConsensusRelation: "broccoli",
Status: "carrot",
Height: 987,
}, nil)
})

It("uses the channel participation API to list all application channels and the system channel (when it exists)", func() {
Expand Down Expand Up @@ -156,10 +149,70 @@ var _ = Describe("osnadmin", func() {
checkStatusOutput(output, exit, err, 200, expectedOutput)
})

Context("when TLS is disabled", func() {
BeforeEach(func() {
tlsConfig = nil
})

It("uses the channel participation API to list all channels", func() {
args := []string{
"channel",
"list",
"--orderer-address", ordererURL,
}
output, exit, err := executeForArgs(args)
Expect(err).NotTo(HaveOccurred())
Expect(exit).To(Equal(0))

expectedOutput := types.ChannelList{
Channels: []types.ChannelInfoShort{
{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
},
{
Name: "another-participation-trophy",
URL: "/participation/v1/channels/another-participation-trophy",
},
},
SystemChannel: &types.ChannelInfoShort{
Name: "fight-the-system",
URL: "/participation/v1/channels/fight-the-system",
},
}
checkStatusOutput(output, exit, err, 200, expectedOutput)
})
})
})

Describe("Info", func() {
BeforeEach(func() {
mockChannelManagement.ChannelListReturns(types.ChannelList{
Channels: []types.ChannelInfoShort{
{
Name: "participation-trophy",
},
{
Name: "another-participation-trophy",
},
},
SystemChannel: &types.ChannelInfoShort{
Name: "fight-the-system",
},
})

mockChannelManagement.ChannelInfoReturns(types.ChannelInfo{
Name: "asparagus",
ConsensusRelation: "broccoli",
Status: "carrot",
Height: 987,
}, nil)
})

It("uses the channel participation API to list the details of a single channel", func() {
args := []string{
"channel",
"list",
"info",
"--orderer-address", ordererURL,
"--channelID", "tell-me-your-secrets",
"--ca-file", ordererCACert,
Expand All @@ -185,7 +238,7 @@ var _ = Describe("osnadmin", func() {
It("returns 404 not found", func() {
args := []string{
"channel",
"list",
"info",
"--orderer-address", ordererURL,
"--channelID", "tell-me-your-secrets",
"--ca-file", ordererCACert,
Expand All @@ -205,39 +258,10 @@ var _ = Describe("osnadmin", func() {
tlsConfig = nil
})

It("uses the channel participation API to list all channels", func() {
args := []string{
"channel",
"list",
"--orderer-address", ordererURL,
}
output, exit, err := executeForArgs(args)
Expect(err).NotTo(HaveOccurred())
Expect(exit).To(Equal(0))

expectedOutput := types.ChannelList{
Channels: []types.ChannelInfoShort{
{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
},
{
Name: "another-participation-trophy",
URL: "/participation/v1/channels/another-participation-trophy",
},
},
SystemChannel: &types.ChannelInfoShort{
Name: "fight-the-system",
URL: "/participation/v1/channels/fight-the-system",
},
}
checkStatusOutput(output, exit, err, 200, expectedOutput)
})

It("uses the channel participation API to list the details of a single channel", func() {
args := []string{
"channel",
"list",
"info",
"--orderer-address", ordererURL,
"--channelID", "tell-me-your-secrets",
}
Expand All @@ -254,6 +278,25 @@ var _ = Describe("osnadmin", func() {
}
checkStatusOutput(output, exit, err, 200, expectedOutput)
})
Context("when the channel does not exist", func() {
BeforeEach(func() {
mockChannelManagement.ChannelInfoReturns(types.ChannelInfo{}, errors.New("eat-your-peas"))
})

It("returns 404 not found with the info subcommand", func() {
args := []string{
"channel",
"info",
"--orderer-address", ordererURL,
"--channelID", "tell-me-your-secrets",
}
output, exit, err := executeForArgs(args)
expectedOutput := types.ErrorResponse{
Error: "eat-your-peas",
}
checkStatusOutput(output, exit, err, 404, expectedOutput)
})
})
})
})

Expand Down Expand Up @@ -581,6 +624,18 @@ var _ = Describe("osnadmin", func() {
})
})

Context("when an unknown flag is used with the info subcommand", func() {
It("returns an error for long flags", func() {
_, _, err := executeForArgs([]string{"channel", "info", "--bad-flag"})
Expect(err).To(MatchError("unknown long flag '--bad-flag'"))
})

It("returns an error for short flags", func() {
_, _, err := executeForArgs([]string{"channel", "info", "-z"})
Expect(err).To(MatchError("unknown short flag '-z'"))
})
})

Context("when the ca cert cannot be read", func() {
BeforeEach(func() {
ordererCACert = "not-the-ca-cert-youre-looking-for"
Expand All @@ -591,6 +646,25 @@ var _ = Describe("osnadmin", func() {
"channel",
"list",
"--orderer-address", ordererURL,
"--ca-file", ordererCACert,
"--client-cert", clientCert,
"--client-key", clientKey,
}
output, exit, err := executeForArgs(args)
checkFlagError(output, exit, err, "reading orderer CA certificate: open not-the-ca-cert-youre-looking-for: no such file or directory")
})
})

Context("when the ca cert cannot be read with the info subcommand", func() {
BeforeEach(func() {
ordererCACert = "not-the-ca-cert-youre-looking-for"
})

It("returns with exit code 1 and prints the error with the info subcommand", func() {
args := []string{
"channel",
"info",
"--orderer-address", ordererURL,
"--channelID", channelID,
"--ca-file", ordererCACert,
"--client-cert", clientCert,
Expand Down Expand Up @@ -640,6 +714,26 @@ var _ = Describe("osnadmin", func() {
})
})

Context("when the client cert/key pair fail to load with the info subcommand", func() {
BeforeEach(func() {
clientKey = "brussel-sprouts"
})

It("returns with exit code 1 and prints the error with the info subcommand", func() {
args := []string{
"channel",
"info",
"--orderer-address", ordererURL,
"--channelID", channelID,
"--ca-file", ordererCACert,
"--client-cert", clientCert,
"--client-key", clientKey,
}
output, exit, err := executeForArgs(args)
checkFlagError(output, exit, err, "loading client cert/key pair: open brussel-sprouts: no such file or directory")
})
})

Context("when the config block cannot be read", func() {
var configBlockPath string

Expand Down
Loading