Skip to content

Commit a00e941

Browse files
committed
'release' output does not require META-INF prefix
When using an external builder, the `release` executable is provided with the directory to populate with metadata information for the peer to consume. Given it's defined role, it doesn't make sense to require an additional META-INF subdirectory within it. Update the metadata provider to implicitly prepend the META-INF prefix when packaging the output and update the integration test implementation to adhere to the contract. FAB-16861 #done Change-Id: Ia64bd6bb91a72fcf3a0e9a6a8ced249fd70bfd16 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent a7603fc commit a00e941

File tree

8 files changed

+30
-25
lines changed

8 files changed

+30
-25
lines changed

core/chaincode/lifecycle/event_broker_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ SPDX-License-Identifier: Apache-2.0
77
package lifecycle_test
88

99
import (
10+
"archive/tar"
11+
"bytes"
12+
"io"
13+
1014
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle"
1115
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
1216
"github.com/hyperledger/fabric/core/chaincode/lifecycle/mock"
@@ -143,8 +147,7 @@ var _ = Describe("EventBroker", func() {
143147
}
144148
})
145149

146-
By("invoking ProcessInstallEvent function")
147-
It("invokes listener", func() {
150+
It("invokes listener when ProcessInstallEvent is called", func() {
148151
eventBroker.ProcessInstallEvent(localChaincode)
149152
Expect(fakeListener.HandleChaincodeDeployCallCount()).To(Equal(1))
150153
def, md := fakeListener.HandleChaincodeDeployArgsForCall(0)
@@ -158,8 +161,7 @@ var _ = Describe("EventBroker", func() {
158161
Expect(fakeListener.ChaincodeDeployDoneCallCount()).To(Equal(1))
159162
})
160163

161-
By("invoking ProcessApproveOrDefineEvent function")
162-
It("invokes listener", func() {
164+
It("invokes listener when ProcessApproveOrDefineEvent is called", func() {
163165
eventBroker.ProcessApproveOrDefineEvent("channel-1", "chaincode-1", cachedChaincodeDef)
164166
Expect(fakeListener.HandleChaincodeDeployCallCount()).To(Equal(1))
165167
Expect(fakeListener.ChaincodeDeployDoneCallCount()).To(Equal(0))
@@ -181,7 +183,19 @@ var _ = Describe("EventBroker", func() {
181183
Hash: []byte("external-built-cc"),
182184
Version: "version-1",
183185
}))
184-
Expect(len(md)).To(Equal(2048)) // A tar, and not our mock value
186+
187+
mdContents := map[string]struct{}{}
188+
tr := tar.NewReader(bytes.NewBuffer(md))
189+
for {
190+
hdr, err := tr.Next()
191+
if err == io.EOF {
192+
break
193+
}
194+
Expect(err).NotTo(HaveOccurred())
195+
mdContents[hdr.Name] = struct{}{}
196+
}
197+
Expect(mdContents).To(HaveKey("META-INF/"))
198+
Expect(mdContents).To(HaveKey("META-INF/index.json"))
185199
})
186200
})
187201

core/container/externalbuilders/metadataprovider.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ func (mp *MetadataProvider) PackageMetadata(ccid string) ([]byte, error) {
3333
if os.IsNotExist(err) {
3434
return nil, nil
3535
}
36-
3736
if err != nil {
3837
return nil, errors.WithMessage(err, "could not stat path")
3938
}
4039

4140
buffer := bytes.NewBuffer(nil)
42-
4341
tw := tar.NewWriter(buffer)
4442

4543
logger.Debugf("Walking package release dir '%s'", releasePath)
@@ -48,21 +46,17 @@ func (mp *MetadataProvider) PackageMetadata(ccid string) ([]byte, error) {
4846
return err
4947
}
5048

51-
if releasePath == file {
52-
// No need to add '.' to our tar
53-
return nil
54-
}
55-
5649
header, err := tar.FileInfoHeader(fi, file)
5750
if err != nil {
5851
return err
5952
}
6053

61-
header.Name, err = filepath.Rel(releasePath, file)
54+
name, err := filepath.Rel(releasePath, file)
6255
if err != nil {
6356
return err
6457
}
6558

59+
header.Name = filepath.Join("META-INF", name)
6660
if fi.IsDir() {
6761
header.Name += "/"
6862
}

core/container/externalbuilders/metadataprovider_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import (
1818
)
1919

2020
var _ = Describe("Metadataprovider", func() {
21-
var (
22-
mp *externalbuilders.MetadataProvider
23-
)
21+
var mp *externalbuilders.MetadataProvider
2422

2523
BeforeEach(func() {
2624
mp = &externalbuilders.MetadataProvider{

integration/externalbuilders/binary/bin/build

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set -euo pipefail
88

99
if [ "$#" -ne 3 ]; then
10-
echo "Expected 3 directories got $#"
10+
>&2 echo "Expected 3 directories got $#"
1111
exit 1
1212
fi
1313

@@ -16,8 +16,7 @@ META="$2"
1616
BLD="$3"
1717

1818
if [ -e "$SRC/metadata" ] ; then
19-
mkdir "$BLD/metadata"
20-
mv "$SRC/metadata" "$BLD/metadata/META-INF"
19+
cp -a "$SRC/metadata" "$BLD"
2120
fi
2221

2322
cp "$(jq -r .path "$META/metadata.json")" "$BLD/chaincode"

integration/externalbuilders/binary/bin/detect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set -euo pipefail
88

99
if [ "$#" -ne 2 ]; then
10-
echo "Expected 2 directories got $#"
10+
>&2 echo "Expected 2 directories got $#"
1111
exit 2
1212
fi
1313

@@ -18,5 +18,5 @@ if [ "$(jq -r .type "$META/metadata.json")" == "binary" ]; then
1818
exit 0
1919
fi
2020

21-
echo "binary is the only supported type"
21+
>&2 echo "binary is the only supported type"
2222
exit 1

integration/externalbuilders/binary/bin/release

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
set -euo pipefail
88

99
if [ "$#" -ne 2 ]; then
10-
echo "Expected 2 directories got $#"
10+
>&2 echo "Expected 2 directories got $#"
1111
exit 2
1212
fi
1313

1414
BLD="$1"
1515
RELEASE="$2"
1616

17-
if [ -d "$BLD/metadata/META-INF" ] ; then
18-
cp -a "$BLD/metadata/META-INF" "$RELEASE"
17+
if [ -d "$BLD/metadata" ] ; then
18+
cp -a "$BLD/metadata/"* "$RELEASE"
1919
fi

integration/externalbuilders/binary/bin/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set -euo pipefail
88

99
if [ "$#" -ne 2 ]; then
10-
echo "Expected 2 directories got $#"
10+
>&2 echo "Expected 2 directories got $#"
1111
exit 1
1212
fi
1313

0 commit comments

Comments
 (0)