github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/spec_connector.go (about)

     1  package e2e
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1"
     7  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework"
     8  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement"
     9  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common"
    10  	"github.com/interconnectedcloud/qdr-operator/test/e2e/validation"
    11  	"github.com/onsi/ginkgo"
    12  	"github.com/onsi/gomega"
    13  )
    14  
    15  var _ = ginkgo.Describe("[spec_connector] Connector manipulation tests", func() {
    16  
    17  	var (
    18  		icName = "connector"
    19  		size   = 3
    20  	)
    21  
    22  	// Framework instance to be used across test specs
    23  	f := framework.NewFramework(icName, nil)
    24  
    25  	//
    26  	// Validating manipulation of normal, inter-router and edge connectors
    27  	//
    28  	ginkgo.It("Defines connectors without SSL Profile", func() {
    29  		ginkgo.By("creating an Interconnect with connectors")
    30  		// Create a new Interconnect with the corresponding AMQP connectors
    31  		ic, err := f.CreateInterconnect(f.Namespace, int32(size), specConnectorNoSSL)
    32  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    33  		gomega.Expect(ic).NotTo(gomega.BeNil())
    34  
    35  		// Wait till Interconnect up and running
    36  		err = framework.WaitForDeployment(f.KubeClient, f.Namespace, ic.Name, size, framework.RetryInterval, framework.Timeout)
    37  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    38  
    39  		// Wait till mesh is formed
    40  		ginkgo.By("Waiting until full interconnect initial qdr entities")
    41  		ctx, fn := context.WithTimeout(context.Background(), framework.Timeout)
    42  		defer fn()
    43  		err = qdrmanagement.WaitUntilFullInterconnectWithQdrEntities(ctx, f, ic)
    44  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    45  
    46  		// Retrieve current Interconnect
    47  		ic, err = f.GetInterconnect(ic.Name)
    48  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    49  
    50  		// Validating the defined connectors are present
    51  		validation.ValidateSpecConnector(ic, f, validation.ConnectorMapByPort{
    52  			"5672": {
    53  				"Name":         "normal-amqp",
    54  				"Host":         "1.1.1.1",
    55  				"Role":         common.RoleNormal,
    56  				"Port":         "5672",
    57  				"LinkCapacity": 200,
    58  			},
    59  			"15672": {
    60  				"Name":         "inter-amqp",
    61  				"Host":         "1.1.1.1",
    62  				"Role":         common.RoleInterRouter,
    63  				"Port":         "15672",
    64  				"LinkCapacity": 200,
    65  			},
    66  			"25672": {
    67  				"Name":         "edge-amqp",
    68  				"Host":         "1.1.1.1",
    69  				"Role":         common.RoleEdge,
    70  				"Port":         "25672",
    71  				"LinkCapacity": 200,
    72  			},
    73  		})
    74  	})
    75  
    76  	ginkgo.It("Defines connectors with SSL Profile - cert-manager installed", func() {
    77  		if !f.CertManagerPresent {
    78  			ginkgo.Skip("No cert-manager installed")
    79  		}
    80  
    81  		ginkgo.By("creating an Interconnect with connectors")
    82  		// Create a new Interconnect with the corresponding AMQPS connectors
    83  		ic, err := f.CreateInterconnect(f.Namespace, int32(size), specConnectorSSL, specConnectorNormalSslProfile)
    84  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    85  		gomega.Expect(ic).NotTo(gomega.BeNil())
    86  
    87  		// Wait for deployment
    88  		err = framework.WaitForDeployment(f.KubeClient, f.Namespace, ic.Name, size, framework.RetryInterval, framework.Timeout)
    89  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    90  
    91  		// Wait till Interconnect up and running
    92  		ginkgo.By("Waiting until full interconnect initial qdr entities")
    93  		ctx, fn := context.WithTimeout(context.Background(), framework.Timeout)
    94  		defer fn()
    95  		err = qdrmanagement.WaitUntilFullInterconnectWithQdrEntities(ctx, f, ic)
    96  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    97  
    98  		// Retrieve current Interconnect
    99  		ic, err = f.GetInterconnect(ic.Name)
   100  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
   101  
   102  		// Validating the defined connectors are present
   103  		ginkgo.By("Validating defined connectors")
   104  		validation.ValidateSpecConnector(ic, f, validation.ConnectorMapByPort{
   105  			"5671": {
   106  				"Name":         "normal-amqps",
   107  				"Host":         "1.1.1.1",
   108  				"Role":         common.RoleNormal,
   109  				"SslProfile":   "amqps",
   110  				"Port":         "5671",
   111  				"LinkCapacity": 200,
   112  			},
   113  			"15671": {
   114  				"Name":         "inter-amqps",
   115  				"Host":         "1.1.1.1",
   116  				"Role":         common.RoleInterRouter,
   117  				"SslProfile":   "amqps",
   118  				"Port":         "15671",
   119  				"LinkCapacity": 200,
   120  			},
   121  			"25671": {
   122  				"Name":         "edge-amqps",
   123  				"Host":         "1.1.1.1",
   124  				"Role":         common.RoleEdge,
   125  				"SslProfile":   "amqps",
   126  				"Port":         "25671",
   127  				"LinkCapacity": 200,
   128  			},
   129  		})
   130  
   131  		// Validating defined SSL Profiles
   132  		ginkgo.By("Validating SSL Profiles")
   133  		validation.ValidateSslProfileModels(ic, f, validation.SslProfileMapByName{
   134  			"amqps": {
   135  				"Name":           "amqps",
   136  				"CaCertFile":     fmt.Sprintf("/etc/qpid-dispatch-certs/%s/%s/ca.crt", "amqps", "amqps-crt"), // amqps-crt because of mutual auth (otherwise would be amqps-ca
   137  				"CertFile":       fmt.Sprintf("/etc/qpid-dispatch-certs/%s/%s/tls.crt", "amqps", "amqps-crt"),
   138  				"PrivateKeyFile": fmt.Sprintf("/etc/qpid-dispatch-certs/%s/%s/tls.key", "amqps", "amqps-crt"),
   139  			},
   140  		})
   141  
   142  		// Verify amqps-ca Issuer exists (as MutualAuth: true)
   143  		ginkgo.By("Validating Issuers")
   144  		issuer, err := f.GetResource(framework.Issuers, "amqps-ca")
   145  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
   146  		gomega.Expect(issuer).NotTo(gomega.BeNil())
   147  		gomega.Expect(issuer.GetKind()).To(gomega.Equal("Issuer"))
   148  
   149  		// Verify certificates have been generated
   150  		ginkgo.By("Validating Certificates")
   151  		expectedCertificates := []string{"amqps-ca", "amqps-crt"}
   152  		for _, certName := range expectedCertificates {
   153  			cert, err := f.GetResource(framework.Certificates, certName)
   154  			gomega.Expect(err).NotTo(gomega.HaveOccurred())
   155  			gomega.Expect(cert).NotTo(gomega.BeNil())
   156  			gomega.Expect(cert.GetKind()).To(gomega.Equal("Certificate"))
   157  		}
   158  
   159  		// Deleting the Interconnect instance and validating resources
   160  		err = f.DeleteInterconnect(ic)
   161  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
   162  
   163  		// Waiting till Interconnect is deleted
   164  		ctx, fn = context.WithTimeout(context.Background(), framework.Timeout)
   165  		defer fn()
   166  		err = framework.WaitForDeploymentDeleted(ctx, f.KubeClient, f.Namespace, ic.Name)
   167  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
   168  
   169  		// Verify amqps-ca Issuer has been removed
   170  		ginkgo.By("Validating Issuers removed")
   171  		issuer, err = f.GetResource(framework.Issuers, "amqps-ca")
   172  		gomega.Expect(err).To(gomega.HaveOccurred())
   173  		gomega.Expect(issuer).To(gomega.BeNil())
   174  
   175  		// Verify certificates have been removed
   176  		ginkgo.By("Validating Certificates removed")
   177  		for _, certName := range expectedCertificates {
   178  			cert, err := f.GetResource(framework.Certificates, certName)
   179  			gomega.Expect(err).To(gomega.HaveOccurred())
   180  			gomega.Expect(cert).To(gomega.BeNil())
   181  		}
   182  
   183  	})
   184  })
   185  
   186  func specConnectorNoSSL(interconnect *v1alpha1.Interconnect) {
   187  	interconnect.Spec.Connectors = []v1alpha1.Connector{
   188  		{
   189  			Name:         "normal-amqp",
   190  			Host:         "1.1.1.1",
   191  			Port:         int32(5672),
   192  			LinkCapacity: int32(200),
   193  		},
   194  	}
   195  	interconnect.Spec.InterRouterConnectors = []v1alpha1.Connector{
   196  		{
   197  			Name:         "inter-amqp",
   198  			Host:         "1.1.1.1",
   199  			Port:         int32(15672),
   200  			LinkCapacity: int32(200),
   201  		},
   202  	}
   203  	interconnect.Spec.EdgeConnectors = []v1alpha1.Connector{
   204  		{
   205  			Name:         "edge-amqp",
   206  			Host:         "1.1.1.1",
   207  			Port:         int32(25672),
   208  			LinkCapacity: int32(200),
   209  		},
   210  	}
   211  }
   212  
   213  func specConnectorSSL(interconnect *v1alpha1.Interconnect) {
   214  	interconnect.Spec.Connectors = []v1alpha1.Connector{
   215  		{
   216  			Name:         "normal-amqps",
   217  			Host:         "1.1.1.1",
   218  			Port:         int32(5671),
   219  			SslProfile:   "amqps",
   220  			LinkCapacity: int32(200),
   221  		},
   222  	}
   223  	interconnect.Spec.InterRouterConnectors = []v1alpha1.Connector{
   224  		{
   225  			Name:         "inter-amqps",
   226  			Host:         "1.1.1.1",
   227  			Port:         int32(15671),
   228  			SslProfile:   "amqps",
   229  			LinkCapacity: int32(200),
   230  		},
   231  	}
   232  	interconnect.Spec.EdgeConnectors = []v1alpha1.Connector{
   233  		{
   234  			Name:         "edge-amqps",
   235  			Host:         "1.1.1.1",
   236  			Port:         int32(25671),
   237  			SslProfile:   "amqps",
   238  			LinkCapacity: int32(200),
   239  		},
   240  	}
   241  }
   242  
   243  func specConnectorNormalSslProfile(interconnect *v1alpha1.Interconnect) {
   244  	interconnect.Spec.SslProfiles = []v1alpha1.SslProfile{
   245  		{
   246  			Name:                "amqps",
   247  			Credentials:         "amqps-crt",
   248  			CaCert:              "amqps-ca",
   249  			GenerateCredentials: true,
   250  			GenerateCaCert:      true,
   251  			MutualAuth:          true,
   252  		},
   253  	}
   254  }