def test_get_container_list_with_filters(self): container1 = utils.create_test_container( name='container-one', uuid=magnum_utils.generate_uuid(), bay_uuid=magnum_utils.generate_uuid()) container2 = utils.create_test_container( name='container-two', uuid=magnum_utils.generate_uuid(), bay_uuid=magnum_utils.generate_uuid()) res = self.dbapi.get_container_list(self.context, filters={'name': 'container-one'}) self.assertEqual([container1.id], [r.id for r in res]) res = self.dbapi.get_container_list(self.context, filters={'name': 'container-two'}) self.assertEqual([container2.id], [r.id for r in res]) res = self.dbapi.get_container_list(self.context, filters={'name': 'bad-container'}) self.assertEqual([], [r.id for r in res]) res = self.dbapi.get_container_list( self.context, filters={'bay_uuid': container1.bay_uuid}) self.assertEqual([container1.id], [r.id for r in res])
def test_detail_containers_with_pagination_marker(self, mock_container_list, mock_container_show): container_list = [] for id_ in range(4): test_container = utils.create_test_container( id=id_, uuid=comm_utils.generate_uuid()) container_list.append(objects.Container(self.context, **test_container)) mock_container_list.return_value = container_list[-1:] mock_container_show.return_value = container_list[-1] response = self.app.get('/v1/containers/detail?limit=3&marker=%s' % container_list[2].uuid) self.assertEqual(200, response.status_int) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) self.assertEqual(container_list[-1].uuid, actual_containers[0].get('uuid')) self.assertIn('name', actual_containers[0]) self.assertIn('bay_uuid', actual_containers[0]) self.assertIn('status', actual_containers[0]) self.assertIn('image', actual_containers[0]) self.assertIn('command', actual_containers[0]) self.assertIn('memory', actual_containers[0]) self.assertIn('environment', actual_containers[0])
def test_update_container(self): container = utils.create_test_container() old_image = container.image new_image = 'new-image' self.assertNotEqual(old_image, new_image) res = self.dbapi.update_container(container.id, {'image': new_image}) self.assertEqual(new_image, res.image)
def test_destroy_bay_that_has_containers_by_uuid(self): bay = utils.create_test_bay() container = utils.create_test_container(bay_uuid=bay.uuid) self.assertEqual(bay.uuid, container.bay_uuid) self.dbapi.destroy_bay(bay.uuid) self.assertRaises(exception.ContainerNotFound, self.dbapi.get_container_by_id, self.context, container.id)
def test_get_container_list(self): uuids = [] for i in range(1, 6): container = utils.create_test_container( uuid=magnum_utils.generate_uuid()) uuids.append(six.text_type(container['uuid'])) res = self.dbapi.get_container_list(self.context) res_uuids = [r.uuid for r in res] self.assertEqual(sorted(uuids), sorted(res_uuids))
def test_get_container_list_sorted(self): uuids = [] for _ in range(5): container = utils.create_test_container( uuid=magnum_utils.generate_uuid()) uuids.append(six.text_type(container.uuid)) res = self.dbapi.get_container_list(self.context, sort_key='uuid') res_uuids = [r.uuid for r in res] self.assertEqual(sorted(uuids), res_uuids) self.assertRaises(exception.InvalidParameterValue, self.dbapi.get_container_list, self.context, sort_key='foo')
def test_get_all_containers_with_pagination_marker(self, mock_container_list, mock_container_show): container_list = [] for id_ in range(4): test_container = utils.create_test_container( id=id_, uuid=comm_utils.generate_uuid()) container_list.append(objects.Container(self.context, **test_container)) mock_container_list.return_value = container_list[-1:] mock_container_show.return_value = container_list[-1] response = self.app.get('/v1/containers?limit=3&marker=%s' % container_list[2].uuid) self.assertEqual(response.status_int, 200) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) self.assertEqual(container_list[-1].uuid, actual_containers[0].get('uuid'))
def test_get_all_containers_with_pagination_marker(self, mock_container_list, mock_container_show): container_list = [] for id_ in range(4): test_container = utils.create_test_container( id=id_, uuid=comm_utils.generate_uuid()) container_list.append( objects.Container(self.context, **test_container)) mock_container_list.return_value = container_list[-1:] mock_container_show.return_value = container_list[-1] response = self.app.get('/v1/containers?limit=3&marker=%s' % container_list[2].uuid) self.assertEqual(response.status_int, 200) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) self.assertEqual(container_list[-1].uuid, actual_containers[0].get('uuid'))
def test_get_container_by_name(self): container = utils.create_test_container() res = self.dbapi.get_container_by_name(self.context, container.name) self.assertEqual(container.id, res.id) self.assertEqual(container.uuid, res.uuid)
def test_create_container_already_exists(self): utils.create_test_container() self.assertRaises(exception.ContainerAlreadyExists, utils.create_test_container)
def test_update_container_uuid(self): container = utils.create_test_container() self.assertRaises(exception.InvalidParameterValue, self.dbapi.update_container, container.id, {'uuid': ''})
def test_destroy_container_by_uuid(self): container = utils.create_test_container() self.dbapi.destroy_container(container.uuid) self.assertRaises(exception.ContainerNotFound, self.dbapi.get_container_by_uuid, self.context, container.uuid)
def test_create_container(self): utils.create_test_container()