From 7f321ae7740185e68074a272bf0940ac8c515266 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Tue, 9 Aug 2022 10:14:46 +0200 Subject: [PATCH 1/2] fix(api): do not init db connection in event subscriber --- doc/API/centreon-api-v22.10.yaml | 2 +- src/EventSubscriber/UpdateEventSubscriber.php | 12 ++--- .../PlatformInstallationStatusContext.php | 52 +++++++++++++++++++ tests/api/behat.yml | 4 ++ .../PlatformInstallationStatus.feature | 18 +++++++ 5 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 tests/api/Context/PlatformInstallationStatusContext.php create mode 100644 tests/api/features/PlatformInstallationStatus.feature diff --git a/doc/API/centreon-api-v22.10.yaml b/doc/API/centreon-api-v22.10.yaml index 47d8a780ac9..9da16ed3042 100644 --- a/doc/API/centreon-api-v22.10.yaml +++ b/doc/API/centreon-api-v22.10.yaml @@ -3707,7 +3707,7 @@ paths: application/json: schema: type: object - required: ["installed_version", "has_upgrade_available"] + required: ["is_installed", "has_upgrade_available"] properties: is_installed: type: boolean diff --git a/src/EventSubscriber/UpdateEventSubscriber.php b/src/EventSubscriber/UpdateEventSubscriber.php index 254b78bc514..9c629695103 100644 --- a/src/EventSubscriber/UpdateEventSubscriber.php +++ b/src/EventSubscriber/UpdateEventSubscriber.php @@ -47,6 +47,10 @@ public function __construct( */ public static function getSubscribedEvents(): array { + if (! file_exists(_CENTREON_ETC_ . DIRECTORY_SEPARATOR . 'centreon.conf.php')) { + return []; + } + return [ KernelEvents::REQUEST => [ ['validateCentreonWebVersionOrFail', 35], @@ -55,19 +59,13 @@ public static function getSubscribedEvents(): array } /** - * validation centreon web installed version + * validate centreon web installed version when update endpoint is called * * @param RequestEvent $event * @throws \Exception */ public function validateCentreonWebVersionOrFail(RequestEvent $event): void { - $this->debug('Checking if database configuration file exists to know if centreon is already installed'); - if (! file_exists(_CENTREON_ETC_ . DIRECTORY_SEPARATOR . 'centreon.conf.php')) { - $this->debug('Centreon database configuration file not found'); - return; - } - $this->debug('Checking if route matches updates endpoint'); if ( $event->getRequest()->getMethod() === Request::METHOD_PATCH diff --git a/tests/api/Context/PlatformInstallationStatusContext.php b/tests/api/Context/PlatformInstallationStatusContext.php new file mode 100644 index 00000000000..e1bf8b4e561 --- /dev/null +++ b/tests/api/Context/PlatformInstallationStatusContext.php @@ -0,0 +1,52 @@ +getContainer()->execute( + 'mysql -e "DROP DATABASE centreon_storage"', + 'web' + ); + $this->getContainer()->execute( + 'mysql -e "DROP DATABASE centreon"', + 'web' + ); + $this->getContainer()->execute( + 'rm -f /etc/centreon/centreon.conf.php', + 'web' + ); + $this->getContainer()->execute( + 'rm -rf /var/cache/centreon/symfony', + 'web' + ); + } +} diff --git a/tests/api/behat.yml b/tests/api/behat.yml index 028cd4c2713..2fbb5af99ee 100644 --- a/tests/api/behat.yml +++ b/tests/api/behat.yml @@ -80,6 +80,10 @@ default: paths: [ "%paths.base%/features/PlatformInformation.feature" ] contexts: - Centreon\Test\Api\Context\PlatformInformationContext + platform_fresh_install: + paths: [ "%paths.base%/features/PlatformFreshInstall.feature" ] + contexts: + - Centreon\Test\Api\Context\PlatformFreshInstallContext platform_update: paths: [ "%paths.base%/features/PlatformUpdate.feature" ] contexts: diff --git a/tests/api/features/PlatformInstallationStatus.feature b/tests/api/features/PlatformInstallationStatus.feature new file mode 100644 index 00000000000..5df7be8f915 --- /dev/null +++ b/tests/api/features/PlatformInstallationStatus.feature @@ -0,0 +1,18 @@ +Feature: + In order to maintain centreon platform + As an administrator + I want to known the platform installation status + + Background: + Given a running instance of Centreon Web API + And the endpoints are described in Centreon Web API documentation + + Scenario: Update platform information + When I send a GET request to '/api/latest/platform/installation/status' + Then the response code should be "200" + And the JSON node "is_installed" should be equal to true + + Given Centreon Web is not installed + When I send a GET request to '/api/latest/platform/installation/status' + Then the response code should be "200" + And the JSON node "is_installed" should be equal to false From d7f56cebf44d57d2c99eb2b448c92448be6bdad2 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Tue, 9 Aug 2022 10:45:47 +0200 Subject: [PATCH 2/2] typo --- tests/api/behat.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/api/behat.yml b/tests/api/behat.yml index 2fbb5af99ee..975f73d260d 100644 --- a/tests/api/behat.yml +++ b/tests/api/behat.yml @@ -81,9 +81,9 @@ default: contexts: - Centreon\Test\Api\Context\PlatformInformationContext platform_fresh_install: - paths: [ "%paths.base%/features/PlatformFreshInstall.feature" ] + paths: [ "%paths.base%/features/PlatformInstallationStatus.feature" ] contexts: - - Centreon\Test\Api\Context\PlatformFreshInstallContext + - Centreon\Test\Api\Context\PlatformInstallationStatusContext platform_update: paths: [ "%paths.base%/features/PlatformUpdate.feature" ] contexts: