From 7ac3e7e29a0701d66c4f1737e0a9e6024f456372 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Fri, 13 Oct 2017 14:18:24 +0200 Subject: [PATCH] fixed tests accordingly --- dogstatsd.py | 6 +++--- tests/core/fixtures/config/bad.conf | 8 ++++---- tests/core/fixtures/config/multiple_apikeys.conf | 2 +- .../core/fixtures/config/multiple_endpoints.conf | 2 +- .../fixtures/config/multiple_endpoints_bad.conf | 2 +- tests/core/fixtures/config/one_endpoint.conf | 2 +- tests/core/test_config.py | 16 ++++++++-------- tests/core/test_dogstatsd.py | 6 +++++- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/dogstatsd.py b/dogstatsd.py index 8a565e9131..b5bfc9dd3b 100755 --- a/dogstatsd.py +++ b/dogstatsd.py @@ -205,14 +205,14 @@ class Reporter(threading.Thread): """ def __init__(self, interval, metrics_aggregator, api_host, api_key=None, - use_watchdog=False, event_chunk_size=None): + use_watchdog=False, event_chunk_size=None, hostname=None): threading.Thread.__init__(self) self.interval = int(interval) self.finished = threading.Event() self.metrics_aggregator = metrics_aggregator self.flush_count = 0 self.log_count = 0 - self.hostname = get_hostname() + self.hostname = hostname or get_hostname() self.watchdog = None if use_watchdog: @@ -617,7 +617,7 @@ def init5(agent_config=None, use_watchdog=False, use_forwarder=False, args=None) ) # Start the reporting thread. - reporter = Reporter(interval, aggregator, target, api_key, use_watchdog, event_chunk_size) + reporter = Reporter(interval, aggregator, target, api_key, use_watchdog, event_chunk_size, hostname) # NOTICE: when `non_local_traffic` is passed we need to bind to any interface on the box. The forwarder uses # Tornado which takes care of sockets creation (more than one socket can be used at once depending on the diff --git a/tests/core/fixtures/config/bad.conf b/tests/core/fixtures/config/bad.conf index a9077f56e2..84c7e2d3fd 100644 --- a/tests/core/fixtures/config/bad.conf +++ b/tests/core/fixtures/config/bad.conf @@ -1,12 +1,12 @@ [Main] -# The host of the Datadog intake server to send agent data to +# The host of the Datadog intake server to send agent data to dd_url: https://app.datadoghq.com -# The Datadog api key to associate your agent's data with your organization. -# Can be found here: +# The Datadog api key to associate your agent's data with your organization. +# Can be found here: # https://app.datadoghq.com/account/settings -api_key: 1234 +api_key: 0123456789abcdefghijklmnopqrstuv # Force the hostname to whatever you want. #hostname: mymachine.mydomain diff --git a/tests/core/fixtures/config/multiple_apikeys.conf b/tests/core/fixtures/config/multiple_apikeys.conf index 15838c64c9..327fbada07 100644 --- a/tests/core/fixtures/config/multiple_apikeys.conf +++ b/tests/core/fixtures/config/multiple_apikeys.conf @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com # The Datadog api key to associate your agent's data with your organization. # Can be found here: # https://app.datadoghq.com/account/settings -api_key: 1234, 5678 , 901 +api_key: 0123456789abcdefghijklmnopqrstuv, 123456789abcdefghijklmnopqrstuv0 , 23456789abcdefghijklmnopqrstuv01 diff --git a/tests/core/fixtures/config/multiple_endpoints.conf b/tests/core/fixtures/config/multiple_endpoints.conf index 6ed91707fc..d2f50ab1cf 100644 --- a/tests/core/fixtures/config/multiple_endpoints.conf +++ b/tests/core/fixtures/config/multiple_endpoints.conf @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com, https://app.example.com, https://app.example. # The Datadog api key to associate your agent's data with your organization. # Can be found here: # https://app.datadoghq.com/account/settings -api_key: 1234,5678, 901 +api_key: 0123456789abcdefghijklmnopqrstuv,123456789abcdefghijklmnopqrstuv0 , 23456789abcdefghijklmnopqrstuv01 diff --git a/tests/core/fixtures/config/multiple_endpoints_bad.conf b/tests/core/fixtures/config/multiple_endpoints_bad.conf index 0d25b994ad..8c2005ce79 100644 --- a/tests/core/fixtures/config/multiple_endpoints_bad.conf +++ b/tests/core/fixtures/config/multiple_endpoints_bad.conf @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com, https://app.example.com # The Datadog api key to associate your agent's data with your organization. # Can be found here: # https://app.datadoghq.com/account/settings -api_key: 1234, 5678, 901 +api_key: 0123456789abcdefghijklmnopqrstuv, 123456789abcdefghijklmnopqrstuv0 , 23456789abcdefghijklmnopqrstuv01 diff --git a/tests/core/fixtures/config/one_endpoint.conf b/tests/core/fixtures/config/one_endpoint.conf index 5eede6206a..7a5a818569 100644 --- a/tests/core/fixtures/config/one_endpoint.conf +++ b/tests/core/fixtures/config/one_endpoint.conf @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com # The Datadog api key to associate your agent's data with your organization. # Can be found here: # https://app.datadoghq.com/account/settings -api_key: 1234 +api_key: 0123456789abcdefghijklmnopqrstuv diff --git a/tests/core/test_config.py b/tests/core/test_config.py index e3f23ab576..045a934c17 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -42,7 +42,7 @@ def testWhiteSpaceConfig(self): agentConfig = self.get_config('bad.conf') self.assertEquals(agentConfig["dd_url"], "https://app.datadoghq.com") - self.assertEquals(agentConfig["api_key"], "1234") + self.assertEquals(agentConfig["api_key"], "0123456789abcdefghijklmnopqrstuv") self.assertEquals(agentConfig["nagios_log"], "/var/log/nagios3/nagios.log") self.assertEquals(agentConfig["graphite_listen_port"], 17126) self.assertTrue("statsd_metric_namespace" in agentConfig) @@ -50,17 +50,17 @@ def testWhiteSpaceConfig(self): def test_one_endpoint(self): agent_config = self.get_config('one_endpoint.conf') self.assertEquals(agent_config["dd_url"], "https://app.datadoghq.com") - self.assertEquals(agent_config["api_key"], "1234") - endpoints = {'https://app.datadoghq.com': ['1234']} + self.assertEquals(agent_config["api_key"], "0123456789abcdefghijklmnopqrstuv") + endpoints = {'https://app.datadoghq.com': ['0123456789abcdefghijklmnopqrstuv']} self.assertEquals(agent_config['endpoints'], endpoints) def test_multiple_endpoints(self): agent_config = self.get_config('multiple_endpoints.conf') self.assertEquals(agent_config["dd_url"], "https://app.datadoghq.com") - self.assertEquals(agent_config["api_key"], "1234") + self.assertEquals(agent_config["api_key"], "0123456789abcdefghijklmnopqrstuv") endpoints = { - 'https://app.datadoghq.com': ['1234'], - 'https://app.example.com': ['5678', '901'] + 'https://app.datadoghq.com': ['0123456789abcdefghijklmnopqrstuv'], + 'https://app.example.com': ['123456789abcdefghijklmnopqrstuv0', '23456789abcdefghijklmnopqrstuv01'] } self.assertEquals(agent_config['endpoints'], endpoints) with self.assertRaises(AssertionError): @@ -69,9 +69,9 @@ def test_multiple_endpoints(self): def test_multiple_apikeys(self): agent_config = self.get_config('multiple_apikeys.conf') self.assertEquals(agent_config["dd_url"], "https://app.datadoghq.com") - self.assertEquals(agent_config["api_key"], "1234") + self.assertEquals(agent_config["api_key"], "0123456789abcdefghijklmnopqrstuv") endpoints = { - 'https://app.datadoghq.com': ['1234', '5678', '901'] + 'https://app.datadoghq.com': ['0123456789abcdefghijklmnopqrstuv', '123456789abcdefghijklmnopqrstuv0', '23456789abcdefghijklmnopqrstuv01'] } self.assertEquals(agent_config['endpoints'], endpoints) diff --git a/tests/core/test_dogstatsd.py b/tests/core/test_dogstatsd.py index 985c9d3373..b199fbcc42 100644 --- a/tests/core/test_dogstatsd.py +++ b/tests/core/test_dogstatsd.py @@ -40,6 +40,8 @@ def test_init5(self, s): cfg = defaultdict(str) cfg['non_local_traffic'] = True cfg['use_dogstatsd'] = True + cfg['api_key'] = "0123456789abcdefghijklmnopqrstuv" + cfg['hostname'] = "hostname" init5(cfg) @@ -51,7 +53,7 @@ def test_init5(self, s): @mock.patch('dogstatsd.get_config_path') def test_init6(self, gcp): cfg = defaultdict(str) - cfg['api_key'] = "deadbeeffeebdaed" + cfg['api_key'] = "0123456789abcdefghijklmnopqrstuv" cfg['use_dogstatsd'] = True cfg['dogstatsd6_enable'] = True cfg['dogstatsd6_stats_port'] = 5050 @@ -67,6 +69,8 @@ def test_init_with_so_rcvbuf(self, s): cfg = defaultdict(str) cfg['use_dogstatsd'] = True cfg['statsd_so_rcvbuf'] = '1024' + cfg['api_key'] = "0123456789abcdefghijklmnopqrstuv" + cfg['hostname'] = "hostname" init5(cfg)