def test_search_for_hosts_by_composed_queries(self): """Create one host and test composed queries.""" db_api.host_create(_get_fake_host_values(mem=8192)) self.assertEqual( 1, len( db_api.host_get_all_by_queries( ['memory_mb > 2048', 'cpu_info like %Westmere%']))) self.assertEqual( 0, len( db_api.host_get_all_by_queries( ['memory_mb < 2048', 'cpu_info like %Westmere%']))) self.assertRaises(db_exceptions.BlazarDBInvalidFilter, db_api.host_get_all_by_queries, ['memory_mb <']) self.assertRaises(db_exceptions.BlazarDBNotFound, db_api.host_get_all_by_queries, ['apples < 2048']) self.assertRaises(db_exceptions.BlazarDBInvalidFilterOperator, db_api.host_get_all_by_queries, ['memory_mb wrongop 2048']) self.assertEqual( 1, len(db_api.host_get_all_by_queries(['memory_mb in 4096,8192']))) self.assertEqual( 1, len(db_api.host_get_all_by_queries(['memory_mb != null'])))
def test_search_for_hosts_by_extra_capability(self): """Create one host and test extra capability queries.""" # We create a first host, with extra capabilities db_api.host_create(_get_fake_host_values(id=1)) db_api.host_extra_capability_create( _get_fake_host_extra_capabilities(computehost_id=1)) db_api.host_extra_capability_create( _get_fake_host_extra_capabilities( computehost_id=1, name='nic_model', value='ACME Model A', )) # We create a second host, without any extra capabilities db_api.host_create(_get_fake_host_values(id=2)) self.assertEqual(1, len(db_api.host_get_all_by_queries(['vgpu == 2']))) self.assertEqual(0, len(db_api.host_get_all_by_queries(['vgpu != 2']))) self.assertEqual( 1, len( db_api.host_get_all_by_queries( ['cpu_info like %Westmere%', 'vgpu == 2']))) self.assertEqual( 0, len( db_api.host_get_all_by_queries( ['cpu_info like %wrongcpu%', 'vgpu == 2']))) self.assertRaises(db_exceptions.BlazarDBNotFound, db_api.host_get_all_by_queries, ['apples < 2048']) self.assertEqual( 1, len(db_api.host_get_all_by_queries(['nic_model == ACME Model A'])))
def test_search_for_hosts_by_cpu_info(self): """Create one host and search within cpu_info.""" db_api.host_create(_get_fake_host_values()) self.assertEqual( 1, len(db_api.host_get_all_by_queries(['cpu_info like %Westmere%'])))
def test_search_for_hosts_by_ram(self): """Check RAM info search Create two hosts and check that we can find a host per its RAM info. """ db_api.host_create(_get_fake_host_values(id=1, mem=2048)) db_api.host_create(_get_fake_host_values(id=2, mem=4096)) self.assertEqual( 2, len(db_api.host_get_all_by_queries(['memory_mb >= 2048']))) self.assertEqual( 0, len(db_api.host_get_all_by_queries(['memory_mb lt 2048'])))
def test_delete_host(self): db_api.host_create(_get_fake_host_values(id=1)) db_api.host_destroy(1) self.assertIsNone(db_api.host_get(1)) self.assertRaises(db_exceptions.BlazarDBNotFound, db_api.host_destroy, 2)
def test_update_host(self): db_api.host_create(_get_fake_host_values(id=1)) db_api.host_update(1, {'status': 'updated'}) self.assertEqual('updated', db_api.host_get(1)['status'])
def test_get_hosts_per_filter(self): db_api.host_create(_get_fake_host_values(id=1)) db_api.host_create(_get_fake_host_values(id=2)) filters = {'status': 'free'} self.assertEqual(2, len(db_api.host_get_all_by_filters(filters)))
def test_list_hosts(self): db_api.host_create(_get_fake_host_values(id=1)) db_api.host_create(_get_fake_host_values(id=2)) self.assertEqual(2, len(db_api.host_list()))
def test_create_duplicated_host(self): """Create a duplicated host and verify that an exception is raised.""" db_api.host_create(_get_fake_host_values(id='1')) # Making sure we still raise a DuplicateDBEntry self.assertRaises(db_exceptions.BlazarDBDuplicateEntry, db_api.host_create, _get_fake_host_values(id='1'))
def test_create_host(self): """Create a host and verify that all tables have been populated.""" result = db_api.host_create(_get_fake_host_values(id='1')) self.assertEqual(result['id'], _get_fake_host_values(id='1')['id'])