Your 2009 MacBook Pro can only upgrade as far as Mac OS X El Capitan 10.11.6.
It cannot upgrade to Sierra or any other newer OS's. And Leopard is a very old OS,
its numerical identifier was 10.5 which is six versions of OS before El Capitan 10.11.
To upgrade to El Capitan follow the instructions below.
How to get old versions of macOS – Apple Support
Go to Download OS and click on OS X El Capitan 10.11
this downloads InstallMacOSX.dmg to your Downloads folder.
The next section can only be done on a mac that is capable of running El Capitan,
a mac that came preinstalled with an OS later than El Capitan will refuse to do the next bit.
When downloaded open to InstallMacOSX.pkg, double-click on
that and an installation window will open, this does not install El Capitan
but converts the InstallMacOSX.pkg to the Install OS X El Capitan.app which
you will find in your Applications folder, it should be 6.2GBs in size.
(If the installation window asks which disk you want to install to, you must pick
the disk that you are booted to at the time. Not any internal or external disk that
you want to eventually install El Capitan on, that is for later.)
To start the installation of El Capitan double click on the Install OS X El Capitan.app.
The copy of the install app self deletes after installing El Capitan, so make sure you keep a copy of the
InstallMacOSX.dmg if you need it in future, or you could just make a copy of the Install OS X El Capitan.app
prior to installing and moving it to an external drive for safe keeping.
It is also possible to create a bootable USB installer disk using the Install OS X El Capitan.app in the Applications
folder and the createinstallmedia command in the Terminal app.
Read the instructions here,
How to create a bootable installer for macOS – Apple Support
Simply installing El Capitan over your install of Yosemite is fine and will not overwrite or
erase any of your data.
But it is recommended to always make a full backup of your mac before upgrading.
Also check that any third party apps you use in Yosemite are compatible with El Capitan,
use this app, https://roaringapps.com/apps. Use the Options button to select/ deselect
the OS's you want to compare, and enter the apps name in the Search field.