From 8818e37952d7aa639746ac4113eec8da9d259bcd Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 25 Nov 2026 13:44:43 -0500 Subject: [PATCH 1/2] flasharray: skip hosts missing on the array and say so on attach --- .../adapter/flasharray/FlashArrayAdapter.java | 44 +++++++----- .../flasharray/FlashArrayAdapterTest.java | 70 +++++++++++++++++++ 2 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java diff --git a/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java b/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java index fae94bb1bea0..920779377c93 100644 --- a/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java +++ b/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java @@ -153,11 +153,13 @@ public String attach(ProviderAdapterContext context, ProviderAdapterDataObject d try { FlashArrayList list = null; FlashArrayHost host = getHost(hostname); - if (host != null) { - list = POST("/connections?host_names=" + host.getName() + "&volume_names=" + volumeName, null, - new TypeReference>() { - }); + if (host == null) { + throw new RuntimeException("Host [" + hostname + "] not found in FlashArray at [" + url + + "]. The host object on the array must have the same name as the CloudStack host"); } + list = POST("/connections?host_names=" + host.getName() + "&volume_names=" + volumeName, null, + new TypeReference>() { + }); if (list == null || list.getItems() == null || list.getItems().size() == 0) { throw new RuntimeException("Volume attach did not return lun information"); @@ -180,7 +182,7 @@ public String attach(ProviderAdapterContext context, ProviderAdapterDataObject d if (list != null && list.getItems() != null) { for (FlashArrayConnection conn : list.getItems()) { if (conn.getHost() != null && conn.getHost().getName() != null && - (conn.getHost().getName().equals(hostname) || conn.getHost().getName().equals(hostname.substring(0, hostname.indexOf('.')))) && + (conn.getHost().getName().equals(hostname) || conn.getHost().getName().equals(shortHostName(hostname))) && conn.getLun() != null) { return "" + conn.getLun(); } @@ -571,25 +573,31 @@ public boolean canAccessHost(ProviderAdapterContext context, String hostname) { return false; } - private FlashArrayHost getHost(String hostname) { - FlashArrayList list = null; + FlashArrayHost getHost(String hostname) { + FlashArrayHost host = findHost(hostname); + String shortName = shortHostName(hostname); + if (host == null && !shortName.equals(hostname)) { + host = findHost(shortName); + } + return host; + } + // The array answers 400 for an unknown host name, which is a normal "not found" here + FlashArrayHost findHost(String name) { try { - list = GET("/hosts?names=" + hostname, + FlashArrayList list = GET("/hosts?names=" + name, new TypeReference>() { }); + return (FlashArrayHost) getFlashArrayItem(list); } catch (Exception e) { - + logger.debug("Host [" + name + "] not found in FlashArray at [" + url + "]: " + e.getMessage()); + return null; } + } - if (list == null) { - if (hostname.indexOf('.') > 0) { - list = GET("/hosts?names=" + hostname.substring(0, (hostname.indexOf('.'))), - new TypeReference>() { - }); - } - } - return (FlashArrayHost) getFlashArrayItem(list); + static String shortHostName(String hostname) { + int dot = hostname.indexOf('.'); + return dot > 0 ? hostname.substring(0, dot) : hostname; } private String getAccessToken() { @@ -941,7 +949,7 @@ private FlashArrayVolume getSnapshot(String snapshotName) { } private Object getFlashArrayItem(FlashArrayList list) { - if (list.getItems() != null && list.getItems().size() > 0) { + if (list != null && list.getItems() != null && list.getItems().size() > 0) { return list.getItems().get(0); } else { return null; diff --git a/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java b/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java new file mode 100644 index 000000000000..c967641f79f8 --- /dev/null +++ b/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java @@ -0,0 +1,70 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.datastore.adapter.flasharray; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +public class FlashArrayAdapterTest { + + private FlashArrayAdapter adapter() { + return mock(FlashArrayAdapter.class, Mockito.CALLS_REAL_METHODS); + } + + @Test + public void shortHostNameStripsDomain() { + Assert.assertEquals("b08-36", FlashArrayAdapter.shortHostName("b08-36.lab.local")); + Assert.assertEquals("b08-36", FlashArrayAdapter.shortHostName("b08-36")); + } + + @Test + public void getHostReturnsNullWhenHostIsMissing() { + FlashArrayAdapter adapter = adapter(); + doReturn(null).when(adapter).findHost("b08-36"); + + Assert.assertNull(adapter.getHost("b08-36")); + Assert.assertFalse(adapter.canAccessHost(null, "b08-36")); + } + + @Test + public void getHostFallsBackToShortName() { + FlashArrayAdapter adapter = adapter(); + FlashArrayHost host = new FlashArrayHost(); + doReturn(null).when(adapter).findHost("b08-36.lab.local"); + doReturn(host).when(adapter).findHost("b08-36"); + + Assert.assertSame(host, adapter.getHost("b08-36.lab.local")); + Assert.assertTrue(adapter.canAccessHost(null, "b08-36.lab.local")); + } + + @Test + public void getHostDoesNotRetryShortNameWithoutDomain() { + FlashArrayAdapter adapter = adapter(); + FlashArrayHost host = new FlashArrayHost(); + doReturn(host).when(adapter).findHost("b08-36"); + + Assert.assertSame(host, adapter.getHost("b08-36")); + verify(adapter, Mockito.times(1)).findHost("b08-36"); + verify(adapter, never()).findHost("b08-36.lab.local"); + } +} From 9bb26dd5794080d2cda94307afda80c2fbb3d3b6 Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Wed, 2 Dec 2026 18:15:55 -0500 Subject: [PATCH 2/2] flasharray: only a rejected name means the host is missing --- .../adapter/flasharray/FlashArrayAdapter.java | 25 +++++++++++++----- .../flasharray/FlashArrayAdapterTest.java | 26 ++++++++++++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java b/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java index 920779377c93..190a611862f3 100644 --- a/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java +++ b/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java @@ -582,19 +582,28 @@ FlashArrayHost getHost(String hostname) { return host; } - // The array answers 400 for an unknown host name, which is a normal "not found" here + // The array answers 400 for an unknown host name, which is a normal "not found" here. + // Any other failure (array unreachable, login failed) is passed on as it is. FlashArrayHost findHost(String name) { try { - FlashArrayList list = GET("/hosts?names=" + name, - new TypeReference>() { - }); - return (FlashArrayHost) getFlashArrayItem(list); - } catch (Exception e) { + return (FlashArrayHost) getFlashArrayItem(listHosts(name)); + } catch (FlashArrayRequestRejectedException e) { logger.debug("Host [" + name + "] not found in FlashArray at [" + url + "]: " + e.getMessage()); return null; } } + FlashArrayList listHosts(String name) { + return GET("/hosts?names=" + name, new TypeReference>() { + }); + } + + static class FlashArrayRequestRejectedException extends CloudRuntimeException { + FlashArrayRequestRejectedException(String message) { + super(message); + } + } + static String shortHostName(String hostname) { int dot = hostname.indexOf('.'); return dot > 0 ? hostname.substring(0, dot) : hostname; @@ -1128,6 +1137,10 @@ private T GET(String path, final TypeReference type) { throw new CloudRuntimeException( "Authentication or Authorization to FlashArray [" + url + "] with user [" + username + "] failed, unable to retrieve session token"); + } else if (statusCode == 400) { + throw new FlashArrayRequestRejectedException( + "Unexpected HTTP response code from FlashArray on GET [" + request.getURI() + "] - [" + + statusCode + "] - " + response.getStatusLine().getReasonPhrase()); } else { throw new CloudRuntimeException( "Unexpected HTTP response code from FlashArray on GET [" + request.getURI() + "] - [" diff --git a/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java b/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java index c967641f79f8..0397e19975cb 100644 --- a/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java +++ b/plugins/storage/volume/flasharray/src/test/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapterTest.java @@ -17,18 +17,24 @@ package org.apache.cloudstack.storage.datastore.adapter.flasharray; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import org.apache.logging.log4j.LogManager; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; +import com.cloud.utils.exception.CloudRuntimeException; + public class FlashArrayAdapterTest { private FlashArrayAdapter adapter() { - return mock(FlashArrayAdapter.class, Mockito.CALLS_REAL_METHODS); + FlashArrayAdapter adapter = mock(FlashArrayAdapter.class, Mockito.CALLS_REAL_METHODS); + adapter.logger = LogManager.getLogger(FlashArrayAdapter.class); + return adapter; } @Test @@ -67,4 +73,22 @@ public void getHostDoesNotRetryShortNameWithoutDomain() { verify(adapter, Mockito.times(1)).findHost("b08-36"); verify(adapter, never()).findHost("b08-36.lab.local"); } + + @Test + public void findHostReturnsNullWhenArrayRejectsTheName() { + FlashArrayAdapter adapter = adapter(); + doThrow(new FlashArrayAdapter.FlashArrayRequestRejectedException("400")) + .when(adapter).listHosts("b08-36"); + + Assert.assertNull(adapter.findHost("b08-36")); + } + + @Test(expected = CloudRuntimeException.class) + public void findHostPassesOnOtherFailures() { + FlashArrayAdapter adapter = adapter(); + doThrow(new CloudRuntimeException("Error sending request to FlashArray")) + .when(adapter).listHosts("b08-36"); + + adapter.findHost("b08-36"); + } }