Merge lp:~arosales/charms/precise/ubuntu/add-basic-amulet-test into lp:charms/ubuntu

Proposed by Antonio Rosales
Status: Merged
Merged at revision: 7
Proposed branch: lp:~arosales/charms/precise/ubuntu/add-basic-amulet-test
Merge into: lp:charms/ubuntu
Diff against target: 88 lines (+78/-0)
2 files modified
tests/00-setup.sh (+7/-0)
tests/10-deploy-test.py (+71/-0)
To merge this branch: bzr merge lp:~arosales/charms/precise/ubuntu/add-basic-amulet-test
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+203199@code.launchpad.net

Description of the change

Add basic Amulet based tests. Sinc the Ubuntu charm does not have any config or relations the tests are very basic and just ensure Ubuntu has indeed been deployed.

To post a comment you must log in.
Revision history for this message
Antonio Rosales (arosales) wrote :

Note I am getting the following error:

$ juju test 10-deploy-test.py
juju-test INFO : Starting test run on hp-scale using Juju 1.17.0
Launching instance
 - 3461791
Waiting for address
Attempting to connect to 10.5.31.158:22
Attempting to connect to 15.185.125.174:22
Connection to 15.185.125.174 closed.
2014-01-24 20:05:35 Starting deployment of hp-scale
2014-01-24 20:05:39 Deploying services...
2014-01-24 20:05:41 Deploying service ubuntu-sentry using local:precise/ubuntu-sentry
2014-01-24 20:05:44 Exposing service 'ubuntu-sentry'
2014-01-24 20:05:44 Deploying service relation-sentry using local:precise/relation-sentry
2014-01-24 20:05:48 Exposing service 'relation-sentry'
2014-01-24 20:05:48 Deploying service ubuntu using local:precise/ubuntu
2014-01-24 20:08:12 Config specifies num units for subordinate: ubuntu-sentry
2014-01-24 20:08:12 Adding relations...
2014-01-24 20:08:13 Adding relation ubuntu:juju-info <-> ubuntu-sentry:juju-info
2014-01-24 20:09:20 Deployment complete in 225.05 seconds
Traceback (most recent call last):
  File "tests/10-deploy-test.py", line 50, in <module>
    output, code = d.sentry.unit['ubuntu/0'].run(lsb_release_command)
  File "/usr/lib/python3/dist-packages/amulet/sentry.py", line 98, in run
    r = self.query('/run', data=command)
  File "/usr/lib/python3/dist-packages/amulet/sentry.py", line 47, in query
    return self._fetch(self.config['address'], endpoint, query, data)
  File "/usr/lib/python3/dist-packages/amulet/sentry.py", line 50, in _fetch
    url = "%s/%s?%s" % (address, endpoint, urllib.parse.urlencode(query))
AttributeError: 'module' object has no attribute 'parse'
juju-test.conductor.10-deploy-test.py RESULT : ✘
juju-test INFO : Results: 0 passed, 1 failed, 0 errored
ERROR exit status 1

However, I think this may be a bug that Marco has already fixed in Amulet but has not been released in the package yet.

-thanks,
Antonio

Revision history for this message
James Troup (elmo) wrote :

So maybe it's just me, but a test suite, that assumes it has functional (passwordless?) sudo and that its okay to use that to enable an arbitrary PPA on a system and install packages from it, really makes me uncomfortable.

Revision history for this message
Benjamin Saller (bcsaller) wrote :

The direction for our automated testing is to run each substrates test in their own LXC container with deps installed only in that container. There is a longer term plan to use the same container setup with the default 'charm test' with using a flag, --container for example.

This should remove those (shared) concerns.

Revision history for this message
Antonio Rosales (arosales) wrote :

In regards to the stack trace I was seeing, after updating amulet to version 1.2.1 I no longer see the errors and the tests pass successfully:

