Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: infra_libs/ts_mon/test/config_test.py

Issue 2114073002: Add HttpsMonitor (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix coverage Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « infra_libs/ts_mon/config.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import argparse 5 import argparse
6 import json 6 import json
7 import os 7 import os
8 import requests 8 import requests
9 import tempfile 9 import tempfile
10 import unittest 10 import unittest
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 self.assertIsInstance(interface.state.target, targets.DeviceTarget) 59 self.assertIsInstance(interface.state.target, targets.DeviceTarget)
60 self.assertEquals(interface.state.target.hostname, 'slave1-a1') 60 self.assertEquals(interface.state.target.hostname, 'slave1-a1')
61 self.assertEquals(interface.state.target.region, 'reg') 61 self.assertEquals(interface.state.target.region, 'reg')
62 self.assertEquals(args.ts_mon_flush, 'auto') 62 self.assertEquals(args.ts_mon_flush, 'auto')
63 self.assertIsNotNone(interface.state.flush_thread) 63 self.assertIsNotNone(interface.state.flush_thread)
64 self.assertTrue(standard_metrics.up.get()) 64 self.assertTrue(standard_metrics.up.get())
65 65
66 @mock.patch('requests.get', autospec=True) 66 @mock.patch('requests.get', autospec=True)
67 @mock.patch('socket.getfqdn', autospec=True) 67 @mock.patch('socket.getfqdn', autospec=True)
68 @mock.patch('infra_libs.ts_mon.common.monitors.HttpsMonitor.'
69 '_load_credentials', autospec=True)
70 def test_https_monitor_args(self, _load_creds, fake_fqdn, fake_get):
71 print [_load_creds, fake_fqdn, fake_get]
72 fake_fqdn.return_value = 'slave1-a1.reg.tld'
73 fake_get.return_value.side_effect = requests.exceptions.ConnectionError
74 p = argparse.ArgumentParser()
75 config.add_argparse_options(p)
76 args = p.parse_args([
77 '--ts-mon-credentials', '/path/to/creds.p8.json',
78 '--ts-mon-endpoint', 'https://test/random:insert'])
79
80 config.process_argparse_options(args)
81
82 self.assertIsInstance(interface.state.global_monitor,
83 monitors.HttpsMonitor)
84
85 self.assertIsInstance(interface.state.target, targets.DeviceTarget)
86 self.assertEquals(interface.state.target.hostname, 'slave1-a1')
87 self.assertEquals(interface.state.target.region, 'reg')
88 self.assertEquals(args.ts_mon_flush, 'auto')
89 self.assertIsNotNone(interface.state.flush_thread)
90 self.assertTrue(standard_metrics.up.get())
91
92 @mock.patch('requests.get', autospec=True)
93 @mock.patch('socket.getfqdn', autospec=True)
68 def test_default_target_uppercase_fqdn(self, fake_fqdn, fake_get): 94 def test_default_target_uppercase_fqdn(self, fake_fqdn, fake_get):
69 fake_fqdn.return_value = 'SLAVE1-A1.REG.TLD' 95 fake_fqdn.return_value = 'SLAVE1-A1.REG.TLD'
70 fake_get.return_value.side_effect = requests.exceptions.ConnectionError 96 fake_get.return_value.side_effect = requests.exceptions.ConnectionError
71 p = argparse.ArgumentParser() 97 p = argparse.ArgumentParser()
72 config.add_argparse_options(p) 98 config.add_argparse_options(p)
73 args = p.parse_args([ 99 args = p.parse_args([
74 '--ts-mon-credentials', '/path/to/creds.p8.json', 100 '--ts-mon-credentials', '/path/to/creds.p8.json',
75 '--ts-mon-endpoint', 'unsupported://www.googleapis.com/some/api']) 101 '--ts-mon-endpoint', 'unsupported://www.googleapis.com/some/api'])
76 config.process_argparse_options(args) 102 config.process_argparse_options(args)
77 self.assertIsInstance(interface.state.target, targets.DeviceTarget) 103 self.assertIsInstance(interface.state.target, targets.DeviceTarget)
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 with infra_libs.temporary_directory() as temp_dir: 384 with infra_libs.temporary_directory() as temp_dir:
359 filename = os.path.join(temp_dir, 'config') 385 filename = os.path.join(temp_dir, 'config')
360 with open(filename, 'w') as fh: 386 with open(filename, 'w') as fh:
361 fh.write('not a json file') 387 fh.write('not a json file')
362 388
363 with self.assertRaises(ValueError): 389 with self.assertRaises(ValueError):
364 config.load_machine_config(filename) 390 config.load_machine_config(filename)
365 391
366 def test_load_machine_config_not_exists(self): 392 def test_load_machine_config_not_exists(self):
367 self.assertEquals({}, config.load_machine_config('does not exist')) 393 self.assertEquals({}, config.load_machine_config('does not exist'))
OLDNEW
« no previous file with comments | « infra_libs/ts_mon/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698