From 933394436a3a5efbc15ed47deedbe2b5fa55d472 Mon Sep 17 00:00:00 2001 From: Sudesh Shetty Date: Wed, 2 May 2018 14:11:21 -0400 Subject: [PATCH] [FAB-9808] test config file cleanup - marked channels..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 --- pkg/client/resmgmt/opts.go | 9 ++++--- pkg/client/resmgmt/resmgmt_test.go | 2 +- pkg/common/providers/fab/provider.go | 2 +- pkg/core/config/testdata/template/config.yaml | 1 + pkg/fab/endpointconfig.go | 25 +++++++++++++++---- test/fixtures/config/config_pkcs11_test.yaml | 10 +++++--- test/fixtures/config/config_test.yaml | 9 ++++--- .../config/config_test_endpoints.yaml | 5 ++-- test/integration/e2e/end_to_end.go | 4 +-- .../expiredpeer/expired_certificate_test.go | 2 +- test/integration/orgs/multiple_orgs_test.go | 6 ++--- test/integration/revoked/revoked_peer_test.go | 6 ++--- test/integration/sdk/resmgmt_queries_test.go | 12 +-------- 13 files changed, 52 insertions(+), 41 deletions(-) diff --git a/pkg/client/resmgmt/opts.go b/pkg/client/resmgmt/opts.go index e0162481ae..21a6f498af 100644 --- a/pkg/client/resmgmt/opts.go +++ b/pkg/client/resmgmt/opts.go @@ -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) diff --git a/pkg/client/resmgmt/resmgmt_test.go b/pkg/client/resmgmt/resmgmt_test.go index 31c7bfc5b9..660f1d3ede 100644 --- a/pkg/client/resmgmt/resmgmt_test.go +++ b/pkg/client/resmgmt/resmgmt_test.go @@ -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()) } diff --git a/pkg/common/providers/fab/provider.go b/pkg/common/providers/fab/provider.go index 885ee2fdb8..f9fc71cef1 100644 --- a/pkg/common/providers/fab/provider.go +++ b/pkg/common/providers/fab/provider.go @@ -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) diff --git a/pkg/core/config/testdata/template/config.yaml b/pkg/core/config/testdata/template/config.yaml index 4022319559..fd5bd9c801 100755 --- a/pkg/core/config/testdata/template/config.yaml +++ b/pkg/core/config/testdata/template/config.yaml @@ -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 diff --git a/pkg/fab/endpointconfig.go b/pkg/fab/endpointconfig.go index 83dabaeae3..11d5f89369 100644 --- a/pkg/fab/endpointconfig.go +++ b/pkg/fab/endpointconfig.go @@ -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 } diff --git a/test/fixtures/config/config_pkcs11_test.yaml b/test/fixtures/config/config_pkcs11_test.yaml index 06ff2354b1..6fada2abc6 100755 --- a/test/fixtures/config/config_pkcs11_test.yaml +++ b/test/fixtures/config/config_pkcs11_test.yaml @@ -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: @@ -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: diff --git a/test/fixtures/config/config_test.yaml b/test/fixtures/config/config_test.yaml index b69c242d46..ffa7dd6f61 100755 --- a/test/fixtures/config/config_test.yaml +++ b/test/fixtures/config/config_test.yaml @@ -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: @@ -163,8 +164,8 @@ channels: # multi-org test channel orgchannel: - orderers: - - orderer.example.com +# orderers: +# - orderer.example.com peers: peer0.org1.example.com: diff --git a/test/fixtures/config/config_test_endpoints.yaml b/test/fixtures/config/config_test_endpoints.yaml index 418c270870..6c101fbcd6 100755 --- a/test/fixtures/config/config_test_endpoints.yaml +++ b/test/fixtures/config/config_test_endpoints.yaml @@ -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: diff --git a/test/integration/e2e/end_to_end.go b/test/integration/e2e/end_to_end.go index 12e0d20129..4036f70b5b 100644 --- a/test/integration/e2e/end_to_end.go +++ b/test/integration/e2e/end_to_end.go @@ -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) } @@ -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") } diff --git a/test/integration/expiredpeer/expired_certificate_test.go b/test/integration/expiredpeer/expired_certificate_test.go index aedb4b6ef4..fb0aad4c84 100644 --- a/test/integration/expiredpeer/expired_certificate_test.go +++ b/test/integration/expiredpeer/expired_certificate_test.go @@ -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") diff --git a/test/integration/orgs/multiple_orgs_test.go b/test/integration/orgs/multiple_orgs_test.go index 02c7a68189..2cba3ffd75 100644 --- a/test/integration/orgs/multiple_orgs_test.go +++ b/test/integration/orgs/multiple_orgs_test.go @@ -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) } @@ -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) } @@ -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") } diff --git a/test/integration/revoked/revoked_peer_test.go b/test/integration/revoked/revoked_peer_test.go index 10730cd779..233088851a 100644 --- a/test/integration/revoked/revoked_peer_test.go +++ b/test/integration/revoked/revoked_peer_test.go @@ -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) } @@ -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) } @@ -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") } diff --git a/test/integration/sdk/resmgmt_queries_test.go b/test/integration/sdk/resmgmt_queries_test.go index bb834cbc8c..69f5f8e0c1 100644 --- a/test/integration/sdk/resmgmt_queries_test.go +++ b/test/integration/sdk/resmgmt_queries_test.go @@ -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) }