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)
33 node.set("hostname", hostname)
35 node.set("username", username)
37 node.set("identity", identity)
39 # If we don't return the reference to the EC
40 # it will be released by the garbage collector since
41 # the resources only save a weak refernce to it.
44 def skipIfNotAlive(func):
46 def wrapped(*args, **kwargs):
48 if host != "localhost":
58 node, ec = create_node(host, user, identity)
60 if not node.is_alive():
61 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
62 name, node.get("hostname"))
65 return func(*args, **kwargs)
69 def skipIfAnyNotAlive(func):
71 def wrapped(*args, **kwargs):
74 for i in xrange(len(argss)/2):
76 hostname = argss[i*2+1]
77 node, ec = create_node(hostname, username)
79 if not node.is_alive():
80 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
81 name, node.get("hostname"))
84 return func(*args, **kwargs)
88 def skipInteractive(func):
90 def wrapped(*args, **kwargs):
91 mode = os.environ.get("NEPI_INTERACTIVE_TEST", False)
92 mode = mode and mode.lower() in ['true', 'yes']
94 print "*** WARNING: Skipping test %s: Interactive mode off \n" % name
97 return func(*args, **kwargs)
101 def skipIfNotPLCredentials(func):
103 def wrapped(*args, **kwargs):
104 pl_user = os.environ.get("PL_USER")
105 pl_pass = os.environ.get("PL_PASS")
106 if not (pl_user and pl_pass):
107 print "*** WARNING: Skipping test %s: Planetlab user, password and slicename not defined\n" % name
110 return func(*args, **kwargs)
114 def skipIfNotPythonVersion(func):
116 def wrapped(*args, **kwargs):
117 if sys.version_info < 2.7:
118 print "*** WARNING: Skipping test %s: total_seconds() method doesn't exist\n" % name
121 return func(*args, **kwargs)
125 def skipIfNotSfaCredentials(func):
127 def wrapped(*args, **kwargs):
128 sfa_user = os.environ.get("SFA_USER")
129 sfa_pk = os.environ.get("SFA_PK")
131 if not (sfa_user and os.path.exists(os.path.expanduser(sfa_pk))):
132 print "*** WARNING: Skipping test %s: SFA path to private key doesn't exist\n" % name
135 return func(*args, **kwargs)
139 def skipIfNotSfi(func):
141 def wrapped(*args, **kwargs):
143 from sfa.client.sfi import Sfi
144 from sfa.util.xrn import hrn_to_urn
146 print "*** WARNING: Skipping test %s: sfi-client or sfi-common not installed\n" % name
149 return func(*args, **kwargs)
153 def skipIf(cond, text):
154 def wrapped(func, text):
157 def banner(*args, **kwargs):
158 sys.stderr.write("*** WARNING: Skipping test %s: `%s'\n" %
163 return (lambda func: wrapped(func, text)) if cond else lambda func: func