github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/validation/listener.go (about) 1 package validation 2 3 import ( 4 "github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1" 5 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework" 6 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement" 7 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities" 8 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common" 9 "github.com/onsi/gomega" 10 "k8s.io/api/core/v1" 11 ) 12 13 // ListenerMapByPort represents a map that contains 14 type ListenerMapByPort map[string]map[string]interface{} 15 16 // ValidateDefaultListeners ensures that the default listeners (if no others specified) 17 // have been created 18 func ValidateDefaultListeners(ic *v1alpha1.Interconnect, f *framework.Framework, pods []v1.Pod) { 19 var expLs int = 3 20 var expIntLs int = 2 21 22 // Expected inter-router listener port might change if CertManager is present 23 var interRouterPort = "55672" 24 var interRouterSslProfile = "" 25 if f.CertManagerPresent { 26 expLs++ 27 interRouterPort = "55671" 28 interRouterSslProfile = "inter-router" 29 } 30 31 for _, pod := range pods { 32 var lsFound int = 0 33 var intLsFound int = 0 34 35 listeners, err := qdrmanagement.QdmanageQuery(f, pod.Name, entities.Listener{}, nil) 36 gomega.Expect(err).To(gomega.BeNil()) 37 38 // Validate returned listeners 39 for _, e := range listeners { 40 l := e.(entities.Listener) 41 switch l.Port { 42 case "5671": 43 ValidateEntityValues(l, map[string]interface{}{ 44 "Port": "5671", 45 "Role": common.RoleNormal, 46 "Http": false, 47 }) 48 lsFound++ 49 case "5672": 50 ValidateEntityValues(l, map[string]interface{}{ 51 "Port": "5672", 52 "Role": common.RoleNormal, 53 "Http": false, 54 }) 55 lsFound++ 56 case "8080": 57 ValidateEntityValues(l, map[string]interface{}{ 58 "Port": "8080", 59 "Role": common.RoleNormal, 60 "Http": true, 61 "AuthenticatePeer": true, 62 }) 63 lsFound++ 64 case "8888": 65 ValidateEntityValues(l, map[string]interface{}{ 66 "Port": "8888", 67 "Role": common.RoleNormal, 68 "Http": true, 69 "Healthz": true, 70 "Metrics": true, 71 "Websockets": false, 72 "HttpRootDir": "invalid", 73 }) 74 lsFound++ 75 } 76 } 77 78 // Expect default listener count to match 79 gomega.Expect(expLs).To(gomega.Equal(lsFound)) 80 81 // 82 // Interior only 83 // 84 if ic.Spec.DeploymentPlan.Role != v1alpha1.RouterRoleInterior { 85 return 86 } 87 88 // Validate interior listeners 89 for _, e := range listeners { 90 l := e.(entities.Listener) 91 switch l.Port { 92 // inter-router listener 93 case interRouterPort: 94 ValidateEntityValues(l, map[string]interface{}{ 95 "Port": interRouterPort, 96 "Role": common.RoleInterRouter, 97 "SslProfile": interRouterSslProfile, 98 }) 99 intLsFound++ 100 // edge listener 101 case "45672": 102 ValidateEntityValues(l, map[string]interface{}{ 103 "Port": "45672", 104 "Role": common.RoleEdge, 105 }) 106 intLsFound++ 107 } 108 } 109 110 // Validate all default interior listeners are present 111 gomega.Expect(expIntLs).To(gomega.Equal(intLsFound)) 112 } 113 } 114 115 // ValidateSpecListener asserts that the listener models provided through the lsMap 116 // are present across all pods from the given ic instance. 117 func ValidateSpecListener(ic *v1alpha1.Interconnect, f *framework.Framework, lsMap ListenerMapByPort) { 118 // Retrieve fresh version of given Interconnect instance 119 icNew, err := f.GetInterconnect(ic.Name) 120 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 121 122 // Retrieve pod list 123 pods, err := f.GetInterconnectPods(icNew) 124 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 125 126 // Iterate through all pods and assert that listeners are available across all instances 127 for _, pod := range pods { 128 // Same amount of listeners from lsMap are expected to be found 129 lsFound := 0 130 131 // Retrieve listeners 132 listeners, err := qdrmanagement.QdmanageQuery(f, pod.Name, entities.Listener{}, nil) 133 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 134 135 // Loop through returned listeners 136 for _, e := range listeners { 137 listener := e.(entities.Listener) 138 lsModel, found := lsMap[listener.Port] 139 if !found { 140 continue 141 } 142 // Validating listener that exists on lsMap 143 ValidateEntityValues(listener, lsModel) 144 lsFound++ 145 } 146 147 // Assert that all listeners from lsMap have been found 148 gomega.Expect(lsFound).To(gomega.Equal(len(lsMap))) 149 } 150 }