~pwlars/ubuntu-test-cases/server-fix-ttyS0

« back to all changes in this revision

Viewing changes to testsuites/floodlight/test_daemons/test.py

  • Committer: James Page
  • Date: 2012-09-21 09:09:54 UTC
  • Revision ID: james.page@canonical.com-20120921090954-3nmgb8zwrx5xplvd
Added floodlight/openvswitch test suite

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import logging
 
2
import os.path
 
3
import subprocess
 
4
import unittest
 
5
import time
 
6
import urllib2
 
7
 
 
8
logging.basicConfig(level=logging.INFO)
 
9
 
 
10
class FloodlightDaemonTest(unittest.TestCase):
 
11
 
 
12
    def testOpenvSwitchDaemons(self):
 
13
        cmd = ["pgrep", "ovs-vswitchd"]
 
14
        logging.debug("Cmd: %s" % (cmd))
 
15
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
16
        logging.debug("Cmd output: %s", output)
 
17
        self.assertTrue(output.count('\n') >= 1,
 
18
                        "ovs-vswitchd not running or to many daemons running: %s" % output)
 
19
        cmd = ["pgrep", "ovsdb-server"]
 
20
        logging.debug("Cmd: %s" % (cmd))
 
21
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
22
        logging.debug("Cmd output: %s", output)
 
23
        self.assertTrue(output.count('\n') >= 1,
 
24
                        "ovsdb-server not running or to many daemons running: %s" % output)
 
25
 
 
26
    def testFloodlightDaemon(self):
 
27
        cmd = ["service", "floodlight", "status"]
 
28
        logging.debug("Cmd: %s" % (cmd))
 
29
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
30
        logging.debug("Cmd output: %s", output)
 
31
        self.assertTrue("running" in output,
 
32
                        "Floodlight daemon is not running: %s" % output)
 
33
 
 
34
    def testPorts(self):
 
35
        cmd = ["netstat", "-an"]
 
36
        logging.debug("Cmd: %s" % (cmd))
 
37
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
38
        logging.debug("Cmd output: %s", output)
 
39
        self.assertTrue(":::6633" in output,
 
40
                        "Floodlight Openflow Controller Port not found (6633)")
 
41
        self.assertTrue(":::8080" in output,
 
42
                        "Floodlight Web UI Port not found (8080)")
 
43
        self.assertTrue(":::6655" in output,
 
44
                        "Floodlight Debug Port not found (6655)")
 
45
 
 
46
    def testWebUI(self):
 
47
        local_host_url = 'http://localhost:8080/ui/index.html'
 
48
        try:
 
49
            fh = urllib2.urlopen(local_host_url)
 
50
        except urllib2.HTTPError, e:
 
51
            logging.error("Failed to open localhost, '%s' error", e)
 
52
            self.fail("Failed to connect to the localhost")
 
53
        output = fh.read()
 
54
        self.assertTrue('Floodlight is the awesomest OpenFlow controller, and you\'re running it right now.' in output,
 
55
                        output)
 
56
 
 
57
 
 
58
if __name__ == '__main__':
 
59
    unittest.main()