summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/Driver/test.py.old
blob: 7e93feed25320bbc6e1d2cae10deb6ce6d119c53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'''
Created on Aug 10, 2011

@author: steger
'''
import unittest
from random import randint
from Example.Resources import PLnodes
from threading import Thread
from Example.credentials import noviCredential, sonomaCredential
from SshExec import SshExec
from SOAPClient import SOAPClient

class Test(unittest.TestCase):
    testnodes = map(lambda x: x.get_ipaddress("eth0")[0], PLnodes)
    cred_novi = noviCredential
    url_sonoma = "http://complex.elte.hu/~steger/sonoma/user.wsdl"
    cred_sonoma = sonomaCredential
    

    def setUp(self):
        pass

    def tearDown(self):
        pass
    
    def gettestnode(self):
        '''
        @summary: Return a test node IP address chosen random
        @return: ip address
        @rtype: string 
        '''
        return self.testnodes[randint(1, len(self.testnodes))-1]

    def test_helloworldWithMaster(self):
        '''
        @summary: Execute remote command in the name of the testuser authenticated with the master key
        '''
        proc = SshExec(host = self.gettestnode(), credential = self.cred_novi)
        result = proc.execute().read()
        self.assertTrue(result.startswith("helloworld @ "), "Remote command output differs from expected")

    def echoWithMaster(self, address):
        '''
        @summary: Execute remote echo command in the name of the testuser authenticated with the master key
        @param address: ip address of the remote machine
        @type address: string  
        '''
        try:
            n = randint(0, 10000)
            command = "echo %d" % n
            proc = SshExec(host = address, credential = self.cred_novi, command = command)
            result = proc.execute().read()
            self.assertTrue(result.strip() == str(n), "Remote command @%s output differs from expected: (%s != %d)" % (address, result, n))
        except Exception, e:
            self.assertFalse(True, "Got an error %s" % e)

    def test_echoWithMaster(self):
        '''
        @summary: Execute remote echo command in the name of the testuser authenticated with the master key
        '''
        self.echoWithMaster(self.gettestnode())
        
    def test_distributedEcho(self):
        '''
        @summary: Execute parallel remote echo commands in a distributed fashion
        '''
        threads = []
        for n in self.testnodes:
            t = Thread(target = self.echoWithMaster, args = (n,))
            t.daemon = True
            t.start()
            threads.append(t)
        while len(threads):
            t = threads.pop()
            t.join(5)

    def test_parallelEcho(self):
        '''
        @summary: Execute parallel remote echo commands in a test node
        '''
        N = 20
        n = self.gettestnode()
        threads = []
        while N:
            N -= 1
            t = Thread(target = self.echoWithMaster, args = (n,))
            t.daemon = True
            t.start()
            threads.append(t)
        while len(threads):
            t = threads.pop()
            t.join(5)

    def test_stress(self):
        '''
        @summary: Consecutively execute parallel remote echo commands in a distributed fashion
        '''
        threads = []
        for n in self.testnodes:
            N = randint(5, 20)
            while N:
                N -= 1
                t = Thread(target = self.echoWithMaster, args = (n,))
                t.daemon = True
                t.start()
                threads.append(t)
        while len(threads):
            t = threads.pop()
            t.join(5)
    
    def test_soap(self):
        '''
        @summary: Run SONoMA getNodeList
        '''
        client = SOAPClient(self.url_sonoma)
        resources = client.service.getNodeList(filter = "AVAILABLE")
        self.assertGreater(len(resources), 0, "sonoma reports no nodes") 

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_helloworldWithMaster']
    unittest.main()