From 5b9f6b76465249d6b51a5820130258cfd0a52256 Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Wed, 9 Apr 2014 09:52:56 -0600 Subject: [PATCH] JCLOUDS-317: Fix NPE when ComputeService.listNodes() Follow-up to f4aaf70 --- .../NovaComputeServiceContextModule.java | 39 ++++++++++++------- .../ServerInZoneToNodeMetadataTest.java | 9 ++++- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java index 311d4abf24..cd00ce1082 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java @@ -236,21 +236,30 @@ public class NovaComputeServiceContextModule extends @VisibleForTesting public static final Map toPortableNodeStatus = ImmutableMap - . builder().put(Server.Status.ACTIVE, NodeMetadata.Status.RUNNING)// - .put(Server.Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)// - .put(Server.Status.DELETED, NodeMetadata.Status.TERMINATED)// - .put(Server.Status.PAUSED, NodeMetadata.Status.SUSPENDED)// - .put(Server.Status.RESIZE, NodeMetadata.Status.PENDING)// - .put(Server.Status.VERIFY_RESIZE, NodeMetadata.Status.PENDING)// - .put(Server.Status.REVERT_RESIZE, NodeMetadata.Status.PENDING)// - .put(Server.Status.BUILD, NodeMetadata.Status.PENDING)// - .put(Server.Status.PASSWORD, NodeMetadata.Status.PENDING)// - .put(Server.Status.REBUILD, NodeMetadata.Status.PENDING)// - .put(Server.Status.ERROR, NodeMetadata.Status.ERROR)// - .put(Server.Status.REBOOT, NodeMetadata.Status.PENDING)// - .put(Server.Status.HARD_REBOOT, NodeMetadata.Status.PENDING)// - .put(Server.Status.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED)// - .put(Server.Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build(); + . builder() + .put(Server.Status.ACTIVE, NodeMetadata.Status.RUNNING) + .put(Server.Status.BUILD, NodeMetadata.Status.PENDING) + .put(Server.Status.DELETED, NodeMetadata.Status.TERMINATED) + .put(Server.Status.ERROR, NodeMetadata.Status.ERROR) + .put(Server.Status.HARD_REBOOT, NodeMetadata.Status.PENDING) + .put(Server.Status.MIGRATING, NodeMetadata.Status.PENDING) + .put(Server.Status.PASSWORD, NodeMetadata.Status.PENDING) + .put(Server.Status.PAUSED, NodeMetadata.Status.SUSPENDED) + .put(Server.Status.REBOOT, NodeMetadata.Status.PENDING) + .put(Server.Status.REBUILD, NodeMetadata.Status.PENDING) + .put(Server.Status.RESCUE, NodeMetadata.Status.PENDING) + .put(Server.Status.RESIZE, NodeMetadata.Status.PENDING) + .put(Server.Status.REVERT_RESIZE, NodeMetadata.Status.PENDING) + .put(Server.Status.SHELVED, NodeMetadata.Status.SUSPENDED) + .put(Server.Status.SHELVED_OFFLOADED, NodeMetadata.Status.SUSPENDED) + .put(Server.Status.SHUTOFF, NodeMetadata.Status.SUSPENDED) + .put(Server.Status.SOFT_DELETED, NodeMetadata.Status.TERMINATED) + .put(Server.Status.STOPPED, NodeMetadata.Status.SUSPENDED) + .put(Server.Status.SUSPENDED, NodeMetadata.Status.SUSPENDED) + .put(Server.Status.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED) + .put(Server.Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED) + .put(Server.Status.VERIFY_RESIZE, NodeMetadata.Status.PENDING) + .build(); @Singleton @Provides diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java index 7ef9fa7047..72b82d5023 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java @@ -196,7 +196,14 @@ public class ServerInZoneToNodeMetadataTest { assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131", "76.32.1.231")); } - // TODO: clean up this syntax + @Test + public void testPortableNodeStatusNotNull() { + for (Server.Status serverStatus: Server.Status.values()) { + assertNotNull(NovaComputeServiceContextModule.toPortableNodeStatus.get(serverStatus)); + } + } + + // TODO: clean up this syntax private void checkHardwareAndImageStatus(Hardware expectedHardware, Hardware existingHardware, String expectedImageId, OperatingSystem expectedOs, Image existingImage) {