diff --git a/tests/acceptance/bootstrap/OcisConfigContext.php b/tests/acceptance/bootstrap/OcisConfigContext.php index 187528864c9..e50101957fe 100644 --- a/tests/acceptance/bootstrap/OcisConfigContext.php +++ b/tests/acceptance/bootstrap/OcisConfigContext.php @@ -199,7 +199,7 @@ public function theConfigHasBeenSetToValue(TableNode $table): void { * @return void * @throws GuzzleException */ - public function theOcisServerHasExcludedService(string $service) { + public function theOcisServerHasServedServiceSeparately(string $service) { $response = OcisConfigHelper::startService($service); Assert::assertEquals( diff --git a/tests/ociswrapper/README.md b/tests/ociswrapper/README.md index b0c0a63cb8e..676cd2b30d2 100644 --- a/tests/ociswrapper/README.md +++ b/tests/ociswrapper/README.md @@ -125,7 +125,7 @@ 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/` +6. `POST /services/{service-name}` Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor. @@ -143,7 +143,7 @@ Also, see `./bin/ociswrapper help` for more information. - `200 OK` - oCIS server is stopped - `500 Internal Server Error` - Unable to stop oCIS server -7. `DELETE /services/` +7. `DELETE /services/{service-name}` Stop individually running oCIS service diff --git a/tests/ociswrapper/ocis/ocis.go b/tests/ociswrapper/ocis/ocis.go index 8ca3e1d7824..cab4b714bbc 100644 --- a/tests/ociswrapper/ocis/ocis.go +++ b/tests/ociswrapper/ocis/ocis.go @@ -29,6 +29,7 @@ var EnvConfigs = []string{} var runningServices = make(map[string]int) func Start(envMap []string) { + log.Println("Starting oCIS service........\n") StartService("", envMap) } @@ -37,7 +38,7 @@ func Stop() (bool, string) { stopSignal = true for service := range runningServices { - StopService(service) + go StopService(service) } success, message := waitUntilCompleteShutdown() @@ -188,14 +189,7 @@ func RunCommand(command string, inputs []string) (int, string) { return c.ProcessState.ExitCode(), cmdOutput } -func RunOcisService(service string, envMap []string) { - log.Println(fmt.Sprintf("Environment variable envMap: %s\n", envMap)) - StartService(service, envMap) -} - -// startService is a common function for starting a service (ocis or other) func StartService(service string, envMap []string) { - log.Println(fmt.Sprintf("Start service: %s with Environment variable envMap: %s\n", service, envMap)) // Initialize command args based on service presence cmdArgs := []string{"server"} // Default command args @@ -244,8 +238,8 @@ func StartService(service string, envMap []string) { runningServices[service] = cmd.Process.Pid } - for listservice, pid := range runningServices { - log.Println(fmt.Sprintf("Service started: %s with process and id: %v\n", listservice, pid)) + for listService, pid := range runningServices { + log.Println(fmt.Sprintf("%s service started with process id %v\n", listService, pid)) } // Read the logs when the 'ocis server' command is running @@ -303,7 +297,7 @@ func StartService(service string, envMap []string) { func StopService(service string) (bool, string) { pid, exists := runningServices[service] if !exists { - return false, fmt.Sprintf("Service %s is not running", service) + return false, fmt.Sprintf("Running service doesn't not include %s service", service) } process, err := os.FindProcess(pid) diff --git a/tests/ociswrapper/wrapper/handlers/handler.go b/tests/ociswrapper/wrapper/handlers/handler.go index f0b0c3660bc..06343cc135a 100644 --- a/tests/ociswrapper/wrapper/handlers/handler.go +++ b/tests/ociswrapper/wrapper/handlers/handler.go @@ -9,7 +9,6 @@ import ( "net/http" "ociswrapper/common" "ociswrapper/ocis" - "strings" ) type BasicResponse struct { @@ -206,29 +205,15 @@ func CommandHandler(res http.ResponseWriter, req *http.Request) { } func OcisServiceHandler(res http.ResponseWriter, req *http.Request) { - if req.Method != http.MethodPost && req.Method != http.MethodDelete { - sendResponse(res, http.StatusMethodNotAllowed, "Method not allowed") - return - } - - serviceName := strings.TrimPrefix(req.URL.Path, "/services/") - - if serviceName == "" { - sendResponse(res, http.StatusUnprocessableEntity, "Service name not specified") - return - } - + serviceName := req.PathValue("service") envMap := []string{fmt.Sprintf("OCIS_EXCLUDE_RUN_SERVICES=%s", serviceName)} if req.Method == http.MethodPost { // restart oCIS without service that need to start separately success, _ := ocis.Restart(envMap) if success { - // Clear `EnvConfigs` to prevent persistence of temporary changes - log.Println(fmt.Sprintf("Environment Config when service Post request has been hit: %s\n", ocis.EnvConfigs)) - var envBody map[string]interface{} - var envMap []string + var serviceEnvMap []string if req.Body != nil && req.ContentLength > 0 { var err error @@ -240,29 +225,27 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) { } for key, value := range envBody { - envMap = append(envMap, fmt.Sprintf("%s=%v", key, value)) + serviceEnvMap = append(serviceEnvMap, fmt.Sprintf("%s=%v", key, value)) } - log.Println(fmt.Sprintf("serviceName to start: %s\n", serviceName)) + log.Println(fmt.Sprintf("Starting oCIS service %s......", serviceName)) - go ocis.RunOcisService(serviceName, envMap) + go ocis.StartService(serviceName, serviceEnvMap) success, _ := ocis.WaitForConnection() if success { sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s started successfully", serviceName)) return } } - sendResponse(res, http.StatusInternalServerError, fmt.Sprintf("Failed to restart oCIS without service %s", serviceName)) - } - - if req.Method == http.MethodDelete { + } else if req.Method == http.MethodDelete { success, message := ocis.StopService(serviceName) if success { sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s stopped successfully", serviceName)) } else { sendResponse(res, http.StatusInternalServerError, message) } + } else { + sendResponse(res, http.StatusMethodNotAllowed, "Invalid method requested") } - } diff --git a/tests/ociswrapper/wrapper/wrapper.go b/tests/ociswrapper/wrapper/wrapper.go index 2c28077cd35..8c14006adf0 100644 --- a/tests/ociswrapper/wrapper/wrapper.go +++ b/tests/ociswrapper/wrapper/wrapper.go @@ -27,7 +27,7 @@ func Start(port string) { mux.HandleFunc("/command", handlers.CommandHandler) mux.HandleFunc("/stop", handlers.StopOcisHandler) mux.HandleFunc("/start", handlers.StartOcisHandler) - mux.HandleFunc("/services/", handlers.OcisServiceHandler) + mux.HandleFunc("/services/{service}", handlers.OcisServiceHandler) httpServer.Handler = mux