github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/e2e/connect/connect.go (about) 1 package connect 2 3 import ( 4 "os" 5 6 "github.com/hashicorp/nomad/e2e/e2eutil" 7 "github.com/hashicorp/nomad/e2e/framework" 8 "github.com/hashicorp/nomad/helper/uuid" 9 ) 10 11 const ( 12 // envConsulToken is the consul http token environment variable 13 envConsulToken = "CONSUL_HTTP_TOKEN" 14 15 // demoConnectJob is the example connect enabled job useful for testing 16 demoConnectJob = "connect/input/demo.nomad" 17 18 // demoConnectCustomProxyExposed is a connect job with custom sidecar_task 19 // that also uses the expose check feature. 20 demoConnectCustomProxyExposed = "connect/input/expose-custom.nomad" 21 22 // demoConnectNativeJob is the example connect native enabled job useful for testing 23 demoConnectNativeJob = "connect/input/native-demo.nomad" 24 25 // demoConnectIngressGateway is the example ingress gateway job useful for testing 26 demoConnectIngressGateway = "connect/input/ingress-gateway.nomad" 27 28 // demoConnectMultiIngressGateway is the example multi ingress gateway job useful for testing 29 demoConnectMultiIngressGateway = "connect/input/multi-ingress.nomad" 30 31 // demoConnectTerminatingGateway is the example terminating gateway job useful for testing 32 demoConnectTerminatingGateway = "connect/input/terminating-gateway.nomad" 33 ) 34 35 type ConnectE2ETest struct { 36 framework.TC 37 jobIds []string 38 } 39 40 func init() { 41 // Connect tests without Consul ACLs enabled. 42 framework.AddSuites(&framework.TestSuite{ 43 Component: "Connect", 44 CanRunLocal: true, 45 Consul: true, 46 Cases: []framework.TestCase{ 47 new(ConnectE2ETest), 48 new(ConnectClientStateE2ETest), 49 }, 50 }) 51 52 // Connect tests with Consul ACLs enabled. These are now gated behind the 53 // NOMAD_TEST_CONNECT_ACLS environment variable, because they cause lots of 54 // problems for e2e test flakiness (due to restarting consul, nomad, etc.). 55 // 56 // Run these tests locally when working on Connect. 57 if os.Getenv("NOMAD_TEST_CONNECT_ACLS") == "1" { 58 framework.AddSuites(&framework.TestSuite{ 59 Component: "ConnectACLs", 60 CanRunLocal: false, 61 Consul: true, 62 Parallel: false, 63 Cases: []framework.TestCase{ 64 new(ConnectACLsE2ETest), 65 }, 66 }) 67 } 68 } 69 70 func (tc *ConnectE2ETest) BeforeAll(f *framework.F) { 71 e2eutil.WaitForLeader(f.T(), tc.Nomad()) 72 e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2) 73 } 74 75 func (tc *ConnectE2ETest) AfterEach(f *framework.F) { 76 if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" { 77 return 78 } 79 80 for _, id := range tc.jobIds { 81 tc.Nomad().Jobs().Deregister(id, true, nil) 82 } 83 tc.jobIds = []string{} 84 tc.Nomad().System().GarbageCollect() 85 } 86 87 func connectJobID() string { 88 return "connect" + uuid.Generate()[0:8] 89 } 90 91 // TestConnectDemo tests the demo job file used in Connect Integration examples. 92 func (tc *ConnectE2ETest) TestConnectDemo(f *framework.F) { 93 t := f.T() 94 95 jobID := connectJobID() 96 tc.jobIds = append(tc.jobIds, jobID) 97 98 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectJob, jobID, "") 99 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 100 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 101 } 102 103 // TestConnectCustomSidecarExposed tests that a connect sidecar with custom task 104 // definition can also make use of the expose service check feature. 105 func (tc *ConnectE2ETest) TestConnectCustomSidecarExposed(f *framework.F) { 106 t := f.T() 107 108 jobID := connectJobID() 109 tc.jobIds = append(tc.jobIds, jobID) 110 111 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectCustomProxyExposed, jobID, "") 112 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 113 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 114 } 115 116 // TestConnectNativeDemo tests the demo job file used in Connect Native Integration examples. 117 func (tc *ConnectE2ETest) TestConnectNativeDemo(f *framework.F) { 118 t := f.T() 119 120 jobID := connectJobID() 121 tc.jobIds = append(tc.jobIds, jobID) 122 123 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectNativeJob, jobID, "") 124 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 125 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 126 } 127 128 func (tc *ConnectE2ETest) TestConnectIngressGatewayDemo(f *framework.F) { 129 t := f.T() 130 131 jobID := connectJobID() 132 tc.jobIds = append(tc.jobIds, jobID) 133 134 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectIngressGateway, jobID, "") 135 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 136 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 137 } 138 139 func (tc *ConnectE2ETest) TestConnectMultiIngressGatewayDemo(f *framework.F) { 140 t := f.T() 141 142 jobID := connectJobID() 143 tc.jobIds = append(tc.jobIds, jobID) 144 145 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectMultiIngressGateway, jobID, "") 146 147 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 148 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 149 } 150 151 func (tc *ConnectE2ETest) TestConnectTerminatingGatewayDemo(f *framework.F) { 152 153 t := f.T() 154 155 jobID := connectJobID() 156 tc.jobIds = append(tc.jobIds, jobID) 157 158 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectTerminatingGateway, jobID, "") 159 160 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 161 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 162 }