Merge lp:~mbruzek/charm-tools/bash-updates into lp:charm-tools/1.6

Proposed by Matt Bruzek
Status: Rejected
Rejected by: Matt Bruzek
Proposed branch: lp:~mbruzek/charm-tools/bash-updates
Merge into: lp:charm-tools/1.6
Diff against target: 159 lines (+98/-11)
8 files modified
charmtools/templates/bash/files/hooks/config-changed (+9/-1)
charmtools/templates/bash/files/hooks/install (+2/-2)
charmtools/templates/bash/files/revision (+0/-1)
charmtools/templates/bash/files/tests/00-setup (+13/-0)
charmtools/templates/bash/files/tests/10-deploy (+50/-0)
charmtools/templates/python/files/revision (+0/-1)
charmtools/templates/python/files/tests/00-setup (+12/-3)
charmtools/templates/python_services/files/tests/00-setup (+12/-3)
To merge this branch: bzr merge lp:~mbruzek/charm-tools/bash-updates
Reviewer Review Type Date Requested Status
Charm Toolers Pending
Review via email: mp+252518@code.launchpad.net

Description of the change

This proposal updates the bash template for charms.

To post a comment you must log in.
Revision history for this message
Matt Bruzek (mbruzek) wrote :

This merge is over 2 years old and will not be merged. Closing

Unmerged revisions

353. By Matt Bruzek

