github.com/IBM-Blockchain/fabric-operator@v1.0.4/integration/migration/fabric/orderer_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  	. "github.com/onsi/ginkgo/v2"
    28  	. "github.com/onsi/gomega"
    29  
    30  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    31  	"github.com/IBM-Blockchain/fabric-operator/integration"
    32  	"github.com/IBM-Blockchain/fabric-operator/integration/helper"
    33  	baseorderer "github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/orderer"
    34  
    35  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    36  )
    37  
    38  const (
    39  	ordererUsername = "orderer"
    40  )
    41  
    42  var _ = Describe("Fabric orderer migration", func() {
    43  	var (
    44  		node1 *helper.Orderer
    45  	)
    46  
    47  	BeforeEach(func() {
    48  		orderer := GetOrderer()
    49  		err := helper.CreateOrderer(ibpCRClient, orderer.CR)
    50  		Expect(err).NotTo(HaveOccurred())
    51  
    52  		node1 = &orderer.Nodes[0]
    53  
    54  		By("starting orderer pod", func() {
    55  			Eventually(node1.PodIsRunning).Should((Equal(true)))
    56  		})
    57  	})
    58  
    59  	AfterEach(func() {
    60  		// Set flag if a test falls
    61  		if CurrentGinkgoTestDescription().Failed {
    62  			testFailed = true
    63  		}
    64  	})
    65  
    66  	Context("migration from v1.4.x to v2.x", func() {
    67  		BeforeEach(func() {
    68  			result := ibpCRClient.
    69  				Get().
    70  				Namespace(namespace).
    71  				Resource("ibporderers").
    72  				Name(node1.Name).
    73  				Do(context.TODO())
    74  			Expect(result.Error()).NotTo(HaveOccurred())
    75  
    76  			ibporderer := &current.IBPOrderer{}
    77  			result.Into(ibporderer)
    78  
    79  			ibporderer.Spec.Images.OrdererTag = integration.OrdererTag
    80  			ibporderer.Spec.FabricVersion = integration.FabricVersion
    81  
    82  			bytes, err := json.Marshal(ibporderer)
    83  			Expect(err).NotTo(HaveOccurred())
    84  
    85  			// Update the orderer's CR spec
    86  			result = ibpCRClient.
    87  				Put().
    88  				Namespace(namespace).
    89  				Resource("ibporderers").
    90  				Name(node1.Name).
    91  				Body(bytes).
    92  				Do(context.TODO())
    93  			Expect(result.Error()).NotTo(HaveOccurred())
    94  		})
    95  
    96  		It("terminates pod", func() {
    97  			Eventually(func() int {
    98  				return len(node1.GetRunningPods())
    99  			}).Should((Equal(0)))
   100  		})
   101  
   102  		It("restarts pod", func() {
   103  			Eventually(node1.PodIsRunning).Should((Equal(true)))
   104  		})
   105  	})
   106  })
   107  
   108  func GetOrderer() *helper.Orderer {
   109  	enrollment := &current.EnrollmentSpec{
   110  		Component: &current.Enrollment{
   111  			CAHost: caHost,
   112  			CAPort: "443",
   113  			CAName: "ca",
   114  			CATLS: &current.CATLS{
   115  				CACert: base64.StdEncoding.EncodeToString(tlsCert),
   116  			},
   117  			EnrollID:     ordererUsername,
   118  			EnrollSecret: "ordererpw",
   119  		},
   120  		TLS: &current.Enrollment{
   121  			CAHost: caHost,
   122  			CAPort: "443",
   123  			CAName: "tlsca",
   124  			CATLS: &current.CATLS{
   125  				CACert: base64.StdEncoding.EncodeToString(tlsCert),
   126  			},
   127  			EnrollID:     ordererUsername,
   128  			EnrollSecret: "ordererpw",
   129  		},
   130  	}
   131  
   132  	cr := &current.IBPOrderer{
   133  		ObjectMeta: metav1.ObjectMeta{
   134  			Name:      "ibporderer1",
   135  			Namespace: namespace,
   136  		},
   137  		Spec: current.IBPOrdererSpec{
   138  			License: current.License{
   139  				Accept: true,
   140  			},
   141  			ClusterSize:       1,
   142  			OrdererType:       "etcdraft",
   143  			SystemChannelName: "testchainid",
   144  			OrgName:           "orderermsp",
   145  			MSPID:             "orderermsp",
   146  			ImagePullSecrets:  []string{"regcred"},
   147  			GenesisProfile:    "Initial",
   148  			Domain:            domain,
   149  			Images: &current.OrdererImages{
   150  				GRPCWebImage:     integration.GrpcwebImage,
   151  				GRPCWebTag:       integration.GrpcwebTag,
   152  				OrdererImage:     integration.OrdererImage,
   153  				OrdererTag:       integration.Orderer14Tag,
   154  				OrdererInitImage: integration.InitImage,
   155  				OrdererInitTag:   integration.InitTag,
   156  			},
   157  			ClusterSecret: []*current.SecretSpec{
   158  				&current.SecretSpec{
   159  					Enrollment: enrollment,
   160  				},
   161  			},
   162  			FabricVersion: "1.4.12",
   163  		},
   164  	}
   165  
   166  	nodes := []helper.Orderer{
   167  		helper.Orderer{
   168  			Name:      cr.Name + "node1",
   169  			Namespace: namespace,
   170  			CR:        cr.DeepCopy(),
   171  			NodeName:  fmt.Sprintf("%s%s%d", cr.Name, baseorderer.NODE, 1),
   172  			NativeResourcePoller: integration.NativeResourcePoller{
   173  				Name:      cr.Name + "node1",
   174  				Namespace: namespace,
   175  				Client:    kclient,
   176  			},
   177  		},
   178  	}
   179  
   180  	nodes[0].CR.ObjectMeta.Name = cr.Name + "node1"
   181  
   182  	return &helper.Orderer{
   183  		Name:      cr.Name,
   184  		Namespace: namespace,
   185  		CR:        cr,
   186  		NodeName:  fmt.Sprintf("%s-%s%d", cr.Name, baseorderer.NODE, 1),
   187  		NativeResourcePoller: integration.NativeResourcePoller{
   188  			Name:      cr.Name,
   189  			Namespace: namespace,
   190  			Client:    kclient,
   191  		},
   192  		Nodes: nodes,
   193  	}
   194  }