| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 1 | import asyncio |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 2 | from tempfile import NamedTemporaryFile |
| 3 | |
| Adam Israel | b8a8281 | 2019-03-27 14:50:11 -0400 | [diff] [blame] | 4 | import pytest |
| 5 | |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 6 | from .. import base |
| 7 | |
| 8 | |
| 9 | @base.bootstrapped |
| 10 | @pytest.mark.asyncio |
| 11 | async def test_status(event_loop): |
| 12 | async with base.CleanModel() as model: |
| 13 | await model.deploy( |
| 14 | 'ubuntu-0', |
| 15 | application_name='ubuntu', |
| 16 | series='trusty', |
| 17 | channel='stable', |
| 18 | ) |
| 19 | |
| 20 | await asyncio.wait_for( |
| 21 | model.block_until(lambda: len(model.machines)), |
| 22 | timeout=240) |
| 23 | machine = model.machines['0'] |
| 24 | |
| 25 | assert machine.status in ('allocating', 'pending') |
| 26 | assert machine.agent_status == 'pending' |
| 27 | assert not machine.agent_version |
| 28 | |
| Adam Israel | b8a8281 | 2019-03-27 14:50:11 -0400 | [diff] [blame] | 29 | # there is some inconsistency in the capitalization of status_message |
| 30 | # between different providers |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 31 | await asyncio.wait_for( |
| Adam Israel | b8a8281 | 2019-03-27 14:50:11 -0400 | [diff] [blame] | 32 | model.block_until( |
| 33 | lambda: (machine.status == 'running' and |
| 34 | machine.status_message.lower() == 'running' and |
| 35 | machine.agent_status == 'started')), |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 36 | timeout=480) |
| 37 | |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 38 | |
| 39 | @base.bootstrapped |
| 40 | @pytest.mark.asyncio |
| 41 | async def test_scp(event_loop): |
| Adam Israel | b8a8281 | 2019-03-27 14:50:11 -0400 | [diff] [blame] | 42 | # ensure that asyncio.subprocess will work; |
| 43 | try: |
| 44 | asyncio.get_child_watcher().attach_loop(event_loop) |
| 45 | except RuntimeError: |
| 46 | pytest.skip('test_scp will always fail outside of MainThread') |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 47 | async with base.CleanModel() as model: |
| 48 | await model.add_machine() |
| 49 | await asyncio.wait_for( |
| 50 | model.block_until(lambda: model.machines), |
| 51 | timeout=240) |
| 52 | machine = model.machines['0'] |
| 53 | await asyncio.wait_for( |
| 54 | model.block_until(lambda: (machine.status == 'running' and |
| 55 | machine.agent_status == 'started')), |
| 56 | timeout=480) |
| 57 | |
| 58 | with NamedTemporaryFile() as f: |
| 59 | f.write(b'testcontents') |
| 60 | f.flush() |
| Adam Israel | b8a8281 | 2019-03-27 14:50:11 -0400 | [diff] [blame] | 61 | await machine.scp_to(f.name, 'testfile', scp_opts='-p') |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 62 | |
| 63 | with NamedTemporaryFile() as f: |
| Adam Israel | b8a8281 | 2019-03-27 14:50:11 -0400 | [diff] [blame] | 64 | await machine.scp_from('testfile', f.name, scp_opts='-p') |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 65 | assert f.read() == b'testcontents' |