Do not load 'maasng' w/o 'netaddr' python library
Change-Id: I11c900335b0316eaef3e4e4f00e5c547ada69d07
Related: PROD-27273
diff --git a/_modules/maasng.py b/_modules/maasng.py
index 29a2c07..72f22b7 100644
--- a/_modules/maasng.py
+++ b/_modules/maasng.py
@@ -21,7 +21,6 @@
import logging
import time
import urllib2
-import netaddr
# Salt utils
from salt.exceptions import CommandExecutionError, SaltInvocationError
@@ -41,12 +40,17 @@
}
# Import third party libs
-HAS_MASS = False
+try:
+ import netaddr
+ HAS_NETADDR = True
+except ImportError:
+ HAS_NETADDR = False
+
try:
from maas_client import MAASClient, MAASDispatcher, MAASOAuth
HAS_MASS = True
except ImportError:
- LOG.debug('Missing MaaS client module is Missing. Skipping')
+ HAS_MASS = False
def __virtual__():
@@ -54,9 +58,11 @@
Only load this module if maas-client
is installed on this minion.
"""
- if HAS_MASS:
- return 'maasng'
- return False
+ if not HAS_NETADDR:
+ return False, "'netaddr' python library is unavailable"
+ if not HAS_MASS:
+ return False, "MaaS client library is unavailable"
+ return 'maasng'
APIKEY_FILE = '/var/lib/maas/.maas_credentials'