From e028049602dd1dfff9b6de8854a147d1f18a135e Mon Sep 17 00:00:00 2001 From: Roiy Zysman Date: Sat, 28 Nov 2026 20:24:36 +0000 Subject: [PATCH 1/4] Name the cause when pool registration cannot reach the project; document slower attaches with a node down Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 ++++ docs/known-limitations-and-issues.md | 5 +++ .../LightbitsPrimaryDataStoreLifeCycle.java | 35 ++++++++++++++-- .../LightbitsLifeCyclePreflightTest.java | 41 ++++++++++++++++++- 4 files changed, 86 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a8156..c5a85e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + 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 diff --git a/docs/known-limitations-and-issues.md b/docs/known-limitations-and-issues.md index f83e64c..03810ea 100644 --- a/docs/known-limitations-and-issues.md +++ b/docs/known-limitations-and-issues.md @@ -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 diff --git a/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java b/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java index e2557b1..6fa7066 100644 --- a/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java +++ b/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java @@ -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; @@ -147,6 +148,36 @@ 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.getHttpStatus() < 0) { + 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"; + } + 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 dsInfos) { String url = (String) dsInfos.get("url"); @SuppressWarnings("unchecked") @@ -167,9 +198,7 @@ public PreflightResult preflight(Map 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); diff --git a/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java b/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java index 95b8898..f742026 100644 --- a/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java +++ b/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java @@ -156,11 +156,50 @@ 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 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, From 3e8a647d58e116ef8174e5cbaf230e2714c8b167 Mon Sep 17 00:00:00 2001 From: Roiy Zysman Date: Sun, 29 Nov 2026 08:03:55 +0000 Subject: [PATCH 2/4] Registration error: a broken answer is not reported as an unchecked token Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- .../lifecycle/LightbitsPrimaryDataStoreLifeCycle.java | 7 ++++++- .../lifecycle/LightbitsLifeCyclePreflightTest.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a85e9..ff39268 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ### 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 - cluster refused the token, the cluster has no such project, or the cluster answered with an + 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 diff --git a/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java b/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java index 6fa7066..d38d03c 100644 --- a/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java +++ b/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java @@ -166,11 +166,16 @@ static String projectAccessError(LightbitsPoolConfig cfg, RuntimeException e) { return head + "the cluster has no such project (HTTP 404): " + e.getMessage() + ": check the project name in the URL"; case TRANSIENT: - if (api.getHttpStatus() < 0) { + if (api.isNeverSent()) { 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"; } + if (api.getHttpStatus() < 0) { + return head + "no complete answer from the API (the connection broke or timed out after the request" + + " was sent): " + 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: diff --git a/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java b/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java index f742026..342991a 100644 --- a/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java +++ b/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java @@ -178,6 +178,16 @@ void preflightNamesTheNetworkWhenNoEndpointAnswers() throws Exception { 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 preflightNamesTheProjectWhenTheClusterHasNone() { wm.stubFor(get(urlPathEqualTo("/api/v2/projects/default/volumes")) From fc80c2b4d935bd9cfe771a35377407e5f3f4a13b Mon Sep 17 00:00:00 2001 From: Roiy Zysman Date: Sun, 29 Nov 2026 08:10:42 +0000 Subject: [PATCH 3/4] Registration error: report an unchecked token only when no attempt reached an endpoint Co-Authored-By: Claude Opus 5.5 --- .../datastore/client/LightbitsApiClient.java | 11 +++++++++++ .../LightbitsPrimaryDataStoreLifeCycle.java | 6 +++--- .../LightbitsLifeCyclePreflightTest.java | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java b/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java index 05adfd6..4a3dc67 100644 --- a/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java +++ b/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java @@ -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 @@ -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; } @@ -1410,6 +1415,12 @@ private String execute(String method, String path, String jsonBody, String ifMat sleep(retryBackoffMillis * round); } } + if (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; } diff --git a/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java b/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java index d38d03c..0209a44 100644 --- a/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java +++ b/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsPrimaryDataStoreLifeCycle.java @@ -172,9 +172,9 @@ static String projectAccessError(LightbitsPoolConfig cfg, RuntimeException e) { + " server, and the TLS fingerprint; the token was not checked"; } if (api.getHttpStatus() < 0) { - return head + "no complete answer from the API (the connection broke or timed out after the request" - + " was sent): " + e.getMessage() + ": check the network to the cluster and the cluster's health," - + " and try again"; + 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"; diff --git a/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java b/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java index 342991a..5c85d53 100644 --- a/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java +++ b/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/LightbitsLifeCyclePreflightTest.java @@ -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; @@ -188,6 +189,24 @@ void aBrokenAnswerIsNotReportedAsAnUncheckedToken() { 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")) From 0459fb93e28507be0d28aad208acb9917d267a7d Mon Sep 17 00:00:00 2001 From: Roiy Zysman Date: Sun, 29 Nov 2026 08:59:55 +0000 Subject: [PATCH 4/4] API client: guard the failover's last failure against null Co-Authored-By: Claude Opus 5.5 --- .../cloudstack/storage/datastore/client/LightbitsApiClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java b/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java index 4a3dc67..0505b19 100644 --- a/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java +++ b/src/main/java/org/apache/cloudstack/storage/datastore/client/LightbitsApiClient.java @@ -1415,7 +1415,7 @@ private String execute(String method, String path, String jsonBody, String ifMat sleep(retryBackoffMillis * round); } } - if (last.isNeverSent() && reached != null) { + 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: "