blob: 070208a568fbe639fde52a1235a03cfbbfab0f51 [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 Israelb8a82812019-03-27 14:50:11 -04004import 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
Adam Israelb8a82812019-03-27 14:50:11 -040029 # there is some inconsistency in the capitalization of status_message
30 # between different providers
Adam Israeldcdf82b2017-08-15 15:26:43 -040031 await asyncio.wait_for(
Adam Israelb8a82812019-03-27 14:50:11 -040032 model.block_until(
33 lambda: (machine.status == 'running' and
34 machine.status_message.lower() == 'running' and
35 machine.agent_status == 'started')),
Adam Israeldcdf82b2017-08-15 15:26:43 -040036 timeout=480)
37
Adam Israeldcdf82b2017-08-15 15:26:43 -040038
39@base.bootstrapped
40@pytest.mark.asyncio
41async def test_scp(event_loop):
Adam Israelb8a82812019-03-27 14:50:11 -040042 # 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 Israeldcdf82b2017-08-15 15:26:43 -040047 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 Israelb8a82812019-03-27 14:50:11 -040061 await machine.scp_to(f.name, 'testfile', scp_opts='-p')
Adam Israeldcdf82b2017-08-15 15:26:43 -040062
63 with NamedTemporaryFile() as f:
Adam Israelb8a82812019-03-27 14:50:11 -040064 await machine.scp_from('testfile', f.name, scp_opts='-p')
Adam Israeldcdf82b2017-08-15 15:26:43 -040065 assert f.read() == b'testcontents'