21255932 Only use pkg validation routines if available
authorMatt Keenan <matt.keenan@oracle.com>
Fri, 03 Jul 2015 01:17:45 +0100
changeset 4590 d39971eb17ab
parent 4588 913c846a2d69
child 4597 967ce4c39e36
21255932 Only use pkg validation routines if available
components/openstack/ironic/files/drivers/modules/solaris_ipmitool.py
--- a/components/openstack/ironic/files/drivers/modules/solaris_ipmitool.py	Thu Jul 02 12:30:56 2015 -0700
+++ b/components/openstack/ironic/files/drivers/modules/solaris_ipmitool.py	Fri Jul 03 01:17:45 2015 +0100
@@ -38,8 +38,7 @@
 
 from lockfile import LockFile, LockTimeout
 from oslo.config import cfg
-from pkg.fmri import is_valid_pkg_name
-from pkg.misc import valid_pub_prefix, valid_pub_url
+
 from scp import SCPClient
 
 from ironic.common import boot_devices, exception, images, keystone, states, \
@@ -57,6 +56,9 @@
 PLATFORM = platform.system()
 if PLATFORM != "SunOS":
     import tarfile
+else:
+    from pkg.fmri import is_valid_pkg_name
+    from pkg.misc import valid_pub_prefix, valid_pub_url
 
 
 AI_OPTS = [
@@ -1105,7 +1107,7 @@
     if not url.path:
         raise exception.InvalidParameterValue(_(
             "Missing IPS package name in fmri (%s).") % (fmri))
-    else:
+    elif PLATFORM == "SunOS":
         # Validate package name
         if not is_valid_pkg_name(url.path.strip("/")):
             raise exception.InvalidParameterValue(_(
@@ -1135,13 +1137,14 @@
                 "Malformed IPS publisher must be of format "
                 "[email protected] (%s).") % (pub))
 
-        if not valid_pub_prefix(name):
-            raise exception.InvalidParameterValue(_(
-                "Malformed IPS publisher name (%s).") % (name))
-
-        if not valid_pub_url(origin):
-            raise exception.InvalidParameterValue(_(
-                "Malformed IPS publisher origin (%s).") % (origin))
+        if PLATFORM == "SunOS":
+            if not valid_pub_prefix(name):
+                raise exception.InvalidParameterValue(_(
+                    "Malformed IPS publisher name (%s).") % (name))
+
+            if not valid_pub_url(origin):
+                raise exception.InvalidParameterValue(_(
+                    "Malformed IPS publisher origin (%s).") % (origin))
 
 
 def _fetch_and_create(task, obj_type, obj_name, obj_uri, aiservice, mac,