~ibmcharmers/charms/trusty/layer-ibm-mobilefirst-server/devel

« back to all changes in this revision

Viewing changes to tests/10-bundles-test.py

  • Committer: Suchitra Venugopal
  • Date: 2016-05-04 09:59:42 UTC
  • Revision ID: suchvenu@in.ibm.com-20160504095942-f3hp9a4iydhbnw3i
DB2 layered charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
# This amulet test deploys the bundles.yaml file in this directory.
 
4
 
 
5
import os
 
6
import unittest
 
7
import yaml
 
8
import amulet
 
9
import sys
 
10
import time
 
11
import requests
 
12
 
 
13
seconds_to_wait = 20000
 
14
 
 
15
 
 
16
class BundleTest(unittest.TestCase):
 
17
    """ Create a class for testing the charm in the unit test framework. """
 
18
    @classmethod
 
19
    def setUpClass(cls):
 
20
        """ Set up an amulet deployment using the bundle. """
 
21
        d = amulet.Deployment(juju_env='local', series='trusty')
 
22
        # We have a contextual test, if no config is present, initialze the
 
23
        # test with an empty configuration set
 
24
        config = {}
 
25
        local_path = os.path.join(os.path.dirname(__file__), 'local.yaml')
 
26
        with open(local_path, "r") as fd:
 
27
           config = yaml.safe_load(fd)
 
28
 
 
29
        curl_url = config.get('ibm-repo').get('db2_curl_url')
 
30
        if not curl_url:
 
31
             message = 'Please provide the curl url from where the package can be downloaded.'
 
32
             amulet.raise_status(amulet.FAIL, msg=message)
 
33
             sys.exit(1)
 
34
        
 
35
        curl_opts =  config.get('ibm-repo').get('db2_curl_opts')
 
36
        if not curl_opts:
 
37
             message = 'Please provide the curl_opts to specify the credentials to download the packages.'
 
38
             amulet.raise_status(amulet.FAIL, msg=message)
 
39
             sys.exit(1)
 
40
 
 
41
 
 
42
        d.add('ibm-db2')
 
43
 
 
44
        d.configure('ibm-db2', { 'license_accepted': True, 
 
45
                                 'curl_url': curl_url, 
 
46
                                 'curl_opts': curl_opts })
 
47
        d.setup(seconds_to_wait)
 
48
        d.sentry.wait(seconds_to_wait)
 
49
        cls.d = d
 
50
 
 
51
 
 
52
 
 
53
    def test_deployed(self):
 
54
        """ Test to see if the bundle deployed successfully. """
 
55
        self.assertTrue(self.d.deployed)
 
56
 
 
57
        db2_unit = self.d.sentry['ibm-db2'][0]
 
58
        # Get the port num where db2 is running and check for netstat
 
59
        output, code = db2_unit.run("su - db2inst1 -c 'db2 get dbm cfg' | grep -i svce | cut -d'=' -f2")
 
60
        if code != 0:
 
61
          message = 'Unable to get the port number where DB2 is running. Exiting before completing rest of the verification tests.'
 
62
          amulet.raise_status(amulet.FAIL, msg=message)
 
63
        print('DB2 running in port num : %s' % output)
 
64
        print('Checking netstat command')
 
65
        cmd = "su - db2inst1 -c 'netstat -an' | grep LISTEN | grep %s" % output
 
66
        output, code = db2_unit.run(cmd)
 
67
        if code != 0:
 
68
         message = 'Unable to get the port number where DB2 is running. Exiting before completing rest of the verification tests.'
 
69
         amulet.raise_status(amulet.FAIL, msg=message)
 
70
        print('Output of netstat command id %s' % output)
 
71
 
 
72
if __name__ == '__main__':
 
73
    unittest.main()