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

Subscribers

People subscribed via source and target branches

to all changes: