Merge ~vultaire/charm-logrotated:black-20.08 into charm-logrotated:master

Proposed by Paul Goins on 2020-08-06
Status: Merged
Approved by: Xav Paice on 2020-08-10
Approved revision: 98174e23a023bad96dbaa1b6ab396d05d0046301
Merged at revision: 1ec74c351769c8e778ae23604e379b1b3c6540f3
Proposed branch: ~vultaire/charm-logrotated:black-20.08
Merge into: charm-logrotated:master
Prerequisite: ~vultaire/charm-logrotated:makefile-20.08
Diff against target: 668 lines (+147/-122)
10 files modified
src/actions/actions.py (+1/-1)
src/lib/lib_cron.py (+22/-12)
src/lib/lib_logrotate.py (+33/-28)
src/reactive/logrotate.py (+15/-15)
src/tests/functional/conftest.py (+11/-10)
src/tests/functional/juju_tools.py (+13/-11)
src/tests/functional/test_logrotate.py (+15/-19)
src/tests/unit/conftest.py (+14/-12)
src/tests/unit/test_logrotate.py (+21/-9)
src/tox.ini (+2/-5)
Reviewer Review Type Date Requested Status
Xav Paice 2020-08-06 Approve on 2020-08-10
Canonical IS Reviewers 2020-08-06 Pending
Review via email: mp+388839@code.launchpad.net

Commit message

Blackened repository to 88 lines

To post a comment you must log in.

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

Paul Goins (vultaire) wrote :

Just rebased today.

Xav Paice (xavpaice) wrote :

lgtm

review: Approve

