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
|
#!/usr/bin/env python3
import amulet
import re
import unittest
seconds_to_wait = 20000
class TestDeploy(unittest.TestCase):
"""
Deployment test for the IBM DB2 charm.
"""
def setUp(self):
self.d = amulet.Deployment(series='xenial')
self.d.add('ibm-db2', '/root/charms/xenial/ibm-db2')
self.d.setup(seconds_to_wait)
self.d.sentry.wait(seconds_to_wait)
def test_deploy_with_placeholder_resource(self):
# The status message when using placeholder resources will include the
# string "ibm_db2_installer resource". If we see that, the test is
# successful.
sentry_re = re.compile('ibm_db2_installer resource')
self.d.sentry.wait_for_messages({"ibm-db2": sentry_re})
def test_deployed(self):
""" Test to see if the bundle deployed successfully. """
self.assertTrue(self.d.deployed)
db2_unit = self.d.sentry['ibm-db2'][0]
# Get the port num where db2 is running and check for netstat
output, code = db2_unit.run("su - db2inst1 -c 'db2 get dbm cfg'"
" | grep -i svce | cut -d'=' -f2")
if code != 0:
message = 'Unable to get the port number where DB2 is running.'
' Exiting before completing'
'rest of the verification tests.'
amulet.raise_status(amulet.FAIL, msg=message)
print('DB2 running in port num : %s' % output)
print('Checking netstat command')
cmd = "su - db2inst1 -c 'netstat -an' | grep LISTEN | grep %s" % output
output, code = db2_unit.run(cmd)
if code != 0:
message = 'Unable to get the port number where DB2 is running.'\
' Exiting before completing rest of the verification tests.'
amulet.raise_status(amulet.FAIL, msg=message)
print('Output of netstat command id %s' % output)
if __name__ == '__main__':
unittest.main()
|