Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/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 urllib
# Lots of prereqs on this charm (eg: java), so give it a large timeout
seconds_to_wait = 1000
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()
# We have a contextual test, if no config is present, initialze the
# test with an empty configuration set
config = {}
cfgpath = os.path.join(os.path.dirname(__file__), 'local.yaml')
if os.path.exists(cfgpath):
config = load_config(cfgpath)
bundle_path = os.path.join(os.path.dirname(__file__), 'bundles.yaml')
with open(bundle_path, 'r') as bundle_file:
contents = yaml.safe_load(bundle_file)
d.load(contents)
# Software doesn't actually install until you accept the license
import pdb; pdb.set_trace()
d.configure('db2', config)
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)
# Python unit testing frameworks only invokes methods prefixed with test_
# this will only be called when implicitly invoked
def load_config(config_path):
with open(config_path, 'r') as f:
bundle_options = yaml.safe_load(f)
if 'db2_url' not in bundle_options.keys():
raise ValueError("db2_url is a required configuration value")
if 'db2_package_name' not in bundle_options.keys():
raise ValueError("db2_package is a required configuration value")
return bundle_options
if __name__ == '__main__':
unittest.main()
ibm-db2-bundle:
services:
"db2":
charm: "local:trusty/db2"
num_units: 1
annotations:
"gui-x": "300"
"gui-y": "300"
relations: []
series: trusty
db2_url: "http://9.124.100.99/debs/DB2"
db2_package_name: "DB2_Svr_10.5.0.3_Linux_x86-64.tar.gz"
accept-ibm-db2-license: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment