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

Side by Side Diff: appengine/swarming/server/bot_management_test.py

Issue 2402543002: Create a BotEvent when a bot is leased from Machine Provider (Closed)
Patch Set: Fix tests Created 4 years, 2 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The LUCI Authors. All rights reserved. 2 # Copyright 2014 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import datetime 6 import datetime
7 import hashlib 7 import hashlib
8 import logging 8 import logging
9 import sys 9 import sys
10 import unittest 10 import unittest
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 version=hashlib.sha1().hexdigest(), quarantined=False, task_id=None, 44 version=hashlib.sha1().hexdigest(), quarantined=False, task_id=None,
45 task_name=None) 45 task_name=None)
46 46
47 expected = { 47 expected = {
48 'authenticated_as': 'bot:id1.domain', 48 'authenticated_as': 'bot:id1.domain',
49 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']}, 49 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']},
50 'external_ip': u'8.8.4.4', 50 'external_ip': u'8.8.4.4',
51 'first_seen_ts': now, 51 'first_seen_ts': now,
52 'id': 'id1', 52 'id': 'id1',
53 'last_seen_ts': now, 53 'last_seen_ts': now,
54 'lease_id': None,
55 'lease_expiration_ts': None,
54 'quarantined': False, 56 'quarantined': False,
55 'state': {u'ram': 65}, 57 'state': {u'ram': 65},
56 'task_id': None, 58 'task_id': None,
57 'task_name': None, 59 'task_name': None,
58 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709', 60 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709',
59 } 61 }
60 self.assertEqual( 62 self.assertEqual(
61 expected, bot_management.get_info_key('id1').get().to_dict()) 63 expected, bot_management.get_info_key('id1').get().to_dict())
62 64
63 def test_get_events_query(self): 65 def test_get_events_query(self):
64 now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6) 66 now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
65 self.mock_now(now) 67 self.mock_now(now)
66 bot_management.bot_event( 68 bot_management.bot_event(
67 event_type='bot_connected', bot_id='id1', 69 event_type='bot_connected', bot_id='id1',
68 external_ip='8.8.4.4', authenticated_as='bot:id1.domain', 70 external_ip='8.8.4.4', authenticated_as='bot:id1.domain',
69 dimensions={'id': ['id1'], 'foo': ['bar']}, state={'ram': 65}, 71 dimensions={'id': ['id1'], 'foo': ['bar']}, state={'ram': 65},
70 version=hashlib.sha1().hexdigest(), quarantined=False, task_id=None, 72 version=hashlib.sha1().hexdigest(), quarantined=False, task_id=None,
71 task_name=None) 73 task_name=None)
72 expected = [ 74 expected = [
73 { 75 {
74 'authenticated_as': 'bot:id1.domain', 76 'authenticated_as': 'bot:id1.domain',
75 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']}, 77 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']},
76 'event_type': u'bot_connected', 78 'event_type': u'bot_connected',
77 'external_ip': u'8.8.4.4', 79 'external_ip': u'8.8.4.4',
80 'lease_id': None,
81 'lease_expiration_ts': None,
78 'message': None, 82 'message': None,
79 'quarantined': False, 83 'quarantined': False,
80 'state': {u'ram': 65}, 84 'state': {u'ram': 65},
81 'task_id': None, 85 'task_id': None,
82 'ts': now, 86 'ts': now,
83 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709', 87 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709',
84 }, 88 },
85 ] 89 ]
86 self.assertEqual( 90 self.assertEqual(
87 expected, 91 expected,
(...skipping 10 matching lines...) Expand all
98 task_name=None) 102 task_name=None)
99 103
100 # Assert that BotInfo was updated too. 104 # Assert that BotInfo was updated too.
101 expected = { 105 expected = {
102 'authenticated_as': 'bot:id1.domain', 106 'authenticated_as': 'bot:id1.domain',
103 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']}, 107 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']},
104 'external_ip': u'8.8.4.4', 108 'external_ip': u'8.8.4.4',
105 'first_seen_ts': now, 109 'first_seen_ts': now,
106 'id': 'id1', 110 'id': 'id1',
107 'last_seen_ts': now, 111 'last_seen_ts': now,
112 'lease_id': None,
113 'lease_expiration_ts': None,
108 'quarantined': True, 114 'quarantined': True,
109 'state': {u'ram': 65}, 115 'state': {u'ram': 65},
110 'task_id': None, 116 'task_id': None,
111 'task_name': None, 117 'task_name': None,
112 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709', 118 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709',
113 } 119 }
114 bot_info = bot_management.get_info_key('id1').get() 120 bot_info = bot_management.get_info_key('id1').get()
115 self.assertEqual(expected, bot_info.to_dict()) 121 self.assertEqual(expected, bot_info.to_dict())
116 self.assertEqual(False, bot_info.is_busy) 122 self.assertEqual(False, bot_info.is_busy)
117 123
(...skipping 10 matching lines...) Expand all
128 version=hashlib.sha1().hexdigest(), quarantined=False, task_id='12311', 134 version=hashlib.sha1().hexdigest(), quarantined=False, task_id='12311',
129 task_name='yo') 135 task_name='yo')
130 136
131 expected = { 137 expected = {
132 'authenticated_as': 'bot:id1.domain', 138 'authenticated_as': 'bot:id1.domain',
133 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']}, 139 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']},
134 'external_ip': u'8.8.4.4', 140 'external_ip': u'8.8.4.4',
135 'first_seen_ts': now, 141 'first_seen_ts': now,
136 'id': 'id1', 142 'id': 'id1',
137 'last_seen_ts': now, 143 'last_seen_ts': now,
144 'lease_id': None,
145 'lease_expiration_ts': None,
138 'quarantined': False, 146 'quarantined': False,
139 'state': {u'ram': 65}, 147 'state': {u'ram': 65},
140 'task_id': u'12311', 148 'task_id': u'12311',
141 'task_name': u'yo', 149 'task_name': u'yo',
142 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709', 150 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709',
143 } 151 }
144 bot_info = bot_management.get_info_key('id1').get() 152 bot_info = bot_management.get_info_key('id1').get()
145 self.assertEqual(expected, bot_info.to_dict()) 153 self.assertEqual(expected, bot_info.to_dict())
146 self.assertEqual(True, bot_info.is_busy) 154 self.assertEqual(True, bot_info.is_busy)
147 155
148 expected = [ 156 expected = [
149 { 157 {
150 'authenticated_as': 'bot:id1.domain', 158 'authenticated_as': 'bot:id1.domain',
151 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']}, 159 'dimensions': {u'foo': [u'bar'], u'id': [u'id1']},
152 'event_type': u'request_task', 160 'event_type': u'request_task',
153 'external_ip': u'8.8.4.4', 161 'external_ip': u'8.8.4.4',
162 'lease_id': None,
163 'lease_expiration_ts': None,
154 'message': None, 164 'message': None,
155 'quarantined': False, 165 'quarantined': False,
156 'state': {u'ram': 65}, 166 'state': {u'ram': 65},
157 'task_id': u'12311', 167 'task_id': u'12311',
158 'ts': now, 168 'ts': now,
159 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709', 169 'version': u'da39a3ee5e6b4b0d3255bfef95601890afd80709',
160 }, 170 },
161 ] 171 ]
162 self.assertEqual( 172 self.assertEqual(
163 expected, 173 expected,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 def test_filter_dimensions(self): 243 def test_filter_dimensions(self):
234 pass # Tested in handlers_endpoints_test 244 pass # Tested in handlers_endpoints_test
235 245
236 def test_filter_availability(self): 246 def test_filter_availability(self):
237 pass # Tested in handlers_endpoints_test 247 pass # Tested in handlers_endpoints_test
238 248
239 if __name__ == '__main__': 249 if __name__ == '__main__':
240 logging.basicConfig( 250 logging.basicConfig(
241 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 251 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
242 unittest.main() 252 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/server/bot_management.py ('k') | appengine/swarming/server/lease_management.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698