Skip to content

Commit bc85d19

Browse files
committed
Minor linting fixups
1 parent 884c242 commit bc85d19

File tree

10 files changed

+34
-36
lines changed

10 files changed

+34
-36
lines changed

plugins/module_utils/acm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
# on behalf of Telstra Corporation Limited
2222
#
2323
# Common functionality to be used by the modules:
24-
# - acm
24+
# - acm_certificate
25+
# - acm_certificate_info
2526

2627
from __future__ import (absolute_import, division, print_function)
2728
__metaclass__ = type
@@ -213,7 +214,7 @@ def import_certificate(self, client, module, certificate, private_key, arn=None,
213214
module.debug("Attempting to delete the cert we just created, arn=%s" % arn)
214215
try:
215216
self.delete_certificate_with_backoff(client, arn)
216-
except Exception as f:
217+
except Exception:
217218
module.warn("Certificate %s exists, and is not tagged. So Ansible will not see it on the next run.")
218219
module.fail_json_aws(e, msg="Couldn't tag certificate %s, couldn't delete it either" % arn)
219220
module.fail_json_aws(e, msg="Couldn't tag certificate %s" % arn)

plugins/module_utils/botocore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None
7272
except (botocore.exceptions.ProfileNotFound, botocore.exceptions.PartialCredentialsError,
7373
botocore.exceptions.NoCredentialsError, botocore.exceptions.ConfigParseError) as e:
7474
module.fail_json(msg=to_native(e))
75-
except botocore.exceptions.NoRegionError as e:
75+
except botocore.exceptions.NoRegionError:
7676
module.fail_json(msg="The %s module requires a region and none was found in configuration, "
7777
"environment variables or module parameters" % module._name)
7878

@@ -155,7 +155,7 @@ def get_aws_region(module, boto3=None):
155155
try:
156156
profile_name = module.params.get('profile')
157157
return botocore.session.Session(profile=profile_name).get_config_variable('region')
158-
except botocore.exceptions.ProfileNotFound as e:
158+
except botocore.exceptions.ProfileNotFound:
159159
return None
160160

161161

plugins/module_utils/iam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_aws_account_info(module):
4747
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError):
4848
try:
4949
iam_client = module.client('iam', retry_decorator=AWSRetry.jittered_backoff())
50-
arn, partition, service, reg, account_id, resource = iam_client.get_user(aws_retry=True)['User']['Arn'].split(':')
50+
_arn, partition, _service, _reg, account_id, _resource = iam_client.get_user(aws_retry=True)['User']['Arn'].split(':')
5151
except is_boto3_error_code('AccessDenied') as e:
5252
try:
5353
except_msg = to_native(e.message)

plugins/module_utils/modules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def __init__(self, **kwargs):
124124
if not HAS_BOTO3:
125125
self._module.fail_json(
126126
msg=missing_required_lib('botocore or boto3'))
127-
current_versions = self._gather_versions()
128127
if not self.botocore_at_least('1.21.0'):
129128
self.warn('botocore < 1.21.0 is not supported or tested.'
130129
' Some features may not work.')

tests/unit/module_utils/core/ansible_aws_module/test_fail_json_aws.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_fail_client_minimal(self, monkeypatch, stdin, capfd):
6161
with pytest.raises(SystemExit) as ctx:
6262
module.fail_json_aws(e)
6363
assert ctx.value.code == 1
64-
out, err = capfd.readouterr()
64+
out, _err = capfd.readouterr()
6565
return_val = json.loads(out)
6666

6767
assert return_val.get("msg") == self.EXAMPLE_MSG
@@ -88,7 +88,7 @@ def test_fail_client_msg(self, monkeypatch, stdin, capfd):
8888
with pytest.raises(SystemExit) as ctx:
8989
module.fail_json_aws(e, msg=self.FAIL_MSG)
9090
assert ctx.value.code == 1
91-
out, err = capfd.readouterr()
91+
out, _err = capfd.readouterr()
9292
return_val = json.loads(out)
9393

9494
assert return_val.get("msg") == self.FAIL_MSG + ": " + self.EXAMPLE_MSG
@@ -115,7 +115,7 @@ def test_fail_client_positional_msg(self, monkeypatch, stdin, capfd):
115115
with pytest.raises(SystemExit) as ctx:
116116
module.fail_json_aws(e, self.FAIL_MSG)
117117
assert ctx.value.code == 1
118-
out, err = capfd.readouterr()
118+
out, _err = capfd.readouterr()
119119
return_val = json.loads(out)
120120

121121
assert return_val.get("msg") == self.FAIL_MSG + ": " + self.EXAMPLE_MSG
@@ -142,7 +142,7 @@ def test_fail_client_key(self, monkeypatch, stdin, capfd):
142142
with pytest.raises(SystemExit) as ctx:
143143
module.fail_json_aws(e, extra_key="Some Value")
144144
assert ctx.value.code == 1
145-
out, err = capfd.readouterr()
145+
out, _err = capfd.readouterr()
146146
return_val = json.loads(out)
147147

