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

Subscribers

People subscribed via source and target branches

to all changes: