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

Subscribers

People subscribed via source and target branches

to all changes: