Skip to content

Commit

Permalink
[FAB-9808] test config file cleanup
Browse files Browse the repository at this point in the history
- marked channels.<CHANNEL-ID>.orderers as deprecated
and commented out in test files.
- passing orderer id as an opts to save, join and
QueryConfigFromOrderer functions.
- Refactored endpointConfig.OrdererConfig()

Change-Id: If38c82f903af84e8aaa4c69f098c4c98670b26f2
Signed-off-by: Sudesh Shetty <[email protected]>
  • Loading branch information
sudeshrshetty committed May 2, 2018
1 parent 0404e72 commit 9333944
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 41 deletions.
9 changes: 5 additions & 4 deletions pkg/client/resmgmt/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ func WithTimeout(timeoutType fab.TimeoutType, timeout time.Duration) RequestOpti
}

// WithOrdererURL allows an orderer to be specified for the request.
// The orderer will be looked-up based on the url argument.
func WithOrdererURL(url string) RequestOption {
// The orderer will be looked-up based on the name/url argument.
func WithOrdererURL(nameOrURL string) RequestOption {

return func(ctx context.Client, opts *requestOptions) error {

ordererCfg, err := ctx.EndpointConfig().OrdererConfig(url)
ordererCfg, err := ctx.EndpointConfig().OrdererConfig(nameOrURL)
if err != nil {
return errors.Wrapf(err, "orderer not found for url : %s", url)
return errors.Wrapf(err, "orderer not found for url : %s", nameOrURL)
}

orderer, err := ctx.InfraProvider().CreateOrdererFromConfig(ordererCfg)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func TestJoinChannelWithOptsRequiredParameters(t *testing.T) {
}

// Test targets only
err = rc.JoinChannel("mychannel", WithTargets(peers...))
err = rc.JoinChannel("mychannel", WithTargets(peers...), WithOrdererURL("orderer.example.com"))
if err != nil {
t.Fatalf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/providers/fab/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type EndpointConfig interface {
MSPID(org string) (string, error)
PeerMSPID(name string) (string, error)
OrderersConfig() ([]OrdererConfig, error)
OrdererConfig(name string) (*OrdererConfig, error)
OrdererConfig(nameOrURL string) (*OrdererConfig, error)
PeersConfig(org string) ([]PeerConfig, error)
PeerConfig(nameOrURL string) (*PeerConfig, error)
NetworkConfig() (*NetworkConfig, error)
Expand Down
1 change: 1 addition & 0 deletions pkg/core/config/testdata/template/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ channels:
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
# operational decisions to share loads from applications among the orderers. The values must
# be "names" of orgs defined under "organizations/peers"
# deprecated: not recommended, to override any orderer configuration items, entity matchers should be used.
# orderers:
# - orderer.example.com

Expand Down
25 changes: 20 additions & 5 deletions pkg/fab/endpointconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,34 @@ func (c *EndpointConfig) OrderersConfig() ([]fab.OrdererConfig, error) {
}

// OrdererConfig returns the requested orderer
func (c *EndpointConfig) OrdererConfig(name string) (*fab.OrdererConfig, error) {
func (c *EndpointConfig) OrdererConfig(nameOrURL string) (*fab.OrdererConfig, error) {
networkConfig, err := c.NetworkConfig()
if err != nil {
return nil, err
}
orderer, ok := networkConfig.Orderers[strings.ToLower(name)]
orderer, ok := networkConfig.Orderers[strings.ToLower(nameOrURL)]

if !ok {
ordererCfgs, err := c.OrderersConfig()
if err != nil {
return nil, err
}
for _, ordererCfg := range ordererCfgs {
if strings.EqualFold(ordererCfg.URL, nameOrURL) {
orderer = ordererCfg
ok = true
break
}
}
}

if !ok {
logger.Debugf("Could not find Orderer for [%s], trying with Entity Matchers", name)
matchingOrdererConfig := c.tryMatchingOrdererConfig(networkConfig, strings.ToLower(name))
logger.Debugf("Could not find Orderer for [%s], trying with Entity Matchers", nameOrURL)
matchingOrdererConfig := c.tryMatchingOrdererConfig(networkConfig, strings.ToLower(nameOrURL))
if matchingOrdererConfig == nil {
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoMatchingOrdererEntity.ToInt32(), "no matching orderer config found", nil))
}
logger.Debugf("Found matching Orderer Config for [%s]", name)
logger.Debugf("Found matching Orderer Config for [%s]", nameOrURL)
orderer = *matchingOrdererConfig
}

Expand Down
10 changes: 6 additions & 4 deletions test/fixtures/config/config_pkcs11_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ channels:
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
# operational decisions to share loads from applications among the orderers. The values must
# be "names" of orgs defined under "organizations/peers"
orderers:
- orderer.example.com
# deprecated: not recommended, to override any orderer configuration items, entity matchers should be used.
# orderers:
# - orderer.example.com

# Required. list of peers from participating orgs
peers:
Expand Down Expand Up @@ -144,8 +145,9 @@ channels:
# multi-org test channel
orgchannel:

orderers:
- orderer.example.com
# deprecated: not recommended, to override any orderer configuration items, entity matchers should be used.
# orderers:
# - orderer.example.com

peers:
peer0.org1.example.com:
Expand Down
9 changes: 5 additions & 4 deletions test/fixtures/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ channels:
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
# operational decisions to share loads from applications among the orderers. The values must
# be "names" of orgs defined under "organizations/peers"
orderers:
- orderer.example.com
# deprecated: not recommended, to override any orderer configuration items, entity matchers should be used.
# orderers:
# - orderer.example.com

# Required. list of peers from participating orgs
peers:
Expand Down Expand Up @@ -163,8 +164,8 @@ channels:
# multi-org test channel
orgchannel:

orderers:
- orderer.example.com
# orderers:
# - orderer.example.com

peers:
peer0.org1.example.com:
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/config/config_test_endpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ channels:
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
# operational decisions to share loads from applications among the orderers. The values must
# be "names" of orgs defined under "organizations/peers"
orderers:
- orderer.example.com
# deprecated: not recommended, to override any orderer configuration items, entity matchers should be used.
# orderers:
# - orderer.example.com

# Required. list of peers from participating orgs
peers:
Expand Down
4 changes: 2 additions & 2 deletions test/integration/e2e/end_to_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func createChannelAndCC(t *testing.T, sdk *fabsdk.FabricSDK) {
}

// Org peers join channel
if err = orgResMgmt.JoinChannel(channelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts)); err != nil {
if err = orgResMgmt.JoinChannel(channelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com")); err != nil {
t.Fatalf("Org peers failed to JoinChannel: %s", err)
}

Expand Down Expand Up @@ -204,7 +204,7 @@ func createChannel(sdk *fabsdk.FabricSDK, t *testing.T, resMgmtClient *resmgmt.C
req := resmgmt.SaveChannelRequest{ChannelID: channelID,
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []msp.SigningIdentity{adminIdentity}}
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com"))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")
}
2 changes: 1 addition & 1 deletion test/integration/expiredpeer/expired_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestExpiredPeersCert(t *testing.T) {
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com"))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")

Expand Down
6 changes: 3 additions & 3 deletions test/integration/orgs/multiple_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
}

// Org1 peers join channel
if err = org1ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts)); err != nil {
if err = org1ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com")); err != nil {
t.Fatalf("Org1 peers failed to JoinChannel: %s", err)
}

Expand All @@ -127,7 +127,7 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
}

