Heat the olive oil in a large frying pan over medium heat and fry the onion until tender. Add the pasta sauce, black beans, kidney beans and corn, and mix well. Stir in the cumin, hot pepper sauce, salt and pepper. Simmer for 15 to 20 minutes.
Meanwhile, cook spaghetti in a large pot of boiling salted water until al dente. Drain.
Return spaghetti to pot, add sauce and toss. Serve with grated parmesan cheese.