Merge ~axino/charm-telegraf/+git/telegraf-charm:fix_unit_tests into ~telegraf-charmers/charm-telegraf:master

Proposed by Junien F
Status: Merged
Approved by: Junien F
Approved revision: 54d03dd1b9149d0b3ced8b2c25b18ceb7cb6e9e8
Merged at revision: dee9926ef323ee1bab11dc48496078606e099dc3
Proposed branch: ~axino/charm-telegraf/+git/telegraf-charm:fix_unit_tests
Merge into: ~telegraf-charmers/charm-telegraf:master
Diff against target: 105 lines (+41/-2)
1 file modified
unit_tests/test_telegraf.py (+41/-2)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+359759@code.launchpad.net

Commit message

fix unit tests

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
Tom Haddon (mthaddon) wrote :

A few lint failures (some unrelated to this change, but would be good to fix unit_tests/test_telegraf.py at least:

$ make lint
tox -e lint
lint create: /home/ubuntu/fix-unit-tests/.tox/lint
lint installdeps: flake8
lint installed: flake8==3.6.0,mccabe==0.6.1,pkg-resources==0.0.0,pycodestyle==2.4.0,pyflakes==2.0.0
lint runtests: PYTHONHASHSEED='1702027581'
lint runtests: commands[0] | flake8 reactive/ unit_tests/ tests/
reactive/telegraf.py:843:7: W605 invalid escape sequence '\d'
reactive/telegraf.py:846:7: W605 invalid escape sequence '\d'
reactive/telegraf.py:850:7: W605 invalid escape sequence '\d'
reactive/telegraf.py:854:7: W605 invalid escape sequence '\d'
reactive/telegraf.py:906:13: W504 line break after binary operator
unit_tests/test_telegraf.py:693:5: F841 local variable 'network_get' is assigned to but never used
unit_tests/test_telegraf.py:815:5: F841 local variable 'network_get' is assigned to but never used
ERROR: InvocationError: '/home/ubuntu/fix-unit-tests/.tox/lint/bin/flake8 reactive/ unit_tests/ tests/'
________________________________________________________________________________________________________________________________________ summary _________________________________________________________________________________________________________________________________________
ERROR: lint: commands failed
Makefile:19: recipe for target 'lint' failed
make: *** [lint] Error 1

Otherwise looks good.

Revision history for this message
Stuart Bishop (stub) wrote :

Looks good to land, once the lint is cleaned up per mthaddon's comment.

review: Approve
Revision history for this message
Junien F (axino) wrote :

On cosmic :

% make lint
tox -e lint
lint installed: flake8==3.5.0,mccabe==0.6.1,pkg-resources==0.0.0,pycodestyle==2.3.1,pyflakes==1.6.0
lint runtests: PYTHONHASHSEED='4188387134'
lint runtests: commands[0] | flake8 reactive/ unit_tests/ tests/
______________________________________________________________________ summary _______________________________________________________________________
  lint: commands succeeded
  congratulations :)

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

