23
23
cls.unit = cls.deployment.sentry.unit['ethercalc/0']
26
# Now you can use self.deployment.sentry.unit[UNIT] to address each of
27
# the units and perform more in-depth steps. You can also reference
28
# the first unit as self.unit.
29
# There are three test statuses that can be triggered with
30
# amulet.raise_status():
34
# Each unit has the following methods:
35
# - .info - An array of the information of that unit from Juju
36
# - .file(PATH) - Get the details of a file on that unit
37
# - .file_contents(PATH) - Get plain text output of PATH file from that unit
38
# - .directory(PATH) - Get details of directory
39
# - .directory_contents(PATH) - List files and folders in PATH on that unit
40
# - .relation(relation, service:rel) - Get relation data from return service
41
# add tests here to confirm service is up and working properly
42
# For example, to confirm that it has a functioning HTTP server:
43
# page = requests.get('http://{}'.format(self.unit.info['public-address']))
44
# page.raise_for_status()
45
# More information on writing Amulet tests can be found at:
46
# https://juju.ubuntu.com/docs/tools-amulet.html
25
def test_website(self):
26
''' Test that ethercalc responds to HTTP get requests. '''
27
# Get the address for ethercalc.
28
server = self.ethercalc_unit.info['public-address']
30
# Create a URL to the ethercalc unit.
31
url = 'http://{0}:{1}'.format(server, port)
32
response = requests.get(url)
33
response.raise_for_status()
34
if 'EtherCalc' not in str(response.content):
35
message = 'EtherCalc was not in the HTTP response from {0}'
36
amulet.raise_status(amulet.FAIL, msg=message.format(url))
37
# Get the address for haproxy.
38
server = self.haproxy_unit.info['public-address']
40
# Create a URL to the haproxy unit
41
url = 'http://{0}:{1}'.format(server, port)
42
response = requests.get(url)
43
response.raise_for_status()
44
if 'EtherCalc' not in str(response.content):
45
message = 'EtherCalc was not in the HTTP response from {0}'
46
amulet.raise_status(amulet.FAIL, msg=message.format(url))