2 # Copyright 2016 Canonical Ltd.
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
27 class TestCharm(unittest.TestCase):
31 def id_generator(self, size=6, chars=string.ascii_uppercase + string.digits):
32 return ''.join(random.choice(chars) for _ in range(size))
36 # Setup random user/password
37 self.user = self.id_generator()
38 self.passwd = self.id_generator()
40 self.d = amulet.Deployment()
42 self.d.add('sshproxy')
45 self.d.expose('sshproxy')
47 self.d.setup(timeout=900)
51 ubuntu_0 = d.sentry['ubuntu'][0]
52 ubuntu_0.ssh("sudo adduser {}".format(self.user))
53 ubuntu_0.ssh("echo '{}' | sudo passwd {} --stdin".format(self.passwd, self.user))
55 self.unit = self.d.sentry['sshproxy'][0]
57 def test_service(self):
65 # test we can access over http
66 # page = requests.get('http://{}'.format(self.unit.info['public-address']))
67 # self.assertEqual(page.status_code, 200)
68 # Now you can use self.d.sentry[SERVICE][UNIT] to address each of the units and perform
69 # more in-depth steps. Each self.d.sentry[SERVICE][UNIT] has the following methods:
70 # - .info - An array of the information of that unit from Juju
71 # - .file(PATH) - Get the details of a file on that unit
72 # - .file_contents(PATH) - Get plain text output of PATH file from that unit
73 # - .directory(PATH) - Get details of directory
74 # - .directory_contents(PATH) - List files and folders in PATH on that unit
75 # - .relation(relation, service:rel) - Get relation data from return service