| 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 | c3e6c2e | 2018-03-01 09:31:50 -0500 | [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 | |
| 29 | await asyncio.wait_for( |
| 30 | model.block_until(lambda: (machine.status == 'running' and |
| Adam Israel | 1a15d1c | 2017-10-23 12:00:49 -0400 | [diff] [blame] | 31 | machine.agent_status == 'started' and |
| 32 | machine.agent_version is not None)), |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 33 | timeout=480) |
| 34 | |
| 35 | assert machine.status == 'running' |
| 36 | # there is some inconsistency in the message case between providers |
| 37 | assert machine.status_message.lower() == 'running' |
| 38 | assert machine.agent_status == 'started' |
| 39 | assert machine.agent_version.major >= 2 |
| 40 | |
| 41 | |
| 42 | @base.bootstrapped |
| 43 | @pytest.mark.asyncio |
| 44 | async def test_scp(event_loop): |
| Adam Israel | c3e6c2e | 2018-03-01 09:31:50 -0500 | [diff] [blame^] | 45 | # ensure that asyncio.subprocess will work; |
| 46 | try: |
| 47 | asyncio.get_child_watcher().attach_loop(event_loop) |
| 48 | except RuntimeError: |
| 49 | pytest.skip('test_scp will always fail outside of MainThread') |
| Adam Israel | dcdf82b | 2017-08-15 15:26:43 -0400 | [diff] [blame] | 50 | async with base.CleanModel() as model: |
| 51 | await model.add_machine() |
| 52 | await asyncio.wait_for( |
| 53 | model.block_until(lambda: model.machines), |
| 54 | timeout=240) |
| 55 | machine = model.machines['0'] |
| 56 | await asyncio.wait_for( |
| 57 | model.block_until(lambda: (machine.status == 'running' and |
| 58 | machine.agent_status == 'started')), |
| 59 | timeout=480) |
| 60 | |
| 61 | with NamedTemporaryFile() as f: |
| 62 | f.write(b'testcontents') |
| 63 | f.flush() |
| 64 | await machine.scp_to(f.name, 'testfile') |
| 65 | |
| 66 | with NamedTemporaryFile() as f: |
| 67 | await machine.scp_from('testfile', f.name) |
| 68 | assert f.read() == b'testcontents' |