github.com/IBM-Blockchain/fabric-operator@v1.0.4/integration/migration/fabric/peer_test.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package fabric_test 20 21 import ( 22 "context" 23 "encoding/base64" 24 "encoding/json" 25 "fmt" 26 27 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 28 "github.com/IBM-Blockchain/fabric-operator/integration" 29 "github.com/IBM-Blockchain/fabric-operator/integration/helper" 30 "github.com/IBM-Blockchain/fabric-operator/version" 31 . "github.com/onsi/ginkgo/v2" 32 . "github.com/onsi/gomega" 33 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 34 ) 35 36 const ( 37 peerUsername = "peer" 38 ) 39 40 var _ = Describe("Fabric peer migration", func() { 41 var ( 42 peer *helper.Peer 43 ) 44 45 BeforeEach(func() { 46 peer = GetPeer() 47 err := helper.CreatePeer(ibpCRClient, peer.CR) 48 Expect(err).NotTo(HaveOccurred()) 49 50 By("starting peer pod", func() { 51 Eventually(peer.PodIsRunning).Should((Equal(true))) 52 }) 53 }) 54 55 AfterEach(func() { 56 // Set flag if a test falls 57 if CurrentGinkgoTestDescription().Failed { 58 testFailed = true 59 } 60 }) 61 62 Context("migration from v1.4.x to v2.x peer", func() { 63 BeforeEach(func() { 64 result := ibpCRClient. 65 Get(). 66 Namespace(namespace). 67 Resource("ibppeers"). 68 Name(peer.Name). 69 Do(context.TODO()) 70 Expect(result.Error()).NotTo(HaveOccurred()) 71 72 ibppeer := ¤t.IBPPeer{} 73 result.Into(ibppeer) 74 75 ibppeer.Spec.Images.PeerTag = integration.PeerTag 76 ibppeer.Spec.FabricVersion = version.V2_2_5 77 78 bytes, err := json.Marshal(ibppeer) 79 Expect(err).NotTo(HaveOccurred()) 80 81 // Update the peer's CR spec 82 result = ibpCRClient. 83 Put(). 84 Namespace(namespace). 85 Resource("ibppeers"). 86 Name(ibppeer.Name). 87 Body(bytes). 88 Do(context.TODO()) 89 Expect(result.Error()).NotTo(HaveOccurred()) 90 }) 91 92 It("migrates", func() { 93 By("starting migration job", func() { 94 Eventually(func() bool { 95 dbmigrationJobName, err := helper.GetJobID(kclient, namespace, fmt.Sprintf("%s-dbmigration", peer.CR.Name)) 96 if err != nil { 97 return false 98 } 99 100 _, err = kclient.BatchV1().Jobs(namespace). 101 Get(context.TODO(), dbmigrationJobName, metav1.GetOptions{}) 102 if err != nil { 103 return false 104 } 105 return true 106 }).Should(Equal(true)) 107 }) 108 109 By("starting peer pod", func() { 110 Eventually(func() int { 111 deps := peer.DeploymentList() 112 dep := deps.Items[0] 113 return len(dep.Spec.Template.Spec.Containers) 114 }).Should(Equal(4)) 115 Eventually(peer.PodIsRunning).Should((Equal(true))) 116 }) 117 118 By("adding chaincode launcher container and removing dind", func() { 119 deps := peer.DeploymentList() 120 dep := deps.Items[0] 121 122 containerNames := []string{} 123 for _, cont := range dep.Spec.Template.Spec.Containers { 124 containerNames = append(containerNames, cont.Name) 125 } 126 127 Expect(containerNames).To(ContainElement("chaincode-launcher")) 128 Expect(containerNames).NotTo(ContainElement("dind")) 129 }) 130 }) 131 }) 132 }) 133 134 // TODO:OSS 135 func GetPeer() *helper.Peer { 136 name := "ibppeer1" 137 cr := ¤t.IBPPeer{ 138 TypeMeta: metav1.TypeMeta{ 139 Kind: "IBPPeer", 140 APIVersion: "ibp.com/v1beta1", 141 }, 142 ObjectMeta: metav1.ObjectMeta{ 143 Name: name, 144 Namespace: namespace, 145 }, 146 Spec: current.IBPPeerSpec{ 147 License: current.License{ 148 Accept: true, 149 }, 150 MSPID: "test-peer-mspid", 151 Region: "select", 152 Zone: "select", 153 ImagePullSecrets: []string{"regcred"}, 154 Images: ¤t.PeerImages{ 155 // TODO: OSS 156 CouchDBImage: "ghcr.io/ibm-blockchain/couchdb", 157 CouchDBTag: "2.3.1-20210826-amd64", 158 // do not change dind tag, it is used for loading dind faster 159 DindImage: "ghcr.io/ibm-blockchain/dind", 160 DindTag: "noimages-amd64", 161 FluentdImage: "ghcr.io/ibm-blockchain/fluentd", 162 FluentdTag: "1.0.0-20210826-amd64", 163 GRPCWebImage: "ghcr.io/ibm-blockchain/grpcweb", 164 GRPCWebTag: "1.0.0-20210826-amd64", 165 PeerImage: "ghcr.io/ibm-blockchain/peer", 166 PeerTag: "1.4.12-20210826-amd64", 167 PeerInitImage: "ghcr.io/ibm-blockchain/init", 168 PeerInitTag: "1.0.0-20210826-amd64", 169 EnrollerImage: "ghcr.io/ibm-blockchain/enroller", 170 EnrollerTag: "1.0.0-20210826-amd64", 171 }, 172 Domain: domain, 173 Secret: ¤t.SecretSpec{ 174 Enrollment: ¤t.EnrollmentSpec{ 175 Component: ¤t.Enrollment{ 176 CAHost: caHost, 177 CAPort: "443", 178 CAName: "ca", 179 CATLS: ¤t.CATLS{ 180 CACert: base64.StdEncoding.EncodeToString(tlsCert), 181 }, 182 EnrollID: peerUsername, 183 EnrollSecret: "peerpw", 184 }, 185 TLS: ¤t.Enrollment{ 186 CAHost: caHost, 187 CAPort: "443", 188 CAName: "tlsca", 189 CATLS: ¤t.CATLS{ 190 CACert: base64.StdEncoding.EncodeToString(tlsCert), 191 }, 192 EnrollID: peerUsername, 193 EnrollSecret: "peerpw", 194 }, 195 }, 196 }, 197 FabricVersion: "1.4.12", 198 }, 199 } 200 201 return &helper.Peer{ 202 Domain: domain, 203 Name: cr.Name, 204 Namespace: namespace, 205 CR: cr, 206 CRClient: ibpCRClient, 207 KClient: kclient, 208 NativeResourcePoller: integration.NativeResourcePoller{ 209 Name: cr.Name, 210 Namespace: namespace, 211 Client: kclient, 212 }, 213 } 214 }