3
# This amulet test deploys the bundles.yaml file in this directory.
13
seconds_to_wait = 20000
16
class BundleTest(unittest.TestCase):
17
""" Create a class for testing the charm in the unit test framework. """
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
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)
29
curl_url = config.get('ibm-repo').get('db2_curl_url')
31
message = 'Please provide the curl url from where the package can be downloaded.'
32
amulet.raise_status(amulet.FAIL, msg=message)
35
curl_opts = config.get('ibm-repo').get('db2_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)
44
d.configure('ibm-db2', { 'license_accepted': True,
46
'curl_opts': curl_opts })
47
d.setup(seconds_to_wait)
48
d.sentry.wait(seconds_to_wait)
53
def test_deployed(self):
54
""" Test to see if the bundle deployed successfully. """
55
self.assertTrue(self.d.deployed)
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")
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)
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)
72
if __name__ == '__main__':