[ONOS-5098] Fix the IP release issue when rebooting VMs

Change-Id: I05d8228ccfdc04de12e2a5998f041bb93779923c
diff --git a/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
index b7c5669..ed039f6 100644
--- a/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
+++ b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
@@ -225,6 +225,15 @@
     @Override
     public Ip4Address releaseIP(HostId hostId) {
         if (allocationMap.containsKey(hostId)) {
+            // If the IP has been assigned with Option_RangeNotEnforced,
+            // we do not release the IP address nor remove the host from HostService.
+            // Therefore, if the IP is assigned statically, the IP needs to be released statically.
+            Versioned<IpAssignment> assignmentVersioned = allocationMap.get(hostId);
+            if (Versioned.valueOrNull(assignmentVersioned) != null &&
+                    assignmentVersioned.value().assignmentStatus().equals(Option_RangeNotEnforced)) {
+                return null;
+            }
+
             IpAssignment newAssignment = IpAssignment.builder(allocationMap.get(hostId).value())
                     .assignmentStatus(IpAssignment.AssignmentStatus.Option_Expired)
                     .build();