~ibmcharmers/charms/xenial/ibm-db2/trunk

« back to all changes in this revision

Viewing changes to tests/01-deploy.py

  • Committer: Ankammarao Chittet
  • Date: 2017-02-22 09:10:29 UTC
  • Revision ID: achittet@in.ibm.com-20170222091029-tquu7bjhik7i9pxa
2nd checkin for IBM-DB2 charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
import amulet
 
4
import re
 
5
import unittest
 
6
 
 
7
seconds_to_wait = 20000
 
8
 
 
9
 
 
10
class TestDeploy(unittest.TestCase):
 
11
    """
 
12
    Deployment test for the IBM DB2 charm.
 
13
    """
 
14
    def setUp(self):
 
15
        self.d = amulet.Deployment(series='xenial')
 
16
        self.d.add('ibm-db2', '/root/charms/xenial/ibm-db2')
 
17
        self.d.setup(seconds_to_wait)
 
18
        self.d.sentry.wait(seconds_to_wait)
 
19
 
 
20
    def test_deploy_with_placeholder_resource(self):
 
21
        # The status message when using placeholder resources will include the
 
22
        # string "ibm_db2_installer resource". If we see that, the test is
 
23
        # successful.
 
24
        sentry_re = re.compile('ibm_db2_installer resource')
 
25
        self.d.sentry.wait_for_messages({"ibm-db2": sentry_re})
 
26
 
 
27
    def test_deployed(self):
 
28
        """ Test to see if the bundle deployed successfully. """
 
29
        self.assertTrue(self.d.deployed)
 
30
 
 
31
        db2_unit = self.d.sentry['ibm-db2'][0]
 
32
        # Get the port num where db2 is running and check for netstat
 
33
        output, code = db2_unit.run("su - db2inst1 -c 'db2 get dbm cfg'"
 
34
                                    " | grep -i svce | cut -d'=' -f2")
 
35
        if code != 0:
 
36
            message = 'Unable to get the port number where DB2 is running.'
 
37
            ' Exiting before completing'
 
38
            'rest of the verification tests.'
 
39
            amulet.raise_status(amulet.FAIL, msg=message)
 
40
        print('DB2 running in port num : %s' % output)
 
41
        print('Checking netstat command')
 
42
        cmd = "su - db2inst1 -c 'netstat -an' | grep LISTEN | grep %s" % output
 
43
        output, code = db2_unit.run(cmd)
 
44
        if code != 0:
 
45
            message = 'Unable to get the port number where DB2 is running.'\
 
46
                   ' Exiting before completing rest of the verification tests.'
 
47
            amulet.raise_status(amulet.FAIL, msg=message)
 
48
        print('Output of netstat command id %s' % output)
 
49
 
 
50
 
 
51
if __name__ == '__main__':
 
52
    unittest.main()