Merge "[CVP] Fixed cleaning up cvp containers" into release/proposed/2019.2.0
diff --git a/src/com/mirantis/mk/Openstack.groovy b/src/com/mirantis/mk/Openstack.groovy
index b11f628..98df398 100644
--- a/src/com/mirantis/mk/Openstack.groovy
+++ b/src/com/mirantis/mk/Openstack.groovy
@@ -22,9 +22,9 @@
  * @param version     Version of the OpenStack clients
  */
 
-def setupOpenstackVirtualenv(path, version = 'latest') {
-    def python = new com.mirantis.mk.Python()
-    python.setupDocutilsVirtualenv(path)
+def setupOpenstackVirtualenv(path, version = 'latest', python="python2") {
+    def pythonLib = new com.mirantis.mk.Python()
+    pythonLib.setupDocutilsVirtualenv(path)
 
     def openstack_kilo_packages = [
         //XXX: hack to fix https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
@@ -41,7 +41,7 @@
         'oslo.i18n>=2.3.0,<2.4.0',
         'oslo.serialization>=1.8.0,<1.9.0',
         'oslo.utils>=1.4.0,<1.5.0',
-        'docutils'
+        'docutils==0.16'
     ]
 
     def openstack_latest_packages = [
@@ -54,9 +54,11 @@
         'cmd2<0.9.0;python_version=="2.7"',
         'cmd2>=0.9.1;python_version=="3.4"',
         'cmd2>=0.9.1;python_version=="3.5"',
-        'python-openstackclient',
-        'python-heatclient',
-        'docutils'
+        // NOTE: pin client packages to current latest to prevent
+        // downloading packages which are not support Python 2.7
+        'python-openstackclient==4.0.0',
+        'python-heatclient==1.18.0',
+        'docutils==0.16'
     ]
 
     if (version == 'kilo') {
@@ -68,7 +70,7 @@
     } else {
         requirements = openstack_latest_packages
     }
-    python.setupVirtualenv(path, 'python2', requirements, null, true)
+    pythonLib.setupVirtualenv(path, python, requirements, null, true)
 }
 
 /**
diff --git a/src/com/mirantis/mk/Python.groovy b/src/com/mirantis/mk/Python.groovy
index f009107..29288f9 100644
--- a/src/com/mirantis/mk/Python.groovy
+++ b/src/com/mirantis/mk/Python.groovy
@@ -32,17 +32,18 @@
     }
     common.infoMsg("[Python ${path}] Setup ${python} environment")
     sh(returnStdout: true, script: virtualenv_cmd)
-    if(!offlineDeployment){
-      try {
-          def pipPackage = 'pip'
-          if (python == 'python2') {
-              pipPackage = "\"pip<=19.3.1\""
-              common.infoMsg("Pinning pip package due to end of life of Python2 to ${pipPackage} version.")
-          }
-          runVirtualenvCommand(path, "pip install -U setuptools ${pipPackage}")
-      } catch(Exception e) {
-          common.warningMsg("Setuptools and pip cannot be updated, you might be offline but OFFLINE_DEPLOYMENT global property not initialized!")
-      }
+    if (!offlineDeployment) {
+        try {
+            def pipPackage = 'pip'
+            if (python == 'python2') {
+                pipPackage = "\"pip<=19.3.1\""
+                common.infoMsg("Pinning pip package due to end of life of Python2 to ${pipPackage} version.")
+            }
+            // NOTE(vsaienko): pin setuptools explicitly for latest version that works with python2
+            runVirtualenvCommand(path, "pip install -U \"setuptools<45.0.0\" ${pipPackage}")
+        } catch (Exception e) {
+            common.warningMsg("Setuptools and pip cannot be updated, you might be offline but OFFLINE_DEPLOYMENT global property not initialized!")
+        }
     }
     if (reqs_path==null) {
         def args = ""
@@ -87,11 +88,11 @@
  *
  * @param path        Path where virtualenv is created
  */
-def setupDocutilsVirtualenv(path) {
+def setupDocutilsVirtualenv(path, python="python2") {
     requirements = [
-      'docutils',
+      'docutils==0.16',
     ]
-    setupVirtualenv(path, 'python2', requirements)
+    setupVirtualenv(path, python, requirements)
 }
 
 
@@ -370,8 +371,8 @@
  */
 def setupJinjaVirtualenv(path) {
     requirements = [
-      'jinja2-cli',
-      'pyyaml',
+      'jinja2-cli==0.7.0',
+      'pyyaml==5.3',
     ]
     setupVirtualenv(path, 'python2', requirements)
 }