2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 from nepi.resources.linux.node import LinuxNode
24 class DummyEC(object):
29 def create_node(hostname, username = None, identity = None):
31 node = LinuxNode(ec, 1)
33 node.set("hostname", hostname)
36 node.set("username", username)
39 node.set("identity", identity)
41 # If we don't return the reference to the EC
42 # it will be released by the garbage collector since
43 # the resources only save a weak refernce to it.
46 def skipIfNotAlive(func):
48 def wrapped(*args, **kwargs):
50 if hostname != "localhost":
60 node, ec = create_node(hostname, username, identity)
62 if not node.is_alive():
63 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
64 name, node.get("hostname"))
67 return func(*args, **kwargs)
71 def skipIfAnyNotAlive(func):
73 def wrapped(*args, **kwargs):
77 for i in xrange(len(argss)/2):
79 hostname = argss[i*2+1]
80 node, ec = create_node(hostname, username)
82 if not node.is_alive():
83 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
84 name, node.get("hostname"))
87 return func(*args, **kwargs)
91 def skipIfAnyNotAliveWithIdentity(func):
93 def wrapped(*args, **kwargs):
96 for i in xrange(len(argss)/3):
98 hostname = argss[i*3+1]
99 identity = argss[i*3+2]
101 node, ec = create_node(hostname, username, identity)
103 if not node.is_alive():
104 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
105 name, node.get("hostname"))
108 return func(*args, **kwargs)
113 def skipInteractive(func):
115 def wrapped(*args, **kwargs):
116 mode = os.environ.get("NEPI_INTERACTIVE_TEST", False)
117 mode = mode and mode.lower() in ['true', 'yes']
119 print "*** WARNING: Skipping test %s: Interactive mode off \n" % name
122 return func(*args, **kwargs)
126 def skipIfNotPLCredentials(func):
128 def wrapped(*args, **kwargs):
129 pl_user = os.environ.get("PL_USER")
130 pl_pass = os.environ.get("PL_PASS")
131 if not (pl_user and pl_pass):
132 print "*** WARNING: Skipping test %s: Planetlab user, password and slicename not defined\n" % name
135 return func(*args, **kwargs)
139 def skipIfNotPythonVersion(func):
141 def wrapped(*args, **kwargs):
142 if sys.version_info < 2.7:
143 print "*** WARNING: Skipping test %s: total_seconds() method doesn't exist\n" % name
146 return func(*args, **kwargs)
150 def skipIfNotSfaCredentials(func):
152 def wrapped(*args, **kwargs):
153 sfa_user = os.environ.get("SFA_USER")
154 sfa_pk = os.environ.get("SFA_PK")
156 if not (sfa_user and os.path.exists(os.path.expanduser(sfa_pk))):
157 print "*** WARNING: Skipping test %s: SFA path to private key doesn't exist\n" % name
160 return func(*args, **kwargs)
164 def skipIfNotSfi(func):
166 def wrapped(*args, **kwargs):
168 from sfa.client.sfi import Sfi
169 from sfa.util.xrn import hrn_to_urn
171 print "*** WARNING: Skipping test %s: sfi-client or sfi-common not installed\n" % name
174 return func(*args, **kwargs)
178 def skipIf(cond, text):
179 def wrapped(func, text):
182 def banner(*args, **kwargs):
183 sys.stderr.write("*** WARNING: Skipping test %s: `%s'\n" %
188 return (lambda func: wrapped(func, text)) if cond else lambda func: func