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 as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.resources.linux.node import LinuxNode
25 class DummyEC(object):
30 def create_node(hostname, username = None, identity = None):
32 node = LinuxNode(ec, 1)
34 node.set("hostname", hostname)
37 node.set("username", username)
40 node.set("identity", identity)
42 # If we don't return the reference to the EC
43 # it will be released by the garbage collector since
44 # the resources only save a weak refernce to it.
47 def skipIfNotAlive(func):
49 def wrapped(*args, **kwargs):
51 if hostname != "localhost":
61 node, ec = create_node(hostname, username, identity)
63 if not node.is_alive():
64 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
65 name, node.get("hostname"))
68 return func(*args, **kwargs)
72 def skipIfAnyNotAlive(func):
74 def wrapped(*args, **kwargs):
78 for i in xrange(len(argss)/2):
80 hostname = argss[i*2+1]
81 node, ec = create_node(hostname, username)
83 if not node.is_alive():
84 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
85 name, node.get("hostname"))
88 return func(*args, **kwargs)
92 def skipIfAnyNotAliveWithIdentity(func):
94 def wrapped(*args, **kwargs):
97 for i in xrange(len(argss)/3):
99 hostname = argss[i*3+1]
100 identity = argss[i*3+2]
102 node, ec = create_node(hostname, username, identity)
104 if not node.is_alive():
105 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
106 name, node.get("hostname"))
109 return func(*args, **kwargs)
114 def skipInteractive(func):
116 def wrapped(*args, **kwargs):
117 mode = os.environ.get("NEPI_INTERACTIVE_TEST", False)
118 mode = mode and mode.lower() in ['true', 'yes']
120 print "*** WARNING: Skipping test %s: Interactive mode off \n" % name
123 return func(*args, **kwargs)
127 def skipIfNotPLCredentials(func):
129 def wrapped(*args, **kwargs):
130 pl_user = os.environ.get("PL_USER")
131 pl_pass = os.environ.get("PL_PASS")
132 if not (pl_user and pl_pass):
133 print "*** WARNING: Skipping test %s: Planetlab user, password and slicename not defined\n" % name
136 return func(*args, **kwargs)
140 def skipIfNotPythonVersion(func):
142 def wrapped(*args, **kwargs):
143 if sys.version_info < 2.7:
144 print "*** WARNING: Skipping test %s: total_seconds() method doesn't exist\n" % name
147 return func(*args, **kwargs)
151 def skipIfNotSfaCredentials(func):
153 def wrapped(*args, **kwargs):
154 sfa_user = os.environ.get("SFA_USER")
155 sfa_pk = os.environ.get("SFA_PK")
157 if not (sfa_user and os.path.exists(os.path.expanduser(sfa_pk))):
158 print "*** WARNING: Skipping test %s: SFA path to private key doesn't exist\n" % name
161 return func(*args, **kwargs)
165 def skipIfNotSfi(func):
167 def wrapped(*args, **kwargs):
169 from sfa.client.sfi import Sfi
170 from sfa.util.xrn import hrn_to_urn
172 print "*** WARNING: Skipping test %s: sfi-client or sfi-common not installed\n" % name
175 return func(*args, **kwargs)
179 def skipIf(cond, text):
180 def wrapped(func, text):
183 def banner(*args, **kwargs):
184 sys.stderr.write("*** WARNING: Skipping test %s: `%s'\n" %
189 return (lambda func: wrapped(func, text)) if cond else lambda func: func