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 __future__ import print_function
21 from nepi.resources.linux.node import LinuxNode
26 class DummyEC(object):
31 def create_node(hostname, username = None, identity = None):
33 node = LinuxNode(ec, 1)
35 node.set("hostname", hostname)
38 node.set("username", username)
41 node.set("identity", identity)
43 # If we don't return the reference to the EC
44 # it will be released by the garbage collector since
45 # the resources only save a weak refernce to it.
48 def skipIfNotAlive(func):
50 def wrapped(*args, **kwargs):
52 if hostname != "localhost":
62 node, ec = create_node(hostname, username, identity)
64 if not node.is_alive():
65 print("*** WARNING: Skipping test %s: Node %s is not alive\n" % (
66 name, node.get("hostname")))
69 return func(*args, **kwargs)
73 def skipIfAnyNotAlive(func):
75 def wrapped(*args, **kwargs):
79 for i in range(len(argss)/2):
81 hostname = argss[i*2+1]
82 node, ec = create_node(hostname, username)
84 if not node.is_alive():
85 print("*** WARNING: Skipping test %s: Node %s is not alive\n" % (
86 name, node.get("hostname")))
89 return func(*args, **kwargs)
93 def skipIfAnyNotAliveWithIdentity(func):
95 def wrapped(*args, **kwargs):
98 for i in range(len(argss)/3):
100 hostname = argss[i*3+1]
101 identity = argss[i*3+2]
103 node, ec = create_node(hostname, username, identity)
105 if not node.is_alive():
106 print("*** WARNING: Skipping test %s: Node %s is not alive\n" % (
107 name, node.get("hostname")))
110 return func(*args, **kwargs)
115 def skipInteractive(func):
117 def wrapped(*args, **kwargs):
118 mode = os.environ.get("NEPI_INTERACTIVE_TEST", False)
119 mode = mode and mode.lower() in ['true', 'yes']
121 print("*** WARNING: Skipping test %s: Interactive mode off \n" % name)
124 return func(*args, **kwargs)
128 def skipIfNotPLCredentials(func):
130 def wrapped(*args, **kwargs):
131 pl_user = os.environ.get("PL_USER")
132 pl_pass = os.environ.get("PL_PASS")
133 if not (pl_user and pl_pass):
134 print("*** WARNING: Skipping test %s: Planetlab user, password and slicename not defined\n" % name)
137 return func(*args, **kwargs)
141 def skipIfNotPythonVersion(func):
143 def wrapped(*args, **kwargs):
144 if sys.version_info < 2.7:
145 print("*** WARNING: Skipping test %s: total_seconds() method doesn't exist\n" % name)
148 return func(*args, **kwargs)
152 def skipIfNotSfaCredentials(func):
154 def wrapped(*args, **kwargs):
155 sfa_user = os.environ.get("SFA_USER")
156 sfa_pk = os.environ.get("SFA_PK")
158 if not (sfa_user and os.path.exists(os.path.expanduser(sfa_pk))):
159 print("*** WARNING: Skipping test %s: SFA path to private key doesn't exist\n" % name)
162 return func(*args, **kwargs)
166 def skipIfNotSfi(func):
168 def wrapped(*args, **kwargs):
170 from sfa.client.sfi import Sfi
171 from sfa.util.xrn import hrn_to_urn
173 print("*** WARNING: Skipping test %s: sfi-client or sfi-common not installed\n" % name)
176 return func(*args, **kwargs)
180 def skipIf(cond, text):
181 def wrapped(func, text):
184 def banner(*args, **kwargs):
185 sys.stderr.write("*** WARNING: Skipping test %s: `%s'\n" %
190 return (lambda func: wrapped(func, text)) if cond else lambda func: func