def setUp(self):
     api_test.ApiTest.setUp(self)
     self.lab1 = datastore_test_util.CreateLabInfo('lab1')
     self.lab_config1 = datastore_test_util.CreateLabConfig('lab1')
     self.lab2 = datastore_test_util.CreateLabInfo('lab2')
     self.lab_config2 = datastore_test_util.CreateLabConfig('lab2')
     self.lab3 = datastore_test_util.CreateLabInfo('lab3')
     self.lab_config3 = datastore_test_util.CreateLabConfig(
         'lab3', owners=['owner3', 'owner4'])
     self.labs = [self.lab1, self.lab2, self.lab3]
     self.lab_configs = [
         self.lab_config1, self.lab_config2, self.lab_config3
     ]
 def testUpdateLabs_calculateHostUpdateStateSummaryFromClusterInfos(self):
     datastore_test_util.CreateLabInfo('alab', owners=['user1'])
     cluster1 = datastore_test_util.CreateCluster(
         'cluster1',
         lab_name='alab',
         host_update_state_summary=datastore_entities.
         HostUpdateStateSummary(total=13,
                                pending=1,
                                syncing=2,
                                shutting_down=3,
                                restarting=4,
                                errored=3))
     cluster2 = datastore_test_util.CreateCluster(
         'cluster2',
         lab_name='alab',
         host_update_state_summary=datastore_entities.
         HostUpdateStateSummary(total=14,
                                shutting_down=3,
                                restarting=4,
                                errored=2,
                                timed_out=2,
                                succeeded=1,
                                unknown=2))
     device_monitor._UpdateLabs([cluster1, cluster2])
     lab_info = datastore_entities.LabInfo.get_by_id('alab')
     self.assertCountEqual(['user1'], lab_info.owners)
     self.assertEqual(27, lab_info.host_update_state_summary.total)
     self.assertEqual(1, lab_info.host_update_state_summary.pending)
     self.assertEqual(2, lab_info.host_update_state_summary.syncing)
     self.assertEqual(6, lab_info.host_update_state_summary.shutting_down)
     self.assertEqual(8, lab_info.host_update_state_summary.restarting)
     self.assertEqual(5, lab_info.host_update_state_summary.errored)
     self.assertEqual(2, lab_info.host_update_state_summary.timed_out)
     self.assertEqual(1, lab_info.host_update_state_summary.succeeded)
     self.assertEqual(2, lab_info.host_update_state_summary.unknown)
Beispiel #3
0
 def testListLabs_keys(self):
     """Tests ListLabs's key."""
     lab_list = [
         datastore_test_util.CreateLabInfo('lab1'),
         datastore_test_util.CreateLabInfo('lab2'),
         datastore_test_util.CreateLabInfo('lab3')
     ]
     api_request = {'type': 'LAB'}
     api_response = self.testapp.post_json(
         '/_ah/api/FilterHintApi.ListFilterHints', api_request)
     lab_collection = protojson.decode_message(
         api_messages.FilterHintCollection, api_response.body)
     self.assertEqual('200 OK', api_response.status)
     self.assertEqual(3, len(lab_collection.filter_hints))
     labs = list(lab_collection.filter_hints)
     self.assertEqual(labs[0].value, lab_list[0].lab_name)
     self.assertEqual(labs[1].value, lab_list[1].lab_name)
     self.assertEqual(labs[2].value, lab_list[2].lab_name)
 def testGetLab_displayHostUpdateStateSummary(self):
     """Test GetLab returns host update state summary."""
     datastore_test_util.CreateLabInfo(
         'lab4',
         host_update_state_summary=datastore_entities.
         HostUpdateStateSummary(total=3, syncing=1, succeeded=2))
     api_request = {'lab_name': 'lab4'}
     api_response = self.testapp.post_json(
         '/_ah/api/LabManagementApi.GetLab', api_request)
     lab_info = protojson.decode_message(api_messages.LabInfo,
                                         api_response.body)
     self.assertEqual('200 OK', api_response.status)
     self.assertEqual('lab4', lab_info.lab_name)
     self.assertEqual(3, lab_info.host_update_state_summary.total)
     self.assertEqual(1, lab_info.host_update_state_summary.syncing)
     self.assertEqual(2, lab_info.host_update_state_summary.succeeded)
 def testGetLab_displayHostCountByHarnessVersion(self):
     """Test GetLab returns host count by harness version."""
     host_count_by_harness_version = {
         'version1': 12,
         'version2': 1,
         'version3': 668,
     }
     datastore_test_util.CreateLabInfo(
         'lab4',
         host_count_by_harness_version=host_count_by_harness_version)
     api_request = {'lab_name': 'lab4'}
     api_response = self.testapp.post_json(
         '/_ah/api/LabManagementApi.GetLab', api_request)
     lab_info = protojson.decode_message(api_messages.LabInfo,
                                         api_response.body)
     self.assertEqual('200 OK', api_response.status)
     self.assertEqual('lab4', lab_info.lab_name)
     expected_host_counts = [
         api_messages.KeyValuePair(key='version1', value='12'),
         api_messages.KeyValuePair(key='version2', value='1'),
         api_messages.KeyValuePair(key='version3', value='668'),
     ]
     self.assertCountEqual(expected_host_counts,
                           lab_info.host_count_by_harness_version)
 def setUp(self):
     super(DatastoreUtilTest, self).setUp()
     for i in range(10):
         datastore_test_util.CreateLabInfo('lab' + str(i))
 def testGetOrCreateDatastoreEntity_GetWithValidID(self):
     datastore_test_util.CreateLabInfo(lab_name='lab-name-100')
     lab_info_entity = datastore_util.GetOrCreateEntity(
         datastore_entities.LabInfo, entity_id='lab-name-100')
     self.assertEqual('lab-name-100', lab_info_entity.lab_name)