Merge lp:~mbruzek/charms/trusty/ntp/amulet into lp:charms/trusty/ntp

Proposed by Matt Bruzek
Status: Merged
Merged at revision: 12
Proposed branch: lp:~mbruzek/charms/trusty/ntp/amulet
Merge into: lp:charms/trusty/ntp
Diff against target: 113 lines (+103/-0)
2 files modified
tests/00-setup (+13/-0)
tests/10-deploy-test.py (+90/-0)
To merge this branch: bzr merge lp:~mbruzek/charms/trusty/ntp/amulet
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Review via email: mp+223914@code.launchpad.net

Description of the change

Adding amulet tests to the trusty version of the ntp charm. Tests passed on hp-cloud and local environment.

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

2014-06-20 09:17:07 Starting deployment of amazon
2014-06-20 09:17:26 Deploying services...
2014-06-20 09:17:32 Deploying service ntp using local:precise/ntp
2014-06-20 09:17:44 Deploying service ntpmaster using cs:precise/ntpmaster-3
2014-06-20 09:17:52 Deploying service ntpmaster-sentry using local:precise/ntpmaster-sentry
2014-06-20 09:18:04 Deploying service relation-sentry using local:precise/relation-sentry
2014-06-20 09:18:16 Deploying service ubuntu using cs:precise/ubuntu-4
2014-06-20 09:18:23 Deploying service ubuntu-sentry using local:precise/ubuntu-sentry
2014-06-20 09:18:47 Config specifies num units for subordinate: ntp
2014-06-20 09:18:47 Config specifies num units for subordinate: ntpmaster-sentry
2014-06-20 09:18:47 Config specifies num units for subordinate: ubuntu-sentry
2014-06-20 09:21:48 Adding relations...
2014-06-20 09:21:53 Adding relation ntp:juju-info <-> ubuntu:juju-info
2014-06-20 09:21:54 Adding relation ntpmaster:juju-info <-> ntpmaster-sentry:juju-info
2014-06-20 09:21:54 Adding relation ubuntu:juju-info <-> ubuntu-sentry:juju-info
2014-06-20 09:21:54 Adding relation relation-sentry:requires-ntp_master-ntpmaster_master <-> ntp:master
2014-06-20 09:21:54 Adding relation relation-sentry:provides-ntp_master-ntpmaster_master <-> ntpmaster:master
2014-06-20 09:23:01 Exposing service 'ntpmaster-sentry'
2014-06-20 09:23:01 Exposing service 'relation-sentry'
2014-06-20 09:23:01 Exposing service 'ubuntu-sentry'
2014-06-20 09:23:01 Deployment complete in 354.26 seconds
juju-test.conductor.10-deploy-test.py RESULT : ✔

LGTM - Ship it

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'tests'
=== added file 'tests/00-setup'
--- tests/00-setup 1970-01-01 00:00:00 +0000
+++ tests/00-setup 2014-06-20 13:02:43 +0000
@@ -0,0 +1,13 @@
1#!/bin/bash
2
3set -ex
4
5# Check if amulet is installed before adding repository and updating apt-get.
6dpkg -s amulet
7if [ $? -ne 0 ]; then
8 sudo add-apt-repository -y ppa:juju/stable
9 sudo apt-get update
10 sudo apt-get install -y amulet
11fi
12
13# Install any additional python packages or software here.
014
=== added file 'tests/10-deploy-test.py'
--- tests/10-deploy-test.py 1970-01-01 00:00:00 +0000
+++ tests/10-deploy-test.py 2014-06-20 13:02:43 +0000
@@ -0,0 +1,90 @@
1#!/usr/bin/python3
2
3# This amulet code is to test the ntp charm. NTP = Network Time Protocol.
4
5import amulet
6
7# The number of seconds to wait for Juju to set up the environment.
8seconds = 900
9ntp_server_0 = 'ntp.your.org'
10ntp_server_1 = 'us.pool.ntp.org'
11ntp_server_2 = 'tock.mtnlion.com'
12
13# The ntp configuration to test.
14ntp_configuration = {
15 'source': ntp_server_0 + ' ' + ntp_server_1 + ' ' + ntp_server_2
16}
17
18d = amulet.Deployment()
19# Add the ntp charm to the deployment.
20d.add('ntp')
21# Add the ntpmaster charm to the deployment.
22d.add('ntpmaster')
23# Add the ubuntu charm to the deployment.
24d.add('ubuntu')
25# Configure the ntp charm.
26d.configure('ntp', ntp_configuration)
27
28# Relate the ntp and ntpmaster charms.
29d.relate('ntp:master', 'ntpmaster:master')
30# Relate the ntp and the ubuntu charm.
31d.relate('ntp:juju-info', 'ubuntu:juju-info')
32
33# Deploy the environment and wait for it to setup.
34try:
35 d.setup(timeout=seconds)
36 d.sentry.wait(seconds)
37except amulet.helpers.TimeoutError:
38 message = 'The environment did not setup in %d seconds.' % seconds
39 # The SKIP status enables skip or fail the test based on configuration.
40 amulet.raise_status(amulet.SKIP, msg=message)
41except:
42 raise
43
44# Unable to get the sentry unit for ntp because it is a subordinate.
45# ntp_unit = d.sentry.unit['ntp/0']
46
47# Get the sentry unit for ntpmaster.
48ntpmaster_unit = d.sentry.unit['ntpmaster/0']
49
50# Get the sentry unit for ubuntu.
51ubuntu_unit = d.sentry.unit['ubuntu/0']
52
53# Get the public address for the system running the ntmpmaster charm.
54master_public_address = ntpmaster_unit.info['public-address']
55print('ntpmaster public address ' + master_public_address)
56# Get the relation of ntpmaster to ntp, fail if the relation does not exist.
57master_relation = ntpmaster_unit.relation('master', 'ntp:master')
58# Get the private address for the system running the ntpmaster charm.
59master_private_address = master_relation['private-address']
60print('ntpmaster private address ' + master_private_address)
61
62# Create a command to check the ntp service.
63command = 'sudo service ntp status'
64print(command)
65# Run the command to see if apache2 is running.
66output, code = ubuntu_unit.run(command)
67print(output)
68if code != 0 or output.find('NTP server is running') == -1:
69 message = 'The NTP service is not running on the ubuntu unit.'
70 print(message)
71 amulet.raise_status(amulet.FAIL, msg=message)
72
73# The ubuntu cloud image does not have ntp installed by default,
74# and therefore does not have the /etc/ntp.conf file.
75
76# Read in the ntp configuration file from the ubuntu unit.
77configuration_file = ubuntu_unit.file_contents('/etc/ntp.conf')
78# This call will fail with an IO exception if the file does not exist.
79
80# Search for ntp server 0 in the config file, raise an exception if not found.
81configuration_file.index(ntp_server_0)
82# Search for ntp server 1 in the config file, raise an exception if not found.
83configuration_file.index(ntp_server_1)
84# Search for ntp server 2 in the config file, raise an exception if not found.
85configuration_file.index(ntp_server_2)
86
87# Search for the ntpmaster IP address in the config file, added by relation.
88configuration_file.index(master_private_address)
89
90print('The ntp deploy test completed successfully.')

Subscribers

People subscribed via source and target branches

to all changes: