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

Side by Side Diff: infra/services/master_manager_launcher/test/desired_state_parser_test.py

Issue 1128783003: Add master_manager_launch script which launches master_manager scripts for each master on a host. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Address agable's comments. Created 5 years, 7 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/services/master_manager_launcher/test/data/valid.json ('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
(Empty)
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
3 # found in the LICENSE file.
4
5 import os
6 import unittest
7
8 from infra.libs.buildbot import master
9 from infra.libs.time_functions import timestamp
10 from infra.services.master_manager_launcher import desired_state_parser
11 from testing_support import auto_stub
12
13
14 DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
15
16
17 class TestDesiredStateValidation(auto_stub.TestCase):
18 def setUp(self):
19 super(TestDesiredStateValidation, self).setUp()
20
21 self.mock(timestamp, 'utcnow_ts', lambda: 5000)
22
23 def testValidState(self):
24 self.assertTrue(desired_state_parser.desired_master_state_is_valid({
25 'master.chromium.fyi': [
26 {'desired_state': 'running', 'transition_time_utc': 4000},
27 {'desired_state': 'offline', 'transition_time_utc': 6000},
28 ]}))
29
30 def testNoDesiredState(self):
31 self.assertFalse(desired_state_parser.desired_master_state_is_valid({
32 'master.chromium.fyi': [
33 {'transition_time_utc': 4000},
34 {'desired_state': 'offline', 'transition_time_utc': 6000},
35 ]}))
36
37 def testNoTransitionTime(self):
38 self.assertFalse(desired_state_parser.desired_master_state_is_valid({
39 'master.chromium.fyi': [
40 {'desired_state': 'running', 'transition_time_utc': 4000},
41 {'desired_state': 'offline'},
42 ]}))
43
44 def testTransitionTimeInvalid(self):
45 self.assertFalse(desired_state_parser.desired_master_state_is_valid({
46 'master.chromium.fyi': [
47 {'desired_state': 'running', 'transition_time_utc': 'boats'},
48 {'desired_state': 'offline', 'transition_time_utc': 'llama'},
49 ]}))
50
51 def testNotSorted(self):
52 self.assertFalse(desired_state_parser.desired_master_state_is_valid({
53 'master.chromium.fyi': [
54 {'desired_state': 'offline', 'transition_time_utc': 6000},
55 {'desired_state': 'running', 'transition_time_utc': 4000},
56 ]}))
57
58 def testInvalidState(self):
59 self.assertFalse(desired_state_parser.desired_master_state_is_valid({
60 'master.chromium.fyi': [
61 {'desired_state': 'pajamas', 'transition_time_utc': 4000},
62 {'desired_state': 'offline', 'transition_time_utc': 6000},
63 ]}))
64
65 def testUncertainPresent(self):
66 self.assertFalse(desired_state_parser.desired_master_state_is_valid({
67 'master.chromium.fyi': [
68 {'desired_state': 'running', 'transition_time_utc': 6000},
69 {'desired_state': 'offline', 'transition_time_utc': 8000},
70 ]}))
71
72 def testValidFile(self):
73 desired_state_parser.load_desired_state_file(
74 os.path.join(DATA_DIR, 'valid.json'))
75
76 def testInvalidFile(self):
77 with self.assertRaises(desired_state_parser.InvalidDesiredMasterState):
78 desired_state_parser.load_desired_state_file(
79 os.path.join(DATA_DIR, 'invalid.json'))
80
81
82 class TestMasterStateLookup(unittest.TestCase):
83 STATES = [
84 {'desired_state': 'pajamas', 'transition_time_utc': 4000},
85 {'desired_state': 'offline', 'transition_time_utc': 6000},
86 ]
87
88 def testUnknownPast(self):
89 state = desired_state_parser.get_master_state(self.STATES, now=300)
90 self.assertIsNone(state)
91
92 def testMiddle(self):
93 state = desired_state_parser.get_master_state(self.STATES, now=4500)
94 self.assertEqual(state, self.STATES[0])
95
96 def testEnd(self):
97 state = desired_state_parser.get_master_state(self.STATES, now=8000)
98 self.assertEqual(state, self.STATES[1])
99
100
101 class TestHostnameLookup(auto_stub.TestCase):
102 def setUp(self):
103 super(TestHostnameLookup, self).setUp()
104
105 self.mock(master, 'get_mastermap_for_host', lambda _x, _y: [
106 {'dirname': 'master.chromium', 'internal': False},
107 {'dirname': 'master.chromium.fyi', 'internal': False},
108 {'dirname': 'master.supersecret', 'internal': True},
109 {'dirname': 'master.ultrasecret', 'internal': True},
110 ])
111
112
113 def testHostnameLookup(self):
114 """Test that selected masters are triggered and all else are ignored."""
115 desired_state = {
116 'master.chromium.fyi': [
117 {'desired_state': 'running', 'transition_time_utc': 4000},
118 ],
119 'master.supersecret': [
120 {'desired_state': 'running', 'transition_time_utc': 4000},
121 ],
122 }
123 triggered, ignored = desired_state_parser.get_masters_for_host(
124 desired_state,
125 'bananas/',
126 'impenetrablefortress.cool'
127 )
128
129 self.assertEqual(len(triggered), 2)
130 self.assertEqual(len(ignored), 2)
131
132 self.assertEqual(sorted(ignored), [
133 'master.chromium',
134 'master.ultrasecret',
135 ])
136
137 for master_dict in triggered:
138 self.assertIn(master_dict['dirname'], desired_state)
OLDNEW
« no previous file with comments | « infra/services/master_manager_launcher/test/data/valid.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698