yellow team mailing list archive
-
yellow team
-
Mailing list archive
-
Message #00405
[Merge] lp:~frankban/charms/oneiric/buildbot-slave/02-09 into lp:~yellow/charms/oneiric/buildbot-slave/trunk
Francesco Banconi has proposed merging lp:~frankban/charms/oneiric/buildbot-slave/02-09 into lp:~yellow/charms/oneiric/buildbot-slave/trunk.
Requested reviews:
Launchpad Yellow Squad (yellow)
For more details, see:
https://code.launchpad.net/~frankban/charms/oneiric/buildbot-slave/02-09/+merge/92340
Changes from frankban and gmb (2012-02-09)
==========================================
- added hacking info
- charms repository for tests is now handled by juju_wrapper
- implemented the script test (ensure that a script is correctly downloaded and executed when `juju deploy` is called using a config file).
--
https://code.launchpad.net/~frankban/charms/oneiric/buildbot-slave/02-09/+merge/92340
Your team Launchpad Yellow Squad is requested to review the proposed merge of lp:~frankban/charms/oneiric/buildbot-slave/02-09 into lp:~yellow/charms/oneiric/buildbot-slave/trunk.
=== added file 'HACKING.txt'
--- HACKING.txt 1970-01-01 00:00:00 +0000
+++ HACKING.txt 2012-02-09 18:12:20 +0000
@@ -0,0 +1,27 @@
+Running the charm tests
+=======================
+
+1) Establish a charm repository if you do not already have one. A charm
+ repository is a directory with subdirectories for each Ubuntu version being
+ used. Inside those per-Ubuntu-version directories are the charm
+ directories. For example, to make a charm repository for this charm under
+ Oneiric follow these steps:
+
+ a) mkdir -p ~/juju-charms/oneiric
+ b) ln -s `pwd` ~/juju-charms/oneiric/buildbot-slave
+
+2) Copy the juju_wrapper file into some place earlier in your PATH than the
+ real juju executable, naming it "juju". Edit the CHARM_TEST_REPO variable
+ therein to reflect the location of the charm repo from step 1.
+
+3) Bootstrap the juju environment if not already done:
+
+ juju bootstrap
+
+4) Run the tests: RESOLVE_TEST_CHARMS=1 tests/buildbot-slave.test
+
+
+Running the charm helper tests
+==============================
+
+Just run "python hooks/tests.py".
=== added file 'juju_wrapper'
--- juju_wrapper 1970-01-01 00:00:00 +0000
+++ juju_wrapper 2012-02-09 18:12:20 +0000
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+[ -n "$RESOLVE_TEST_CHARMS" ] || exec /usr/bin/juju $@
+#set -x
+
+CHARM_TEST_REPO=~/juju-charms # <---- Change this.
+
+cmd=$1
+case $cmd in
+deploy)
+ shift
+ charm=$1
+ shift
+ exec /usr/bin/juju deploy --repository $CHARM_TEST_REPO local:$charm $@
+ ;;
+*)
+ exec /usr/bin/juju $@
+ ;;
+esac
=== modified file 'tests/buildbot-slave.test'
--- tests/buildbot-slave.test 2012-02-09 15:49:50 +0000
+++ tests/buildbot-slave.test 2012-02-09 18:12:20 +0000
@@ -4,7 +4,6 @@
# GNU Affero General Public License version 3 (see the file LICENSE).
import os
-import time
import unittest
from helpers import (
@@ -15,9 +14,9 @@
wait_for_relation,
wait_for_unit,
)
-from openport import (
- PORT,
- TEXT,
+from create_file import (
+ CONTENT,
+ PATH,
)
@@ -28,7 +27,6 @@
def setUp(self):
self.charm_name = 'buildbot-slave'
- self.repository = os.getenv('JUJU_REPOSITORY')
self.environment = os.getenv('JUJU_ENVIRONMENT')
self.tests_dir = os.path.dirname(os.path.abspath(__file__))
self.started_services = set()
@@ -38,24 +36,13 @@
juju('destroy-service', service_name)
def deploy(self, service_name, config=None):
- args = ['deploy']
- deploy_name = service_name
- if self.repository is not None:
- args.append('--repository=' + self.repository)
- deploy_name = 'local:' + deploy_name
+ args = ['deploy', service_name]
if self.environment is not None:
args.append('--environment=' + self.environment)
if config:
args.append('--config=' + config)
- args.append(deploy_name)
juju(*args)
self.started_services.add(service_name)
- # XXX 2012-02-09 frankban
- # We use a timeout of 600 seconds to avoid runtime errors
- # occurring if the instance is not created
- # (e.g. just after `juju bootstrap`).
- # We should try to wait for unit in a smarter way
- # (maybe checking for "pending"?).
def add_relation(self, relation, service1, service2):
juju('add-relation',
@@ -74,6 +61,7 @@
self.assertEqual('started', unit_info(self.charm_name, 'state'))
def test_master_slave_relationship(self):
+ # Ensure the master-slave relationship is correctly established.
master_charm_name = 'buildbot-master'
# We deploy both and then wait because it's quite a bit faster.
self.deploy(master_charm_name)
@@ -91,6 +79,22 @@
wait_for_page_contents(url, 'buildbot-slave/')
wait_for_page_contents(url, 'Idle')
+ def test_script(self):
+ # Ensure the script is run when the charm is deployed.
+ config = os.path.join(self.tests_dir, 'config.test.yaml')
+ self.deploy(self.charm_name, config=config)
+ wait_for_unit(self.charm_name)
+ address = unit_info(self.charm_name, 'public-address')
+ ssh = command(
+ 'ssh',
+ '-o', 'StrictHostKeyChecking=no',
+ '-o', 'UserKnownHostsFile=/dev/null',
+ 'ubuntu@' + address,
+ '--',
+ )
+ self.assertEqual(CONTENT, ssh('cat {}'.format(PATH)))
+ ssh('rm {}'.format(PATH))
+
if __name__ == '__main__':
unittest.main()
=== modified file 'tests/config.test.yaml'
--- tests/config.test.yaml 2012-02-08 14:38:12 +0000
+++ tests/config.test.yaml 2012-02-09 18:12:20 +0000
@@ -1,5 +1,4 @@
buildbot-slave:
script-retrieval-method: bzr_cat
- script-url: "http://bazaar.launchpad.net/~yellow/charms/oneiric/buildbot-slave/charm-tests/tests/openport.py"
- script-path: openport.py
- script-args: -d
+ script-url: "http://bazaar.launchpad.net/~yellow/charms/oneiric/buildbot-slave/charm-tests/tests/create_file.py"
+ script-path: create_file.py
=== added file 'tests/create_file.py'
--- tests/create_file.py 1970-01-01 00:00:00 +0000
+++ tests/create_file.py 2012-02-09 18:12:20 +0000
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+# A little python script to create a file on the buildslave so that we can
+# test that it's actually deployed successfully.
+
+import pwd
+import os
+
+CONTENT = 'IT WORKS!'
+PATH = '/tmp/buildslave_test'
+
+
+if __name__ == "__main__":
+ with open(PATH, 'w') as f:
+ f.write(CONTENT)
+ os.chmod(PATH, 0777)
+ userdata = pwd.getpwnam('ubuntu')
+ os.chown(PATH, userdata.pw_uid, userdata.pw_gid)
=== removed file 'tests/openport.py'
--- tests/openport.py 2012-02-08 14:45:58 +0000
+++ tests/openport.py 1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright 2012 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-# A little python script to open a port on the buildslave so that we can
-# test that it's actually deployed successfully.
-
-import os
-import sys
-import subprocess
-from BaseHTTPServer import (
- BaseHTTPRequestHandler,
- HTTPServer,
- )
-
-
-PORT = 9000
-TEXT = 'The slave is UP!'
-
-
-class Handler(BaseHTTPRequestHandler):
- def do_GET(self):
- self.send_response(200, 'OK')
- self.send_header('Content-type', 'text/palin')
- self.end_headers()
- self.wfile.write(TEXT)
-
-
-if __name__ == "__main__":
- ## HACKETTY HACK.
- options = sys.argv[1:]
- if options and options[0] == '-d':
- # OH MY GOD.
- os.system('{} &'.format(sys.argv[0]))
- sys.exit(0)
- subprocess.call(['open-port', '{}/TCP'.format(PORT)])
- HTTPServer(('', PORT), Handler).serve_forever()
Follow ups