Merge pull request #11107 from owncloud/empty-service-congig-after-service-stopped

[tests-only][full-ci]Support services rollback in ociswrapper
This commit is contained in:
Amrita authored and GitHub committed 2025-03-13 09:06:03 +05:45
commit c2736dfb47
5 files changed
+74

No files matched your search

@@ -135,4 +135,13 @@ class OcisConfigHelper {
$url = self::getWrapperUrl() . "/services/" . $service;
return self::sendRequest($url, "POST", \json_encode($envs));
}
/**
* @return ResponseInterface
* @throws GuzzleException
*/
public static function rollbackServices(): ResponseInterface {
$url = self::getWrapperUrl() . "/services/rollback";
return self::sendRequest($url, "DELETE");
}
}
@@ -221,6 +221,16 @@ class OcisConfigContext implements Context {
* @AfterScenario @env-config
*
* @return void
* @throws GuzzleException
*/
public function rollback(): void {
$this->rollbackServices();
$this->rollbackOcis();
}
/**
* @return void
* @throws GuzzleException
*/
public function rollbackOcis(): void {
$response = OcisConfigHelper::rollbackOcis();
@@ -230,4 +240,17 @@ class OcisConfigContext implements Context {
"Failed to rollback ocis server. Check if oCIS is started with ociswrapper."
);
}
/**
* @return void
* @throws GuzzleException
*/
public function rollbackServices(): void {
$response = OcisConfigHelper::rollbackServices();
Assert::assertEquals(
200,
$response->getStatusCode(),
"Failed to rollback services."
);
}
}
+9
View File
@@ -177,3 +177,12 @@ Also, see `./bin/ociswrapper help` for more information.
- `200 OK` - service is successfully reconfigured
- `500 Internal Server Error` - service is not running
9. `DELETE /services/rollback`
Stop and rollback all service configurations to the starting point.
Returns:
- `200 OK` - rollback is successful
- `500 Internal Server Error` - oCIS server is not running
@@ -278,3 +278,35 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) {
}
sendResponse(res, http.StatusMethodNotAllowed, "Method Not Allowed")
}
func RollbackServicesHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodDelete {
sendResponse(res, http.StatusMethodNotAllowed, "")
return
}
var rollbackFailed bool
var message string
for serviceName := range ocis.ServiceEnvConfigs {
if serviceName != "ocis" {
if success := ocis.WaitForServiceStatus(serviceName, true); success {
success, message := ocis.StopService(serviceName)
log.Println(message)
if !success {
rollbackFailed = true
break
}
delete(ocis.ServiceEnvConfigs, serviceName)
}
}
}
if rollbackFailed {
sendResponse(res, http.StatusInternalServerError, message)
} else {
sendResponse(res, http.StatusOK, "All services have been rolled back successfully")
}
}
+1
View File
@@ -28,6 +28,7 @@ func Start(port string) {
mux.HandleFunc("/stop", handlers.StopOcisHandler)
mux.HandleFunc("/start", handlers.StartOcisHandler)
mux.HandleFunc("/services/{service}", handlers.OcisServiceHandler)
mux.HandleFunc("/services/rollback", handlers.RollbackServicesHandler)
httpServer.Handler = mux