def get_dimensions(): """Returns bot_config.py's get_attributes() dict.""" # Importing this administrator provided script could have side-effects on # startup. That is why it is imported late. try: if _in_load_test_mode(): # Returns a minimal set of dimensions so it doesn't run tasks by error. dimensions = os_utilities.get_dimensions() return { 'id': dimensions['id'], 'load_test': ['1'], } import bot_config out = bot_config.get_dimensions() if not isinstance(out, dict): raise ValueError('Unexpected type %s' % out.__class__) return out except Exception as e: try: out = os_utilities.get_dimensions() out['error'] = [str(e)] out['quarantined'] = ['1'] return out except Exception as e: try: botid = os_utilities.get_hostname_short() except Exception as e2: botid = 'error_%s' % str(e2) return { 'id': [botid], 'error': ['%s\n%s' % (e, traceback.format_exc()[-2048:])], 'quarantined': ['1'], }
def test_get_dimensions(self): dimensions = os_utilities.get_dimensions() for key, values in dimensions.iteritems(): self.assertIsInstance(key, unicode) self.assertIsInstance(values, list) for value in values: self.assertIsInstance(value, unicode) actual = set(dimensions) # Only set when the process is running in a properly configured GUI context. actual.discard(u'locale') # Only set on machines with SSD. actual.discard(u'ssd') # There are cases where this dimension is not set. actual.discard(u'machine_type') expected = {u'cores', u'cpu', u'gpu', u'id', u'os', u'pool', u'python'} if platforms.is_gce(): expected.add(u'image') expected.add(u'zone') if sys.platform == 'darwin': expected.add(u'hidpi') expected.add(u'mac_model') expected.add(u'xcode_version') if sys.platform == 'linux2': expected.add(u'inside_docker') expected.add(u'kvm') if sys.platform == 'win32': expected.add(u'integrity') self.assertEqual(expected, actual)
def test_get_dimensions(self): actual = set(os_utilities.get_dimensions()) # Only set on GCE. actual.discard('machine_type') actual.discard('zone') # Only set on Mac. actual.discard('hidpi') expected = set(['cores', 'cpu', 'gpu', 'id', 'os']) self.assertEqual(expected, actual)
def test_override_id_via_env(self): mock_env = os.environ.copy() mock_env['SWARMING_BOT_ID'] = 'customid' self.mock(os, 'environ', mock_env) dimensions = os_utilities.get_dimensions() self.assertIsInstance(dimensions[u'id'], list) self.assertEqual(len(dimensions[u'id']), 1) self.assertIsInstance(dimensions[u'id'][0], six.text_type) self.assertEqual(dimensions[u'id'][0], u'customid')
def test_get_dimensions(self): actual = set(os_utilities.get_dimensions()) # Only set on GCE. actual.discard(u'machine_type') actual.discard(u'zone') # Only set on Mac. actual.discard(u'hidpi') expected = set([u'cores', u'cpu', u'gpu', u'id', u'os']) self.assertEqual(expected, actual)
def test_get_dimensions(self): actual = set(os_utilities.get_dimensions()) # Only set on GCE. actual.discard(u'machine_type') actual.discard(u'zone') # Only set on Mac. actual.discard(u'hidpi') expected = {u'cores', u'cpu', u'gpu', u'id', u'os', u'pool'} if sys.platform == 'darwin': expected.add(u'xcode_version') self.assertEqual(expected, actual)
def get_dimensions(): """Returns dict with the bot's dimensions. The dimensions are what are used to select the bot that can run each task. The bot id will be automatically selected based on the hostname with os_utilities.get_dimensions(). If you want something more special, specify it in your bot_config.py and override the item 'id'. See https://code.google.com/p/swarming/wiki/SwarmingMagicValues. """ return os_utilities.get_dimensions()
def test_get_dimensions(self): dimensions = os_utilities.get_dimensions() for key, values in dimensions.items(): self.assertIsInstance(key, six.text_type) self.assertIsInstance(values, list) for value in values: self.assertIsInstance(value, six.text_type) actual = set(dimensions) # Only set when the process is running in a properly configured GUI context. actual.discard(u'locale') # Only set on machines with SSD. actual.discard(u'ssd') # There are cases where this dimension is not set. actual.discard(u'machine_type') # Only set on ARM Linux machines. actual.discard(u'device_tree_compatible') # Only set on bare metal Linux machines. actual.discard(u'cpu_governor') # Only set on Windows machines. actual.discard(u'visual_studio_version') # Only set on Windows machines. actual.discard(u'windows_client_version') expected = { u'cores', u'cpu', u'gce', u'gpu', u'id', u'os', u'pool', u'python' } if platforms.is_gce(): expected.add(u'image') expected.add(u'zone') expected.add(u'gcp') if sys.platform == 'darwin': expected.add(u'mac_model') # Bot may not have HiDPI and Xcode preinstalled actual.discard(u'hidpi') actual.discard(u'xcode_version') actual.discard(u'device') # iOS devices if sys.platform.startswith('linux'): expected.add(u'inside_docker') expected.add(u'kvm') if sys.platform == 'win32': expected.add(u'integrity') self.assertEqual(expected, actual)
def get_state(sleep_streak): """Returns dict with a state of the bot reported to the server with each poll. """ try: if _in_load_test_mode(): state = os_utilities.get_state() state['dimensions'] = os_utilities.get_dimensions() else: import bot_config state = bot_config.get_state() if not isinstance(state, dict): state = {'error': state} except Exception as e: state = { 'error': '%s\n%s' % (e, traceback.format_exc()[-2048:]), 'quarantined': True, } state['sleep_streak'] = sleep_streak return state