DevOps is a hot topic in software engineering these days, and Python is one of the
most popular programming languages in the world. What could be better than a
pithy book combining the two? Well, that is exactly what Moshe Zadka, a long-time
open-source contributor, has given us.
The first chapter of this book deals with installing Python.
It is a very detailed tutorial about different ways to install Python in different
operating systems. It describes the benefits and limitations of
each type of installation. The author also offers detailed instructions for
installing pyenv using shell commands.
This book is friendly to the new Python user, but the author does assume the
reader has fundamental knowledge of shell and git.
We also wonder if this section really has a place in the book--is someone who
doesn’t have Python installed going to pick up a book called DevOps in
Python?
This book’s packaging chapter is worth
reading even for people who don’t have a special interest in DevOps. It is very helpful
for setting up a valid, standard Python environment for projects. It gives a
systematic view of many useful features like virtual
environments and Tox. As developers who rely on
websites for much of our information, we think this book gave us a
better understanding of a lot of packages we have been using.
The interactive usage
chapter discusses the use of “Read-Eval-Print-Loop” (REPL) programming in
Python. This is interactive programming where a shell reads some typed in code,
evaluates that code, prints the result of the evaluation, and loops back to
read another piece of code.
As the author notes, “The faster the feedback
cycle, the faster we can deploy new tested solution.” And that is why interactive consoles are relevant to DevOps.
The section on “OS Automation” would be better named “How to Write Shell
Scripts in Python.” And there are reasons one might want to do so, for
instance, Python certainly has better and more varied control structures than
any shell we’ve used, and if your script needs to loop over a list of
dictionaries, you should certainly write it in Python.
The author notes that Python is not as good as shell languages at connecting
tools together in pipelines, but goes on to make the odd
remark, “those long pipelines of text transformers turn out to
be an artifact of shell limitations.” But these pipelines are not an “artifact”
of anything: no, they were a quite deliberate design decision by the early UNIX
developers.
Turning to testing, the author discusses testing strategies, with particular
emphasis on testing the code “used for automating systems.” As Zadka notes,
such code often suffers from a lack of proper testing compared to the
application code itself. This is unfortunate, because “testing is one of the
best ways to increase code quality.”
The brief chapter on text manipulation discusses useful Python text
processing capabilities, such as the built-in handling of JSON and CSV formats and
regular expressions. While all of this can be used in a DevOps setting, there
is nothing specifically “DevOpsy” about it.
The requests chapter deals with creating application programming interface (API) servers and handling calls to them.
There is a section on REST services, but it is not clear the author really
understands what distinguishes a RESTful service from one that is not REST, as
he doesn’t discuss making the server not store application state.
(Instead he talks about idempotence, which is a different concept.)
We were not aware of the Paramiko package for dealing with SSH through Python, so
including it was a nice discovery for us. But the author doesn’t make it
completely clear why one would use Paramiko to SSH rather than an OS shell.
Salt Stack and Ansible are “infrastructure-as-code” tools. They are included in
this book because Salt can be scripted in Python, while Ansible is
scriptable (for inventories) and extensible in Python.
In his chapter on Docker, Zadka introduces DockerPy, a library for interfacing
with Docker through Python. Although we have been working with Docker for
several years, we did not know about this facility, so this chapter was a great
find for us. When trying to automate the creation and deployment of Docker
containers, it seems likely--we haven’t had the chance to try it yet!--that DockerPy will be a major advance over the Docker CLI and shell scripts.
There is a similar package freely available for dealing with Amazon Web
Services, which also appears to be worth mastering.
There is a lot of useful information in this short book. The text could have
been cleaned up a bit more; however, if you are a Python user looking to get into
DevOps, it should prove very useful.