27
27
from testconfig import config
28
from urlparse import urlparse
29
# For Python 3.0 and later
30
from urllib.parse import urlparse
32
# Fall back to Python 2's urllib2
33
from urlparse import urlparse
30
35
# pip install nose-testconfig
33
38
# nosetests test_HP3ParClient_host.py -v --tc-file config.ini
36
class HP3ParClientBaseTestCase(unittest.TestCase):
41
class HP3ParClientBaseTestCase(unittest.TestCase):
38
43
user = config['TEST']['user']
39
44
password = config['TEST']['pass']
41
46
url_3par = config['TEST']['3par_url']
42
47
debug = config['TEST']['debug'].lower() == 'true'
43
48
unitTest = config['TEST']['unit'].lower() == 'true'
50
def setUp(self, withSSH=False):
47
52
cwd = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
50
55
self.printHeader('Using flask ' + self.flask_url)
51
self.cl = client.HP3ParClient(self.flask_url)
52
56
parsed_url = urlparse(self.flask_url)
53
57
userArg = '-user=%s' % self.user
54
58
passwordArg = '-password=%s' % self.password
57
61
script = 'test_HP3ParMockServer_flask.py'
58
62
path = "%s/%s" % (cwd, script)
60
self.mockServer = subprocess.Popen([sys.executable,
64
self.mockServer = subprocess.Popen([sys.executable,
65
stdout=subprocess.PIPE,
66
stderr=subprocess.PIPE,
69
stdout=subprocess.PIPE,
70
stderr=subprocess.PIPE,
67
71
stdin=subprocess.PIPE
69
73
except Exception as e:
76
self.cl = client.HP3ParClient(self.flask_url)
77
# SSH is not supported in flask, so not initializing
78
# those tests are expected to fail
73
80
self.printHeader('Using 3PAR ' + self.url_3par)
74
81
self.cl = client.HP3ParClient(self.url_3par)
83
# This seems to slow down the test cases, so only use this when
85
parsed_3par_url = urlparse(self.url_3par)
86
ip = parsed_3par_url.hostname.split(':').pop()
88
# Set the conn_timeout to None so that the ssh connections will
89
# use the default transport values which will allow the test
90
# case process to terminate after completing
91
self.cl.setSSHOptions(ip, self.user, self.password, conn_timeout=None)
92
except Exception as ex:
94
self.fail("failed to start ssh client")
77
97
self.cl.debug_rest(True)
79
99
self.cl.login(self.user, self.password)
81
102
def tearDown(self):
83
104
if self.unitTest :
84
105
#TODO: it seems to kill all the process except the last one...
86
107
self.mockServer.kill()
88
109
def printHeader(self, name):
89
print "\n##Start testing '%s'" % name
110
print("\n##Start testing '%s'" % name)
91
112
def printFooter(self, name):
92
print "##Compeleted testing '%s\n" % name
113
print("##Compeleted testing '%s\n" % name)
94
115
def findInDict(self, dic, key, value):
96
117
if key in i and i[key] == value :