Make --buildbot mode require cgroup support.

Sampling the builders, this won't impact them.  It's primarily a
sanity check since we utilize cgroup code as a safety net to ensure
we don't leak processes.

This originally was at Icddb70257479aa18e83893e9865c1b8bfcb450a0;
it's being reuploaded since gerrit screwed up.  The CL was pushed
to a seperate testing branch to verify gerrit semantics; gerrit
closed the original CL however thinking it had landed.  Gerrit
doesn't check which branch a CL is open for when doing closing
for direct pushes.

BUG=chromium-os:26916
TEST=find a system w/out cgroups support, run:
     cbuildbot x86-generic-full --buildbot
     Barring that, modify CgroupsSupported to return False.

Change-Id: Ib8329517250f1e5d7bed81f5799bef14d30a26ad
Reviewed-on: https://gerrit.chromium.org/gerrit/17761
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Brian Harring <ferringb@chromium.org>
Commit-Ready: Brian Harring <ferringb@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index 2778423..66190aa 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -916,6 +916,13 @@
       parser.error('Reference path %s does not look to be the base of a '
                    'repo checkout; no .repo exists in the root.'
                    % (options.reference_repo,))
+  if options.buildbot:
+    if not options.cgroups:
+      parser.error('Options --buildbot and --nocgroups cannot be used '
+                   'together.  Cgroup support is required for buildbot mode.')
+    if not cgroups.Cgroup.CgroupsSupported():
+      parser.error('Option --buildbot was given, but this system does not '
+                   'support cgroups.   Failing.')
 
   if options.reference_repo:
     options.reference_repo = os.path.abspath(options.reference_repo)
@@ -930,12 +937,11 @@
   if not options.buildroot:
     if options.buildbot:
       parser.error('Please specify a buildroot with the --buildroot option.')
-    else:
-      options.buildroot = _DetermineDefaultBuildRoot(build_config['internal'])
-      # We use a marker file in the buildroot to indicate the user has
-      # consented to using this directory.
-      if not os.path.exists(repository.GetTrybotMarkerPath(options.buildroot)):
-        _ConfirmBuildRoot(options.buildroot)
+    options.buildroot = _DetermineDefaultBuildRoot(build_config['internal'])
+    # We use a marker file in the buildroot to indicate the user has
+    # consented to using this directory.
+    if not os.path.exists(repository.GetTrybotMarkerPath(options.buildroot)):
+      _ConfirmBuildRoot(options.buildroot)
 
   # Sanity check of buildroot- specifically that it's not pointing into the
   # midst of an existing repo since git-repo doesn't support nesting.