blob: 8957ae16b6330847b31624d9eb4cba19d6eae562 [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001import asyncio
Adam Israeldcdf82b2017-08-15 15:26:43 -04002from tempfile import NamedTemporaryFile
3
Adam Israelc3e6c2e2018-03-01 09:31:50 -05004import pytest
5
Adam Israeldcdf82b2017-08-15 15:26:43 -04006from .. import base
7
8
9@base.bootstrapped
10@pytest.mark.asyncio
11async 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 Israel1a15d1c2017-10-23 12:00:49 -040031 machine.agent_status == 'started' and
32 machine.agent_version is not None)),
Adam Israeldcdf82b2017-08-15 15:26:43 -040033 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
44async def test_scp(event_loop):
Adam Israelc3e6c2e2018-03-01 09:31:50 -050045 # 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 Israeldcdf82b2017-08-15 15:26:43 -040050 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'