From 06b3b73c031f47828f5b431f448b1d92c87a1676 Mon Sep 17 00:00:00 2001 From: Anurag Mittal <1321012+anurag4DSB@users.noreply.github.com> Date: Fri, 26 Jun 2026 10:56:46 +0200 Subject: [PATCH] OSIS-155: do not log the expected headTenant pre-create 404 as an error --- .../service/impl/ScalityOsisServiceImpl.java | 3 +- .../impl/ScalityOsisServiceTenantTests.java | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/osis-core/src/main/java/com/scality/osis/service/impl/ScalityOsisServiceImpl.java b/osis-core/src/main/java/com/scality/osis/service/impl/ScalityOsisServiceImpl.java index 6b5c7132..c17bf70d 100644 --- a/osis-core/src/main/java/com/scality/osis/service/impl/ScalityOsisServiceImpl.java +++ b/osis-core/src/main/java/com/scality/osis/service/impl/ScalityOsisServiceImpl.java @@ -907,7 +907,8 @@ public void headTenant(String tenantId) { // and for other errors a generic exception should be thrown such as RuntimeException // Post testing with Vmware OSE 2.2.0.1, OSE expects a 404 in any error scenario and does not handle any other error code // Reference: https://developer.vmware.com/apis/1034#/tenant/headTenant - logger.error("Head Tenant error. Error details: ", e); + // OSE probes headTenant before the account exists during tenant activation, so this expected + // pre-create 404 is not logged as an error here; the 404 is still rethrown for OSE compatibility. throw new NotFoundException("Head Tenant error. Error details: " + e.getMessage()); } } diff --git a/osis-core/src/test/java/com/scality/osis/service/impl/ScalityOsisServiceTenantTests.java b/osis-core/src/test/java/com/scality/osis/service/impl/ScalityOsisServiceTenantTests.java index b13dc5f5..6fb58e5a 100644 --- a/osis-core/src/test/java/com/scality/osis/service/impl/ScalityOsisServiceTenantTests.java +++ b/osis-core/src/test/java/com/scality/osis/service/impl/ScalityOsisServiceTenantTests.java @@ -1,5 +1,9 @@ package com.scality.osis.service.impl; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import com.scality.osis.model.OsisTenant; import com.scality.osis.model.PageOfTenants; import com.scality.osis.model.exception.BadRequestException; @@ -8,6 +12,7 @@ import com.scality.vaultclient.dto.*; import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import com.scality.osis.model.exception.NotFoundException; @@ -399,4 +404,41 @@ void testHeadTenant400() { scalityOsisServiceUnderTest.headTenant("bad_tenant_id"); }); } + + /** + * During tenant activation OSE does a headTenant existence check before the account + * exists, so the platform answers with a 404 and OSIS rethrows NotFoundException. That is + * the expected pre-create path: the service must not log it as an error nor dump a stack + * trace. This pins that the misleading "invalid account ID" stack trace stays gone. + */ + @Test + void testHeadTenantPreCreateNotFoundIsNotLoggedAsError() { + // Setup: account does not exist yet, platform returns a 404 + when(vaultAdminMock.getAccount(any(GetAccountRequestDTO.class))) + .thenAnswer((Answer) invocation -> { + throw new VaultServiceException(HttpStatus.NOT_FOUND, "The account does not exist"); + }); + + final Logger serviceLogger = (Logger) LoggerFactory.getLogger(ScalityOsisServiceImpl.class); + final ListAppender appender = new ListAppender<>(); + appender.start(); + serviceLogger.addAppender(appender); + + try { + // Contract: still a 404 for the caller + assertThrows(NotFoundException.class, + () -> scalityOsisServiceUnderTest.headTenant(SAMPLE_TENANT_ID)); + + // The expected pre-create 404 must not be logged at ERROR or WARN by the service, + // and must not carry a stack trace. + assertTrue(appender.list.stream().noneMatch(e -> e.getLevel() == Level.ERROR), + "the expected pre-create 404 must not be logged at ERROR"); + assertTrue(appender.list.stream().noneMatch(e -> e.getLevel() == Level.WARN), + "the expected pre-create 404 must not be logged at WARN"); + assertTrue(appender.list.stream().allMatch(e -> e.getThrowableProxy() == null), + "the expected pre-create 404 must not dump a stack trace"); + } finally { + serviceLogger.detachAppender(appender); + } + } }