def test_report_ignores_plugins(self, gethostname, post):
     gethostname.return_value = "myhost"
     status_reporter = StatusReporter("", "", 1)
     envs = {
         "TSURU_HOST": "http://tsuru.io:8080",
         "TSURU_APP_TOKEN": "abc123",
         "TSURU_APPNAME": "something"
     }
     os.environ.update(envs)
     call = mock.Mock()
     call.return_value = {"statuses": {"plugin:tsuru-hooks": "stopped",
                                       "something": "active"}}
     status_reporter.call = call
     status_reporter.report()
     call.assert_called_once()
     url = "http://tsuru.io:8080/apps/something/units/myhost"
     post.assert_called_with(url, data={"status": "started"},
                             headers={"Authorization": "bearer abc123"})
Example #2
0
 def test_init(self):
     hostname = socket.gethostname()
     status_reporter = StatusReporter("",
                                      "",
                                      1,
                                      loop_rate="180",
                                      apprc="/etc/apprc")
     self.assertEqual(180, status_reporter.loop_rate)
     self.assertEqual(hostname, status_reporter.hostname)
Example #3
0
 def test_report_ignores_plugins(self, gethostname, post):
     gethostname.return_value = "myhost"
     status_reporter = StatusReporter("", "", 1)
     envs = {
         "TSURU_HOST": "http://tsuru.io:8080",
         "TSURU_APP_TOKEN": "abc123",
         "TSURU_APPNAME": "something"
     }
     os.environ.update(envs)
     call = mock.Mock()
     call.return_value = {
         "statuses": {
             "plugin:tsuru-hooks": "stopped",
             "something": "active"
         }
     }
     status_reporter.call = call
     status_reporter.report()
     call.assert_called_once()
     url = "http://tsuru.io:8080/apps/something/units/myhost"
     post.assert_called_with(url,
                             data={"status": "started"},
                             headers={"Authorization": "bearer abc123"})
 def test_handle_stop(self):
     status_reporter = StatusReporter("", "", 1)
     status_reporter.period.stop = mock.Mock()
     status_reporter.handle_stop()
     status_reporter.period.stop.assert_called_once()
 def test_handle_init(self):
     status_reporter = StatusReporter("", "", 1)
     status_reporter.period.start = mock.Mock()
     status_reporter.handle_init()
     status_reporter.period.start.assert_called_once()
Example #6
0
 def test_handle_stop(self):
     status_reporter = StatusReporter("", "", 1)
     status_reporter.period.stop = mock.Mock()
     status_reporter.handle_stop()
     status_reporter.period.stop.assert_called_once()
Example #7
0
 def test_handle_init(self):
     status_reporter = StatusReporter("", "", 1)
     status_reporter.period.start = mock.Mock()
     status_reporter.handle_init()
     status_reporter.period.start.assert_called_once()
Example #8
0
 def test_init_default_config_values(self):
     status_reporter = StatusReporter("", "", 1)
     self.assertEqual(60, status_reporter.loop_rate)