Use py3 for latest setupOpenstackVirtualenv

PROD-00000

Change-Id: Iac73eac2ac627f0405bc20c9ca708045e6bcafd8
diff --git a/src/com/mirantis/mk/Openstack.groovy b/src/com/mirantis/mk/Openstack.groovy
index 9fa683f..7a45dbe 100644
--- a/src/com/mirantis/mk/Openstack.groovy
+++ b/src/com/mirantis/mk/Openstack.groovy
@@ -18,62 +18,79 @@
 /**
  * Install OpenStack service clients in isolated environment
  *
- * @param path        Path where virtualenv is created
- * @param version     Version of the OpenStack clients
+ * @param path Path where virtualenv is created
+ * @param version Version of the OpenStack clients
  */
 
 def setupOpenstackVirtualenv(path, version = 'latest') {
+    setupOpenstackVirtualenv(['path': path, 'version': version])
+}
+
+/**
+ * Install OpenStack service clients in isolated environment
+ *
+ * @param config : Config map with opts:
+ *        path Path where virtualenv is created
+ *        version Version of the OpenStack clients
+ *        pyversion Version of the Python exec.
+ *        requirements list of additional pip packages to be installed
+ *
+ */
+
+def setupOpenstackVirtualenv(LinkedHashMap config) {
     def python = new com.mirantis.mk.Python()
-    python.setupDocutilsVirtualenv(path)
 
-    def openstack_kilo_packages = [
-        //XXX: hack to fix https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
-        'cliff==2.8',
-        'python-cinderclient>=1.3.1,<1.4.0',
-        'python-glanceclient>=0.19.0,<0.20.0',
-        'python-heatclient>=0.6.0,<0.7.0',
-        'python-keystoneclient>=1.6.0,<1.7.0',
-        'python-neutronclient>=2.2.6,<2.3.0',
-        'python-novaclient>=2.19.0,<2.20.0',
-        'python-swiftclient>=2.5.0,<2.6.0',
-        'python-openstackclient>=1.7.0,<1.8.0',
-        'oslo.config>=2.2.0,<2.3.0',
-        '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'
-    ]
+    def path = config.path
+    def version = config.get('version', 'latest')
+    def pyversion = config.get('pyversion', 'python2')
+    def requirements = config.get('requirements', [])
+    def os_requirements = []
 
-    def openstack_latest_packages = [
-        //XXX: hack to fix https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
-        'cliff==2.8',
-        // NOTE(vsaienko): cmd2 is dependency for cliff, since we don't using upper-contstraints
-        // we have to pin cmd2 < 0.9.0 as later versions are not compatible with python2.
-        // the same for warlock package due: https://github.com/bcwaldon/warlock/commit/4241a7a9fbccfce7eb3298c2abdf00ca2dede64a
-        // TODO(vsaienko): use upper-constraints here, as in requirements we set only lowest library
-        //                 versions.
-        'cmd2<0.9.0;python_version=="2.7"',
-        'cmd2>=0.9.1;python_version=="3.4"',
-        'cmd2>=0.9.1;python_version=="3.5"',
-        'warlock<=1.3.1;python_version=="2.7"',
-        'warlock>1.3.1;python_version=="3.4"',
-        'warlock>1.3.1;python_version=="3.5"',
-        'python-openstackclient',
-        'python-octaviaclient',
-        'python-heatclient',
-        'docutils'
-    ]
 
-    if (version == 'kilo') {
-        requirements = openstack_kilo_packages
-    } else if (version == 'liberty') {
-        requirements = openstack_kilo_packages
-    } else if (version == 'mitaka') {
-        requirements = openstack_kilo_packages
+    if (version in ['kilo', 'liberty', 'mitaka']) {
+        os_requirements = [
+            //XXX: hack to fix https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
+            'cliff==2.8',
+            'python-cinderclient>=1.3.1,<1.4.0',
+            'python-glanceclient>=0.19.0,<0.20.0',
+            'python-heatclient>=0.6.0,<0.7.0',
+            'python-keystoneclient>=1.6.0,<1.7.0',
+            'python-neutronclient>=2.2.6,<2.3.0',
+            'python-novaclient>=2.19.0,<2.20.0',
+            'python-swiftclient>=2.5.0,<2.6.0',
+            'python-openstackclient>=1.7.0,<1.8.0',
+            'oslo.config>=2.2.0,<2.3.0',
+            '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'
+        ]
     } else {
-        requirements = openstack_latest_packages
+        pyversion = 'python3'
+        os_requirements = [
+            //XXX: hack to fix https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
+            'cliff==2.8',
+            // NOTE(vsaienko): cmd2 is dependency for cliff, since we don't using upper-contstraints
+            // we have to pin cmd2 < 0.9.0 as later versions are not compatible with python2.
+            // the same for warlock package due: https://github.com/bcwaldon/warlock/commit/4241a7a9fbccfce7eb3298c2abdf00ca2dede64a
+            // TODO(vsaienko): use upper-constraints here, as in requirements we set only lowest library
+            //                 versions.
+            'cmd2<0.9.0;python_version=="2.7"',
+            'cmd2>=0.9.1;python_version=="3.4"',
+            'cmd2>=0.9.1;python_version=="3.5"',
+            'warlock<=1.3.1;python_version=="2.7"',
+            'warlock>1.3.1;python_version=="3.4"',
+            'warlock>1.3.1;python_version=="3.5"',
+            'python-openstackclient',
+            'python-octaviaclient',
+            'python-heatclient',
+            'docutils'
+        ]
     }
-    python.setupVirtualenv(path, 'python2', requirements, null, true)
+    requirements = requirements + os_requirements
+    // (alexz): could we install docutils at single stage?
+    python.setupVirtualenv(path, pyversion, ['docutils'], null, true)
+    python.setupVirtualenv(path, pyversion, requirements.unique(), null, true)
 }
 
 /**