Change successfully merged at revision 1ec74c351769c8e778ae23604e379b1b3c6540f3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/actions/actions.py b/src/actions/actions.py
2index 8178850..dd311d4 100755
3--- a/src/actions/actions.py
4+++ b/src/actions/actions.py
5@@ -10,7 +10,7 @@ from lib_cron import CronHelper
6
7 from lib_logrotate import LogrotateHelper
8
9-sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
10+sys.path.insert(0, os.path.join(os.environ["CHARM_DIR"], "lib"))
11
12 hooks = hookenv.Hooks()
13 logrotate = LogrotateHelper()
14diff --git a/src/lib/lib_cron.py b/src/lib/lib_cron.py
15index b7d24c4..5c17738 100644
16--- a/src/lib/lib_cron.py
17+++ b/src/lib/lib_cron.py
18@@ -24,9 +24,9 @@ class CronHelper:
19 """
20 config_file = open(self.cronjob_etc_config, "r")
21 lines = config_file.read()
22- lines = lines.split('\n')
23+ lines = lines.split("\n")
24
25- if lines[0] == 'True':
26+ if lines[0] == "True":
27 self.cronjob_enabled = True
28 else:
29 self.cronjob_enabled = False
30@@ -43,17 +43,22 @@ class CronHelper:
31
32 if self.cronjob_enabled is True:
33 cronjob_path = os.path.realpath(__file__)
34- cron_file_path = self.cronjob_base_path\
35- + self.cronjob_check_paths[clean_up_file]\
36- + "/" + self.cronjob_logrotate_cron_file
37+ cron_file_path = (
38+ self.cronjob_base_path
39+ + self.cronjob_check_paths[clean_up_file]
40+ + "/"
41+ + self.cronjob_logrotate_cron_file
42+ )
43
44 logrotate_unit = hookenv.local_unit()
45- python_venv_path = os.getcwd().replace('charm', '') + '.venv/bin/python3'
46+ python_venv_path = os.getcwd().replace("charm", "") + ".venv/bin/python3"
47 # upgrade to template if logic increases
48- cron_file = open(cron_file_path, 'w')
49+ cron_file = open(cron_file_path, "w")
50 cron_job = """#!/bin/bash
51 /usr/bin/sudo /usr/bin/juju-run {} "{} {}"
52-""".format(logrotate_unit, python_venv_path, cronjob_path)
53+""".format(
54+ logrotate_unit, python_venv_path, cronjob_path
55+ )
56 cron_file.write(cron_job)
57 cron_file.close()
58 os.chmod(cron_file_path, 700)
59@@ -64,7 +69,12 @@ class CronHelper:
60 """Cleanup previous config."""
61 if frequency == -1:
62 for check_path in self.cronjob_check_paths:
63- path = self.cronjob_base_path + check_path + "/" + self.cronjob_logrotate_cron_file
64+ path = (
65+ self.cronjob_base_path
66+ + check_path
67+ + "/"
68+ + self.cronjob_logrotate_cron_file
69+ )
70 if os.path.exists(path):
71 os.remove(path)
72 if os.path.exists(self.cronjob_etc_config):
73@@ -79,13 +89,13 @@ class CronHelper:
74
75 def main():
76 """Ran by cron."""
77- hookenv.status_set('maintenance', 'Executing cron job.')
78+ hookenv.status_set("maintenance", "Executing cron job.")
79 cronhelper = CronHelper()
80 cronhelper.read_config()
81 cronhelper.update_logrotate_etc()
82 cronhelper.install_cronjob()
83- hookenv.status_set('active', 'Unit is ready.')
84+ hookenv.status_set("active", "Unit is ready.")
85
86
87-if __name__ == '__main__':
88+if __name__ == "__main__":
89 main()
90diff --git a/src/lib/lib_logrotate.py b/src/lib/lib_logrotate.py
91index d8c4327..497f609 100644
92--- a/src/lib/lib_logrotate.py
93+++ b/src/lib/lib_logrotate.py
94@@ -13,9 +13,9 @@ class LogrotateHelper:
95
96 def __init__(self):
97 """Init function."""
98- self.retention = hookenv.config('logrotate-retention')
99+ self.retention = hookenv.config("logrotate-retention")
100 self.override_interval_regex = re.compile("(daily|weekly|monthly|yearly)")
101- self.override = json.loads(hookenv.config('override'))
102+ self.override = json.loads(hookenv.config("override"))
103 self.override_files = self.get_override_files()
104
105 def read_config(self):
106@@ -26,7 +26,7 @@ class LogrotateHelper:
107 """
108 config_file = open("/etc/logrotate_cronjob_config", "r")
109 lines = config_file.read()
110- lines = lines.split('\n')
111+ lines = lines.split("\n")
112
113 self.retention = int(lines[2])
114
115@@ -35,7 +35,7 @@ class LogrotateHelper:
116 for config_file in os.listdir(LOGROTATE_DIR):
117 file_path = LOGROTATE_DIR + config_file
118
119- logrotate_file = open(file_path, 'r')
120+ logrotate_file = open(file_path, "r")
121 content = logrotate_file.read()
122 logrotate_file.close()
123
124@@ -43,14 +43,17 @@ class LogrotateHelper:
125
126 mod_contents = self.modify_header(mod_contents)
127
128- logrotate_file = open(file_path, 'w')
129+ logrotate_file = open(file_path, "w")
130 logrotate_file.write(mod_contents)
131 logrotate_file.close()
132
133 def get_override_files(self):
134 """Return paths for files to be overrided."""
135- return [path['path'] for path in self.override
136- if set(path.keys()) == {'path', 'rotate', 'interval'}]
137+ return [
138+ path["path"]
139+ for path in self.override
140+ if set(path.keys()) == {"path", "rotate", "interval"}
141+ ]
142
143 def get_override_settings(self, file_path):
144 """Return settings in key:value pairs for the file_path requested.
145@@ -58,22 +61,22 @@ class LogrotateHelper:
146 param: file_path: path to the file for manual settings.
147 """
148 for override_entry in self.override:
149- if file_path == override_entry['path']:
150- rotate = override_entry['rotate']
151- interval = override_entry['interval']
152- return {'rotate': rotate, 'interval': interval}
153+ if file_path == override_entry["path"]:
154+ rotate = override_entry["rotate"]
155+ interval = override_entry["interval"]
156+ return {"rotate": rotate, "interval": interval}
157
158 def modify_content(self, content, file_path):
159 """Edit the content of a logrotate file."""
160 # Split the contents in a logrotate file in separate entries (if
161 # multiple are found in the file) and put in a list for further
162 # processing
163- split = content.split('\n')
164+ split = content.split("\n")
165 items = []
166 string = ""
167 for row in split:
168- string += row + '\n'
169- if '}' in row:
170+ string += row + "\n"
171+ if "}" in row:
172 items.append(string)
173 string = ""
174 continue
175@@ -84,35 +87,37 @@ class LogrotateHelper:
176 for item in items:
177 # Override rotate, if defined
178 if file_path in self.override_files:
179- count = self.get_override_settings(file_path)['rotate']
180+ count = self.get_override_settings(file_path)["rotate"]
181 else:
182 count = self.calculate_count(item, self.retention)
183- rotate = 'rotate {}'.format(count)
184+ rotate = "rotate {}".format(count)
185 # if rotate is missing, add it as last line in the item entry
186- if 'rotate' in item:
187- result = re.sub(r'rotate \d+\.?[0-9]*', rotate, item)
188+ if "rotate" in item:
189+ result = re.sub(r"rotate \d+\.?[0-9]*", rotate, item)
190 else:
191- result = item.replace('}', ' ' + rotate + '\n}')
192+ result = item.replace("}", " " + rotate + "\n}")
193 results.append(result)
194
195- results = '\n'.join(results)
196+ results = "\n".join(results)
197
198 # Override interval, if defined
199 if file_path in self.override_files:
200- interval = self.get_override_settings(file_path)['interval']
201+ interval = self.get_override_settings(file_path)["interval"]
202 results = self.override_interval_regex.sub(interval, results)
203
204 return results
205
206 def modify_header(self, content):
207 """Add Juju headers to the file."""
208- header = "# Configuration file maintained by Juju. Local changes may be overwritten"
209+ header = (
210+ "# Configuration file maintained by Juju. Local changes may be overwritten"
211+ )
212
213- split = content.split('\n')
214+ split = content.split("\n")
215 if split[0].startswith(header):
216 result = content
217 else:
218- result = header + '\n' + content
219+ result = header + "\n" + content
220
221 return result
222
223@@ -123,16 +128,16 @@ class LogrotateHelper:
224 # better to keep the logs than lose them
225 count = retention
226 # Daily 1:1 to configuration retention period (in days)
227- if 'daily' in item:
228+ if "daily" in item:
229 count = retention
230 # Weekly rounding up, as weeks are 7 days
231- if 'weekly' in item:
232+ if "weekly" in item:
233 count = int(round(retention / 7))
234 # Monthly default 30 days and round up because of 28/31 days months
235- if 'monthly' in item:
236+ if "monthly" in item:
237 count = int(round(retention / 30))
238 # For every 360 days - add 1 year
239- if 'yearly' in item:
240+ if "yearly" in item:
241 count = retention // 360 + 1 if retention > 360 else 1
242
243 return count
244diff --git a/src/reactive/logrotate.py b/src/reactive/logrotate.py
245index b0e349a..119ac96 100644
246--- a/src/reactive/logrotate.py
247+++ b/src/reactive/logrotate.py
248@@ -13,7 +13,7 @@ logrotate = LogrotateHelper()
249 cron = CronHelper()
250
251
252-@when_not('logrotate.installed')
253+@when_not("logrotate.installed")
254 def install_logrotate():
255 """Install the logrotate charm."""
256 try:
257@@ -23,32 +23,32 @@ def install_logrotate():
258 logrotate.modify_configs()
259 cron.install_cronjob()
260 except Exception as ex:
261- hookenv.status_set('blocked', str(ex))
262- hookenv.status_set('active', 'Unit is ready.')
263- set_flag('logrotate.installed')
264+ hookenv.status_set("blocked", str(ex))
265+ hookenv.status_set("active", "Unit is ready.")
266+ set_flag("logrotate.installed")
267
268
269-@when('config.changed')
270+@when("config.changed")
271 def config_changed():
272 """Run when configuration changes."""
273 try:
274 dump_config_to_disk()
275 cron.read_config()
276 logrotate.read_config()
277- hookenv.status_set('maintenance', 'Modifying configs.')
278+ hookenv.status_set("maintenance", "Modifying configs.")
279 logrotate.modify_configs()
280 cron.install_cronjob()
281 except Exception as ex:
282- hookenv.status_set('blocked', str(ex))
283- hookenv.status_set('active', 'Unit is ready.')
284+ hookenv.status_set("blocked", str(ex))
285+ hookenv.status_set("active", "Unit is ready.")
286
287
288 def dump_config_to_disk():
289 """Dump configurations to disk."""
290- cronjob_enabled = hookenv.config('logrotate-cronjob')
291- cronjob_frequency = hookenv.config('logrotate-cronjob-frequency')
292- logrotate_retention = hookenv.config('logrotate-retention')
293- with open('/etc/logrotate_cronjob_config', 'w+') as cronjob_config_file:
294- cronjob_config_file.write(str(cronjob_enabled) + '\n')
295- cronjob_config_file.write(str(cronjob_frequency) + '\n')
296- cronjob_config_file.write(str(logrotate_retention) + '\n')
297+ cronjob_enabled = hookenv.config("logrotate-cronjob")
298+ cronjob_frequency = hookenv.config("logrotate-cronjob-frequency")
299+ logrotate_retention = hookenv.config("logrotate-retention")
300+ with open("/etc/logrotate_cronjob_config", "w+") as cronjob_config_file:
301+ cronjob_config_file.write(str(cronjob_enabled) + "\n")
302+ cronjob_config_file.write(str(cronjob_frequency) + "\n")
303+ cronjob_config_file.write(str(logrotate_retention) + "\n")
304diff --git a/src/tests/functional/conftest.py b/src/tests/functional/conftest.py
305index 1b22cb8..2cc4343 100644
306--- a/src/tests/functional/conftest.py
307+++ b/src/tests/functional/conftest.py
308@@ -21,7 +21,7 @@ from juju_tools import JujuTools
309 import pytest
310
311
312-@pytest.fixture(scope='module')
313+@pytest.fixture(scope="module")
314 def event_loop():
315 """Override the default pytest event loop.
316
317@@ -35,7 +35,7 @@ def event_loop():
318 asyncio.set_event_loop(None)
319
320
321-@pytest.fixture(scope='module')
322+@pytest.fixture(scope="module")
323 async def controller():
324 """Connect to the current controller."""
325 _controller = Controller()
326@@ -44,27 +44,28 @@ async def controller():
327 await _controller.disconnect()
328
329
330-@pytest.fixture(scope='module')
331+@pytest.fixture(scope="module")
332 async def model(controller):
333 """Live only for the duration of the test."""
334 model_name = "functest-{}".format(str(uuid.uuid4())[-12:])
335- _model = await controller.add_model(model_name,
336- cloud_name=os.getenv('PYTEST_CLOUD_NAME'),
337- region=os.getenv('PYTEST_CLOUD_REGION'),
338- )
339+ _model = await controller.add_model(
340+ model_name,
341+ cloud_name=os.getenv("PYTEST_CLOUD_NAME"),
342+ region=os.getenv("PYTEST_CLOUD_REGION"),
343+ )
344 # https://github.com/juju/python-libjuju/issues/267
345- subprocess.check_call(['juju', 'models'])
346+ subprocess.check_call(["juju", "models"])
347 while model_name not in await controller.list_models():
348 await asyncio.sleep(1)
349 yield _model
350 await _model.disconnect()
351- if not os.getenv('PYTEST_KEEP_MODEL'):
352+ if not os.getenv("PYTEST_KEEP_MODEL"):
353 await controller.destroy_model(model_name)
354 while model_name in await controller.list_models():
355 await asyncio.sleep(1)
356
357
358-@pytest.fixture(scope='module')
359+@pytest.fixture(scope="module")
360 async def jujutools(controller, model):
361 """Juju tools."""
362 tools = JujuTools(controller, model)
363diff --git a/src/tests/functional/juju_tools.py b/src/tests/functional/juju_tools.py
364index 5e4a1cc..6ce6f10 100644
365--- a/src/tests/functional/juju_tools.py
366+++ b/src/tests/functional/juju_tools.py
367@@ -37,14 +37,17 @@ class JujuTools:
368 :param target: Unit object or unit name string
369 """
370 python3 = "python3 -c '{}'"
371- python_cmd = ('import pickle;'
372- 'import base64;'
373- '{}'
374- 'print(base64.b64encode(pickle.dumps({})), end="")'
375- .format(imports, remote_cmd))
376+ python_cmd = (
377+ "import pickle;"
378+ "import base64;"
379+ "{}"
380+ 'print(base64.b64encode(pickle.dumps({})), end="")'.format(
381+ imports, remote_cmd
382+ )
383+ )
384 cmd = python3.format(python_cmd)
385 results = await self.run_command(cmd, target)
386- return pickle.loads(base64.b64decode(bytes(results['Stdout'][2:-1], 'utf8')))
387+ return pickle.loads(base64.b64decode(bytes(results["Stdout"][2:-1], "utf8")))
388
389 async def file_stat(self, path, target):
390 """Run stat on a file.
391@@ -52,9 +55,8 @@ class JujuTools:
392 :param path: File path
393 :param target: Unit object or unit name string
394 """
395- imports = 'import os;'
396- python_cmd = ('os.stat("{}")'
397- .format(path))
398+ imports = "import os;"
399+ python_cmd = 'os.stat("{}")'.format(path)
400 print("Calling remote cmd: " + python_cmd)
401 return await self.remote_object(imports, python_cmd, target)
402
403@@ -64,6 +66,6 @@ class JujuTools:
404 :param path: File path
405 :param target: Unit object or unit name string
406 """
407- cmd = 'cat {}'.format(path)
408+ cmd = "cat {}".format(path)
409 result = await self.run_command(cmd, target)
410- return result['Stdout']
411+ return result["Stdout"]
412diff --git a/src/tests/functional/test_logrotate.py b/src/tests/functional/test_logrotate.py
413index 936c577..68ecce0 100644
414--- a/src/tests/functional/test_logrotate.py
415+++ b/src/tests/functional/test_logrotate.py
416@@ -6,48 +6,44 @@ import os
417 import pytest
418
419 pytestmark = pytest.mark.asyncio
420-SERIES = ['xenial',
421- 'bionic',
422- 'focal',
423- ]
424+SERIES = [
425+ "xenial",
426+ "bionic",
427+ "focal",
428+]
429
430
431 ############
432 # FIXTURES #
433 ############
434
435-@pytest.fixture(scope='module',
436- params=SERIES)
437+
438+@pytest.fixture(scope="module", params=SERIES)
439 async def deploy_app(request, model):
440 """Deploy the logrotate charm as a subordinate of ubuntu."""
441 release = request.param
442
443 await model.deploy(
444- 'ubuntu',
445- application_name='ubuntu-' + release,
446- series=release,
447- channel='stable'
448+ "ubuntu", application_name="ubuntu-" + release, series=release, channel="stable"
449 )
450 logrotate_app = await model.deploy(
451- '{}/logrotated'.format(os.getenv('CHARM_BUILD_DIR')),
452- application_name='logrotate-' + release,
453+ "{}/logrotated".format(os.getenv("CHARM_BUILD_DIR")),
454+ application_name="logrotate-" + release,
455 series=release,
456 num_units=0,
457 )
458- await model.add_relation(
459- 'ubuntu-' + release,
460- 'logrotate-' + release
461- )
462+ await model.add_relation("ubuntu-" + release, "logrotate-" + release)
463
464- await model.block_until(lambda: logrotate_app.status == 'active')
465+ await model.block_until(lambda: logrotate_app.status == "active")
466 yield logrotate_app
467
468
469-@pytest.fixture(scope='module')
470+@pytest.fixture(scope="module")
471 async def unit(deploy_app):
472 """Return the logrotate unit we've deployed."""
473 return deploy_app.units.pop()
474
475+
476 #########
477 # TESTS #
478 #########
479@@ -55,4 +51,4 @@ async def unit(deploy_app):
480
481 async def test_deploy(deploy_app):
482 """Tst the deployment."""
483- assert deploy_app.status == 'active'
484+ assert deploy_app.status == "active"
485diff --git a/src/tests/unit/conftest.py b/src/tests/unit/conftest.py
486index b4c0517..2bb8eb8 100644
487--- a/src/tests/unit/conftest.py
488+++ b/src/tests/unit/conftest.py
489@@ -12,19 +12,20 @@ import pytest
490 def mock_layers(monkeypatch):
491 """Layers mock."""
492 import sys
493- sys.modules['charms.layer'] = mock.Mock()
494- sys.modules['reactive'] = mock.Mock()
495+
496+ sys.modules["charms.layer"] = mock.Mock()
497+ sys.modules["reactive"] = mock.Mock()
498 # Mock any functions in layers that need to be mocked here
499
500 def options(layer):
501 # mock options for layers here
502- if layer == 'example-layer':
503- options = {'port': 9999}
504+ if layer == "example-layer":
505+ options = {"port": 9999}
506 return options
507 else:
508 return None
509
510- monkeypatch.setattr('lib_logrotate.layer.options', options)
511+ monkeypatch.setattr("lib_logrotate.layer.options", options)
512
513
514 @pytest.fixture
515@@ -34,38 +35,39 @@ def mock_hookenv_config(monkeypatch):
516
517 def mock_config():
518 cfg = {}
519- yml = yaml.load(open('./config.yaml'))
520+ yml = yaml.load(open("./config.yaml"))
521
522 # Load all defaults
523- for key, value in yml['options'].items():
524- cfg[key] = value['default']
525+ for key, value in yml["options"].items():
526+ cfg[key] = value["default"]
527
528 # Manually add cfg from other layers
529 # cfg['my-other-layer'] = 'mock'
530 return cfg
531
532- monkeypatch.setattr('lib_logrotate.hookenv.config', mock_config)
533+ monkeypatch.setattr("lib_logrotate.hookenv.config", mock_config)
534
535
536 @pytest.fixture
537 def mock_remote_unit(monkeypatch):
538 """Remote unit mock."""
539- monkeypatch.setattr('lib_logrotate.hookenv.remote_unit', lambda: 'unit-mock/0')
540+ monkeypatch.setattr("lib_logrotate.hookenv.remote_unit", lambda: "unit-mock/0")
541
542
543 @pytest.fixture
544 def mock_charm_dir(monkeypatch):
545 """Charm dir mock."""
546- monkeypatch.setattr('lib_logrotate.hookenv.charm_dir', lambda: '/mock/charm/dir')
547+ monkeypatch.setattr("lib_logrotate.hookenv.charm_dir", lambda: "/mock/charm/dir")
548
549
550 @pytest.fixture
551 def logrotate(tmpdir, mock_hookenv_config, mock_charm_dir, monkeypatch):
552 """Logrotate fixture."""
553 from lib_logrotate import LogrotateHelper
554+
555 helper = LogrotateHelper
556
557 # Any other functions that load helper will get this version
558- monkeypatch.setattr('lib_logrotate.LogrotateHelper', lambda: helper)
559+ monkeypatch.setattr("lib_logrotate.LogrotateHelper", lambda: helper)
560
561 return helper
562diff --git a/src/tests/unit/test_logrotate.py b/src/tests/unit/test_logrotate.py
563index 68ed164..b317257 100644
564--- a/src/tests/unit/test_logrotate.py
565+++ b/src/tests/unit/test_logrotate.py
566@@ -1,7 +1,7 @@
567 """Main unit test module."""
568
569
570-class TestLogrotateHelper():
571+class TestLogrotateHelper:
572 """Main test class."""
573
574 def test_pytest(self):
575@@ -11,28 +11,28 @@ class TestLogrotateHelper():
576 def test_daily_retention_count(self, logrotate):
577 """Test daily retention count."""
578 logrotate.retention = 90
579- contents = '/var/log/some.log {\n rotate 123\n daily\n}'
580+ contents = "/var/log/some.log {\n rotate 123\n daily\n}"
581 count = logrotate.calculate_count(contents, logrotate.retention)
582 assert count == 90
583
584 def test_weekly_retention_count(self, logrotate):
585 """Test weekly retention count."""
586 logrotate.retention = 21
587- contents = '/var/log/some.log {\n rotate 123\n weekly\n}'
588+ contents = "/var/log/some.log {\n rotate 123\n weekly\n}"
589 count = logrotate.calculate_count(contents, logrotate.retention)
590 assert count == 3
591
592 def test_monthly_retention_count(self, logrotate):
593 """Test monthly retention count."""
594 logrotate.retention = 60
595- contents = '/var/log/some.log {\n rotate 123\n monthly\n}'
596+ contents = "/var/log/some.log {\n rotate 123\n monthly\n}"
597 count = logrotate.calculate_count(contents, logrotate.retention)
598 assert count == 2
599
600 def test_yearly_retention_count(self, logrotate):
601 """Test yearly retention count."""
602 logrotate.retention = 180
603- contents = '/var/log/some.log {\n rotate 123\n yearly\n}'
604+ contents = "/var/log/some.log {\n rotate 123\n yearly\n}"
605 count = logrotate.calculate_count(contents, logrotate.retention)
606 assert count == 1
607
608@@ -42,9 +42,15 @@ class TestLogrotateHelper():
609 logrotate.retention = 42
610 logrotate.override = []
611 logrotate.override_files = []
612- contents = '/log/some.log {\n rotate 123\n daily\n}\n/log/other.log {\n rotate 456\n weekly\n}'
613+ contents = (
614+ "/log/some.log {\n rotate 123\n daily\n}\n"
615+ "/log/other.log {\n rotate 456\n weekly\n}"
616+ )
617 mod_contents = logrotate.modify_content(logrotate, contents, file_path)
618- expected_contents = '/log/some.log {\n rotate 42\n daily\n}\n\n/log/other.log {\n rotate 6\n weekly\n}\n'
619+ expected_contents = (
620+ "/log/some.log {\n rotate 42\n daily\n}\n\n"
621+ "/log/other.log {\n rotate 6\n weekly\n}\n"
622+ )
623 assert mod_contents == expected_contents
624
625 def test_modify_content_override(self, logrotate):
626@@ -53,7 +59,13 @@ class TestLogrotateHelper():
627 logrotate.retention = 42
628 logrotate.override = []
629 logrotate.override_files = []
630- contents = '/log/some.log {\n rotate 123\n daily\n}\n/log/other.log {\n rotate 456\n weekly\n}'
631+ contents = (
632+ "/log/some.log {\n rotate 123\n daily\n}\n"
633+ "/log/other.log {\n rotate 456\n weekly\n}"
634+ )
635 mod_contents = logrotate.modify_content(logrotate, contents, file_path)
636- expected_contents = '/log/some.log {\n rotate 42\n daily\n}\n\n/log/other.log {\n rotate 6\n weekly\n}\n'
637+ expected_contents = (
638+ "/log/some.log {\n rotate 42\n daily\n}\n\n"
639+ "/log/other.log {\n rotate 6\n weekly\n}\n"
640+ )
641 assert mod_contents == expected_contents
642diff --git a/src/tox.ini b/src/tox.ini
643index 78da1be..2900ead 100644
644--- a/src/tox.ini
645+++ b/src/tox.ini
646@@ -25,7 +25,7 @@ passenv =
647 [testenv:lint]
648 commands =
649 flake8
650-#TODO black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
651+ black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
652 deps =
653 black
654 flake8
655@@ -43,12 +43,9 @@ exclude =
656 mod,
657 .build
658
659-#max-line-length = 88
660+max-line-length = 88
661 max-complexity = 10
662
663-# from old tox.ini
664-max-line-length = 120
665-
666 [testenv:black]
667 commands =
668 black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .

Subscribers

People subscribed via source and target branches