Merge lp:~mbruzek/charms/precise/lamp/trunk into lp:charms/lamp

Proposed by Matt Bruzek
Status: Merged
Merged at revision: 19
Proposed branch: lp:~mbruzek/charms/precise/lamp/trunk
Merge into: lp:charms/lamp
Diff against target: 236 lines (+214/-0)
4 files modified
tests/00-setup (+14/-0)
tests/10-deploy-test.py (+169/-0)
tests/files/connect_database.php (+27/-0)
tests/files/phpinfo.php (+4/-0)
To merge this branch: bzr merge lp:~mbruzek/charms/precise/lamp/trunk
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+207322@code.launchpad.net

Description of the change

Adding apt-get install bzr to the line

https://codereview.appspot.com/67210043/

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

Please take a look.

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

LGTM

review: Approve
Revision history for this message
Matt Bruzek (mbruzek) wrote :

Reviewers: mp+207322_code.launchpad.net,

Message:
Please take a look.

Description:
Adding apt-get install bzr to the line

https://code.launchpad.net/~mbruzek/charms/precise/lamp/trunk/+merge/207322

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/67210043/

Affected files (+214, --1 lines):
   A [revision details]
   A tests/00-setup
   A tests/10-deploy-test.py
   A tests/files/connect_database.php
   A tests/files/mysql_conf
   A tests/files/phpinfo.php

21. By Matt Bruzek <email address hidden>

Fixed errors in 00-setup

22. By Matt Bruzek <email address hidden>

Merged different branches.

23. By Matt Bruzek <email address hidden>

Resolved divergent-branches

