Merge ~peppepetra/charm-sudo-pair:lint-20.08 into charm-sudo-pair:master

Proposed by Giuseppe Petralia
Status: Merged
Merged at revision: 7e3bae46ebed59798e7bfd6d4fe66a14c208d08e
Proposed branch: ~peppepetra/charm-sudo-pair:lint-20.08
Merge into: charm-sudo-pair:master
Prerequisite: ~peppepetra/charm-sudo-pair:blacken-20.08
Diff against target: 276 lines (+49/-29)
9 files modified
src/actions/actions.py (+2/-0)
src/lib/libsudopair.py (+1/-0)
src/reactive/sudo_pair.py (+4/-0)
src/tests/functional/conftest.py (+27/-26)
src/tests/functional/test_deploy.py (+1/-0)
src/tests/unit/conftest.py (+4/-0)
src/tests/unit/test_actions.py (+3/-0)
src/tests/unit/test_libsudopair.py (+4/-0)
src/tox.ini (+3/-3)
Reviewer Review Type Date Requested Status
Drew Freiberger (community) Approve
Paul Goins Approve
Review via email: mp+388999@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paul Goins (vultaire) wrote :

Generally in favor, but the noqa clauses need to be fixed since without the colon they disable all checks.

review: Needs Fixing
Revision history for this message
Paul Goins (vultaire) wrote :

LGTM.

review: Approve
Revision history for this message
Drew Freiberger (afreiberger) wrote :

