Skip to content

Commit

Permalink
Merge pull request #297 from escapewindow/aiohttp-warnings
Browse files Browse the repository at this point in the history
Aiohttp warnings
  • Loading branch information
escapewindow committed Jan 11, 2019
2 parents 5cbbdab + 8f52e6e commit 276f4a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
49 changes: 25 additions & 24 deletions scriptworker/cot/verify.py
Expand Up @@ -1965,6 +1965,30 @@ async def verify_chain_of_trust(chain):


# verify_cot_cmdln {{{1
async def _async_verify_cot_cmdln(opts, tmp):
async with aiohttp.ClientSession() as session:
context = Context()
context.session = session
context.config = dict(deepcopy(DEFAULT_CONFIG))
context.credentials = read_worker_creds()
context.task = await context.queue.task(opts.task_id)
context.config.update({
'cot_product': opts.cot_product,
'work_dir': os.path.join(tmp, 'work'),
'artifact_dir': os.path.join(tmp, 'artifacts'),
'task_log_dir': os.path.join(tmp, 'artifacts', 'public', 'logs'),
'base_gpg_home_dir': os.path.join(tmp, 'gpg'),
'verify_cot_signature': False,
})
context.config = apply_product_config(context.config)
cot = ChainOfTrust(context, opts.task_type, task_id=opts.task_id)
await verify_chain_of_trust(cot)
log.info(format_json(cot.dependent_task_ids()))
log.info("{} : {}".format(cot.name, cot.task_id))
for link in cot.links:
log.info("{} : {}".format(link.name, link.task_id))


def verify_cot_cmdln(args=None, event_loop=None):
"""Test the chain of trust from the commandline, for debugging purposes.
Expand Down Expand Up @@ -1997,31 +2021,8 @@ def verify_cot_cmdln(args=None, event_loop=None):
log.setLevel(logging.DEBUG)
logging.basicConfig()
event_loop = event_loop or asyncio.get_event_loop()
conn = aiohttp.TCPConnector()
try:
session = aiohttp.ClientSession(connector=conn)
context = Context()
context.session = session
context.config = dict(deepcopy(DEFAULT_CONFIG))
context.credentials = read_worker_creds()
context.task = event_loop.run_until_complete(context.queue.task(opts.task_id))
context.config.update({
'cot_product': opts.cot_product,
'work_dir': os.path.join(tmp, 'work'),
'artifact_dir': os.path.join(tmp, 'artifacts'),
'task_log_dir': os.path.join(tmp, 'artifacts', 'public', 'logs'),
'base_gpg_home_dir': os.path.join(tmp, 'gpg'),
'verify_cot_signature': False,
})
context.config = apply_product_config(context.config)
cot = ChainOfTrust(context, opts.task_type, task_id=opts.task_id)
event_loop.run_until_complete(verify_chain_of_trust(cot))
event_loop.run_until_complete(context.session.close())
conn.close()
log.info(format_json(cot.dependent_task_ids()))
log.info("{} : {}".format(cot.name, cot.task_id))
for link in cot.links:
log.info("{} : {}".format(link.name, link.task_id))
event_loop.run_until_complete(_async_verify_cot_cmdln(opts, tmp))
finally:
if opts.cleanup:
rm(tmp)
Expand Down
25 changes: 10 additions & 15 deletions scriptworker/test/__init__.py
Expand Up @@ -271,25 +271,26 @@ async def _close_session(obj):
@pytest.mark.asyncio
@pytest.yield_fixture(scope='function')
async def rw_context(event_loop):
with tempfile.TemporaryDirectory() as tmp:
context = _craft_rw_context(tmp, event_loop, cot_product='firefox')
yield context
await _close_context(context)
async with aiohttp.ClientSession() as session:
with tempfile.TemporaryDirectory() as tmp:
context = _craft_rw_context(tmp, event_loop, cot_product='firefox', session=session)
yield context


@pytest.mark.asyncio
@pytest.yield_fixture(scope='function')
async def mobile_rw_context(event_loop):
with tempfile.TemporaryDirectory() as tmp:
context = _craft_rw_context(tmp, event_loop, cot_product='mobile')
yield context
await _close_context(context)
async with aiohttp.ClientSession() as session:
with tempfile.TemporaryDirectory() as tmp:
context = _craft_rw_context(tmp, event_loop, cot_product='mobile', session=session)
yield context


def _craft_rw_context(tmp, event_loop, cot_product):
def _craft_rw_context(tmp, event_loop, cot_product, session):
config = get_unfrozen_copy(DEFAULT_CONFIG)
config['cot_product'] = cot_product
context = Context()
context.session = session
context.config = apply_product_config(config)
context.config['gpg_lockfile'] = os.path.join(tmp, 'gpg_lockfile')
context.config['cot_job_type'] = "signing"
Expand All @@ -304,11 +305,5 @@ def _craft_rw_context(tmp, event_loop, cot_product):
return context


async def _close_context(context):
await _close_session(context)
await _close_session(context.queue)
await _close_session(context.temp_queue)


async def noop_async(*args, **kwargs):
pass
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -49,7 +49,7 @@ show-source = True
[pytest]
norecursedirs = .tox .git .hg sandbox .eggs build
python_files = test_*.py
addopts = -vv --color=yes
addopts = -vv --color=yes --random-order --durations=10
filterwarnings =
ignore
error:::scriptworker
Expand Down

0 comments on commit 276f4a0

Please sign in to comment.