def test_update_eon_with_stats(self, *_): # example of what comes back from eon compute_list = [ { "cluster_moid": "domain-c84", "id": "ebe3e327-1e02-4feb-bfed-7eaa410bb5c9", "ip_address": "UNSET", "meta_data": [ { "id": "311c3abc-15c6-4156-bf61-38ea304e8675", "name": "hypervisor_id", "value": "1" }, { "id": "7063a114-469f-4591-8315-e042801235ca", "name": "network_properties", "value": "network_properties_blah" }, { "id": "7173ccad-c4c7-4b76-b1e9-91b6da330af6", "name": "cluster_moid", "value": "domain-c3135" }, { "id": "ca70eaac-8bd9-411d-9c98-d90d7812b5a1", "name": "ardana_properties", "value": "ardana_properties_blah" } ], "hypervisor_hostname": "domain-c84.68bb08ca-07ed-4b9d-835f-1815a5f15a85", "name": "Compute-08A", "password": "******", "port": "UNSET", "region": "my_region", "resource_mgr_id": "68bb08ca-07ed-4b9d-835f-1815a5f15a85", "state": "activated", "type": "esxcluster", "username": "******" } ] request = { api.TARGET: 'compute', api.ACTION: 'GET', api.AUTH_TOKEN: 'blah', api.DATA: { api.OPERATION: 'get_compute_list' } } svc = compute_service.ComputeSvc(bll_request=BllRequest(request)) svc._filter_eon_compute_node = mock.Mock(return_value=compute_list) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS]) self.assertFalse('meta_data' in reply[api.DATA][0]) self.assertEquals(reply[api.DATA][0]['network_properties'], 'network_properties_blah') self.assertEquals(reply[api.DATA][0]['ping_status'], 'up')
def test_get(self, *_): svc = compute_service.ComputeSvc(BllRequest( action='GET', operation='get_compute_list', auth_token=get_mock_token())) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS]) self.assertEqual(1, len(reply['data']))
def test_get_non_eon_details(self, *_): svc = compute_service.ComputeSvc(BllRequest( auth_token=get_mock_token(), operation='details', region='region1', data={ 'data': { 'id': '1', 'type': 'kvm' } })) reply = svc.handle() self.assertEqual(reply['data']['ardana']['server-group'], 'some_group') self.assertEqual(reply['data']['monasca']['used_cpu_perc'], 123) self.assertEqual(reply['data']['instances'], 2) self.assertEqual(reply[api.STATUS], api.COMPLETE)
def test_get_compute_details(self, a): request = { api.TARGET: 'compute', api.ACTION: 'GET', api.AUTH_TOKEN: get_mock_token(), api.DATA: { api.OPERATION: 'get_compute_list', api.VERSION: 'v1', api.DATA: { "id": "e90f7f6f-c75f-4830-8f47-e0af2851b132", "hypervisor": "esxcluster", "hypervisor_id": "1" } } } svc = compute_service.ComputeSvc(bll_request=BllRequest(request)) svc.call_service = mock.Mock(return_value=[]) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS])
def test_get_resource_details(self, *_): request = { api.TARGET: 'compute', api.ACTION: 'GET', api.AUTH_TOKEN: get_mock_token(), api.DATA: { api.OPERATION: 'details', api.VERSION: 'v1', api.DATA: { "id": "e90f7f6f-c75f-4830-8f47-e0af2851b132", "type": "esxcluster" } } } svc = compute_service.ComputeSvc(bll_request=BllRequest(request)) # Mock out invocations of call_service svc.call_service = mock.MagicMock() reply = svc.handle() self.assertEqual(reply[api.STATUS], api.COMPLETE)
def test_get_cluster_utilization(self, *_): request = { api.TARGET: 'compute', api.ACTION: 'GET', api.AUTH_TOKEN: get_mock_token(), api.DATA: { api.OPERATION: 'get_cluster_utilization' } } svc = compute_service.ComputeSvc(bll_request=BllRequest(request)) reply = svc.handle() self.assertEqual(api.COMPLETE, reply[api.STATUS]) data = reply[api.DATA] self.assertTrue('ccp:compute' in data) # 3 hosts self.assertEqual(len(data['ccp:compute']), 3) self.assertTrue('host1' in data['ccp:compute']) self.assertTrue('used_memory_perc' in data['ccp:compute']['host1']) self.assertTrue('used_storage_perc' in data['ccp:compute']['host1']) self.assertTrue('used_cpu_perc' in data['ccp:compute']['host1'])