1
0
mirror of https://github.com/owncloud/ocis.git synced 2026-10-23 23:29:02 +03:00
Files
ocis/tests/acceptance/TestHelpers/OcisConfigHelper.php
nirajacharya2 84c0641d7c [tests-only][full-ci] health check for k8s services when restarting services using ociswrapper (#12014)
* test: attach response body to the error message
test: use helper method to determine k8s

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: wait k8s service using health checks

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: store initial env

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: fix intial env load

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: wait for old pod to be deleted

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: improve logging

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: improve logging

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: increase wait timeout

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: separate functions

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: check if env updated

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: remove unnecessary frontend service env

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: fix service config

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: revert service config

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: check service health

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: check grpc server

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: handle missing port

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: do not count emtpy value env

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: log req-res timestamp

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: save initial env and reuse

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: delete user with retry

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: check grpc after health cehck

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: unset extra envs

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: fix public link test

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: disable grpc checks

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: fix test

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

* test: retry on 500 without explicit wait

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>

---------

Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
Co-authored-by: Saw-jan <saw.jan.grg3e@gmail.com>
2026-06-22 09:37:21 +02:00

170 lines
4.1 KiB
PHP

<?php declare(strict_types=1);
/**
* ownCloud
*
* @author Sajan Gurung <sajan@jankaritech.com>
* @copyright Copyright (c) 2023 Sajan Gurung sajan@jankaritech.com
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace TestHelpers;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\ResponseInterface;
/**
* A helper class for configuring oCIS server
*/
class OcisConfigHelper {
/**
* @param string $url
* @param string $method
* @param ?string $body
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function sendRequest(
string $url,
string $method,
?string $body = "",
): ResponseInterface {
$client = HttpRequestHelper::createClient();
$request = new Request(
$method,
$url,
[],
$body,
);
try {
$response = $client->send($request);
} catch (ConnectException $e) {
throw new \Error(
"Cannot connect to the ociswrapper at the moment,"
. "make sure that ociswrapper is running before proceeding with the test run.\n"
. $e->getMessage(),
);
} catch (GuzzleException $ex) {
$response = $ex->getResponse();
if ($response === null) {
throw $ex;
}
}
return $response;
}
/**
* @return string
*/
public static function getWrapperUrl(): string {
$url = \getenv("OCIS_WRAPPER_URL");
if ($url === false) {
$url = "http://localhost:5200";
}
return $url;
}
/**
* @return bool
*/
public static function isK8s(): bool {
if (\getenv('K8S') === "true") {
return true;
}
return false;
}
/**
* @param array $envs
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function reConfigureOcis(array $envs): ResponseInterface {
$url = self::getWrapperUrl() . "/config";
return self::sendRequest($url, "PUT", \json_encode($envs));
}
/**
* @param array $envs
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function reConfigureOcisK8s(array $envs): ResponseInterface {
$url = self::getWrapperUrl() . "/k8s/config";
$response = self::sendRequest($url, "PUT", \json_encode($envs));
return $response;
}
/**
* @return ResponseInterface
* @throws GuzzleException
*/
public static function rollbackOcis(): ResponseInterface {
$url = self::getWrapperUrl() . "/rollback";
return self::sendRequest($url, "DELETE");
}
/**
* @return ResponseInterface
* @throws GuzzleException
*/
public static function stopOcis(): ResponseInterface {
$url = self::getWrapperUrl() . "/stop";
return self::sendRequest($url, "POST");
}
/**
* @return ResponseInterface
* @throws GuzzleException
*/
public static function startOcis(): ResponseInterface {
$url = self::getWrapperUrl() . "/start";
return self::sendRequest($url, "POST");
}
/**
* this method stops the running oCIS instance,
* restarts oCIS without specific services,
* and then starts the excluded services separately.
*
* @param string $service
* @param array $envs
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function startService(string $service, array $envs = []): ResponseInterface {
$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");
}
}