148148
assert return_val.get("msg") == self.EXAMPLE_MSG
@@ -170,7 +170,7 @@ def test_fail_client_msg_and_key(self, monkeypatch, stdin, capfd):
170170
with pytest.raises(SystemExit) as ctx:
171171
module.fail_json_aws(e, extra_key="Some Value", msg=self.FAIL_MSG)
172172
assert ctx.value.code == 1
173-
out, err = capfd.readouterr()
173+
out, _err = capfd.readouterr()
174174
return_val = json.loads(out)
175175

176176
assert return_val.get("msg") == self.FAIL_MSG + ": " + self.EXAMPLE_MSG
@@ -198,7 +198,7 @@ def test_fail_botocore_minimal(self, monkeypatch, stdin, capfd):
198198
with pytest.raises(SystemExit) as ctx:
199199
module.fail_json_aws(e)
200200
assert ctx.value.code == 1
201-
out, err = capfd.readouterr()
201+
out, _err = capfd.readouterr()
202202
return_val = json.loads(out)
203203

204204
assert return_val.get("msg") == self.DEFAULT_CORE_MSG
@@ -225,7 +225,7 @@ def test_fail_botocore_msg(self, monkeypatch, stdin, capfd):
225225
with pytest.raises(SystemExit) as ctx:
226226
module.fail_json_aws(e, msg=self.FAIL_MSG)
227227
assert ctx.value.code == 1
228-
out, err = capfd.readouterr()
228+
out, _err = capfd.readouterr()
229229
return_val = json.loads(out)
230230

231231
assert return_val.get("msg") == self.FAIL_MSG + ": " + self.DEFAULT_CORE_MSG
@@ -253,7 +253,7 @@ def test_fail_botocore_positional_msg(self, monkeypatch, stdin, capfd):
253253
with pytest.raises(SystemExit) as ctx:
254254
module.fail_json_aws(e, self.FAIL_MSG)
255255
assert ctx.value.code == 1
256-
out, err = capfd.readouterr()
256+
out, _err = capfd.readouterr()
257257
return_val = json.loads(out)
258258

259259
assert return_val.get("msg") == self.FAIL_MSG + ": " + self.DEFAULT_CORE_MSG
@@ -280,7 +280,7 @@ def test_fail_botocore_key(self, monkeypatch, stdin, capfd):
280280
with pytest.raises(SystemExit) as ctx:
281281
module.fail_json_aws(e, extra_key="Some Value")
282282
assert ctx.value.code == 1
283-
out, err = capfd.readouterr()
283+
out, _err = capfd.readouterr()
284284
return_val = json.loads(out)
285285

286286
assert return_val.get("msg") == self.DEFAULT_CORE_MSG
@@ -308,7 +308,7 @@ def test_fail_botocore_msg_and_key(self, monkeypatch, stdin, capfd):
308308
with pytest.raises(SystemExit) as ctx:
309309
module.fail_json_aws(e, extra_key="Some Value", msg=self.FAIL_MSG)
310310
assert ctx.value.code == 1
311-
out, err = capfd.readouterr()
311+
out, _err = capfd.readouterr()
312312
return_val = json.loads(out)
313313

314314
assert return_val.get("msg") == self.FAIL_MSG + ": " + self.DEFAULT_CORE_MSG

tests/unit/module_utils/core/ansible_aws_module/test_minimal_versions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def test_no_warn(self, monkeypatch, stdin, capfd):
3636
# Create a minimal module that we can call
3737
module = AnsibleAWSModule(argument_spec=dict())
3838

39-
with pytest.raises(SystemExit) as e:
39+
with pytest.raises(SystemExit):
4040
module.exit_json()
4141

42-
out, err = capfd.readouterr()
42+
out, _err = capfd.readouterr()
4343
return_val = json.loads(out)
4444

4545
assert return_val.get("exception") is None
@@ -59,10 +59,10 @@ def test_no_check(self, monkeypatch, stdin, capfd):
5959
# Create a minimal module that we can call
6060
module = AnsibleAWSModule(argument_spec=dict(), check_boto3=False)
6161

62-
with pytest.raises(SystemExit) as e:
62+
with pytest.raises(SystemExit):
6363
module.exit_json()
6464

65-
out, err = capfd.readouterr()
65+
out, _err = capfd.readouterr()
6666
return_val = json.loads(out)
6767

6868
assert return_val.get("exception") is None
@@ -82,7 +82,7 @@ def test_warn_boto3(self, monkeypatch, stdin, capfd):
8282
# Create a minimal module that we can call
8383
module = AnsibleAWSModule(argument_spec=dict())
8484

85-
with pytest.raises(SystemExit) as e:
85+
with pytest.raises(SystemExit):
8686
module.exit_json()
8787

8888
out, err = capfd.readouterr()
@@ -115,7 +115,7 @@ def test_warn_botocore(self, monkeypatch, stdin, capfd):
115115
# Create a minimal module that we can call
116116
module = AnsibleAWSModule(argument_spec=dict())
117117

