I know this may sound outlandish, but this is for others that google this same problem along with their cd/dvd drive. This is how i found this post regarding this problem since i to ran into the same problem.
I recently purchased an IBM thinkpad T40 second hand. I ran into this same problem where the drive would keep ejecting itself. If the drive can be removeable try taking out the drive and blowing in it like you would any cartridge (nintendo style), also blow into the connectors that are on the laptop itself, and reinsert the drive into the laptop. you might see improvement. the problem might go away if you are lucky. Mine was doing this about 3 weeks into the purchase.
I recommend that you use compressed air instead of just blowing into the connectors too. A restart on the computer is needed if you decide to physically take out the drive while its running. I know I'm bumping a 2 year old thread but it could still apply to recently purchased laptops that are bought today and have the removable feature.