diff --git a/tests/ociswrapper/README.md b/tests/ociswrapper/README.md index dc4e4385ddf..8ed945f3611 100644 --- a/tests/ociswrapper/README.md +++ b/tests/ociswrapper/README.md @@ -125,22 +125,26 @@ Also, see `./bin/ociswrapper help` for more information. - `200 OK` - oCIS server is stopped - `500 Internal Server Error` - Unable to stop oCIS server - 6. `POST /services/{service-name}` +6. `POST /services/{service-name}` - Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor. + Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor. - Body of the request should be a JSON object with the following structure: + Body of the request should be a JSON object with the following structure: + + ```json + { + "ENV_KEY1": "value1", + "ENV_KEY2": "value2" + } + ``` - ```json - { - "ENV_KEY1": "value1", - "ENV_KEY2": "value2" - } - ``` + > **⚠️ Note:** + > + > You need to set the proper addresses to access the service from other steps in the CI pipeline. + > + > `{SERVICE-NAME}_DEBUG_ADDR=0.0.0.0:{DEBUG_PORT}` + > `{SERVICE-NAME}_HTTP_ADDR=0.0.0.0:{HTTP_PORT}` - > **⚠️ WARNING:** - > You need to set the address of the debug server to expose the port in CI - > `{SERVICE-NAME}_DEBUG_ADDR` Returns: diff --git a/tests/ociswrapper/ocis/config/config.go b/tests/ociswrapper/ocis/config/config.go index 300af3bb8bc..600f570ad87 100644 --- a/tests/ociswrapper/ocis/config/config.go +++ b/tests/ociswrapper/ocis/config/config.go @@ -59,10 +59,10 @@ func Get(key string) string { return config[key] } -func SetService(key string, value int) { +func SetServiceDebugPort(key string, value int) { services[key] = value } -func GetService(key string) int { +func GetServiceDebugPort(key string) int { return services[key] } diff --git a/tests/ociswrapper/ocis/ocis.go b/tests/ociswrapper/ocis/ocis.go index a2cf84e234f..90bdcc8bbe0 100644 --- a/tests/ociswrapper/ocis/ocis.go +++ b/tests/ociswrapper/ocis/ocis.go @@ -30,7 +30,7 @@ var EnvConfigs = []string{} var runningServices = make(map[string]int) func Start(envMap []string) { - log.Println("Starting oCIS service........") + log.Println("Starting oCIS service...") StartService("", envMap) } @@ -328,13 +328,13 @@ func StopService(service string) (bool, string) { return true, fmt.Sprintf("Service %s stopped successfully", service) } -// WaitUntilPortListens waits until the port for a given service is listening -func WaitUntilPortListens(service string) bool { +// wait until the port for a given service is listening +func WaitForService(service string) bool { overallTimeout := time.After(30 * time.Second) ticker := time.NewTicker(2 * time.Second) defer ticker.Stop() - port := config.GetService(service) + port := config.GetServiceDebugPort(service) for { select { @@ -349,7 +349,6 @@ func WaitUntilPortListens(service string) bool { continue } - // Check if the port is listening address := fmt.Sprintf(":%d", port) // Try to connect to the port conn, err := net.DialTimeout("tcp", address, 1*time.Second) @@ -358,7 +357,7 @@ func WaitUntilPortListens(service string) bool { log.Println(fmt.Sprintf("%s service is ready to listen port %d", service, port)) return true } - log.Println(fmt.Sprintf("%v port is not ready %v\n", conn, err)) + log.Println(fmt.Sprintf("%s service is not ready on port %v. %v\n", service, port, err)) } } } diff --git a/tests/ociswrapper/wrapper/handlers/handler.go b/tests/ociswrapper/wrapper/handlers/handler.go index b1f27b13206..7f5a4955c6a 100644 --- a/tests/ociswrapper/wrapper/handlers/handler.go +++ b/tests/ociswrapper/wrapper/handlers/handler.go @@ -231,7 +231,7 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) { if strings.HasSuffix(key, "DEBUG_ADDR") { address := strings.Split(value.(string), ":") port, _ := strconv.Atoi(address[1]) - config.SetService(serviceName, port) + config.SetServiceDebugPort(serviceName, port) } } @@ -240,7 +240,7 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) { common.Wg.Add(1) go ocis.StartService(serviceName, serviceEnvMap) - success := ocis.WaitUntilPortListens(serviceName) + success := ocis.WaitForService(serviceName) if success { log.Println(fmt.Sprintf("Found Port for %s......", serviceName)) sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s started successfully", serviceName))