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
diff --git a/unit_tests/test_telegraf.py b/unit_tests/test_telegraf.py
index 3071b10..9fc6739 100644
--- a/unit_tests/test_telegraf.py
+++ b/unit_tests/test_telegraf.py
@@ -176,6 +176,24 @@ def test_get_remote_unit_name_juju1(monkeypatch):
176 'prometheus-rules': {'interface': 'prometheus-rules'}}}176 'prometheus-rules': {'interface': 'prometheus-rules'}}}
177 monkeypatch.setattr(telegraf.hookenv, 'metadata', lambda: md)177 monkeypatch.setattr(telegraf.hookenv, 'metadata', lambda: md)
178178
179 def relation_ids(reltype):
180 if reltype == 'juju-info':
181 return ['juju-info:0']
182 else:
183 return []
184 monkeypatch.setattr(telegraf.hookenv,
185 'relation_ids',
186 relation_ids)
187
188 def related_units(relid):
189 if relid == 'juju-info:0':
190 return ['remote/0']
191 else:
192 return []
193 monkeypatch.setattr(telegraf.hookenv,
194 'related_units',
195 related_units)
196
179 relations = []197 relations = []
180 monkeypatch.setattr(telegraf.hookenv,198 monkeypatch.setattr(telegraf.hookenv,
181 'relations_of_type',199 'relations_of_type',
@@ -663,8 +681,19 @@ def test_prometheus_client_output(mocker, monkeypatch, config):
663 config['prometheus_output_port'] = '' # Not enabled globally681 config['prometheus_output_port'] = '' # Not enabled globally
664 monkeypatch.setattr(telegraf.hookenv, 'open_port',682 monkeypatch.setattr(telegraf.hookenv, 'open_port',
665 lambda p: None)683 lambda p: None)
684
685 relation_ids = ['prometheus-client:0']
686 monkeypatch.setattr(telegraf.hookenv,
687 'relation_ids',
688 lambda r: relation_ids)
689
666 network_get_primary_address = mocker.patch.object(690 network_get_primary_address = mocker.patch.object(
667 telegraf.hookenv, 'network_get_primary_address', return_value="foo")691 telegraf.hookenv, 'network_get_primary_address', return_value="foo")
692
693 mocker.patch.object(
694 telegraf.hookenv, 'network_get',
695 return_value={"ingress_addresses": ["1.2.3.4"]})
696
668 interface = mocker.Mock(spec=RelationBase)697 interface = mocker.Mock(spec=RelationBase)
669 interface.configure = mocker.Mock()698 interface.configure = mocker.Mock()
670 telegraf.prometheus_client(interface)699 telegraf.prometheus_client(interface)
@@ -696,7 +725,7 @@ def test_basic_config(mocker, monkeypatch, config):
696 monkeypatch.setattr(telegraf.host, 'service_running',725 monkeypatch.setattr(telegraf.host, 'service_running',
697 lambda n: True)726 lambda n: True)
698 check_prometheus_port = mocker.patch('reactive.telegraf.check_prometheus_port')727 check_prometheus_port = mocker.patch('reactive.telegraf.check_prometheus_port')
699 bus.set_state('telegraf.installed')728 bus.set_state('apt.installed.telegraf')
700 assert not base_dir().join('telegraf.conf').exists()729 assert not base_dir().join('telegraf.conf').exists()
701 bus.dispatch()730 bus.dispatch()
702 assert 'telegraf.configured' in bus.get_states().keys()731 assert 'telegraf.configured' in bus.get_states().keys()
@@ -711,7 +740,7 @@ def test_config_no_prometheus(mocker, monkeypatch, config):
711 lambda n: True)740 lambda n: True)
712 check_prometheus_port = mocker.patch('reactive.telegraf.check_prometheus_port')741 check_prometheus_port = mocker.patch('reactive.telegraf.check_prometheus_port')
713 config['prometheus_output_port'] = ''742 config['prometheus_output_port'] = ''
714 bus.set_state('telegraf.installed')743 bus.set_state('apt.installed.telegraf')
715 assert not base_dir().join('telegraf.conf').exists()744 assert not base_dir().join('telegraf.conf').exists()
716 bus.dispatch()745 bus.dispatch()
717 assert 'telegraf.configured' in bus.get_states().keys()746 assert 'telegraf.configured' in bus.get_states().keys()
@@ -725,6 +754,7 @@ def test_config_changed_apt(mocker, monkeypatch, config):
725 monkeypatch.setattr(telegraf.host, 'service_running',754 monkeypatch.setattr(telegraf.host, 'service_running',
726 lambda n: True)755 lambda n: True)
727 mocker.patch('reactive.telegraf.check_prometheus_port')756 mocker.patch('reactive.telegraf.check_prometheus_port')
757 bus.set_state('apt.installed.telegraf')
728 bus.set_state('config.changed')758 bus.set_state('config.changed')
729 bus.dispatch()759 bus.dispatch()
730 service_restart.assert_called_once_with('telegraf')760 service_restart.assert_called_once_with('telegraf')
@@ -740,6 +770,7 @@ def test_config_changed_extra_options(mocker, monkeypatch, config):
740 config.save()770 config.save()
741 config.load_previous()771 config.load_previous()
742 config['extra_options'] = yaml.dump({'inputs': {'haproxy': {'timeout': 10}}})772 config['extra_options'] = yaml.dump({'inputs': {'haproxy': {'timeout': 10}}})
773 bus.set_state('apt.installed.telegraf')
743 bus.set_state('config.changed')774 bus.set_state('config.changed')
744 bus.dispatch()775 bus.dispatch()
745 assert 'plugins.haproxy.configured' not in bus.get_states().keys()776 assert 'plugins.haproxy.configured' not in bus.get_states().keys()
@@ -762,6 +793,7 @@ def test_config_changed_extra_plugins(mocker, monkeypatch, config):
762[[outputs.baz]]793[[outputs.baz]]
763 option = "enabled"794 option = "enabled"
764 """795 """
796 bus.set_state('apt.installed.telegraf')
765 bus.set_state('config.changed')797 bus.set_state('config.changed')
766 bus.dispatch()798 bus.dispatch()
767 assert configs_dir().join('extra_plugins.conf').exists()799 assert configs_dir().join('extra_plugins.conf').exists()
@@ -776,6 +808,13 @@ def test_restart_on_output_plugin_relation_departed(mocker, monkeypatch, config)
776 monkeypatch.setattr(telegraf.hookenv, 'relations_of_type', lambda n: [])808 monkeypatch.setattr(telegraf.hookenv, 'relations_of_type', lambda n: [])
777 monkeypatch.setattr(telegraf.hookenv, 'open_port',809 monkeypatch.setattr(telegraf.hookenv, 'open_port',
778 lambda p: None)810 lambda p: None)
811 relation_ids = ['prometheus-client:0']
812 monkeypatch.setattr(telegraf.hookenv,
813 'relation_ids',
814 lambda r: relation_ids)
815 mocker.patch.object(
816 telegraf.hookenv, 'network_get',
817 return_value={"ingress_addresses": ["1.2.3.4"]})
779 config['prometheus_output_port'] = ''818 config['prometheus_output_port'] = ''
780 bus.discover()819 bus.discover()
781 bus.set_state('telegraf.installed')820 bus.set_state('telegraf.installed')

Subscribers

People subscribed via source and target branches

to all changes: