~james-page/charms/oneiric/mysql/charm-tester

« back to all changes in this revision

Viewing changes to hooks/test.py

  • Committer: James Page
  • Date: 2011-08-10 14:25:05 UTC
  • Revision ID: james.page@canonical.com-20110810142505-e7e9vzag3o8flb48
Added hooks for testing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
3
# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
 
4
#
 
5
# This file is part of ubuntu-server-iso-testing.
 
6
 
7
# ubuntu-server-iso-testing is free software: you can redistribute it 
 
8
# and/or modify it under the terms of the GNU General Public License 
 
9
# as published by the Free Software Foundation, either version 3 of 
 
10
# the License, or (at your option) any later version.
 
11
 
12
# ubuntu-server-iso-testing is distributed in the hope that it will 
 
13
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
 
14
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with ubuntu-server-iso-testing.  If not, see 
 
19
# <http://www.gnu.org/licenses/>.
 
20
 
21
 
 
22
 
 
23
import logging
 
24
import os.path
 
25
import subprocess
 
26
import unittest
 
27
 
 
28
logging.basicConfig(level=logging.DEBUG)
 
29
 
 
30
class OpenSSHServerTest(unittest.TestCase):
 
31
 
 
32
    def testOpenSSHDaemon(self):
 
33
        cmd = ["pgrep", "sshd"]
 
34
        logging.debug("Cmd: %s" % (cmd))
 
35
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
36
        logging.debug("Cmd output: %s" % (output))
 
37
        self.assertNotEquals(output, "")
 
38
 
 
39
    def testOpenPorts(self):
 
40
        cmd = ["netstat", "-atuvpn"]
 
41
        logging.debug("Cmd: %s" % (cmd))
 
42
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
43
        logging.debug("Cmd output: %s" % (output))
 
44
        output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
 
45
                         output.strip().split('\n')[2:])
 
46
        self.assertEquals(len(output2), 2, output2)
 
47
 
 
48
if __name__ == '__main__':
 
49
    unittest.main()