$ juju test
juju-test INFO : Starting test run on hp-scale using Juju 1.16.5
[sudo] password for arosales:
gpg: keyring `/tmp/tmp75y1po/secring.gpg' created
gpg: keyring `/tmp/tmp75y1po/pubring.gpg' created
gpg: requesting key C8068B11 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp75y1po/trustdb.gpg: trustdb created
gpg: key C8068B11: public key "Launchpad Ensemble PPA" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
juju-test.conductor.00-setup.sh RESULT : ✔
2014-01-31 17:21:46 Starting deployment of hp-scale
2014-01-31 17:21:50 Deploying services...
2014-01-31 17:21:51 Deploying service ubuntu-sentry using local:precise/ubuntu-sentry
2014-01-31 17:21:56 Exposing service 'ubuntu-sentry'
2014-01-31 17:21:56 Deploying service relation-sentry using local:precise/relation-sentry
2014-01-31 17:22:08 Exposing service 'relation-sentry'
2014-01-31 17:22:08 Deploying service ubuntu using local:precise/ubuntu
2014-01-31 17:24:33 Config specifies num units for subordinate: ubuntu-sentry
2014-01-31 17:24:33 Adding relations...
2014-01-31 17:24:34 Adding relation ubuntu:juju-info <-> ubuntu-sentry:juju-info
2014-01-31 17:25:40 Deployment complete in 234.41 seconds
juju-test.conductor.10-deploy-test.py RESULT : ✔
juju-test INFO : Results: 2 passed, 0 failed, 0 errored

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

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.sh'
3--- tests/00-setup.sh 1970-01-01 00:00:00 +0000
4+++ tests/00-setup.sh 2014-01-25 03:18:21 +0000
5@@ -0,0 +1,7 @@
6+#!/bin/sh
7+
8+# Install Amulet testing harness as it is not on the
9+# default cloud image. Amulet should pull in its dependencies.
10+sudo add-apt-repository -y ppa:juju/stable
11+sudo apt-get update
12+sudo apt-get install -y amulet
13
14=== added file 'tests/10-deploy-test.py'
15--- tests/10-deploy-test.py 1970-01-01 00:00:00 +0000
16+++ tests/10-deploy-test.py 2014-01-25 03:18:21 +0000
17@@ -0,0 +1,71 @@
18+#!/usr/bin/python3
19+
20+# This Amulet based tests
21+# The goal is to ensure the Ubuntu charm
22+# sucessfully deploys and can be accessed.
23+# Note the Ubuntu charm does not have any
24+# relations or config options.
25+
26+import amulet
27+#import os
28+#import requests
29+
30+# Timeout value, in seconds to deploy the environment
31+seconds = 900
32+
33+# Set up the deployer module to interact and set up the environment.
34+d = amulet.Deployment()
35+
36+# Define the environment in terms of charms, their config, and relations.
37+
38+# Add the Ubuntu charm to the deployment.
39+d.add('ubuntu')
40+
41+# Deploy the environment currently defined
42+try:
43+ # Wait the defined about amount of time to deploy the environment.
44+ # Setup makes sure the services are deployed, related, and in a
45+ # "started" state.
46+ d.setup(timeout=seconds)
47+ # Use a sentry to ensure there are no remaining hooks being execute
48+ # on any of the nodes
49+## d.sentry.wait()
50+except amulet.helpers.TimeoutError:
51+ # Pending the configuration the test will fail or be skipped
52+ # if not deployed properly.
53+ error_message = 'The environment did not deploy in %d seconds.' % seconds
54+ amulet.raise_status(amulet.SKIP, msg=error_message)
55+except:
56+ # Something else has gone wrong, raise the error so we can see it and this
57+ # will automatically "FAIL" the test.
58+ raise
59+
60+# Access the Ubuntu instance to ensure it has been deployed correctly
61+
62+# Define the commands to be ran
63+lsb_release_command = 'cat /etc/lsb-release'
64+uname_command = 'uname -a'
65+
66+# Cat the release information
67+output, code = d.sentry.unit['ubuntu/0'].run(lsb_release_command)
68+# Confirm the lsb-release command was ran successfully
69+if (code != 0):
70+ error_message = 'The ' + lsb_release_command + ' did not return the expected return code of 0.'
71+ print(output)
72+ amulet.raise_status(amulet.FAIL, msg=error_message)
73+else:
74+ message = 'The lsb-release command successfully executed.'
75+ print(output)
76+ print(message)
77+
78+# Get the uname -a output
79+output, code = d.sentry.unit['ubuntu/0'].run(uname_command)
80+# Confirm the uname command was ran successfully
81+if (code != 0):
82+ error_message = 'The ' + uname_command + ' did not return the expected return code of 0.'
83+ print(output)
84+ amulet.raise_status(amulet.FAIL, msg=error_message)
85+else:
86+ message = 'The uname command successfully executed.'
87+ print(output)
88+ print(message)

Subscribers

People subscribed via source and target branches

to all changes: