How the Python 3 upgrade happened remotely to all those Ubuntu devices

Chamara Madhushan Liyanage
3 min readMar 22, 2020

--

Please read these articles before starting Article 1, Article 2

As I mentioned earlier this Python agent needs its own environment to run and there’s no way of running the agent software in local development environments or in servers.

In making the Python 3 agent ready for deployment few decisions had to be made.

  1. Creating a virtual environment for the agent and isolate it from the global environment
  2. Remote upgrading mechanisms for all the 10,000+ devices.

Creating a virtual environment for the agent

The agent is running in heterogeneous environments (Ubuntu 14.04 and Ubuntu 18.04). The main challenge was that in Ubuntu 14.04 the default Python 3 version is Python 3.4 again which was deprecated. (This is another issue faced during the migration project and I’m not going to explain how I tackled the problem in this article since it over-complicate the flow). Let’s only focus on how the virtual environments were created in Ubuntu 18.04 remote devices.

The previous agent which ran on Python 2 used the global scope of the OS and we decided not to spoil the global OS environment with Python 3 migration. So we planned to install this agent in the virtual environment and utilize this isolated environment for its purposes.

These devices which I’m not going to share many details about are going to get upgrades using a similar mechanism like Debian OS upgrade that is using a Debian file. Creating a Debian file is out of scope in this article I’ll create a separate article on this.

Think a Debian file as some executable file like (.exe file in Windows, you can install things using that file in your OS). There were 2 Debian files created for this migration. I’ll name these files as Debian 1 and Debian 2 for simplicity.

Debian 1 — It’s basically to install all the pre-requisites needed by Python 3 agents.

It does the following tasks during the installation.

  • Installing pip3 (since Ubuntu does not ship with pip3 by default)
  • Creating a virtual environment for the new agent software
  • Installing dependencies needed by the agent. (There are about 10+ python libraries needed by this agent and those are installed using pip3 in the virtual environment)

Note → During this Debian 1 installation the current Python 2 agent is not hindered in production and it runs in the background.

Debian 2 — It’s the new Python 3 agent software.

This Debian does the following tasks upon its installation.

  • First, it stops the current Python 2 agent (not the production Device just the service of the agent)
  • Change some configuration files ( like upstart/systemd service files)
  • Uninstalls the old deprecated Python 2 agent
  • Installs the new Python 3 agent which is packed in the Debian 2 in the new virtual environment created during the Debian 1 installation.
  • Starts the new Python 3 agent software.

Note → This whole process takes less than 5 seconds and downtime is minimal. (One of the reasons to send 2 Debians in 2 OS upgrades make this minimal downtime achievable)

--

--