From b869b46c6369274760086d900f071d8b1933bb97 Mon Sep 17 00:00:00 2001
From: Iury Gregory Melo Ferreira <imelofer@redhat.com>
Date: Wed, 20 Nov 2019 15:52:10 +0100
Subject: [PATCH] Drop python 2.7 support and testing

OpenStack is dropping the py2.7 support in ussuri cycle.

Ironic is ready with python 3 and ok to drop the
python 2.7 support.

Complete discussion & schedule can be found in
- http://lists.openstack.org/pipermail/openstack-discuss/2019-October/010142.html
- https://etherpad.openstack.org/p/drop-python2-support

Ussuri Communtiy-wide goal - https://review.opendev.org/#/c/691178/

Change-Id: I3cc36d79ffabf31607d503dada9e7512c639647c
---
 devstack/lib/ironic                           |  5 +----
 doc/requirements.txt                          |  1 -
 doc/source/contributor/jobs-description.rst   |  6 -----
 .../notes/drop-py-2-7-5140cb76e321cdd1.yaml   |  6 +++++
 setup.cfg                                     |  2 --
 tox.ini                                       | 22 ++-----------------
 zuul.d/ironic-jobs.yaml                       | 22 +------------------
 zuul.d/project.yaml                           |  5 -----
 8 files changed, 10 insertions(+), 59 deletions(-)
 create mode 100644 releasenotes/notes/drop-py-2-7-5140cb76e321cdd1.yaml