Change successfully merged at revision dee9926ef323ee1bab11dc48496078606e099dc3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/unit_tests/test_telegraf.py b/unit_tests/test_telegraf.py
2index 3071b10..9fc6739 100644
3--- a/unit_tests/test_telegraf.py
4+++ b/unit_tests/test_telegraf.py
5@@ -176,6 +176,24 @@ def test_get_remote_unit_name_juju1(monkeypatch):
6 'prometheus-rules': {'interface': 'prometheus-rules'}}}
7 monkeypatch.setattr(telegraf.hookenv, 'metadata', lambda: md)
8
9+ def relation_ids(reltype):
10+ if reltype == 'juju-info':
11+ return ['juju-info:0']
12+ else:
13+ return []
14+ monkeypatch.setattr(telegraf.hookenv,
15+ 'relation_ids',
16+ relation_ids)
17+
18+ def related_units(relid):
19+ if relid == 'juju-info:0':
20+ return ['remote/0']
21+ else:
22+ return []
23+ monkeypatch.setattr(telegraf.hookenv,
24+ 'related_units',
25+ related_units)
26+
27 relations = []
28 monkeypatch.setattr(telegraf.hookenv,
29 'relations_of_type',
30@@ -663,8 +681,19 @@ def test_prometheus_client_output(mocker, monkeypatch, config):
31 config['prometheus_output_port'] = '' # Not enabled globally
32 monkeypatch.setattr(telegraf.hookenv, 'open_port',
33 lambda p: None)
34+
35+ relation_ids = ['prometheus-client:0']
36+ monkeypatch.setattr(telegraf.hookenv,
37+ 'relation_ids',
38+ lambda r: relation_ids)
39+
40 network_get_primary_address = mocker.patch.object(
41 telegraf.hookenv, 'network_get_primary_address', return_value="foo")
42+
43+ mocker.patch.object(
44+ telegraf.hookenv, 'network_get',
45+ return_value={"ingress_addresses": ["1.2.3.4"]})
46+
47 interface = mocker.Mock(spec=RelationBase)
48 interface.configure = mocker.Mock()
49 telegraf.prometheus_client(interface)
50@@ -696,7 +725,7 @@ def test_basic_config(mocker, monkeypatch, config):
51 monkeypatch.setattr(telegraf.host, 'service_running',
52 lambda n: True)
53 check_prometheus_port = mocker.patch('reactive.telegraf.check_prometheus_port')
54- bus.set_state('telegraf.installed')
55+ bus.set_state('apt.installed.telegraf')
56 assert not base_dir().join('telegraf.conf').exists()
57 bus.dispatch()
58 assert 'telegraf.configured' in bus.get_states().keys()
59@@ -711,7 +740,7 @@ def test_config_no_prometheus(mocker, monkeypatch, config):
60 lambda n: True)
61 check_prometheus_port = mocker.patch('reactive.telegraf.check_prometheus_port')
62 config['prometheus_output_port'] = ''
63- bus.set_state('telegraf.installed')
64+ bus.set_state('apt.installed.telegraf')
65 assert not base_dir().join('telegraf.conf').exists()
66 bus.dispatch()
67 assert 'telegraf.configured' in bus.get_states().keys()
68@@ -725,6 +754,7 @@ def test_config_changed_apt(mocker, monkeypatch, config):
69 monkeypatch.setattr(telegraf.host, 'service_running',
70 lambda n: True)
71 mocker.patch('reactive.telegraf.check_prometheus_port')
72+ bus.set_state('apt.installed.telegraf')
73 bus.set_state('config.changed')
74 bus.dispatch()
75 service_restart.assert_called_once_with('telegraf')
76@@ -740,6 +770,7 @@ def test_config_changed_extra_options(mocker, monkeypatch, config):
77 config.save()
78 config.load_previous()
79 config['extra_options'] = yaml.dump({'inputs': {'haproxy': {'timeout': 10}}})
80+ bus.set_state('apt.installed.telegraf')
81 bus.set_state('config.changed')
82 bus.dispatch()
83 assert 'plugins.haproxy.configured' not in bus.get_states().keys()
84@@ -762,6 +793,7 @@ def test_config_changed_extra_plugins(mocker, monkeypatch, config):
85 [[outputs.baz]]
86 option = "enabled"
87 """
88+ bus.set_state('apt.installed.telegraf')
89 bus.set_state('config.changed')
90 bus.dispatch()
91 assert configs_dir().join('extra_plugins.conf').exists()
92@@ -776,6 +808,13 @@ def test_restart_on_output_plugin_relation_departed(mocker, monkeypatch, config)
93 monkeypatch.setattr(telegraf.hookenv, 'relations_of_type', lambda n: [])
94 monkeypatch.setattr(telegraf.hookenv, 'open_port',
95 lambda p: None)
96+ relation_ids = ['prometheus-client:0']
97+ monkeypatch.setattr(telegraf.hookenv,
98+ 'relation_ids',
99+ lambda r: relation_ids)
100+ mocker.patch.object(
101+ telegraf.hookenv, 'network_get',
102+ return_value={"ingress_addresses": ["1.2.3.4"]})
103 config['prometheus_output_port'] = ''
104 bus.discover()
105 bus.set_state('telegraf.installed')

Subscribers

People subscribed via source and target branches

to all changes: