Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/sync/, pym/portage/sync/modules/rsync/
Date: Tue, 10 Jul 2018 04:28:24
Message-Id: 1531196592.06f304c8718ac653bbdf9b5b999c03cba898bf3e.zmedico@gentoo
1 commit: 06f304c8718ac653bbdf9b5b999c03cba898bf3e
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jul 8 20:09:45 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Tue Jul 10 04:23:12 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=06f304c8
7
8 SyncBase: split out _refresh_keys method (bug 660732)
9
10 Split out a _refresh_keys method from the RsyncSync class,
11 so GitSync can use it for retry support.
12
13 Bug: https://bugs.gentoo.org/660732
14
15 pym/portage/sync/modules/rsync/rsync.py | 33 +-------------------------
16 pym/portage/sync/syncbase.py | 41 +++++++++++++++++++++++++++++++++
17 2 files changed, 42 insertions(+), 32 deletions(-)
18
19 diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
20 index 382a1eaae..a715e2818 100644
21 --- a/pym/portage/sync/modules/rsync/rsync.py
22 +++ b/pym/portage/sync/modules/rsync/rsync.py
23 @@ -7,7 +7,6 @@ import time
24 import signal
25 import socket
26 import datetime
27 -import functools
28 import io
29 import re
30 import random
31 @@ -23,10 +22,8 @@ good = create_color_func("GOOD")
32 bad = create_color_func("BAD")
33 warn = create_color_func("WARN")
34 from portage.const import VCS_DIRS, TIMESTAMP_FORMAT, RSYNC_PACKAGE_ATOM
35 -from portage.util._eventloop.global_event_loop import global_event_loop
36 from portage.util import writemsg, writemsg_stdout
37 from portage.util.futures import asyncio
38 -from portage.util.futures.executor.fork import ForkExecutor
39 from portage.sync.getaddrinfo_validate import getaddrinfo_validate
40 from _emerge.UserQuery import UserQuery
41 from portage.sync.syncbase import NewBase
42 @@ -149,39 +146,11 @@ class RsyncSync(NewBase):
43 # will not be performed and the user will have to fix it and try again,
44 # so we may as well bail out before actual rsync happens.
45 if openpgp_env is not None and self.repo.sync_openpgp_key_path is not None:
46 -
47 try:
48 out.einfo('Using keys from %s' % (self.repo.sync_openpgp_key_path,))
49 with io.open(self.repo.sync_openpgp_key_path, 'rb') as f:
50 openpgp_env.import_key(f)
51 - out.ebegin('Refreshing keys from keyserver')
52 - retry_decorator = self._key_refresh_retry_decorator()
53 - if retry_decorator is None:
54 - openpgp_env.refresh_keys()
55 - else:
56 - def noisy_refresh_keys():
57 - """
58 - Since retry does not help for some types of
59 - errors, display errors as soon as they occur.
60 - """
61 - try:
62 - openpgp_env.refresh_keys()
63 - except Exception as e:
64 - writemsg_level("%s\n" % (e,),
65 - level=logging.ERROR, noiselevel=-1)
66 - raise # retry
67 -
68 - # The ThreadPoolExecutor that asyncio uses by default
69 - # does not support cancellation of tasks, therefore
70 - # use ForkExecutor for task cancellation support, in
71 - # order to enforce timeouts.
72 - loop = global_event_loop()
73 - with ForkExecutor(loop=loop) as executor:
74 - func_coroutine = functools.partial(loop.run_in_executor,
75 - executor, noisy_refresh_keys)
76 - decorated_func = retry_decorator(func_coroutine, loop=loop)
77 - loop.run_until_complete(decorated_func())
78 - out.eend(0)
79 + self._refresh_keys(openpgp_env)
80 except (GematoException, asyncio.TimeoutError) as e:
81 writemsg_level("!!! Manifest verification impossible due to keyring problem:\n%s\n"
82 % (e,),
83
84 diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
85 index 7d4d33272..ce69a4fc0 100644
86 --- a/pym/portage/sync/syncbase.py
87 +++ b/pym/portage/sync/syncbase.py
88 @@ -7,13 +7,16 @@ This class contains common initialization code and functions.
89 '''
90
91 from __future__ import unicode_literals
92 +import functools
93 import logging
94 import os
95
96 import portage
97 from portage.util import writemsg_level
98 +from portage.util._eventloop.global_event_loop import global_event_loop
99 from portage.util.backoff import RandomExponentialBackoff
100 from portage.util.futures.retry import retry
101 +from portage.util.futures.executor.fork import ForkExecutor
102 from . import _SUBMODULE_PATH_MAP
103
104 class SyncBase(object):
105 @@ -189,6 +192,44 @@ class SyncBase(object):
106 multiplier=(1 if retry_delay_mult is None else retry_delay_mult),
107 base=(2 if retry_delay_exp_base is None else retry_delay_exp_base)))
108
109 + def _refresh_keys(self, openpgp_env):
110 + """
111 + Refresh keys stored in openpgp_env. Raises gemato.exceptions.GematoException
112 + or asyncio.TimeoutError on failure.
113 +
114 + @param openpgp_env: openpgp environment
115 + @type openpgp_env: gemato.openpgp.OpenPGPEnvironment
116 + """
117 + out = portage.output.EOutput(quiet=('--quiet' in self.options['emerge_config'].opts))
118 + out.ebegin('Refreshing keys from keyserver')
119 + retry_decorator = self._key_refresh_retry_decorator()
120 + if retry_decorator is None:
121 + openpgp_env.refresh_keys()
122 + else:
123 + def noisy_refresh_keys():
124 + """
125 + Since retry does not help for some types of
126 + errors, display errors as soon as they occur.
127 + """
128 + try:
129 + openpgp_env.refresh_keys()
130 + except Exception as e:
131 + writemsg_level("%s\n" % (e,),
132 + level=logging.ERROR, noiselevel=-1)
133 + raise # retry
134 +
135 + # The ThreadPoolExecutor that asyncio uses by default
136 + # does not support cancellation of tasks, therefore
137 + # use ForkExecutor for task cancellation support, in
138 + # order to enforce timeouts.
139 + loop = global_event_loop()
140 + with ForkExecutor(loop=loop) as executor:
141 + func_coroutine = functools.partial(loop.run_in_executor,
142 + executor, noisy_refresh_keys)
143 + decorated_func = retry_decorator(func_coroutine, loop=loop)
144 + loop.run_until_complete(decorated_func())
145 + out.eend(0)
146 +
147
148 class NewBase(SyncBase):
149 '''Subclasses Syncbase adding a new() and runs it