| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 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 json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 def gen_result_response(**kwargs): | 133 def gen_result_response(**kwargs): |
| 134 out = { | 134 out = { |
| 135 u'bot_id': u'swarm6', | 135 u'bot_id': u'swarm6', |
| 136 u'completed_ts': u'2014-09-24T13:49:16.012345', | 136 u'completed_ts': u'2014-09-24T13:49:16.012345', |
| 137 u'created_ts': u'2014-09-24T13:49:03.012345', | 137 u'created_ts': u'2014-09-24T13:49:03.012345', |
| 138 u'duration': 0.9636809825897217, | 138 u'duration': 0.9636809825897217, |
| 139 u'exit_code': 0, | 139 u'exit_code': 0, |
| 140 u'failure': False, | 140 u'failure': False, |
| 141 u'internal_failure': False, | 141 u'internal_failure': False, |
| 142 u'modified_ts': u'2014-09-24T13:49:17.012345', | 142 u'modified_ts': u'2014-09-24T13:49:17.012345', |
| 143 u'name': u'heartbeat-canary-2014-09-24_13:49:01-os=Linux', | 143 u'name': u'heartbeat-canary-2014-09-24_13:49:01-os=Ubuntu', |
| 144 u'server_versions': [u'1'], | 144 u'server_versions': [u'1'], |
| 145 u'started_ts': u'2014-09-24T13:49:09.012345', | 145 u'started_ts': u'2014-09-24T13:49:09.012345', |
| 146 u'state': 'COMPLETED', | 146 u'state': 'COMPLETED', |
| 147 u'tags': [u'cpu:x86', u'priority:100', u'user:joe@localhost'], | 147 u'tags': [u'cpu:x86', u'priority:100', u'user:joe@localhost'], |
| 148 u'task_id': u'10100', | 148 u'task_id': u'10100', |
| 149 u'try_number': 1, | 149 u'try_number': 1, |
| 150 u'user': u'joe@localhost', | 150 u'user': u'joe@localhost', |
| 151 } | 151 } |
| 152 out.update(kwargs) | 152 out.update(kwargs) |
| 153 return out | 153 return out |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 def test_trigger_task_shards_2_shards(self): | 330 def test_trigger_task_shards_2_shards(self): |
| 331 task_request = swarming.NewTaskRequest( | 331 task_request = swarming.NewTaskRequest( |
| 332 expiration_secs=60*60, | 332 expiration_secs=60*60, |
| 333 name=TEST_NAME, | 333 name=TEST_NAME, |
| 334 parent_task_id=None, | 334 parent_task_id=None, |
| 335 priority=101, | 335 priority=101, |
| 336 properties=swarming.TaskProperties( | 336 properties=swarming.TaskProperties( |
| 337 caches=[], | 337 caches=[], |
| 338 cipd_input=None, | 338 cipd_input=None, |
| 339 command=['a', 'b'], | 339 command=['a', 'b'], |
| 340 dimensions={'foo': 'bar', 'os': 'Mac'}, | 340 dimensions=[('foo', 'bar'), ('os', 'Mac')], |
| 341 env={}, | 341 env={}, |
| 342 execution_timeout_secs=60, | 342 execution_timeout_secs=60, |
| 343 extra_args=[], | 343 extra_args=[], |
| 344 grace_period_secs=30, | 344 grace_period_secs=30, |
| 345 idempotent=False, | 345 idempotent=False, |
| 346 inputs_ref={ | 346 inputs_ref={ |
| 347 'isolated': None, | 347 'isolated': None, |
| 348 'isolatedserver': '', | 348 'isolatedserver': '', |
| 349 'namespace': 'default-gzip', | 349 'namespace': 'default-gzip', |
| 350 }, | 350 }, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 def test_trigger_task_shards_priority_override(self): | 405 def test_trigger_task_shards_priority_override(self): |
| 406 task_request = swarming.NewTaskRequest( | 406 task_request = swarming.NewTaskRequest( |
| 407 expiration_secs=60*60, | 407 expiration_secs=60*60, |
| 408 name=TEST_NAME, | 408 name=TEST_NAME, |
| 409 parent_task_id='123', | 409 parent_task_id='123', |
| 410 priority=101, | 410 priority=101, |
| 411 properties=swarming.TaskProperties( | 411 properties=swarming.TaskProperties( |
| 412 caches=[], | 412 caches=[], |
| 413 cipd_input=None, | 413 cipd_input=None, |
| 414 command=['a', 'b'], | 414 command=['a', 'b'], |
| 415 dimensions={'foo': 'bar', 'os': 'Mac'}, | 415 dimensions=[('foo', 'bar'), ('os', 'Mac')], |
| 416 env={}, | 416 env={}, |
| 417 execution_timeout_secs=60, | 417 execution_timeout_secs=60, |
| 418 extra_args=[], | 418 extra_args=[], |
| 419 grace_period_secs=30, | 419 grace_period_secs=30, |
| 420 idempotent=False, | 420 idempotent=False, |
| 421 inputs_ref={ | 421 inputs_ref={ |
| 422 'isolated': None, | 422 'isolated': None, |
| 423 'isolatedserver': '', | 423 'isolatedserver': '', |
| 424 'namespace': 'default-gzip', | 424 'namespace': 'default-gzip', |
| 425 }, | 425 }, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 caches=[], | 472 caches=[], |
| 473 cipd_input=swarming.CipdInput( | 473 cipd_input=swarming.CipdInput( |
| 474 client_package=None, | 474 client_package=None, |
| 475 packages=[ | 475 packages=[ |
| 476 swarming.CipdPackage( | 476 swarming.CipdPackage( |
| 477 package_name='mypackage', | 477 package_name='mypackage', |
| 478 path='path/to/package', | 478 path='path/to/package', |
| 479 version='abc123')], | 479 version='abc123')], |
| 480 server=None), | 480 server=None), |
| 481 command=['a', 'b'], | 481 command=['a', 'b'], |
| 482 dimensions={'foo': 'bar', 'os': 'Mac'}, | 482 dimensions=[('foo', 'bar'), ('os', 'Mac')], |
| 483 env={}, | 483 env={}, |
| 484 execution_timeout_secs=60, | 484 execution_timeout_secs=60, |
| 485 extra_args=[], | 485 extra_args=[], |
| 486 grace_period_secs=30, | 486 grace_period_secs=30, |
| 487 idempotent=False, | 487 idempotent=False, |
| 488 inputs_ref={ | 488 inputs_ref={ |
| 489 'isolated': None, | 489 'isolated': None, |
| 490 'isolatedserver': '', | 490 'isolatedserver': '', |
| 491 'namespace': 'default-gzip', | 491 'namespace': 'default-gzip', |
| 492 }, | 492 }, |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 self._check_output('', '') | 1499 self._check_output('', '') |
| 1500 self.assertEqual(0, ret) | 1500 self.assertEqual(0, ret) |
| 1501 finally: | 1501 finally: |
| 1502 os.chdir(old_cwd) | 1502 os.chdir(old_cwd) |
| 1503 | 1503 |
| 1504 | 1504 |
| 1505 class TestCommandBot(NetTestCase): | 1505 class TestCommandBot(NetTestCase): |
| 1506 # Specialized test fixture for command 'bot'. | 1506 # Specialized test fixture for command 'bot'. |
| 1507 def setUp(self): | 1507 def setUp(self): |
| 1508 super(TestCommandBot, self).setUp() | 1508 super(TestCommandBot, self).setUp() |
| 1509 # Expected requests are always the same, independent of the test case. | 1509 # Sample data retrieved from actual server. |
| 1510 self.now = unicode(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')) |
| 1511 self.bot_1 = { |
| 1512 u'bot_id': u'swarm1', |
| 1513 u'created_ts': self.now, |
| 1514 u'dimensions': [ |
| 1515 {u'key': u'cores', u'value': [u'8']}, |
| 1516 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, |
| 1517 {u'key': u'gpu', u'value': []}, |
| 1518 {u'key': u'id', u'value': [u'swarm1']}, |
| 1519 {u'key': u'os', u'value': [u'Ubuntu', u'Ubuntu-12.04']}, |
| 1520 ], |
| 1521 u'external_ip': u'1.1.1.1', |
| 1522 u'hostname': u'swarm1.example.com', |
| 1523 u'internal_ip': u'192.168.0.1', |
| 1524 u'is_dead': True, |
| 1525 u'last_seen_ts': 'A long time ago', |
| 1526 u'quarantined': False, |
| 1527 u'task_id': u'', |
| 1528 u'task_name': None, |
| 1529 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', |
| 1530 } |
| 1531 self.bot_2 = { |
| 1532 u'bot_id': u'swarm2', |
| 1533 u'created_ts': self.now, |
| 1534 u'dimensions': [ |
| 1535 {u'key': u'cores', u'value': [u'8']}, |
| 1536 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, |
| 1537 {u'key': u'gpu', u'value': [ |
| 1538 u'15ad', |
| 1539 u'15ad:0405', |
| 1540 u'VMware Virtual SVGA 3D Graphics Adapter', |
| 1541 ]}, |
| 1542 {u'key': u'id', u'value': [u'swarm2']}, |
| 1543 {u'key': u'os', u'value': [u'Windows', u'Windows-6.1']}, |
| 1544 ], |
| 1545 u'external_ip': u'1.1.1.2', |
| 1546 u'hostname': u'swarm2.example.com', |
| 1547 u'internal_ip': u'192.168.0.2', |
| 1548 u'is_dead': False, |
| 1549 u'last_seen_ts': self.now, |
| 1550 u'quarantined': False, |
| 1551 u'task_id': u'', |
| 1552 u'task_name': None, |
| 1553 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', |
| 1554 } |
| 1555 self.bot_3 = { |
| 1556 u'bot_id': u'swarm3', |
| 1557 u'created_ts': self.now, |
| 1558 u'dimensions': [ |
| 1559 {u'key': u'cores', u'value': [u'4']}, |
| 1560 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, |
| 1561 {u'key': u'gpu', u'value': [u'15ad', u'15ad:0405']}, |
| 1562 {u'key': u'id', u'value': [u'swarm3']}, |
| 1563 {u'key': u'os', u'value': [u'Mac', u'Mac-10.9']}, |
| 1564 ], |
| 1565 u'external_ip': u'1.1.1.3', |
| 1566 u'hostname': u'swarm3.example.com', |
| 1567 u'internal_ip': u'192.168.0.3', |
| 1568 u'is_dead': False, |
| 1569 u'last_seen_ts': self.now, |
| 1570 u'quarantined': False, |
| 1571 u'task_id': u'148569b73a89501', |
| 1572 u'task_name': u'browser_tests', |
| 1573 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', |
| 1574 } |
| 1575 self.bot_4 = { |
| 1576 u'bot_id': u'swarm4', |
| 1577 u'created_ts': self.now, |
| 1578 u'dimensions': [ |
| 1579 {u'key': u'cores', u'value': [u'8']}, |
| 1580 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, |
| 1581 {u'key': u'gpu', u'value': []}, |
| 1582 {u'key': u'id', u'value': [u'swarm4']}, |
| 1583 {u'key': u'os', u'value': [u'Ubuntu', u'Ubuntu-12.04']}, |
| 1584 ], |
| 1585 u'external_ip': u'1.1.1.4', |
| 1586 u'hostname': u'swarm4.example.com', |
| 1587 u'internal_ip': u'192.168.0.4', |
| 1588 u'is_dead': False, |
| 1589 u'last_seen_ts': self.now, |
| 1590 u'quarantined': False, |
| 1591 u'task_id': u'14856971a64c601', |
| 1592 u'task_name': u'base_unittests', |
| 1593 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', |
| 1594 } |
| 1595 |
| 1596 def mock_swarming_api(self, bots, cursor): |
| 1597 """Returns fake /api/swarming/v1/bots/list data.""" |
| 1598 # Sample data retrieved from actual server. |
| 1599 return { |
| 1600 u'items': bots, |
| 1601 u'cursor': cursor, |
| 1602 u'death_timeout': 1800.0, |
| 1603 u'limit': 4, |
| 1604 u'now': unicode(self.now), |
| 1605 } |
| 1606 |
| 1607 def test_bots(self): |
| 1608 base_url = 'https://localhost:1/api/swarming/v1/bots/list?' |
| 1510 self.expected_requests( | 1609 self.expected_requests( |
| 1511 [ | 1610 [ |
| 1512 ( | 1611 ( |
| 1513 'https://localhost:1/api/swarming/v1/bots/list?limit=250', | 1612 base_url + 'is_dead=FALSE&is_busy=NONE&is_mp=NONE', |
| 1514 {}, | 1613 {}, |
| 1515 self.mock_swarming_api_v1_bots_page_1(), | 1614 self.mock_swarming_api([self.bot_2], 'opaque'), |
| 1516 ), | 1615 ), |
| 1517 ( | 1616 ( |
| 1518 'https://localhost:1/api/swarming/v1/bots/list?limit=250&' | 1617 base_url + 'is_dead=FALSE&is_busy=NONE&is_mp=NONE&cursor=opaque', |
| 1519 'cursor=opaque_cursor', | |
| 1520 {}, | 1618 {}, |
| 1521 self.mock_swarming_api_v1_bots_page_2(), | 1619 self.mock_swarming_api([self.bot_3], 'opaque2'), |
| 1620 ), |
| 1621 ( |
| 1622 base_url + 'is_dead=FALSE&is_busy=NONE&is_mp=NONE&cursor=opaque2', |
| 1623 {}, |
| 1624 self.mock_swarming_api([self.bot_4], None), |
| 1522 ), | 1625 ), |
| 1523 ]) | 1626 ]) |
| 1524 | |
| 1525 @staticmethod | |
| 1526 def mock_swarming_api_v1_bots_page_1(): | |
| 1527 """Returns fake /api/swarming/v1/bots/list data.""" | |
| 1528 # Sample data retrieved from actual server. | |
| 1529 now = unicode(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')) | |
| 1530 return { | |
| 1531 u'items': [ | |
| 1532 { | |
| 1533 u'bot_id': u'swarm3', | |
| 1534 u'created_ts': now, | |
| 1535 u'dimensions': [ | |
| 1536 {u'key': u'cores', u'value': [u'4']}, | |
| 1537 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, | |
| 1538 {u'key': u'gpu', u'value': [u'15ad', u'15ad:0405']}, | |
| 1539 {u'key': u'id', u'value': [u'swarm3']}, | |
| 1540 {u'key': u'os', u'value': [u'Mac', u'Mac-10.9']}, | |
| 1541 ], | |
| 1542 u'external_ip': u'1.1.1.3', | |
| 1543 u'hostname': u'swarm3.example.com', | |
| 1544 u'internal_ip': u'192.168.0.3', | |
| 1545 u'is_dead': False, | |
| 1546 u'last_seen_ts': now, | |
| 1547 u'quarantined': False, | |
| 1548 u'task_id': u'148569b73a89501', | |
| 1549 u'task_name': u'browser_tests', | |
| 1550 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', | |
| 1551 }, | |
| 1552 { | |
| 1553 u'bot_id': u'swarm1', | |
| 1554 u'created_ts': now, | |
| 1555 u'dimensions': [ | |
| 1556 {u'key': u'cores', u'value': [u'8']}, | |
| 1557 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, | |
| 1558 {u'key': u'gpu', u'value': []}, | |
| 1559 {u'key': u'id', u'value': [u'swarm1']}, | |
| 1560 {u'key': u'os', u'value': [u'Linux', u'Linux-12.04']}, | |
| 1561 ], | |
| 1562 u'external_ip': u'1.1.1.1', | |
| 1563 u'hostname': u'swarm1.example.com', | |
| 1564 u'internal_ip': u'192.168.0.1', | |
| 1565 u'is_dead': True, | |
| 1566 u'last_seen_ts': 'A long time ago', | |
| 1567 u'quarantined': False, | |
| 1568 u'task_id': u'', | |
| 1569 u'task_name': None, | |
| 1570 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', | |
| 1571 }, | |
| 1572 { | |
| 1573 u'bot_id': u'swarm2', | |
| 1574 u'created_ts': now, | |
| 1575 u'dimensions': [ | |
| 1576 {u'key': u'cores', u'value': [u'8']}, | |
| 1577 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, | |
| 1578 {u'key': u'gpu', u'value': [ | |
| 1579 u'15ad', | |
| 1580 u'15ad:0405', | |
| 1581 u'VMware Virtual SVGA 3D Graphics Adapter', | |
| 1582 ]}, | |
| 1583 {u'key': u'id', u'value': [u'swarm2']}, | |
| 1584 {u'key': u'os', u'value': [u'Windows', u'Windows-6.1']}, | |
| 1585 ], | |
| 1586 u'external_ip': u'1.1.1.2', | |
| 1587 u'hostname': u'swarm2.example.com', | |
| 1588 u'internal_ip': u'192.168.0.2', | |
| 1589 u'is_dead': False, | |
| 1590 u'last_seen_ts': now, | |
| 1591 u'quarantined': False, | |
| 1592 u'task_id': u'', | |
| 1593 u'task_name': None, | |
| 1594 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', | |
| 1595 }, | |
| 1596 ], | |
| 1597 u'cursor': u'opaque_cursor', | |
| 1598 u'death_timeout': 1800.0, | |
| 1599 u'limit': 4, | |
| 1600 u'now': unicode(now), | |
| 1601 } | |
| 1602 | |
| 1603 @staticmethod | |
| 1604 def mock_swarming_api_v1_bots_page_2(): | |
| 1605 """Returns fake /api/swarming/v1/bots/list data.""" | |
| 1606 # Sample data retrieved from actual server. | |
| 1607 now = unicode(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')) | |
| 1608 return { | |
| 1609 u'items': [ | |
| 1610 { | |
| 1611 u'bot_id': u'swarm4', | |
| 1612 u'created_ts': now, | |
| 1613 u'dimensions': [ | |
| 1614 {u'key': u'cores', u'value': [u'8']}, | |
| 1615 {u'key': u'cpu', u'value': [u'x86', u'x86-64']}, | |
| 1616 {u'key': u'gpu', u'value': []}, | |
| 1617 {u'key': u'id', u'value': [u'swarm4']}, | |
| 1618 {u'key': u'os', u'value': [u'Linux', u'Linux-12.04']}, | |
| 1619 ], | |
| 1620 u'external_ip': u'1.1.1.4', | |
| 1621 u'hostname': u'swarm4.example.com', | |
| 1622 u'internal_ip': u'192.168.0.4', | |
| 1623 u'is_dead': False, | |
| 1624 u'last_seen_ts': now, | |
| 1625 u'quarantined': False, | |
| 1626 u'task_id': u'14856971a64c601', | |
| 1627 u'task_name': u'base_unittests', | |
| 1628 u'version': u'56918a2ea28a6f51751ad14cc086f118b8727905', | |
| 1629 } | |
| 1630 ], | |
| 1631 u'cursor': None, | |
| 1632 u'death_timeout': 1800.0, | |
| 1633 u'limit': 4, | |
| 1634 u'now': unicode(now), | |
| 1635 } | |
| 1636 | |
| 1637 def test_bots(self): | |
| 1638 ret = self.main_safe(['bots', '--swarming', 'https://localhost:1']) | 1627 ret = self.main_safe(['bots', '--swarming', 'https://localhost:1']) |
| 1639 expected = ( | 1628 expected = ( |
| 1640 u'swarm2\n' | 1629 u'swarm2\n' |
| 1641 u' {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": ' | 1630 u' {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": ' |
| 1642 '["15ad", "15ad:0405", "VMware Virtual SVGA 3D Graphics Adapter"], ' | 1631 '["15ad", "15ad:0405", "VMware Virtual SVGA 3D Graphics Adapter"], ' |
| 1643 '"id": ["swarm2"], "os": ["Windows", "Windows-6.1"]}\n' | 1632 '"id": ["swarm2"], "os": ["Windows", "Windows-6.1"]}\n' |
| 1644 'swarm3\n' | 1633 'swarm3\n' |
| 1645 ' {"cores": ["4"], "cpu": ["x86", "x86-64"], "gpu": ["15ad", ' | 1634 ' {"cores": ["4"], "cpu": ["x86", "x86-64"], "gpu": ["15ad", ' |
| 1646 '"15ad:0405"], "id": ["swarm3"], "os": ["Mac", "Mac-10.9"]}\n' | 1635 '"15ad:0405"], "id": ["swarm3"], "os": ["Mac", "Mac-10.9"]}\n' |
| 1647 u' task: 148569b73a89501\n' | 1636 u' task: 148569b73a89501\n' |
| 1648 u'swarm4\n' | 1637 u'swarm4\n' |
| 1649 u' {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' | 1638 u' {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' |
| 1650 '"id": ["swarm4"], "os": ["Linux", "Linux-12.04"]}\n' | 1639 '"id": ["swarm4"], "os": ["Ubuntu", "Ubuntu-12.04"]}\n' |
| 1651 u' task: 14856971a64c601\n') | 1640 u' task: 14856971a64c601\n') |
| 1652 self._check_output(expected, '') | 1641 self._check_output(expected, '') |
| 1653 self.assertEqual(0, ret) | 1642 self.assertEqual(0, ret) |
| 1654 | 1643 |
| 1655 def test_bots_bare(self): | 1644 def test_bots_bare(self): |
| 1645 base_url = 'https://localhost:1/api/swarming/v1/bots/list?' |
| 1646 self.expected_requests( |
| 1647 [ |
| 1648 ( |
| 1649 base_url + 'is_dead=FALSE&is_busy=NONE&is_mp=NONE', |
| 1650 {}, |
| 1651 self.mock_swarming_api([self.bot_2], 'opaque'), |
| 1652 ), |
| 1653 ( |
| 1654 base_url + 'is_dead=FALSE&is_busy=NONE&is_mp=NONE&cursor=opaque', |
| 1655 {}, |
| 1656 self.mock_swarming_api([self.bot_3], 'opaque2'), |
| 1657 ), |
| 1658 ( |
| 1659 base_url + 'is_dead=FALSE&is_busy=NONE&is_mp=NONE&cursor=opaque2', |
| 1660 {}, |
| 1661 self.mock_swarming_api([self.bot_4], None), |
| 1662 ), |
| 1663 ]) |
| 1656 ret = self.main_safe( | 1664 ret = self.main_safe( |
| 1657 ['bots', '--swarming', 'https://localhost:1', '--bare']) | 1665 ['bots', '--swarming', 'https://localhost:1', '--bare']) |
| 1658 self._check_output("swarm2\nswarm3\nswarm4\n", '') | 1666 self._check_output("swarm2\nswarm3\nswarm4\n", '') |
| 1659 self.assertEqual(0, ret) | 1667 self.assertEqual(0, ret) |
| 1660 | 1668 |
| 1661 def test_bots_filter(self): | 1669 def test_bots_filter(self): |
| 1670 base_url = 'https://localhost:1/api/swarming/v1/bots/list?' |
| 1671 self.expected_requests( |
| 1672 [ |
| 1673 ( |
| 1674 base_url + |
| 1675 'is_dead=FALSE&is_busy=TRUE&is_mp=NONE&dimensions=os%3AWindows', |
| 1676 {}, |
| 1677 self.mock_swarming_api([self.bot_2], None), |
| 1678 ), |
| 1679 ]) |
| 1662 ret = self.main_safe( | 1680 ret = self.main_safe( |
| 1663 [ | 1681 [ |
| 1664 'bots', '--swarming', 'https://localhost:1', | 1682 'bots', '--swarming', 'https://localhost:1', |
| 1683 '--busy', |
| 1665 '--dimension', 'os', 'Windows', | 1684 '--dimension', 'os', 'Windows', |
| 1666 ]) | 1685 ]) |
| 1667 expected = ( | 1686 expected = ( |
| 1668 u'swarm2\n {"cores": ["8"], "cpu": ["x86", "x86-64"], ' | 1687 u'swarm2\n {"cores": ["8"], "cpu": ["x86", "x86-64"], ' |
| 1669 '"gpu": ["15ad", "15ad:0405", "VMware Virtual SVGA 3D Graphics ' | 1688 '"gpu": ["15ad", "15ad:0405", "VMware Virtual SVGA 3D Graphics ' |
| 1670 'Adapter"], "id": ["swarm2"], ' | 1689 'Adapter"], "id": ["swarm2"], ' |
| 1671 '"os": ["Windows", "Windows-6.1"]}\n') | 1690 '"os": ["Windows", "Windows-6.1"]}\n') |
| 1672 self._check_output(expected, '') | 1691 self._check_output(expected, '') |
| 1673 self.assertEqual(0, ret) | 1692 self.assertEqual(0, ret) |
| 1674 | 1693 |
| 1675 def test_bots_filter_keep_dead(self): | 1694 def test_bots_filter_keep_dead(self): |
| 1695 base_url = 'https://localhost:1/api/swarming/v1/bots/list?' |
| 1696 self.expected_requests( |
| 1697 [ |
| 1698 ( |
| 1699 base_url + 'is_dead=NONE&is_busy=NONE&is_mp=NONE', |
| 1700 {}, |
| 1701 self.mock_swarming_api([self.bot_1, self.bot_4], None), |
| 1702 ), |
| 1703 ]) |
| 1676 ret = self.main_safe( | 1704 ret = self.main_safe( |
| 1677 [ | 1705 [ |
| 1678 'bots', '--swarming', 'https://localhost:1', | 1706 'bots', '--swarming', 'https://localhost:1', |
| 1679 '--dimension', 'os', 'Linux', '--keep-dead', | 1707 '--keep-dead', |
| 1680 ]) | 1708 ]) |
| 1681 expected = ( | 1709 expected = ( |
| 1682 u'swarm1\n {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' | 1710 u'swarm1\n {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' |
| 1683 '"id": ["swarm1"], "os": ["Linux", "Linux-12.04"]}\n' | 1711 '"id": ["swarm1"], "os": ["Ubuntu", "Ubuntu-12.04"]}\n' |
| 1684 u'swarm4\n' | 1712 u'swarm4\n' |
| 1685 u' {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' | 1713 u' {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' |
| 1686 '"id": ["swarm4"], "os": ["Linux", "Linux-12.04"]}\n' | 1714 '"id": ["swarm4"], "os": ["Ubuntu", "Ubuntu-12.04"]}\n' |
| 1687 u' task: 14856971a64c601\n') | 1715 u' task: 14856971a64c601\n') |
| 1688 self._check_output(expected, '') | 1716 self._check_output(expected, '') |
| 1689 self.assertEqual(0, ret) | 1717 self.assertEqual(0, ret) |
| 1690 | 1718 |
| 1691 def test_bots_filter_dead_only(self): | 1719 def test_bots_filter_dead_only(self): |
| 1720 base_url = 'https://localhost:1/api/swarming/v1/bots/list?' |
| 1721 self.expected_requests( |
| 1722 [ |
| 1723 ( |
| 1724 base_url + |
| 1725 'is_dead=TRUE&is_busy=NONE&is_mp=NONE&dimensions=os%3AUbuntu', |
| 1726 {}, |
| 1727 self.mock_swarming_api([self.bot_1], None), |
| 1728 ), |
| 1729 ]) |
| 1692 ret = self.main_safe( | 1730 ret = self.main_safe( |
| 1693 [ | 1731 [ |
| 1694 'bots', '--swarming', 'https://localhost:1', | 1732 'bots', '--swarming', 'https://localhost:1', |
| 1695 '--dimension', 'os', 'Linux', '--dead-only', | 1733 '--dimension', 'os', 'Ubuntu', '--dead-only', |
| 1696 ]) | 1734 ]) |
| 1697 expected = ( | 1735 expected = ( |
| 1698 u'swarm1\n {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' | 1736 u'swarm1\n {"cores": ["8"], "cpu": ["x86", "x86-64"], "gpu": [], ' |
| 1699 '"id": ["swarm1"], "os": ["Linux", "Linux-12.04"]}\n') | 1737 '"id": ["swarm1"], "os": ["Ubuntu", "Ubuntu-12.04"]}\n') |
| 1700 self._check_output(expected, '') | 1738 self._check_output(expected, '') |
| 1701 self.assertEqual(0, ret) | 1739 self.assertEqual(0, ret) |
| 1702 | 1740 |
| 1703 | 1741 |
| 1704 if __name__ == '__main__': | 1742 if __name__ == '__main__': |
| 1705 fix_encoding.fix_encoding() | 1743 fix_encoding.fix_encoding() |
| 1706 logging.basicConfig( | 1744 logging.basicConfig( |
| 1707 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 1745 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
| 1708 if '-v' in sys.argv: | 1746 if '-v' in sys.argv: |
| 1709 unittest.TestCase.maxDiff = None | 1747 unittest.TestCase.maxDiff = None |
| 1710 for e in ('ISOLATE_SERVER', 'SWARMING_TASK_ID', 'SWARMING_SERVER'): | 1748 for e in ('ISOLATE_SERVER', 'SWARMING_TASK_ID', 'SWARMING_SERVER'): |
| 1711 os.environ.pop(e, None) | 1749 os.environ.pop(e, None) |
| 1712 unittest.main() | 1750 unittest.main() |
| OLD | NEW |