Formatting: Format all python code with black.
This CL is probably not what you're looking for, it's only
automated formatting. Ignore it with
`git blame --ignore-rev <revision>` for this commit.
BUG=b:233893248
TEST=CQ
Change-Id: I66591d7a738d241aed3290138c0f68065ab10a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3879174
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
diff --git a/scripts/sysmon/puppet_metrics_unittest.py b/scripts/sysmon/puppet_metrics_unittest.py
index 243ea78..780a019 100644
--- a/scripts/sysmon/puppet_metrics_unittest.py
+++ b/scripts/sysmon/puppet_metrics_unittest.py
@@ -16,7 +16,7 @@
from chromite.scripts.sysmon import puppet_metrics
-_SUMMARY = u"""\
+_SUMMARY = """\
---
version:
config: 1499979608
@@ -57,137 +57,237 @@
class TestPuppetRunSummary(cros_test_lib.TestCase):
- """Tests for _PuppetRunSummary."""
+ """Tests for _PuppetRunSummary."""
- def test_config_version(self):
- summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
- self.assertEqual(summary.config_version, 1499979608)
+ def test_config_version(self):
+ summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
+ self.assertEqual(summary.config_version, 1499979608)
- def test_puppet_version(self):
- summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
- self.assertEqual(summary.puppet_version, '3.4.3')
+ def test_puppet_version(self):
+ summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
+ self.assertEqual(summary.puppet_version, "3.4.3")
- def test_events(self):
- summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
- self.assertEqual(summary.events, {
- 'failure': 0,
- 'success': 7
- })
+ def test_events(self):
+ summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
+ self.assertEqual(summary.events, {"failure": 0, "success": 7})
- def test_resources(self):
- summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
- self.assertEqual(summary.resources, {
- 'changed': 7,
- 'failed': 0,
- 'failed_to_restart': 0,
- 'out_of_sync': 7,
- 'restarted': 0,
- 'scheduled': 0,
- 'skipped': 1,
- 'other': 203,
- })
+ def test_resources(self):
+ summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
+ self.assertEqual(
+ summary.resources,
+ {
+ "changed": 7,
+ "failed": 0,
+ "failed_to_restart": 0,
+ "out_of_sync": 7,
+ "restarted": 0,
+ "scheduled": 0,
+ "skipped": 1,
+ "other": 203,
+ },
+ )
- def test_times(self):
- summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
- self.assertEqual(summary.times, {
- 'config_retrieval': 2.862796974,
- 'cron': 0.004638468,
- 'exec': 11.494792536,
- 'file': 0.618018423,
- 'file_line': 0.003589435,
- 'filebucket': 0.000341392,
- 'group': 0.017957332,
- 'ini_subsetting': 0.001235189,
- 'mount': 0.001416499,
- 'other': 0,
- 'package': 4.315027644000001,
- 'schedule': 0.001541641,
- 'service': 10.242378408,
- 'user': 0.001673407,
- 'vcsrepo': 23.393381029,
- })
+ def test_times(self):
+ summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
+ self.assertEqual(
+ summary.times,
+ {
+ "config_retrieval": 2.862796974,
+ "cron": 0.004638468,
+ "exec": 11.494792536,
+ "file": 0.618018423,
+ "file_line": 0.003589435,
+ "filebucket": 0.000341392,
+ "group": 0.017957332,
+ "ini_subsetting": 0.001235189,
+ "mount": 0.001416499,
+ "other": 0,
+ "package": 4.315027644000001,
+ "schedule": 0.001541641,
+ "service": 10.242378408,
+ "user": 0.001673407,
+ "vcsrepo": 23.393381029,
+ },
+ )
- def test_last_run_time(self):
- summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
- self.assertEqual(summary.last_run_time, 1499979671)
+ def test_last_run_time(self):
+ summary = puppet_metrics._PuppetRunSummary(io.StringIO(_SUMMARY))
+ self.assertEqual(summary.last_run_time, 1499979671)
class TestPuppetMetrics(cros_test_lib.TempDirTestCase):
- """Tests for puppet_metrics."""
+ """Tests for puppet_metrics."""
- def setUp(self):
- patcher = mock.patch(
- 'chromite.third_party.infra_libs.ts_mon.common.interface.state.store',
- autospec=True)
- self.store = patcher.start()
- self.addCleanup(patcher.stop)
- self.tempfile = os.path.join(self.tempdir, 'last_run_summary.yaml')
+ def setUp(self):
+ patcher = mock.patch(
+ "chromite.third_party.infra_libs.ts_mon.common.interface.state.store",
+ autospec=True,
+ )
+ self.store = patcher.start()
+ self.addCleanup(patcher.stop)
+ self.tempfile = os.path.join(self.tempdir, "last_run_summary.yaml")
- def test_collect(self):
- with open(self.tempfile, 'w') as f:
- f.write(_SUMMARY)
- with mock.patch('time.time', return_value=1500000000):
- with mock.patch.object(puppet_metrics, 'LAST_RUN_FILE', self.tempfile):
- puppet_metrics.collect_puppet_summary()
+ def test_collect(self):
+ with open(self.tempfile, "w") as f:
+ f.write(_SUMMARY)
+ with mock.patch("time.time", return_value=1500000000):
+ with mock.patch.object(
+ puppet_metrics, "LAST_RUN_FILE", self.tempfile
+ ):
+ puppet_metrics.collect_puppet_summary()
- setter = self.store.set
- calls = [
- mock.call('puppet/version/config', (), None,
- 1499979608, enforce_ge=mock.ANY),
- mock.call('puppet/version/puppet', (), None,
- '3.4.3', enforce_ge=mock.ANY),
- mock.call('puppet/events', ('failure',), None,
- 0, enforce_ge=mock.ANY),
- mock.call('puppet/events', ('success',), None,
- 7, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('scheduled',), None,
- 0, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('skipped',), None,
- 1, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('restarted',), None,
- 0, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('changed',), None,
- 7, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('failed',), None,
- 0, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('other',), None,
- 203, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('failed_to_restart',), None,
- 0, enforce_ge=mock.ANY),
- mock.call('puppet/resources', ('out_of_sync',), None,
- 7, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('vcsrepo',), None,
- 23.393381029, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('exec',), None,
- 11.494792536, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('cron',), None,
- 0.004638468, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('file_line',), None,
- 0.003589435, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('config_retrieval',), None,
- 2.862796974, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('user',), None,
- 0.001673407, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('file',), None,
- 0.618018423, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('group',), None,
- 0.017957332, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('service',), None,
- 10.242378408, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('package',), None,
- 4.315027644000001, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('mount',), None,
- 0.001416499, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('schedule',), None,
- 0.001541641, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('other',), None,
- 0.0, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('ini_subsetting',), None,
- 0.001235189, enforce_ge=mock.ANY),
- mock.call('puppet/times', ('filebucket',), None,
- 0.000341392, enforce_ge=mock.ANY),
- mock.call('puppet/age', (), None,
- 20329.0, enforce_ge=mock.ANY),
- ]
- setter.assert_has_calls(calls, any_order=True)
- self.assertEqual(len(setter.mock_calls), len(calls))
+ setter = self.store.set
+ calls = [
+ mock.call(
+ "puppet/version/config",
+ (),
+ None,
+ 1499979608,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/version/puppet", (), None, "3.4.3", enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/events", ("failure",), None, 0, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/events", ("success",), None, 7, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources", ("scheduled",), None, 0, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources", ("skipped",), None, 1, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources", ("restarted",), None, 0, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources", ("changed",), None, 7, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources", ("failed",), None, 0, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources", ("other",), None, 203, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/resources",
+ ("failed_to_restart",),
+ None,
+ 0,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/resources",
+ ("out_of_sync",),
+ None,
+ 7,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("vcsrepo",),
+ None,
+ 23.393381029,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("exec",),
+ None,
+ 11.494792536,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("cron",),
+ None,
+ 0.004638468,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("file_line",),
+ None,
+ 0.003589435,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("config_retrieval",),
+ None,
+ 2.862796974,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("user",),
+ None,
+ 0.001673407,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("file",),
+ None,
+ 0.618018423,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("group",),
+ None,
+ 0.017957332,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("service",),
+ None,
+ 10.242378408,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("package",),
+ None,
+ 4.315027644000001,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("mount",),
+ None,
+ 0.001416499,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("schedule",),
+ None,
+ 0.001541641,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times", ("other",), None, 0.0, enforce_ge=mock.ANY
+ ),
+ mock.call(
+ "puppet/times",
+ ("ini_subsetting",),
+ None,
+ 0.001235189,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call(
+ "puppet/times",
+ ("filebucket",),
+ None,
+ 0.000341392,
+ enforce_ge=mock.ANY,
+ ),
+ mock.call("puppet/age", (), None, 20329.0, enforce_ge=mock.ANY),
+ ]
+ setter.assert_has_calls(calls, any_order=True)
+ self.assertEqual(len(setter.mock_calls), len(calls))