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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/env python3
# This amulet test deploys the bundles.yaml file in this directory.
import os
import unittest
import yaml
import amulet
import sys
import time
import requests
seconds_to_wait = 20000
class BundleTest(unittest.TestCase):
""" Create a class for testing the charm in the unit test framework. """
@classmethod
def setUpClass(cls):
""" Set up an amulet deployment using the bundle. """
d = amulet.Deployment(juju_env='local', series='trusty')
# We have a contextual test, if no config is present, initialze the
# test with an empty configuration set
config = {}
local_path = os.path.join(os.path.dirname(__file__), 'local.yaml')
with open(local_path, "r") as fd:
config = yaml.safe_load(fd)
curl_url = config.get('ibm-repo').get('db2_curl_url')
if not curl_url:
message = 'Please provide the curl url from where the package can be downloaded.'
amulet.raise_status(amulet.FAIL, msg=message)
sys.exit(1)
curl_opts = config.get('ibm-repo').get('db2_curl_opts')
if not curl_opts:
message = 'Please provide the curl_opts to specify the credentials to download the packages.'
amulet.raise_status(amulet.FAIL, msg=message)
sys.exit(1)
d.add('ibm-db2')
d.configure('ibm-db2', { 'license_accepted': True,
'curl_url': curl_url,
'curl_opts': curl_opts })
d.setup(seconds_to_wait)
d.sentry.wait(seconds_to_wait)
cls.d = d
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()
|