def test_resource_count_with_not_admin_project_and_existing_type(self): # Setup graph = self._create_graph() apis = ResourceApis(graph, None, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action resources = apis.count_resources( ctx, resource_type=NOVA_INSTANCE_DATASOURCE, all_tenants=False) resources = json.loads(resources) # Test assertions self.assertEqual(2, resources[NOVA_INSTANCE_DATASOURCE])
def test_resource_count_with_not_admin_project_and_no_existing_type(self): # Setup graph = self._create_graph() apis = ResourceApis(graph, None, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': False} # Action resources = apis.count_resources(ctx, resource_type=NOVA_HOST_DATASOURCE, all_tenants=False) resources = json.loads(resources) # Test assertions self.assertThat(resources.items(), matchers.HasLength(0))
def test_resource_count_with_all_tenants_and_group_by(self): # Setup graph = self._create_graph() apis = ResourceApis(graph, None, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action resources = apis.count_resources(ctx, resource_type=None, all_tenants=True, group_by=VProps.PROJECT_ID) resources = json.loads(resources) # Test assertions self.assertEqual(2, resources['project_1']) self.assertEqual(2, resources['project_2']) self.assertEqual(3, resources[''])
def test_resource_count_with_all_tenants(self): # Setup graph = self._create_graph() apis = ResourceApis(graph, None, self.api_lock) ctx = {'tenant': 'project_1', 'is_admin': False} # Action resources = apis.count_resources(ctx, resource_type=None, all_tenants=True) resources = json.loads(resources) # Test assertions self.assertEqual(4, resources[NOVA_INSTANCE_DATASOURCE]) self.assertEqual(1, resources[NOVA_ZONE_DATASOURCE]) self.assertEqual(1, resources[OPENSTACK_CLUSTER]) self.assertEqual(1, resources[NOVA_HOST_DATASOURCE])
def test_resource_count_with_admin_project_and_query(self): # Setup graph = self._create_graph() apis = ResourceApis(graph, None, self.api_lock) ctx = {'tenant': 'project_2', 'is_admin': True} # Action resources = apis.count_resources( ctx, resource_type=NOVA_INSTANCE_DATASOURCE, all_tenants=False, query={'==': { 'id': 'instance_3' }}) resources = json.loads(resources) # Test assertions self.assertEqual(1, resources[NOVA_INSTANCE_DATASOURCE])