| Adam Israel | 3c17db8 | 2017-03-30 21:39:26 -0400 | [diff] [blame] | 1 | ## |
| 2 | # Copyright 2016 Canonical Ltd. |
| 3 | # All rights reserved. |
| 4 | # |
| 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 |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 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 |
| 15 | # under the License. |
| 16 | ## |
| 17 | |
| 18 | #!/usr/bin/python3 |
| 19 | |
| 20 | import amulet |
| 21 | import requests |
| 22 | import unittest |
| 23 | |
| 24 | |
| 25 | class TestCharm(unittest.TestCase): |
| 26 | def setUp(self): |
| 27 | self.d = amulet.Deployment() |
| 28 | |
| 29 | self.d.add('vnfproxy') |
| 30 | self.d.expose('vnfproxy') |
| 31 | |
| 32 | self.d.setup(timeout=900) |
| 33 | self.d.sentry.wait() |
| 34 | |
| 35 | self.unit = self.d.sentry['vnfproxy'][0] |
| 36 | |
| 37 | def test_service(self): |
| 38 | # test we can access over http |
| 39 | page = requests.get('http://{}'.format(self.unit.info['public-address'])) |
| 40 | self.assertEqual(page.status_code, 200) |
| 41 | # Now you can use self.d.sentry[SERVICE][UNIT] to address each of the units and perform |
| 42 | # more in-depth steps. Each self.d.sentry[SERVICE][UNIT] has the following methods: |
| 43 | # - .info - An array of the information of that unit from Juju |
| 44 | # - .file(PATH) - Get the details of a file on that unit |
| 45 | # - .file_contents(PATH) - Get plain text output of PATH file from that unit |
| 46 | # - .directory(PATH) - Get details of directory |
| 47 | # - .directory_contents(PATH) - List files and folders in PATH on that unit |
| 48 | # - .relation(relation, service:rel) - Get relation data from return service |
| 49 | |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | unittest.main() |