diff --git a/devstack/lib/ironic b/devstack/lib/ironic
index 1c810b7b31..a9e516fe7e 100644
--- a/devstack/lib/ironic
+++ b/devstack/lib/ironic
@@ -793,10 +793,7 @@ function install_virtualbmc {
         git_clone_by_name "virtualbmc"
         setup_dev_lib "virtualbmc"
     else
-        # pyghmi is still not compatible with python3
-        # hence we need to install virtualbmc in python2
-        # environment else IPMI calls will fail at the gate.
-        USE_PYTHON3=False pip_install_gr "virtualbmc"
+        pip_install_gr "virtualbmc"
     fi
 
     local cmd
diff --git a/doc/requirements.txt b/doc/requirements.txt
index 3786949d70..b25aba3fbf 100644
--- a/doc/requirements.txt
+++ b/doc/requirements.txt
@@ -2,7 +2,6 @@ mock>=3.0.0 # BSD
 openstackdocstheme>=1.20.0 # Apache-2.0
 os-api-ref>=1.4.0 # Apache-2.0
 reno>=2.5.0 # Apache-2.0
-sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7' # BSD
 sphinx!=1.6.6,!=1.6.7,!=2.1.0,>=1.6.2;python_version>='3.4' # BSD
 sphinxcontrib-apidoc>=0.2.0  # BSD
 sphinxcontrib-pecanwsme>=0.10.0 # Apache-2.0
diff --git a/doc/source/contributor/jobs-description.rst b/doc/source/contributor/jobs-description.rst
index 88b2aec51e..4f4bd44755 100644
--- a/doc/source/contributor/jobs-description.rst
+++ b/doc/source/contributor/jobs-description.rst
@@ -15,18 +15,12 @@ The description of each jobs that runs in the CI when you submit a patch for
 
    * - Job name
      - Description
-   * - ironic-tox-unit-with-driver-libs
-     - Runs Ironic unit tests with the driver dependencies installed under
-       Python2
    * - ironic-tox-unit-with-driver-libs-python3
      - Runs Ironic unit tests with the driver dependencies installed under
        Python3
    * - ironic-standalone
      - Deploys Ironic in standalone mode and runs tempest tests that match
        the regex `ironic_standalone`.
-   * - ironic-tempest-functional-python2
-     - Deploys Ironic in standalone mode and runs tempest functional tests
-       that matches the regex `ironic_tempest_plugin.tests.api` under Python2
    * - ironic-tempest-functional-python3
      - Deploys Ironic in standalone mode and runs tempest functional tests
        that matches the regex `ironic_tempest_plugin.tests.api` under Python3
diff --git a/releasenotes/notes/drop-py-2-7-5140cb76e321cdd1.yaml b/releasenotes/notes/drop-py-2-7-5140cb76e321cdd1.yaml
new file mode 100644
index 0000000000..8498e9ceee
--- /dev/null
+++ b/releasenotes/notes/drop-py-2-7-5140cb76e321cdd1.yaml
@@ -0,0 +1,6 @@
+---
+upgrade:
+  - |
+    Python 2.7 support has been dropped. Last release of Ironic
+    to support Python 2.7 is OpenStack Train. The minimum version of Python now
+    supported by Ironic is Python 3.6.
diff --git a/setup.cfg b/setup.cfg
index c993ab8faf..aeaac7e7c4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -13,8 +13,6 @@ classifier =
     License :: OSI Approved :: Apache Software License
     Operating System :: POSIX :: Linux
     Programming Language :: Python
-    Programming Language :: Python :: 2
-    Programming Language :: Python :: 2.7
     Programming Language :: Python :: 3
     Programming Language :: Python :: 3.6
     Programming Language :: Python :: 3.7
diff --git a/tox.ini b/tox.ini
index 2d430ad304..a55e4f9e47 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,11 +1,12 @@
 [tox]
 minversion = 2.0
 skipsdist = True
-envlist = py3,py27,pep8
+envlist = py3,pep8
 
 [testenv]
 usedevelop = True
 install_command = pip install -U {opts} {packages}
+basepython = python3
 setenv = VIRTUAL_ENV={envdir}
          PYTHONDONTWRITEBYTECODE = 1
          LANGUAGE=en_US
@@ -20,24 +21,16 @@ commands =
     stestr run {posargs}
 passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
 
-[testenv:unit-with-driver-libs]
-basepython = python2
-deps = {[testenv]deps}
-    -r{toxinidir}/driver-requirements.txt
-
 [testenv:unit-with-driver-libs-python3]
-basepython = python3
 deps = {[testenv]deps}
     -r{toxinidir}/driver-requirements.txt
 
 [testenv:genstates]
-basepython = python3
 deps = {[testenv]deps}
     pydot2
 commands = {toxinidir}/tools/states_to_dot.py -f {toxinidir}/doc/source/images/states.svg --format svg
 
 [testenv:pep8]
-basepython = python3
 whitelist_externals = bash
 commands =
   bash tools/flake8wrap.sh {posargs}
@@ -50,7 +43,6 @@ commands =
   {toxinidir}/tools/check-releasenotes.py
 
 [testenv:cover]
-basepython = python3
 setenv = VIRTUAL_ENV={envdir}
          LANGUAGE=en_US
          PYTHON=coverage run --source ironic --omit='*tests*' --parallel-mode
@@ -62,25 +54,21 @@ commands =
   coverage html -d ./cover --omit='*tests*'
 
 [testenv:genconfig]
-basepython = python3
 sitepackages = False
 envdir = {toxworkdir}/venv
 commands =
   oslo-config-generator --config-file=tools/config/ironic-config-generator.conf
 
 [testenv:genpolicy]
-basepython = python3
 sitepackages = False
 envdir = {toxworkdir}/venv
 commands =
   oslopolicy-sample-generator --config-file=tools/policy/ironic-policy-generator.conf
 
 [testenv:debug]
-basepython = python3
 commands = oslo_debug_helper -t ironic/tests/unit {posargs}
 
 [testenv:docs]
-basepython = python3
 deps =
   -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
   -r{toxinidir}/requirements.txt
@@ -89,7 +77,6 @@ deps =
 commands = sphinx-build -b html -W doc/source doc/build/html
 
 [testenv:pdf-docs]
-basepython = python3
 whitelist_externals = make
 deps = {[testenv:docs]deps}
 commands =
@@ -98,7 +85,6 @@ commands =
 
 
 [testenv:api-ref]
-basepython = python3
 deps =
   -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
   -r{toxinidir}/requirements.txt
@@ -109,7 +95,6 @@ commands =
   sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html
 
 [testenv:releasenotes]
-basepython = python3
 deps =
   -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
   -r{toxinidir}/requirements.txt
@@ -118,7 +103,6 @@ commands =
   sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
 
 [testenv:venv]
-basepython = python3
 setenv = PYTHONHASHSEED=0
 deps =
   -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
@@ -150,14 +134,12 @@ local-check-factory = ironic.hacking.checks.factory
 import_exceptions = testtools.matchers, ironic.common.i18n
 
 [testenv:lower-constraints]
-basepython = python3
 deps =
   -c{toxinidir}/lower-constraints.txt
   -r{toxinidir}/test-requirements.txt
   -r{toxinidir}/requirements.txt
 
 [testenv:bandit]
-basepython = python3
 deps = -r{toxinidir}/test-requirements.txt
 commands = bandit -r ironic -x tests -n5 -ll -c tools/bandit.yml
 
diff --git a/zuul.d/ironic-jobs.yaml b/zuul.d/ironic-jobs.yaml
index cb60a77081..7cb0ceae20 100644
--- a/zuul.d/ironic-jobs.yaml
+++ b/zuul.d/ironic-jobs.yaml
@@ -53,7 +53,6 @@
         Q_AGENT: openvswitch
         Q_ML2_TENANT_NETWORK_TYPE: vxlan
 
-        USE_PYTHON3: True
       devstack_plugins:
         ironic: https://opendev.org/openstack/ironic
       zuul_copy_output:
@@ -318,18 +317,10 @@
         neutron-metadata-agent: False
         neutron-metering: False
 
-- job:
-    name: ironic-tempest-functional-python2
-    description: ironic-tempest-functional-python2
-    parent: ironic-tempest-functional-python3
-    vars:
-      devstack_localrc:
-        USE_PYTHON3: False
-
 - job:
     name: ironic-tempest-ipa-wholedisk-direct-tinyipa-multinode
     description: ironic-tempest-ipa-wholedisk-direct-tinyipa-multinode
-    parent: tempest-multinode-full
+    parent: tempest-multinode-full-py3
     pre-run: playbooks/ci-workarounds/pre.yaml
     timeout: 10800
     required-projects:
@@ -408,7 +399,6 @@
         # ephemeral partition on such nodes
         LIBVIRT_STORAGE_POOL_PATH: /opt/libvirt/images
 
-        USE_PYTHON3: True
       devstack_plugins:
         ironic: https://opendev.org/openstack/ironic
         networking-generic-switch: https://opendev.org/openstack/networking-generic-switch
@@ -474,7 +464,6 @@
           Q_ML2_TENANT_NETWORK_TYPE: vlan
           VIRT_DRIVER: ironic
           PUBLIC_BRIDGE: br-infra
-          USE_PYTHON3: True
         devstack_services:
           c-api: False
           c-bak: False
@@ -485,14 +474,6 @@
           q-agt: True
           n-cpu: True
 
-- job:
-    name: ironic-tox-unit-with-driver-libs
-    parent: tox
-    description: |
-      Run unit tests with driver dependencies installed.
-    vars:
-      tox_envlist: unit-with-driver-libs
-
 - job:
     name: ironic-tox-unit-with-driver-libs-python3
     parent: tox
@@ -518,7 +499,6 @@
     parent: ironic-base
     vars:
       devstack_localrc:
-        USE_PYTHON3: True
         IRONIC_ENABLED_HARDWARE_TYPES: ipmi
         IRONIC_ENABLED_BOOT_INTERFACES: pxe
         IRONIC_VM_SPECS_RAM: 512
diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml
index 730f6f7511..831d325563 100644
--- a/zuul.d/project.yaml
+++ b/zuul.d/project.yaml
@@ -3,17 +3,14 @@
       - check-requirements
       - openstack-cover-jobs
       - openstack-lower-constraints-jobs
-      - openstack-python-jobs
       - openstack-python3-ussuri-jobs
       - periodic-stable-jobs
       - publish-openstack-docs-pti
       - release-notes-jobs-python3
     check:
       jobs:
-        - ironic-tox-unit-with-driver-libs
         - ironic-tox-unit-with-driver-libs-python3
         - ironic-standalone
-        - ironic-tempest-functional-python2
         - ironic-tempest-functional-python3
         - ironic-grenade-dsvm
         # Temporary disable voting because of end of cycle CI instability.
@@ -47,10 +44,8 @@
     gate:
       queue: ironic
       jobs:
-        - ironic-tox-unit-with-driver-libs
         - ironic-tox-unit-with-driver-libs-python3
         - ironic-standalone
-        - ironic-tempest-functional-python2
         - ironic-tempest-functional-python3
         - ironic-grenade-dsvm
         # removing from voting due to end of cycle gate instability.