Merge ~hloeung/apt-stresstest-charm:cleanup into apt-stresstest-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 479bc835de0a57e4d9bd706dfb8dad8c37ac54b5
Merged at revision: a0b8213d82085dc9671068e3e145518b7e156be1
Proposed branch: ~hloeung/apt-stresstest-charm:cleanup
Merge into: apt-stresstest-charm:master
Prerequisite: ~hloeung/apt-stresstest-charm:master
Diff against target: 207 lines (+62/-52)
3 files modified
files/test_apt_mirrors.py (+57/-40)
hooks/relations/telegraf-exec/provides.py (+1/-5)
reactive/apt_stresstest.py (+4/-7)
Reviewer Review Type Date Requested Status
Thomas Cuthbert (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+392416@code.launchpad.net

Commit message

black-ify

Description of the change

black-ify

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Thomas Cuthbert (tcuthbert) wrote :

LGTM but maybe rebase it so there is only the blackify commit in the MP.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change has no commit message, setting status to needs review.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision a0b8213d82085dc9671068e3e145518b7e156be1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/files/test_apt_mirrors.py b/files/test_apt_mirrors.py
2index 0497910..043c4e4 100755
3--- a/files/test_apt_mirrors.py
4+++ b/files/test_apt_mirrors.py
5@@ -37,6 +37,7 @@ log = logging.getLogger('apt-stresstest')
6 log.setLevel(logging.INFO)
7 log.addHandler(file_handler)
8
9+
10 class Timer(object):
11 def __init__(self):
12 self._timer = None
13@@ -60,28 +61,34 @@ def devnull():
14 def parse_args():
15 parser = argparse.ArgumentParser()
16
17- parser.add_argument('-v', '--verbose', help="increase output verbosity.",
18- action="store_true")
19+ parser.add_argument('-v', '--verbose', help="increase output verbosity.", action="store_true")
20
21- parser.add_argument('-p', "--package", help="package to download from repositories.",
22- default="bash")
23+ parser.add_argument('-p', "--package", help="package to download from repositories.", default="bash")
24
25- parser.add_argument('-f', "--hosts-file", help="local path for chrooted /etc/hosts configuration file.",
26- default=None)
27+ parser.add_argument(
28+ '-f', "--hosts-file", help="local path for chrooted /etc/hosts configuration file.", default=None
29+ )
30
31- parser.add_argument('-s', '--send-to', help="where to write the output, e.g. 127.0.0.1:8094",
32- default=None)
33+ parser.add_argument('-s', '--send-to', help="where to write the output, e.g. 127.0.0.1:8094", default=None)
34
35- parser.add_argument('--update-timeout', default=20, type=int,
36- help="apt-get update timeout in seconds. If exceeded metric value will be set to 0",
37- )
38+ parser.add_argument(
39+ '--update-timeout',
40+ default=20,
41+ type=int,
42+ help="apt-get update timeout in seconds. If exceeded metric value will be set to 0",
43+ )
44
45- parser.add_argument('--download-timeout', default=120, type=int,
46- help="apt-get download timeout in seconds. If exceeded metric value will be set to 0",
47- )
48- parser.add_argument('--series', type=int,
49- help="Default Ubuntu release/series to test",
50- )
51+ parser.add_argument(
52+ '--download-timeout',
53+ default=120,
54+ type=int,
55+ help="apt-get download timeout in seconds. If exceeded metric value will be set to 0",
56+ )
57+ parser.add_argument(
58+ '--series',
59+ type=int,
60+ help="Default Ubuntu release/series to test",
61+ )
62
63 return parser.parse_args()
64
65@@ -151,13 +158,7 @@ def run(cmd, stderr=None, timeout=120):
66
67 def render_influx(test, domain, ip, value, metric_name="apt_transaction_duration_seconds"):
68 line_fmt = "{metric_name},test={test},mirror={domain},ip={ip} value={value}"
69- return line_fmt.format(
70- metric_name=metric_name,
71- test=test,
72- domain=domain,
73- ip=ip,
74- value=value
75- )
76+ return line_fmt.format(metric_name=metric_name, test=test, domain=domain, ip=ip, value=value)
77
78
79 def send_to_influx(send_to, metrics):
80@@ -181,24 +182,34 @@ def output_results(result, verbose=False, send_to=None):
81 def run_tests(domain, ip, packages, args):
82
83 log.info("Running apt update 1 and sending to telegraf")
84- output_results(render_influx("update_1", domain, ip,
85- apt_update(ip, timeout=args.update_timeout)),
86- verbose=args.verbose, send_to=args.send_to)
87+ output_results(
88+ render_influx("update_1", domain, ip, apt_update(ip, timeout=args.update_timeout)),
89+ verbose=args.verbose,
90+ send_to=args.send_to,
91+ )
92 log.info("Running apt update 2 and sending to telegraf")
93- output_results(render_influx("update_2", domain, ip,
94- apt_update(ip, timeout=args.update_timeout)),
95- verbose=args.verbose, send_to=args.send_to)
96+ output_results(
97+ render_influx("update_2", domain, ip, apt_update(ip, timeout=args.update_timeout)),
98+ verbose=args.verbose,
99+ send_to=args.send_to,
100+ )
101 for index, package in enumerate(packages):
102 log.info("Performing cached download of {} - {} and sending to telegraf".format(1 + index, package))
103 test_name = "cached_download_{}_{}".format(1 + index, package)
104- output_results(render_influx(test_name, domain, ip,
105- apt_download(package, ip, timeout=args.download_timeout)),
106- verbose=args.verbose, send_to=args.send_to)
107+ output_results(
108+ render_influx(test_name, domain, ip, apt_download(package, ip, timeout=args.download_timeout)),
109+ verbose=args.verbose,
110+ send_to=args.send_to,
111+ )
112 log.info("Performing uncached download of {} - {} and sending to telegraf".format(1 + index, package))
113 test_name = "uncached_download_{}_{}".format(1 + index, package)
114- output_results(render_influx(test_name, domain, ip,
115- apt_download(package, ip, no_cache=True, timeout=args.download_timeout)),
116- verbose=args.verbose, send_to=args.send_to)
117+ output_results(
118+ render_influx(
119+ test_name, domain, ip, apt_download(package, ip, no_cache=True, timeout=args.download_timeout)
120+ ),
121+ verbose=args.verbose,
122+ send_to=args.send_to,
123+ )
124
125
126 def get_apt_config_path(ip):
127@@ -269,10 +280,16 @@ def main():
128 )
129 log.info("Tests done, stopping timer.")
130 timer.stop()
131- output_results(render_influx("N/A", "N/A", "N/A", timer.time, "apt_transaction_total_duration_seconds"),
132- verbose=args.verbose, send_to=args.send_to)
133- output_results(render_influx("N/A", "N/A", "N/A", len(ips), "apt_mirror_units_count"),
134- verbose=args.verbose, send_to=args.send_to)
135+ output_results(
136+ render_influx("N/A", "N/A", "N/A", timer.time, "apt_transaction_total_duration_seconds"),
137+ verbose=args.verbose,
138+ send_to=args.send_to,
139+ )
140+ output_results(
141+ render_influx("N/A", "N/A", "N/A", len(ips), "apt_mirror_units_count"),
142+ verbose=args.verbose,
143+ send_to=args.send_to,
144+ )
145 log.info("Pushed global timer and units count to telegraf.")
146
147
148diff --git a/hooks/relations/telegraf-exec/provides.py b/hooks/relations/telegraf-exec/provides.py
149index ea5de4b..405b1ce 100644
150--- a/hooks/relations/telegraf-exec/provides.py
151+++ b/hooks/relations/telegraf-exec/provides.py
152@@ -35,11 +35,7 @@ class ExecProvides(RelationBase):
153 conversation.remove_state('{relation_name}.available')
154
155 def set_command(self, cmds, timeout, data_fmt):
156- config = json.dumps([{
157- 'commands': cmds,
158- 'timeout': timeout,
159- 'data_format': data_fmt
160- }])
161+ config = json.dumps([{'commands': cmds, 'timeout': timeout, 'data_format': data_fmt}])
162
163 for conversation in self.conversations():
164 conversation.set_remote(key="commands", value=config)
165diff --git a/reactive/apt_stresstest.py b/reactive/apt_stresstest.py
166index 6ab6884..6b5f548 100644
167--- a/reactive/apt_stresstest.py
168+++ b/reactive/apt_stresstest.py
169@@ -64,10 +64,7 @@ def install_script():
170 if os.path.exists('/usr/local/bin/test_apt_mirrors.py'):
171 os.remove('/usr/local/bin/test_apt_mirrors.py')
172
173- shutil.copy(
174- os.path.join(charm_dir, 'files/test_apt_mirrors.py'),
175- '/usr/local/bin/test_apt_mirrors.py'
176- )
177+ shutil.copy(os.path.join(charm_dir, 'files/test_apt_mirrors.py'), '/usr/local/bin/test_apt_mirrors.py')
178
179
180 def install_crontab():
181@@ -77,7 +74,7 @@ def install_crontab():
182 content=APT_STRESSTEST_CRONTAB_TEMPLATE.format(
183 args=stress_test_args(),
184 stresstest_timeout=config.get('stresstest-timeout'),
185- ).encode('utf-8')
186+ ).encode('utf-8'),
187 )
188
189
190@@ -109,7 +106,7 @@ def reconfigure():
191 'apt.installed.run-one',
192 'apt.installed.schroot',
193 'apt.installed.simplestreams',
194- 'apt.installed.ubuntu-cloudimage-keyring'
195+ 'apt.installed.ubuntu-cloudimage-keyring',
196 )
197 @when_not('exec.available')
198 def status_wait_for_telegraf():
199@@ -123,7 +120,7 @@ def status_wait_for_telegraf():
200 'apt.installed.schroot',
201 'apt.installed.simplestreams',
202 'apt.installed.ubuntu-cloudimage-keyring',
203- 'exec.available'
204+ 'exec.available',
205 )
206 @when_not('apt-stresstest.installed')
207 def install_apt_stresstest(exec_relation):

Subscribers

People subscribed via source and target branches