Adding tests for bash template, removing revision file from bash and python, and adding smarter logic to the 00-setup tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/templates/bash/files/hooks/config-changed'
2--- charmtools/templates/bash/files/hooks/config-changed 2014-05-22 20:28:08 +0000
3+++ charmtools/templates/bash/files/hooks/config-changed 2015-03-10 21:48:00 +0000
4@@ -1,2 +1,10 @@
5 #!/bin/bash
6-# config-changed occurs everytime a new configuration value is updated (juju set)
7+
8+# The config-changed is the only hook that runs when a configuration value is
9+# updated by the Juju GUI or command line: juju set $metadata.package key=value
10+
11+# A good practice is to get all the charm's configuration options (config-get)
12+# in the config-changed hook to avoid immutable configuration.
13+STRING=`config-get string-option`
14+BOOLEAN=`config-get boolean-option`
15+INT=`config-get int-option`
16
17=== modified file 'charmtools/templates/bash/files/hooks/install'
18--- charmtools/templates/bash/files/hooks/install 2014-05-22 20:28:08 +0000
19+++ charmtools/templates/bash/files/hooks/install 2015-03-10 21:48:00 +0000
20@@ -1,7 +1,7 @@
21 #!/bin/bash
22 #
23-# Here do anything needed to install the service
24-# i.e. apt-get install -y foo or bzr branch http://myserver/mycode /srv/webroot
25+# Do anything in this hook needed to install the service
26+# i.e. apt-get install -y foo or bzr branch http://myserver/mycode /srv/webroot
27 #
28 # Make sure this hook exits cleanly and is idempotent, common problems here are
29 # failing to account for a debconf question on a dependency, or trying to pull
30
31=== removed file 'charmtools/templates/bash/files/revision'
32--- charmtools/templates/bash/files/revision 2014-05-22 20:28:08 +0000
33+++ charmtools/templates/bash/files/revision 1970-01-01 00:00:00 +0000
34@@ -1,1 +0,0 @@
35-1
36
37=== added directory 'charmtools/templates/bash/files/tests'
38=== added file 'charmtools/templates/bash/files/tests/00-setup'
39--- charmtools/templates/bash/files/tests/00-setup 1970-01-01 00:00:00 +0000
40+++ charmtools/templates/bash/files/tests/00-setup 2015-03-10 21:48:00 +0000
41@@ -0,0 +1,13 @@
42+#!/bin/bash
43+
44+set -x
45+
46+# Check if amulet is installed before adding repository and updating apt-get.
47+dpkg -s amulet
48+if [ $? -ne 0 ]; then
49+ sudo add-apt-repository -y ppa:juju/stable
50+ sudo apt-get update
51+ sudo apt-get install -y amulet
52+fi
53+# Install any additional packages needed for tests here.
54+# sudo apt-get install -y python3-requests
55
56=== added file 'charmtools/templates/bash/files/tests/10-deploy'
57--- charmtools/templates/bash/files/tests/10-deploy 1970-01-01 00:00:00 +0000
58+++ charmtools/templates/bash/files/tests/10-deploy 2015-03-10 21:48:00 +0000
59@@ -0,0 +1,50 @@
60+#!/usr/bin/env python3
61+
62+import amulet
63+import unittest
64+
65+
66+class TestDeployment(unittest.TestCase):
67+ @classmethod
68+ def setUpClass(cls):
69+ cls.deployment = amulet.Deployment()
70+
71+ cls.deployment.add('$metadata.package')
72+ cls.deployment.expose('$metadata.package')
73+
74+ try:
75+ cls.deployment.setup(timeout=900)
76+ cls.deployment.sentry.wait()
77+ except amulet.helpers.TimeoutError:
78+ amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
79+ except:
80+ raise
81+ cls.unit = cls.deployment.sentry.unit['$metadata.package/0']
82+
83+ def test_case(self):
84+ # Now you can use self.deployment.sentry.unit[UNIT] to address each of
85+ # the units and perform more in-depth steps. You can also reference
86+ # the first unit as self.unit.
87+ # There are three test statuses that can be triggered with
88+ # amulet.raise_status():
89+ # - amulet.PASS
90+ # - amulet.FAIL
91+ # - amulet.SKIP
92+ # Each unit has the following methods:
93+ # - .info - An array of the information of that unit from Juju
94+ # - .file(PATH) - Get the details of a file on that unit
95+ # - .file_contents(PATH) - Get plain text output of PATH file from that unit
96+ # - .directory(PATH) - Get details of directory
97+ # - .directory_contents(PATH) - List files and folders in PATH on that unit
98+ # - .relation(relation, service:rel) - Get relation data from return service
99+ # add tests here to confirm service is up and working properly
100+ # For example, to confirm that it has a functioning HTTP server:
101+ # page = requests.get('http://{}'.format(self.unit.info['public-address']))
102+ # page.raise_for_status()
103+ # More information on writing Amulet tests can be found at:
104+ # https://juju.ubuntu.com/docs/tools-amulet.html
105+ pass
106+
107+
108+if __name__ == '__main__':
109+ unittest.main()
110
111=== removed file 'charmtools/templates/python/files/revision'
112--- charmtools/templates/python/files/revision 2014-05-23 20:10:24 +0000
113+++ charmtools/templates/python/files/revision 1970-01-01 00:00:00 +0000
114@@ -1,1 +0,0 @@
115-1
116
117=== modified file 'charmtools/templates/python/files/tests/00-setup'
118--- charmtools/templates/python/files/tests/00-setup 2014-05-23 20:10:24 +0000
119+++ charmtools/templates/python/files/tests/00-setup 2015-03-10 21:48:00 +0000
120@@ -1,5 +1,14 @@
121 #!/bin/bash
122
123-sudo add-apt-repository ppa:juju/stable -y
124-sudo apt-get update
125-sudo apt-get install amulet python-requests -y
126+set -x
127+
128+# Check if amulet is installed before adding repository and updating apt-get.
129+dpkg -s amulet
130+if [ $? -ne 0 ]; then
131+ sudo add-apt-repository -y ppa:juju/stable
132+ sudo apt-get update
133+ sudo apt-get install -y amulet
134+fi
135+# Install any additional packages needed for tests here.
136+sudo apt-get install -y python3-requests
137+
138
139=== modified file 'charmtools/templates/python_services/files/tests/00-setup'
140--- charmtools/templates/python_services/files/tests/00-setup 2014-09-10 18:38:30 +0000
141+++ charmtools/templates/python_services/files/tests/00-setup 2015-03-10 21:48:00 +0000
142@@ -1,5 +1,14 @@
143 #!/bin/bash
144
145-sudo add-apt-repository ppa:juju/stable -y
146-sudo apt-get update
147-sudo apt-get install amulet python-requests -y
148+set -x
149+
150+# Check if amulet is installed before adding repository and updating apt-get.
151+dpkg -s amulet
152+if [ $? -ne 0 ]; then
153+ sudo add-apt-repository -y ppa:juju/stable
154+ sudo apt-get update
155+ sudo apt-get install -y amulet
156+fi
157+# Install any additional packages needed for tests here.
158+sudo apt-get install -y python3-requests
159+

Subscribers

People subscribed via source and target branches