Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Comment thread
anurag4DSB marked this conversation as resolved.
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<AccountData>) invocation -> {
throw new VaultServiceException(HttpStatus.NOT_FOUND, "The account does not exist");
});

final Logger serviceLogger = (Logger) LoggerFactory.getLogger(ScalityOsisServiceImpl.class);
final ListAppender<ILoggingEvent> 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);
}
}
}
Loading