LGTM. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/actions/actions.py b/src/actions/actions.py
index 2416eb3..9ff1ec5 100755
--- a/src/actions/actions.py
+++ b/src/actions/actions.py
@@ -1,4 +1,5 @@
1#!/usr/local/sbin/charm-env python31#!/usr/local/sbin/charm-env python3
2"""Sudo Pair actions."""
2#3#
3# Copyright 2016,2019,2020 Canonical Ltd4# Copyright 2016,2019,2020 Canonical Ltd
4#5#
@@ -39,6 +40,7 @@ ACTIONS = {"remove-sudopair": remove}
3940
4041
41def main(args):42def main(args):
43 """Dispatch actions based on command arguments."""
42 action_name = os.path.basename(args[0])44 action_name = os.path.basename(args[0])
43 try:45 try:
44 ACTIONS[action_name]()46 ACTIONS[action_name]()
diff --git a/src/lib/libsudopair.py b/src/lib/libsudopair.py
index cbaf467..2f7c45b 100644
--- a/src/lib/libsudopair.py
+++ b/src/lib/libsudopair.py
@@ -1,3 +1,4 @@
1"""Sudo pair utilities."""
1import grp2import grp
2import os3import os
34
diff --git a/src/reactive/sudo_pair.py b/src/reactive/sudo_pair.py
index ed1d7ba..caab64f 100644
--- a/src/reactive/sudo_pair.py
+++ b/src/reactive/sudo_pair.py
@@ -1,3 +1,5 @@
1"""Charm reactive hooks."""
2
1from charmhelpers.core import hookenv3from charmhelpers.core import hookenv
24
3from charms.reactive import hook, remove_state, set_state, when, when_not5from charms.reactive import hook, remove_state, set_state, when, when_not
@@ -46,11 +48,13 @@ def install_sudo_pair():
4648
47@hook("config-changed")49@hook("config-changed")
48def reconfigure_sudo_pair_charm():50def reconfigure_sudo_pair_charm():
51 """Run config-changed hook."""
49 sph.set_charm_config(hookenv.config())52 sph.set_charm_config(hookenv.config())
50 remove_state("sudo-pair.configured")53 remove_state("sudo-pair.configured")
5154
5255
53@hook("stop")56@hook("stop")
54def stop():57def stop():
58 """Run stop hook and remove charm configuration."""
55 sph.deconfigure()59 sph.deconfigure()
56 remove_state("sudo-pair.installed")60 remove_state("sudo-pair.installed")
diff --git a/src/tests/functional/conftest.py b/src/tests/functional/conftest.py
index 7a8523e..fdd4356 100644
--- a/src/tests/functional/conftest.py
+++ b/src/tests/functional/conftest.py
@@ -1,4 +1,5 @@
1#!/usr/bin/python31#!/usr/bin/python3
2"""Functional tests utilities."""
23
3import asyncio4import asyncio
4import json5import json
@@ -60,7 +61,7 @@ async def current_model():
6061
6162
62@pytest.fixture63@pytest.fixture
63async def get_app(model):64async def get_app(model): # noqa: D202
64 """Return the application requested."""65 """Return the application requested."""
6566
66 async def _get_app(name):67 async def _get_app(name):
@@ -73,7 +74,7 @@ async def get_app(model):
7374
7475
75@pytest.fixture76@pytest.fixture
76async def get_unit(model):77async def get_unit(model): # noqa: D202
77 """Return the requested <app_name>/<unit_number> unit."""78 """Return the requested <app_name>/<unit_number> unit."""
7879
79 async def _get_unit(name):80 async def _get_unit(name):
@@ -87,7 +88,7 @@ async def get_unit(model):
8788
8889
89@pytest.fixture90@pytest.fixture
90async def get_entity(model, get_unit, get_app):91async def get_entity(model, get_unit, get_app): # noqa: D202
91 """Return a unit or an application."""92 """Return a unit or an application."""
9293
93 async def _get_entity(name):94 async def _get_entity(name):
@@ -103,15 +104,15 @@ async def get_entity(model, get_unit, get_app):
103104
104105
105@pytest.fixture106@pytest.fixture
106async def run_command(get_unit):107async def run_command(get_unit): # noqa: D202
107 """108 """Run a command on an unit."""
108 Run a command on a unit.
109
110 :param cmd: Command to be run
111 :param target: Unit object or unit name string
112 """
113109
114 async def _run_command(cmd, target):110 async def _run_command(cmd, target):
111 """Run a command on a unit.
112
113 :param cmd: Command to be run
114 :param target: Unit object or unit name string
115 """
115 unit = target if type(target) is juju.unit.Unit else await get_unit(target)116 unit = target if type(target) is juju.unit.Unit else await get_unit(target)
116 action = await unit.run(cmd)117 action = await unit.run(cmd)
117 return action.results118 return action.results
@@ -120,15 +121,15 @@ async def run_command(get_unit):
120121
121122
122@pytest.fixture123@pytest.fixture
123async def file_stat(run_command):124async def file_stat(run_command): # noqa: D202
124 """125 """Get file stat from an unit."""
125 Run stat on a file.
126
127 :param path: File path
128 :param target: Unit object or unit name string
129 """
130126
131 async def _file_stat(path, target):127 async def _file_stat(path, target):
128 """Run stat on a file.
129
130 :param path: File path
131 :param target: Unit object or unit name string
132 """
132 cmd = STAT_FILE % path133 cmd = STAT_FILE % path
133 results = await run_command(cmd, target)134 results = await run_command(cmd, target)
134 return json.loads(results["Stdout"])135 return json.loads(results["Stdout"])
@@ -137,15 +138,15 @@ async def file_stat(run_command):
137138
138139
139@pytest.fixture140@pytest.fixture
140async def file_contents(run_command):141async def file_contents(run_command): # noqa: D202
141 """142 """Return the contents of a file."""
142 Return the contents of a file.
143
144 :param path: File path
145 :param target: Unit object or unit name string
146 """
147143
148 async def _file_contents(path, target):144 async def _file_contents(path, target):
145 """Return the contents of a file.
146
147 :param path: File path
148 :param target: Unit object or unit name string
149 """
149 cmd = "cat {}".format(path)150 cmd = "cat {}".format(path)
150 results = await run_command(cmd, target)151 results = await run_command(cmd, target)
151 return results["Stdout"]152 return results["Stdout"]
@@ -154,7 +155,7 @@ async def file_contents(run_command):
154155
155156
156@pytest.fixture157@pytest.fixture
157async def reconfigure_app(get_app, model):158async def reconfigure_app(get_app, model): # noqa: D202
158 """Apply a different config to the requested app."""159 """Apply a different config to the requested app."""
159160
160 async def _reconfigure_app(cfg, target):161 async def _reconfigure_app(cfg, target):
@@ -171,7 +172,7 @@ async def reconfigure_app(get_app, model):
171172
172173
173@pytest.fixture174@pytest.fixture
174async def create_group(run_command):175async def create_group(run_command): # noqa: D202
175 """Create the UNIX group specified."""176 """Create the UNIX group specified."""
176177
177 async def _create_group(group_name, target):178 async def _create_group(group_name, target):
diff --git a/src/tests/functional/test_deploy.py b/src/tests/functional/test_deploy.py
index 7f24224..11e8297 100644
--- a/src/tests/functional/test_deploy.py
+++ b/src/tests/functional/test_deploy.py
@@ -1,4 +1,5 @@
1#!/usr/bin/python3.61#!/usr/bin/python3.6
2"""Charm functional tests."""
23
3import os4import os
45
diff --git a/src/tests/unit/conftest.py b/src/tests/unit/conftest.py
index 9ca50ec..c1df1d0 100644
--- a/src/tests/unit/conftest.py
+++ b/src/tests/unit/conftest.py
@@ -1,4 +1,5 @@
1#!/usr/bin/python31#!/usr/bin/python3
2"""Unit tests utilities."""
23
3import grp4import grp
4import os5import os
@@ -10,6 +11,7 @@ import pytest
1011
11@pytest.fixture12@pytest.fixture
12def mock_hookenv_config(monkeypatch):13def mock_hookenv_config(monkeypatch):
14 """Mock hookenv config."""
13 import yaml15 import yaml
1416
15 def mock_config():17 def mock_config():
@@ -27,11 +29,13 @@ def mock_hookenv_config(monkeypatch):
2729
28@pytest.fixture30@pytest.fixture
29def mock_charm_dir(monkeypatch):31def mock_charm_dir(monkeypatch):
32 """Mock charm dir."""
30 monkeypatch.setattr("charmhelpers.core.hookenv.charm_dir", lambda: ".")33 monkeypatch.setattr("charmhelpers.core.hookenv.charm_dir", lambda: ".")
3134
3235
33@pytest.fixture36@pytest.fixture
34def sph(mock_hookenv_config, mock_charm_dir, tmpdir):37def sph(mock_hookenv_config, mock_charm_dir, tmpdir):
38 """Return SudoPairHelpers with mocks."""
35 from libsudopair import SudoPairHelper39 from libsudopair import SudoPairHelper
3640
37 sph = SudoPairHelper()41 sph = SudoPairHelper()
diff --git a/src/tests/unit/test_actions.py b/src/tests/unit/test_actions.py
index d6d86d7..ddf6003 100644
--- a/src/tests/unit/test_actions.py
+++ b/src/tests/unit/test_actions.py
@@ -1,3 +1,5 @@
1"""Unit tests for charm actions."""
2
1import os3import os
2import sys4import sys
3import unittest.mock as mock5import unittest.mock as mock
@@ -11,6 +13,7 @@ import actions # NOQA
11@mock.patch("actions.action_set")13@mock.patch("actions.action_set")
12@mock.patch("actions.status_set")14@mock.patch("actions.status_set")
13def test_remove_action(status_set, action_set, sudo_pair_helper):15def test_remove_action(status_set, action_set, sudo_pair_helper):
16 """Verify remove action."""
14 actions.remove()17 actions.remove()
15 msg = "Successfully removed sudo-pair config and binaries"18 msg = "Successfully removed sudo-pair config and binaries"
16 action_set.assert_called_with({"message": msg})19 action_set.assert_called_with({"message": msg})
diff --git a/src/tests/unit/test_libsudopair.py b/src/tests/unit/test_libsudopair.py
index 874f0a3..860d8db 100644
--- a/src/tests/unit/test_libsudopair.py
+++ b/src/tests/unit/test_libsudopair.py
@@ -1,3 +1,5 @@
1"""Sudopair lib unit tests."""
2
1import filecmp3import filecmp
2import grp4import grp
3import os5import os
@@ -6,11 +8,13 @@ from libsudopair import check_valid_group, group_id
68
79
8def test_check_valid_group():10def test_check_valid_group():
11 """Check an unix group is valid."""
9 assert not check_valid_group("fake_group")12 assert not check_valid_group("fake_group")
10 assert check_valid_group(grp.getgrgid(os.getgid()).gr_name)13 assert check_valid_group(grp.getgrgid(os.getgid()).gr_name)
1114
1215
13def test_group_id():16def test_group_id():
17 """Verify group_id() is correct."""
14 assert group_id(grp.getgrgid(os.getgid()).gr_name) == os.getgid()18 assert group_id(grp.getgrgid(os.getgid()).gr_name) == os.getgid()
1519
1620
diff --git a/src/tox.ini b/src/tox.ini
index 2085ea9..2900ead 100644
--- a/src/tox.ini
+++ b/src/tox.ini
@@ -29,9 +29,9 @@ commands =
29deps =29deps =
30 black30 black
31 flake831 flake8
32#TODO flake8-docstrings32 flake8-docstrings
33#TODO flake8-import-order33 flake8-import-order
34#TODO pep8-naming34 pep8-naming
35 flake8-colors35 flake8-colors
3636
37[flake8]37[flake8]

Subscribers

People subscribed via source and target branches