← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~chad.smith/cloud-init:ci-deps-fixes into cloud-init:master

 

Chad Smith has proposed merging ~chad.smith/cloud-init:ci-deps-fixes into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/325693

ci dependency installs: Add --test-distro param to read-dependencies to install deps

read-dependencies now takes --test-distro param to indicate we want to install all system package depenencies to allow for testing and building for our continous integration environment. It allows us to install all needed deps on a fresh system with python3 ./tools/read-depenencies --distro ubuntu --test-distro [--dry-run].

Additionally read-dependencies now looks at what version of python is running the script (py2 vs p3) and opts to install python 2 or 3 system deps respectively. This behavior can still be overridden with python3 ./tools/read-dependencies ... --python-version 2.



-- 
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:ci-deps-fixes into cloud-init:master.
diff --git a/Makefile b/Makefile
index c752530..3a69d87 100644
--- a/Makefile
+++ b/Makefile
@@ -54,12 +54,10 @@ unittest3: clean_pyc
 	nosetests3 $(noseopts) tests/unittests
 
 ci-deps-ubuntu:
-	@$(PYVER) $(CWD)/tools/read-dependencies --distro ubuntu --install --python-version 3
-	@$(PYVER) $(CWD)/tools/read-dependencies --distro ubuntu --requirements-file test-requirements.txt --install --python-version 3
+	@$(PYVER) $(CWD)/tools/read-dependencies --distro-ubuntu --ci-deps
 
 ci-deps-centos:
-	@$(PYVER) $(CWD)/tools/read-dependencies --distro centos --install
-	@$(PYVER) $(CWD)/tools/read-dependencies --distro centos --requirements-file test-requirements.txt --install
+	@$(PYVER) $(CWD)/tools/read-dependencies --distro centos --ci-deps
 
 pip-requirements:
 	@echo "Installing cloud-init dependencies..."
diff --git a/packages/bddeb b/packages/bddeb
index e45af6e..c7172d0 100755
--- a/packages/bddeb
+++ b/packages/bddeb
@@ -72,7 +72,9 @@ def write_debian_folder(root, templ_data, is_python2, cloud_util_deps):
     requires = ['cloud-utils | cloud-guest-utils'] if cloud_util_deps else []
     # We consolidate all deps as Build-Depends as our package build runs all
     # tests so we need all runtime dependencies anyway.
-    requires.extend(reqs + test_reqs + [python])
+    # NOTE: For some reason python package dependency can't be specified at the
+    # end of the dependency list. It results in pybuild errors.
+    requires.extend([python] + reqs + test_reqs)
     templater.render_to_file(util.abs_join(find_root(),
                                            'packages', 'debian', 'control.in'),
                              util.abs_join(deb_dir, 'control'),
diff --git a/tools/read-dependencies b/tools/read-dependencies
index 8a58534..ed41e84 100755
--- a/tools/read-dependencies
+++ b/tools/read-dependencies
@@ -40,8 +40,11 @@ DISTRO_INSTALL_PKG_CMD = {
 }
 
 
-# List of base system packages required to start using make
-EXTRA_SYSTEM_BASE_PKGS = ['make', 'sudo', 'tar']
+# List of base system packages required to enable ci automation
+CI_SYSTEM_BASE_PKGS = {
+    'common': ['make', 'sudo', 'tar'],
+    'ubuntu': ['devscripts'],
+    'debian': ['devscripts']}
 
 
 # JSON definition of distro-specific package dependencies
@@ -70,10 +73,16 @@ def get_parser():
         dest='install',
         help='When specified, install the required system packages.')
     parser.add_argument(
-        '-v', '--python-version', type=str, dest='python_version', default="2",
+        '-t', '--test-distro', action='store_true', default=False,
+        dest='test_distro',
+        help='Additionally install continuous integration system packages '
+             'required for build and test automation.')
+    parser.add_argument(
+        '-v', '--python-version', type=str, dest='python_version', default=None,
         choices=["2", "3"],
-        help='The version of python we want to generate system package '
-             'dependencies for.')
+        help='Override the version of python we want to generate system '
+             'package dependencies for. Defaults to the version of python '
+             'this script is called with')
     return parser
 
 
@@ -114,13 +123,17 @@ def parse_pip_requirements(requirements_path):
     return dep_names
 
 
-def translate_pip_to_system_pkg(pip_requires, renames, python_ver="2"):
+def translate_pip_to_system_pkg(pip_requires, renames, python_ver):
     """Translate pip package names to distro-specific package names.
 
     @param pip_requires: List of versionless pip package names to translate.
     @param renames: Dict containg special case renames from pip name to system
         package name for the distro.
+    @param python_ver: Optional python version string "2" or "3". When None,
+     use the python version that is calling this script via sys.version_info.
     """
+    if python_ver is None:
+        python_ver = str(sys.version_info[0])
     if python_ver == "2":
         prefix = "python-"
     else:
@@ -147,6 +160,11 @@ def main(distro):
     else:
         topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
 
+    if args.test_distro:
+        # Give us all the pretty deps in ci_deps install target
+        args.req_files = [os.path.join(topd, DEFAULT_REQUIREMENTS),
+                          os.path.join(topd, 'test-' + DEFAULT_REQUIREMENTS)]
+        args.install = True
     if args.req_files is None:
         args.req_files = [os.path.join(topd, DEFAULT_REQUIREMENTS)]
         if not os.path.isfile(args.req_files[0]):
@@ -179,16 +197,19 @@ def main(distro):
         else:
             all_deps = pip_pkg_names
     if args.install:
-        pkg_install(all_deps, args.distro, args.dry_run)
+        pkg_install(all_deps, args.distro, args.test_distro, args.dry_run)
     else:
         print('\n'.join(all_deps))
 
 
-def pkg_install(pkg_list, distro, dry_run=False):
+def pkg_install(pkg_list, distro, test_distro=False, dry_run=False):
     """Install a list of packages using the DISTRO_INSTALL_PKG_CMD."""
+    if test_distro:
+        pkg_list = list(pkg_list) + CI_SYSTEM_BASE_PKGS['common']
+        distro_base_pkgs = CI_SYSTEM_BASE_PKGS.get(distro, [])
+        pkg_list += distro_base_pkgs
     print('Installing deps: {0}{1}'.format(
           '(dryrun)' if dry_run else '', ' '.join(pkg_list)))
-    pkg_list = list(pkg_list) + EXTRA_SYSTEM_BASE_PKGS
     install_cmd = []
     if dry_run:
        install_cmd.append('echo')

Follow ups