// Org2 peers join channel
if err = org2ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts)); err != nil {
if err = org2ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com")); err != nil {
t.Fatalf("Org2 peers failed to JoinChannel: %s", err)
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func createChannel(org1AdminUser msp.SigningIdentity, org2AdminUser msp.SigningI
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com"))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/revoked/revoked_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestRevokedPeer(t *testing.T) {
}

// Org1 peers join channel
if err = org1ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts)); err != nil {
if err = org1ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com")); err != nil {
t.Fatalf("Org1 peers failed to JoinChannel: %s", err)
}

Expand All @@ -104,7 +104,7 @@ func TestRevokedPeer(t *testing.T) {
}

// Org2 peers join channel
if err = org2ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts)); err != nil {
if err = org2ResMgmt.JoinChannel("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com")); err != nil {
t.Fatalf("Org2 peers failed to JoinChannel: %s", err)
}

Expand Down Expand Up @@ -166,7 +166,7 @@ func createChannel(org1AdminUser msp.SigningIdentity, org2AdminUser msp.SigningI
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererURL("orderer.example.com"))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")
}
Expand Down
12 changes: 1 addition & 11 deletions test/integration/sdk/resmgmt_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,8 @@ func testQueryChannels(t *testing.T, channelID string, target string, client *re
}

func testQueryConfigFromOrderer(t *testing.T, channelID string, client *resmgmt.Client) {

channelCfg, err := client.QueryConfigFromOrderer(channelID, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
if err != nil {
t.Fatalf("QueryConfig return error: %v", err)
}

expected := "orderer.example.com:7050"
if !contains(channelCfg.Orderers(), expected) {
t.Fatalf("Expected orderer %s, got %s", expected, channelCfg.Orderers())
}

channelCfg, err = client.QueryConfigFromOrderer(channelID, resmgmt.WithOrdererURL("orderer.example.com"), resmgmt.WithRetry(retry.DefaultResMgmtOpts))
channelCfg, err := client.QueryConfigFromOrderer(channelID, resmgmt.WithOrdererURL("orderer.example.com"), resmgmt.WithRetry(retry.DefaultResMgmtOpts))
if err != nil {
t.Fatalf("QueryConfig return error: %v", err)
}
Expand Down

0 comments on commit 9333944

Please sign in to comment.