Grokking OpenStack

OpenStack - little pieces

Stepping Through Authenticate()

Armed with the investigative abilities of the debugger, I now can do a little spelunking.

While playing with the debugger set-up in my previous post, I saw that it took me through authenticate() in a rather tidy fashion so I thought I would spend a little time here.

I won’t walk through the entire function, just the first part. We will be looking at the consequences of stepping through parts of the code below. This is from novaclient/client.py:

With the help of the debugger I will be looking at the values of the various arguments and variables both before and after they are defined, and in the case of key and index as their value changes.

So the debugger heads into authenticate(). Before the first line (#301) is executed, I check the values of self and self.authenticate().

Then I check the value of has_keyring: before line #302 runs.

Lines #303 - #305 take a list of values and assigns them to the variable keys. I check the value of keys, which I learn is undefined before the code runs (makes sense) and also the individual values of all the attributes in the list.

After lines #303 - #305 have run, I check the value of keys.

Next we move into lines #306 and #307 which run in a loop 4 times before breaking out to execute line #308. I check the value of key and index during the process. These variables begin as undefined and then their value changes as the code runs through the for loop.

Then back into lines #306 and #307 3 more times before breaking out to execute line #308.

Then we loop through lines #306 - #308 one last time.

We go back up to line #306 but we have enumerated over every element in the list, so then we execute lines #309 and #310, checking the values of the variables as we go.

We have come to the last line of code in this examination, line #325. We check the values before it is executed and after execution it takes us into the function urlsplit() in the python library urlparse.py.

I hope that stepping through the authenticate function with me has been useful for you. I learned a lot creating this post. For learning a code base, I feel that using a debugger can be a very powerful tool.

We didn’t go through the entire authenticate function, but the part that we did takes the various attributes of the HTTPClient object and creates a url to be parsed. I found the investigation rather fun.

Thanks for supporting this GNOME OPW intern,
Anita Kuno.

Comments