Merge lp:~mbruzek/charms/precise/ntp/amulet2 into lp:charms/ntp

Proposed by Matt Bruzek
Status: Merged
Merged at revision: 14
Proposed branch: lp:~mbruzek/charms/precise/ntp/amulet2
Merge into: lp:charms/ntp
Diff against target: 123 lines (+104/-0)
3 files modified
config.yaml (+1/-0)
tests/00-setup (+13/-0)
tests/10-deploy-test.py (+90/-0)
To merge this branch: bzr merge lp:~mbruzek/charms/precise/ntp/amulet2
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+223942@code.launchpad.net

Description of the change

Adding amulet tests to the precise version of ntp.

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM, +1

review: Approve
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

Tests pass, +1 LGTM.

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: