diff options
author | 2016-10-07 12:24:58 -0700 | |
---|---|---|
committer | 2016-10-07 12:24:58 -0700 | |
commit | 4faa7f927149a5c4ef7a03523f7bc14523cb9baa (patch) | |
tree | 0be55aa0809cc395e45baeae63db660b4e72fe83 /charms/trusty/kafka/tests | |
parent | 82f1a7eb5535b30a95b1e71ff18c315d40d1e6f0 (diff) |
Charms for Contrail 3.1 with Mitaka
Change-Id: Id37f3b9743d1974e31fcd7cd9c54be41bb0c47fb
Signed-off-by: Stuart Mackie <wsmackie@juniper.net>
Diffstat (limited to 'charms/trusty/kafka/tests')
-rwxr-xr-x | charms/trusty/kafka/tests/00-setup | 5 | ||||
-rwxr-xr-x | charms/trusty/kafka/tests/100-deploy-kafka | 29 | ||||
-rwxr-xr-x | charms/trusty/kafka/tests/remote/test_dist_config.py | 71 | ||||
-rw-r--r-- | charms/trusty/kafka/tests/tests.yaml | 10 |
4 files changed, 115 insertions, 0 deletions
diff --git a/charms/trusty/kafka/tests/00-setup b/charms/trusty/kafka/tests/00-setup new file mode 100755 index 0000000..36549ea --- /dev/null +++ b/charms/trusty/kafka/tests/00-setup @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo add-apt-repository ppa:juju/stable -y +sudo apt-get update +sudo apt-get install python3 amulet -y diff --git a/charms/trusty/kafka/tests/100-deploy-kafka b/charms/trusty/kafka/tests/100-deploy-kafka new file mode 100755 index 0000000..713a4b4 --- /dev/null +++ b/charms/trusty/kafka/tests/100-deploy-kafka @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +import unittest +import amulet + + +class TestDeploy(unittest.TestCase): + """ + Deployment test for Apache Kafka + """ + + @classmethod + def setUpClass(cls): + cls.d = amulet.Deployment(series='trusty') + # Deploy Kafka Service + cls.d.add('kafka', charm='cs:~bigdata-dev/trusty/apache-kafka') + cls.d.add('zookeeper', charm='cs:~bigdata-dev/trusty/apache-zookeeper') + cls.d.relate('kafka:zookeeper', 'zookeeper:zookeeper') + + cls.d.setup(timeout=1800) + cls.d.sentry.wait(timeout=1800) + cls.unit = cls.d.sentry['kafka'][0] + + def test_deploy(self): + output, retcode = self.unit.run("pgrep -a java") + assert 'Kafka' in output, "Kafka daemon is not started" + + +if __name__ == '__main__': + unittest.main() diff --git a/charms/trusty/kafka/tests/remote/test_dist_config.py b/charms/trusty/kafka/tests/remote/test_dist_config.py new file mode 100755 index 0000000..eb2c3aa --- /dev/null +++ b/charms/trusty/kafka/tests/remote/test_dist_config.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +import grp +import os +import pwd +import unittest + +import jujubigdata + + +class TestDistConfig(unittest.TestCase): + """ + Test that the ``dist.yaml`` settings were applied properly, such as users, groups, and dirs. + + This is done as a remote test on the deployed unit rather than a regular + test under ``tests/`` because filling in the ``dist.yaml`` requires Juju + context (e.g., config). + """ + @classmethod + def setUpClass(cls): + config = None + config_dir = os.environ['JUJU_CHARM_DIR'] + config_file = 'dist.yaml' + if os.path.isfile(os.path.join(config_dir, config_file)): + config = os.path.join(config_dir, config_file) + if not config: + raise IOError('Could not find {} in {}'.format(config_file, config_dir)) + reqs = ['vendor', 'hadoop_version', 'groups', 'users', 'dirs'] + cls.dist_config = jujubigdata.utils.DistConfig(config, reqs) + + def test_groups(self): + for name in self.dist_config.groups: + try: + grp.getgrnam(name) + except KeyError: + self.fail('Group {} is missing'.format(name)) + + def test_users(self): + for username, details in self.dist_config.users.items(): + try: + user = pwd.getpwnam(username) + except KeyError: + self.fail('User {} is missing'.format(username)) + for groupname in details['groups']: + try: + group = grp.getgrnam(groupname) + except KeyError: + self.fail('Group {} referenced by user {} does not exist'.format( + groupname, username)) + if group.gr_gid != user.pw_gid: + self.assertIn(username, group.gr_mem, 'User {} not in group {}'.format( + username, groupname)) + + def test_dirs(self): + for name, details in self.dist_config.dirs.items(): + dirpath = self.dist_config.path(name) + self.assertTrue(dirpath.isdir(), 'Dir {} is missing'.format(name)) + stat = dirpath.stat() + owner = pwd.getpwuid(stat.st_uid).pw_name + group = grp.getgrgid(stat.st_gid).gr_name + perms = stat.st_mode & ~0o40000 + self.assertEqual(owner, details.get('owner', 'root'), + 'Dir {} ({}) has wrong owner: {}'.format(name, dirpath, owner)) + self.assertEqual(group, details.get('group', 'root'), + 'Dir {} ({}) has wrong group: {}'.format(name, dirpath, group)) + self.assertEqual(perms, details.get('perms', 0o755), + 'Dir {} ({}) has wrong perms: 0o{:o}'.format(name, dirpath, perms)) + + +if __name__ == '__main__': + unittest.main() diff --git a/charms/trusty/kafka/tests/tests.yaml b/charms/trusty/kafka/tests/tests.yaml new file mode 100644 index 0000000..771f3fd --- /dev/null +++ b/charms/trusty/kafka/tests/tests.yaml @@ -0,0 +1,10 @@ +# Driver for bundletester: https://github.com/juju-solutions/bundletester +# +# It may be useful to alter the defaults during manual testing. For example, +# set 'reset: false' to reuse existing charms instead of redeploying them. + +# Allow bootstrap of current env, default: true +bootstrap: true + +# Use juju-deployer to reset env between test, default: true +reset: true |