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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## [Unreleased]

### Changed
- A pool registration that fails at the first API call now says why: no API endpoint answered
(check the addresses, the network and the TLS fingerprint; the token was not checked), the
connection broke or timed out after the request was sent, the cluster refused the token, the cluster has no such project, or the cluster answered with an
error. It no longer says "with the supplied credentials" when the cluster could not be reached.
- When a VM starts, each of its volumes' NQN ACL is set to the VM's host alone; NQNs of other
hosts, including any added by hand on the cluster, are removed (with `ipAcl=true`, the IP ACL
follows). Attach to a running VM and live migration still add the host and keep the others,
and so does a start for which the plugin cannot read the VM (it logs "granting without removing
other hosts").

### Known limitations
- Attaches and live migrations take longer while a Lightbits node is down (in the lab, up to
about 15 seconds more per attach); none fails. See
[docs/known-limitations-and-issues.md](docs/known-limitations-and-issues.md).

### Known issues
- A management server stop during a live migration can leave the previous host in the volumes'
access lists until the VM's next start; see
Expand Down
5 changes: 5 additions & 0 deletions docs/known-limitations-and-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ what was known at each release.
attach, VM start or migration. To apply it at once, detach and attach the volume, stop and
start (or migrate) the VM, or combine the change with a size increase (INSTALL.md, "QoS
policy").
- **Attaches and live migrations are slower while a Lightbits node is down.** Before an attach,
the host connects to the cluster's paths, which waits on the missing node. In the lab, with
one node of three cut off, an attach took up to about 15 seconds longer and a live migration
about 22 seconds instead of 4 to 6. No operation failed, and the times return to normal once
the node is back.
- **Volume statistics pause for a minute after a failed read.** If the Lightbits API does not
answer, the plugin stops reading that pool's statistics for 60 seconds and reports the last
figures; a volume with no earlier figure reports an error for that round. Running VMs and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,8 @@ private String execute(String method, String path, String jsonBody, String ifMat
long deadlineNanos) {
boolean read = "GET".equals(method);
LightbitsApiException last = null;
// a failure that reached an endpoint (a read only: a mutation stops at the first one)
LightbitsApiException reached = null;
for (int round = 1; round <= rounds; round++) {
int start = preferred;
// endpoints known to be down go last: still tried, but not before the live ones
Expand Down Expand Up @@ -1402,6 +1404,9 @@ private String execute(String method, String path, String jsonBody, String ifMat
if (!read && !e.isNeverSent()) {
throw e;
}
if (!e.isNeverSent()) {
reached = e;
}
last = e;
failedVia = base;
}
Expand All @@ -1410,6 +1415,12 @@ private String execute(String method, String path, String jsonBody, String ifMat
sleep(retryBackoffMillis * round);
}
}
if (last != null && last.isNeverSent() && reached != null) {
// the last attempt never left the host, but an earlier one reached an endpoint: the
// failure as a whole is not "never sent"
throw new LightbitsApiException(Kind.TRANSIENT, last.getMessage() + "; an earlier attempt reached an endpoint: "
+ reached.getMessage(), last);
}
throw last;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.datastore.client.LightbitsApiClient;
import org.apache.cloudstack.storage.datastore.client.LightbitsApiException;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
import org.apache.cloudstack.storage.datastore.util.LightbitsPoolConfig;
import org.apache.cloudstack.storage.datastore.util.LightbitsUtil;
Expand Down Expand Up @@ -147,6 +148,41 @@ void refuseEnvironmentInUseElsewhere(LightbitsPoolConfig cfg, LightbitsApiClient
* needs the Spring-wired managed context, so it is exercised by the live/Marvin
* tests rather than unit tests. This method isolates the unit-testable logic.
*/
/**
* The registration error, worded by cause: a cluster that did not answer points the operator at the
* network, a refused token at the token, a missing project at the project name.
*/
static String projectAccessError(LightbitsPoolConfig cfg, RuntimeException e) {
String head = "cannot access Lightbits project '" + cfg.getProject() + "' at " + cfg.apiEndpoint() + ": ";
if (!(e instanceof LightbitsApiException)) {
return head + e.getMessage();
}
LightbitsApiException api = (LightbitsApiException) e;
switch (api.getKind()) {
case AUTH:
return head + "the cluster refused the token (HTTP " + api.getHttpStatus() + "): " + e.getMessage()
+ ": check the JWT is a project-admin token for this project";
case NOT_FOUND:
return head + "the cluster has no such project (HTTP 404): " + e.getMessage()
+ ": check the project name in the URL";
case TRANSIENT:
if (api.isNeverSent()) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return head + "no API endpoint answered: " + e.getMessage()
+ ": check the addresses and port in the URL, that they are reachable from the management"
+ " server, and the TLS fingerprint; the token was not checked";
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
if (api.getHttpStatus() < 0) {
return head + "no complete answer from the API (a request reached an endpoint, but the connection"
+ " broke, timed out or the cluster answered with an error): " + e.getMessage() + ": check the"
+ " network to the cluster and the cluster's health, and try again";
}
return head + "the cluster answered with an error (HTTP " + api.getHttpStatus() + "): " + e.getMessage()
+ ": check the cluster's health and try again";
default:
return head + e.getMessage();
}
}

public PreflightResult preflight(Map<String, Object> dsInfos) {
String url = (String) dsInfos.get("url");
@SuppressWarnings("unchecked")
Expand All @@ -167,9 +203,7 @@ public PreflightResult preflight(Map<String, Object> dsInfos) {
LOG.info("Lightbits: verified access to project '{}'{}", cfg.getProject(),
projectUuid == null ? "" : " (uuid=" + projectUuid + ")");
} catch (RuntimeException e) {
throw new IllegalArgumentException("cannot access Lightbits project '" + cfg.getProject()
+ "' at " + cfg.apiEndpoint() + " with the supplied credentials: " + e.getMessage()
+ ": check the JWT is a project-admin token for this project and that the project exists");
throw new IllegalArgumentException(projectAccessError(cfg, e));
}

refuseEnvironmentInUseElsewhere(cfg, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.cloudstack.storage.datastore.client.LightbitsApiClient;
Expand Down Expand Up @@ -156,11 +157,78 @@ void preflightRejectsWhenProjectAccessDenied() {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> lc.preflight(dsInfos("lightbits://h/default?environment=cs1", "jwt")));
assertTrue(e.getMessage().contains("cannot access Lightbits project"), e.getMessage());
assertTrue(e.getMessage().contains("refused the token"), e.getMessage());
assertTrue(e.getMessage().contains("project-admin"), e.getMessage());
assertFalse(e.getMessage().contains("no API endpoint answered"), e.getMessage());
}

@Test
void preflightRejectsUnreachableClusterWithActionableMessage() {
void preflightNamesTheNetworkWhenNoEndpointAnswers() throws Exception {
int closed;
try (java.net.ServerSocket s = new java.net.ServerSocket(0)) {
closed = s.getLocalPort();
}
lc.setClientFactory(cfg -> new LightbitsApiClient(
"http://localhost:" + closed, cfg.getJwt(), cfg.getProject(),
java.net.http.HttpClient.newHttpClient(), 1));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> lc.preflight(dsInfos("lightbits://h/default?environment=cs1", "jwt")));
assertTrue(e.getMessage().contains("no API endpoint answered"), e.getMessage());
assertTrue(e.getMessage().contains("the token was not checked"), e.getMessage());
assertFalse(e.getMessage().contains("refused the token"), e.getMessage());
assertFalse(e.getMessage().contains("credentials"), e.getMessage());
}

@Test
void aBrokenAnswerIsNotReportedAsAnUncheckedToken() {
wm.stubFor(get(urlPathEqualTo("/api/v2/projects/default/volumes"))
.willReturn(aResponse().withFault(com.github.tomakehurst.wiremock.http.Fault.CONNECTION_RESET_BY_PEER)));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> lc.preflight(dsInfos("lightbits://h/default?environment=cs1", "jwt")));
assertTrue(e.getMessage().contains("no complete answer"), e.getMessage());
assertFalse(e.getMessage().contains("the token was not checked"), e.getMessage());
}

@Test
void anEndpointThatAnsweredIsNotHiddenByALaterRefusedConnection() throws Exception {
int closed;
try (java.net.ServerSocket s = new java.net.ServerSocket(0)) {
closed = s.getLocalPort();
}
wm.stubFor(get(urlPathEqualTo("/api/v2/projects/default/volumes"))
.willReturn(aResponse().withStatus(503).withBody("unavailable")));
// the answering endpoint first, the refusing one last: the last failure is the refused connection
lc.setClientFactory(cfg -> new LightbitsApiClient(
List.of("http://localhost:" + wm.port(), "http://localhost:" + closed), cfg.getJwt(), cfg.getProject(),
java.net.http.HttpClient.newHttpClient(), 1));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> lc.preflight(dsInfos("lightbits://h/default?environment=cs1", "jwt")));
assertFalse(e.getMessage().contains("the token was not checked"), e.getMessage());
assertTrue(e.getMessage().contains("an earlier attempt reached an endpoint"), e.getMessage());
}

@Test
void preflightNamesTheProjectWhenTheClusterHasNone() {
wm.stubFor(get(urlPathEqualTo("/api/v2/projects/default/volumes"))
.willReturn(aResponse().withStatus(404).withBody("{\"message\":\"not found\"}")));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> lc.preflight(dsInfos("lightbits://h/default?environment=cs1", "jwt")));
assertTrue(e.getMessage().contains("no such project"), e.getMessage());
assertFalse(e.getMessage().contains("refused the token"), e.getMessage());
}

@Test
void preflightNamesAClusterErrorAsSuch() {
wm.stubFor(get(urlPathEqualTo("/api/v2/projects/default/volumes"))
.willReturn(aResponse().withStatus(503).withBody("unavailable")));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> lc.preflight(dsInfos("lightbits://h/default?environment=cs1", "jwt")));
assertTrue(e.getMessage().contains("answered with an error (HTTP 503)"), e.getMessage());
assertFalse(e.getMessage().contains("refused the token"), e.getMessage());
}

@Test
void preflightRejectsARefusedTokenWithoutPrintingIt() {
wm.stubFor(get(urlPathEqualTo("/api/v2/projects/default/volumes"))
.willReturn(aResponse().withStatus(401).withBody("denied")));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
Expand Down
Loading