Revision history for this message
Matt Bruzek (mbruzek) wrote :

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-02-24 17:36:16 +0000
5@@ -0,0 +1,14 @@
6+#!/bin/bash
7+
8+set -x
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+sudo apt-get install -y python3-requests
20
21=== added file 'tests/10-deploy-test.py'
22--- tests/10-deploy-test.py 1970-01-01 00:00:00 +0000
23+++ tests/10-deploy-test.py 2014-02-24 17:36:16 +0000
24@@ -0,0 +1,169 @@
25+#!/usr/bin/python3
26+
27+# This amulet code is to test the lamp charm.
28+
29+import amulet
30+import requests
31+
32+# The number of seconds to wait for Juju to set up the environment.
33+seconds = 900
34+# The lamp configuration to test.
35+lamp_configuration = {
36+ 'website-database': 'lampdatabase',
37+ 'database-user': 'lamp-user',
38+ 'website-bzr': 'lp:~mbruzek/charms/precise/lamp-tests/trunk',
39+ 'bzr-update': 'yes'
40+}
41+# The mysql charm needs a configuration setting to deploy correctly.
42+mysql_configuration = {'dataset-size': '512M'}
43+
44+d = amulet.Deployment()
45+# Add the lamp charm to the deployment.
46+d.add('lamp')
47+# Add the mysql charm to the deployment.
48+d.add('mysql')
49+# Configure the lamp charm.
50+d.configure('lamp', lamp_configuration)
51+# Configure the mysql charm so it deploys correctly.
52+d.configure('mysql', mysql_configuration)
53+# Relate the lamp and mysql charms.
54+d.relate('lamp:shared-db', 'mysql:shared-db')
55+# Expose the open ports on lamp.
56+d.expose('lamp')
57+
58+# Deploy the environment and wait for it to setup.
59+try:
60+ d.setup(timeout=seconds)
61+ d.sentry.wait(seconds)
62+except amulet.helpers.TimeoutError:
63+ message = 'The environment did not setup in %d seconds.' % seconds
64+ # The SKIP status enables skip or fail the test based on configuration.
65+ amulet.raise_status(amulet.SKIP, msg=message)
66+except:
67+ raise
68+
69+# Get the sentry unit for mysql.
70+mysql_unit = d.sentry.unit['mysql/0']
71+
72+# Get the sentry unit for lamp.
73+lamp_unit = d.sentry.unit['lamp/0']
74+
75+# Get the public address for the system running the lamp charm.
76+lamp_address = lamp_unit.info['public-address']
77+
78+###############################################################################
79+## Verify Linux (the L in LAMP)
80+###############################################################################
81+command = 'uname -a'
82+print(command)
83+# Run the command to get the Linux kernel version.
84+output, code = lamp_unit.run(command)
85+print(output)
86+if code != 0 and output.find('Linux') != -1:
87+ message = 'Unable to get the Linux kernel version:\n%s' % output
88+ amulet.raise_status(amulet.FAIL, msg=message)
89+
90+###############################################################################
91+## Verify Apache (the A in LAMP)
92+###############################################################################
93+command = 'sudo service apache2 status'
94+print(command)
95+# Run the command to see if apache2 is running.
96+output, code = lamp_unit.run(command)
97+print(output)
98+if code != 0:
99+ message = 'Apache2 does not seem to be running on %s' % lamp_address
100+ print(message)
101+ amulet.raise_status(amulet.FAIL, msg=message)
102+
103+###############################################################################
104+## Verify MySQL (The M in LAMP)
105+###############################################################################
106+# Verify that lamp was related to mysql.
107+lamp_relation = lamp_unit.relation('shared-db', 'mysql:shared-db')
108+print('lamp relation to mysql')
109+for key, value in lamp_relation.items():
110+ print(key, value)
111+# Verify that mysql was related to lamp.
112+mysql_relation = mysql_unit.relation('shared-db', 'lamp:shared-db')
113+print('mysql relation to lamp')
114+for key, value in mysql_relation.items():
115+ print(key, value)
116+# Get the username from the mysql relation to lamp.
117+mysql_user = lamp_relation['username']
118+# Verify the relation has the right database-user value.
119+if mysql_user != lamp_configuration['database-user']:
120+ message = 'The database user {0} did not match expected {1}'.format(
121+ mysql_user, lamp_configuration['database-user'])
122+ amulet.raise_status(amulet.FAIL, msg=message)
123+# Get the database from the mysql relation to lamp.
124+mysql_database = lamp_relation['database']
125+# Verify the relation has the right database name value.
126+if mysql_database != lamp_configuration['website-database']:
127+ message = 'The database name {0} did not match expected {1}'.format(
128+ mysql_database, lamp_configuration['website-database'])
129+ amulet.raise_status(amulet.FAIL, msg=message)
130+# Get the db_host from the lamp relation to mysql.
131+mysql_ip = mysql_relation['db_host']
132+# Get the password from the lamp relation to mysql.
133+mysql_password = mysql_relation['password']
134+# Create the command to get the mysql status with username and password.
135+command = 'mysqladmin status -h {0} -u {1} --password={2}'.format(mysql_ip,
136+ mysql_user, mysql_password)
137+print(command)
138+output, code = lamp_unit.run(command)
139+print(output)
140+if code != 0:
141+ message = 'Unable to get the status of mysql server at %s' % mysql_ip
142+ amulet.raise_status(amulet.FAIL, msg=message)
143+
144+###############################################################################
145+## Verify PHP (the P in LAMP)
146+###############################################################################
147+# Create a URL string to the lamp server.
148+lamp_url = 'http://%s' % lamp_address
149+# The name of the file that calls the phpinfo() method.
150+phpinfo = 'phpinfo.php'
151+# Create a url to the phpinfo file on the lamp server.
152+phpinfo_url = '{0}/{1}'.format(lamp_url, phpinfo)
153+print(phpinfo_url)
154+# Get the lamp url with the authentication for guest.
155+response = requests.get(phpinfo_url)
156+# Raise an exception if response is not 200 OK.
157+response.raise_for_status()
158+# Look for PHP Version in the response.
159+version_index = response.text.find('PHP Version')
160+# Look for PHP API in the response.
161+api_index = response.text.find('PHP API')
162+found_php_version = version_index != -1
163+found_php_api = api_index != -1
164+if found_php_version and found_php_api:
165+ print(response.text[version_index:].split('\n')[0])
166+ print(response.text[api_index:].split('\n')[0])
167+ print('Verified PHP was running on lamp server %s' % lamp_address)
168+else:
169+ message = 'PHP was not running correctly on %s' % lamp_address
170+ print(message)
171+ print(response.text)
172+ amulet.raise_status(amulet.FAIL, msg=message)
173+# The name of the file that connects to the database.
174+connect_database_php = 'connect_database.php'
175+# Create a url to the connect_database.php file.
176+connect_database_php_url = '{0}/{1}'.format(lamp_url, connect_database_php)
177+print(connect_database_php_url)
178+# Get the url that returns the connect_database.php results.
179+response = requests.get(connect_database_php_url)
180+print(response.text)
181+# Raise an exception if the response was not 200 OK.
182+response.raise_for_status()
183+# Look for the database connected success message in the response.
184+connect_to_mysql = response.text.find('Connected') != -1
185+# Look for the datbase selected success message in the response.
186+selected_database = response.text.find('Selected database') != -1
187+if connect_to_mysql and selected_database:
188+ print('Verified the PHP code could connect to the mysql database.')
189+else:
190+ message = 'PHP could not connect to the mysql:\n%s' % response.text
191+ amulet.raise_status(amulet.FAIL, msg=message)
192+
193+print('The lamp deploy test completed successfully.')
194
195=== added directory 'tests/files'
196=== added file 'tests/files/connect_database.php'
197--- tests/files/connect_database.php 1970-01-01 00:00:00 +0000
198+++ tests/files/connect_database.php 2014-02-24 17:36:16 +0000
199@@ -0,0 +1,27 @@
200+<?php
201+// The configuration file named mysql has the address of the mysql server.
202+$config_file_name = "mysql";
203+// Read in the /var/webconfig/mysql configuration file written by charm hook.
204+$mysql_results = parse_ini_file("/var/webconfig/{$config_file_name}");
205+// The mysql address is the name of the file containing other mysql information.
206+$mysql_address = $mysql_results['server_ip'];
207+// Read in the /var/webconfig/<server_ip> configuration file written by hook.
208+$mysql_info = parse_ini_file("/var/webconfig/{$mysql_address}");
209+// The database name is in the address configuration file.
210+$mysql_database = $mysql_info['server_db'];
211+
212+// Connect to the database using php.
213+$link = mysql_connect($mysql_address, $mysql_info['server_user'], $mysql_info['server_pass']);
214+if (!$link) {
215+ echo "Failed to connect to {$mysql_address}", PHP_EOL;
216+} else {
217+ echo "Connected to {$mysql_address}", PHP_EOL;
218+}
219+$db_selected = mysql_select_db($mysql_database, $link);
220+if (!$db_selected) {
221+ echo "Failed to select database {$mysql_database}", PHP_EOL;
222+} else {
223+ echo "Selected database {$mysql_database}";
224+}
225+?>
226+
227
228=== added file 'tests/files/mysql_conf'
229=== added file 'tests/files/phpinfo.php'
230--- tests/files/phpinfo.php 1970-01-01 00:00:00 +0000
231+++ tests/files/phpinfo.php 2014-02-24 17:36:16 +0000
232@@ -0,0 +1,4 @@
233+<?php
234+// This file tests if PHP is configured and working on the lamp charm.
235+phpinfo();
236+?>

Subscribers

People subscribed via source and target branches

to all changes: