fix atest host statjson

Bug: chromium:991005
Change-Id: I30b7113c33e1674c547dba2386faa0baa6368a58
Reviewed-on: https://chromium-review.googlesource.com/1735794
Tested-by: Gregory Nisbet <gregorynisbet@google.com>
Commit-Ready: Gregory Nisbet <gregorynisbet@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Garry Wang <xianuowang@chromium.org>
diff --git a/cli/host.py b/cli/host.py
index 65a34b0..ea4538c 100644
--- a/cli/host.py
+++ b/cli/host.py
@@ -430,8 +430,11 @@
             # This enables the steps (renaming the host,
             # copying the inventory information to skylab) to be doable in
             # either order.
-            hostname = _remove_hostname_suffix(stats_map["hostname"],
-                MIGRATED_HOST_SUFFIX)
+            hostname = _remove_hostname_suffix_if_present(
+                stats_map["hostname"],
+                MIGRATED_HOST_SUFFIX
+            )
+
             labels = self._cleanup_labels(labels)
             attrs = [{"key": k, "value": v} for k, v in attributes.iteritems()]
             out_labels = process_labels(labels, platform=stats_map["platform"])
@@ -1108,14 +1111,12 @@
     return hostname + suffix
 
 
-def _remove_hostname_suffix(hostname, suffix):
+def _remove_hostname_suffix_if_present(hostname, suffix):
     """Remove the suffix from the hostname."""
-    if not hostname.endswith(suffix):
-        raise InvalidHostnameError(
-                'Cannot remove "%s" as it doesn\'t contain the suffix.' %
-                suffix)
-
-    return hostname[:len(hostname) - len(suffix)]
+    if hostname.endswith(suffix):
+        return hostname[:len(hostname) - len(suffix)]
+    else:
+        return hostname
 
 
 class host_rename(host):