118-
with pytest.raises(SystemExit) as e:
118+
with pytest.raises(SystemExit):
119119
module.exit_json()
120120

121121
out, err = capfd.readouterr()
@@ -148,7 +148,7 @@ def test_warn_boto3_and_botocore(self, monkeypatch, stdin, capfd):
148148
# Create a minimal module that we can call
149149
module = AnsibleAWSModule(argument_spec=dict())
150150

151-
with pytest.raises(SystemExit) as e:
151+
with pytest.raises(SystemExit):
152152
module.exit_json()
153153

154154
out, err = capfd.readouterr()

tests/unit/module_utils/core/ansible_aws_module/test_require_at_least.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def test_require_botocore_at_least(self, monkeypatch, stdin, desired_version, co
8585
# Create a minimal module that we can call
8686
module = AnsibleAWSModule(argument_spec=dict())
8787

88-
with pytest.raises(SystemExit) as e:
88+
with pytest.raises(SystemExit):
8989
module.require_botocore_at_least(desired_version)
9090
module.exit_json()
9191

92-
out, err = capfd.readouterr()
92+
out, _err = capfd.readouterr()
9393
return_val = json.loads(out)
9494

9595
assert return_val.get("exception") is None
@@ -118,11 +118,11 @@ def test_require_boto3_at_least(self, monkeypatch, stdin, desired_version, compa
118118
# Create a minimal module that we can call
119119
module = AnsibleAWSModule(argument_spec=dict())
120120

121-
with pytest.raises(SystemExit) as e:
121+
with pytest.raises(SystemExit):
122122
module.require_boto3_at_least(desired_version)
123123
module.exit_json()
124124

125-
out, err = capfd.readouterr()
125+
out, _err = capfd.readouterr()
126126
return_val = json.loads(out)
127127

128128
assert return_val.get("exception") is None
@@ -153,11 +153,11 @@ def test_require_botocore_at_least_with_reason(self, monkeypatch, stdin, desired
153153
# Create a minimal module that we can call
154154
module = AnsibleAWSModule(argument_spec=dict())
155155

156-
with pytest.raises(SystemExit) as e:
156+
with pytest.raises(SystemExit):
157157
module.require_botocore_at_least(desired_version, reason=reason)
158158
module.exit_json()
159159

160-
out, err = capfd.readouterr()
160+
out, _err = capfd.readouterr()
161161
return_val = json.loads(out)
162162

163163
assert return_val.get("exception") is None
@@ -189,11 +189,11 @@ def test_require_boto3_at_least_with_reason(self, monkeypatch, stdin, desired_ve
189189
# Create a minimal module that we can call
190190
module = AnsibleAWSModule(argument_spec=dict())
191191

192-
with pytest.raises(SystemExit) as e:
192+
with pytest.raises(SystemExit):
193193
module.require_boto3_at_least(desired_version, reason=reason)
194194
module.exit_json()
195195

196-
out, err = capfd.readouterr()
196+
out, _err = capfd.readouterr()
197197
return_val = json.loads(out)
198198

199199
assert return_val.get("exception") is None

tests/unit/module_utils/test_cloud.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ def _fail():
229229
# the elapsed execution time should be closed to 2sec
230230
for _i in range(3):
231231
start = datetime.now()
232-
raised = False
233232
with self.assertRaises(self.TestException):
234233
_fail()
235234
duration = (datetime.now() - start).seconds
@@ -265,7 +264,6 @@ def _fail_exception():
265264
duration = expection[2]
266265

267266
start = datetime.now()
268-
raised = False
269267
with self.assertRaises(Exception):
270268
decorator(function)()
271269
_duration = (datetime.now() - start).seconds

tests/unit/module_utils/test_elbv2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_get_elb_ip_address_type(self):
178178
# Test modify_ip_address_type idempotency
179179
def test_modify_ip_address_type_idempotency(self):
180180
# Run module
181-
return_value = self.elbv2obj.modify_ip_address_type("ipv4")
181+
self.elbv2obj.modify_ip_address_type("ipv4")
182182
# check that no method was called and this has been retrieved from elb attributes
183183
self.connection.set_ip_address_type.assert_not_called()
184184
# assert we got the expected value
@@ -187,7 +187,7 @@ def test_modify_ip_address_type_idempotency(self):
187187
# Test modify_ip_address_type
188188
def test_modify_ip_address_type_update(self):
189189
# Run module
190-
return_value = self.elbv2obj.modify_ip_address_type("dualstack")
190+
self.elbv2obj.modify_ip_address_type("dualstack")
191191
# check that no method was called and this has been retrieved from elb attributes
192192
self.connection.set_ip_address_type.assert_called_once()
193193
# assert we got the expected value

tests/unit/module_utils/test_retries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_no_failures(self):
3434
def no_failures():
3535
self.counter += 1
3636

37-
r = no_failures()
37+
no_failures()
3838
self.assertEqual(self.counter, 1)
3939

4040
def test_extend_boto3_failures(self):

0 commit comments

Comments
 (0)