~ubuntu-branches/ubuntu/utopic/python-hp3parclient/utopic

« back to all changes in this revision

Viewing changes to test/test_HP3ParClient_base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-02-11 08:27:52 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140211082752-skkw726mt9vibkea
Tags: 3.0.0-0ubuntu1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import pprint
26
26
import inspect
27
27
from testconfig import config
28
 
from urlparse import urlparse
 
28
try:
 
29
    # For Python 3.0 and later
 
30
    from urllib.parse import urlparse
 
31
except ImportError:
 
32
    # Fall back to Python 2's urllib2
 
33
    from urlparse import urlparse
29
34
 
30
35
# pip install nose-testconfig
31
36
 
33
38
# nosetests test_HP3ParClient_host.py -v --tc-file config.ini
34
39
 
35
40
 
36
 
class HP3ParClientBaseTestCase(unittest.TestCase):     
 
41
class HP3ParClientBaseTestCase(unittest.TestCase):
37
42
 
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'
44
 
        
45
 
    def setUp(self):
46
 
            
 
49
 
 
50
    def setUp(self, withSSH=False):
 
51
 
47
52
        cwd = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
48
 
            
 
53
 
49
54
        if self.unitTest :
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)
59
63
            try :
60
 
                self.mockServer = subprocess.Popen([sys.executable, 
61
 
                                                    path, 
 
64
                self.mockServer = subprocess.Popen([sys.executable,
 
65
                                                    path,
62
66
                                                    userArg,
63
67
                                                    passwordArg,
64
 
                                                    portArg], 
65
 
                                               stdout=subprocess.PIPE, 
66
 
                                               stderr=subprocess.PIPE, 
 
68
                                                    portArg],
 
69
                                               stdout=subprocess.PIPE,
 
70
                                               stderr=subprocess.PIPE,
67
71
                                               stdin=subprocess.PIPE
68
72
                                               )
69
73
            except Exception as e:
70
74
                pass
71
 
            time.sleep(1) 
 
75
            time.sleep(1)
 
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
72
79
        else :
73
80
            self.printHeader('Using 3PAR ' + self.url_3par)
74
81
            self.cl = client.HP3ParClient(self.url_3par)
75
 
            
 
82
            if withSSH:
 
83
                # This seems to slow down the test cases, so only use this when
 
84
                # requested
 
85
                parsed_3par_url = urlparse(self.url_3par)
 
86
                ip = parsed_3par_url.hostname.split(':').pop()
 
87
                try:
 
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:
 
93
                    print ex
 
94
                    self.fail("failed to start ssh client")
 
95
 
76
96
        if self.debug :
77
97
            self.cl.debug_rest(True)
78
 
         
 
98
 
79
99
        self.cl.login(self.user, self.password)
80
100
 
 
101
 
81
102
    def tearDown(self):
82
103
        self.cl.logout()
83
104
        if self.unitTest :
84
105
            #TODO: it seems to kill all the process except the last one...
85
 
            #don't know why 
 
106
            #don't know why
86
107
            self.mockServer.kill()
87
108
 
88
109
    def printHeader(self, name):
89
 
        print "\n##Start testing '%s'" % name
 
110
        print("\n##Start testing '%s'" % name)
90
111
 
91
112
    def printFooter(self, name):
92
 
        print "##Compeleted testing '%s\n" % name
93
 
        
 
113
        print("##Compeleted testing '%s\n" % name)
 
114
 
94
115
    def findInDict(self, dic, key, value):
95
116
        for i in dic :
96
117
            if key in i and i[key] == value :