Description: Cherry-pick upstream fixes for python module (staging branch)

Cherry-pick a few fixes from the staging branch:
 - PEP-8 syntax fix.
 - Raise an exception when getting a Container instance as non-root.
 - Make wait() convert any passed state string to its uppercase equivalent.

Index: ubuntu-lxc-bzr/src/python-lxc/lxc/__init__.py
===================================================================
--- ubuntu-lxc-bzr.orig/src/python-lxc/lxc/__init__.py	2012-09-13 10:20:15.459137148 -0400
+++ ubuntu-lxc-bzr/src/python-lxc/lxc/__init__.py	2012-09-13 10:20:15.583137143 -0400
@@ -32,6 +32,7 @@
 warnings.warn("The python-lxc API isn't yet stable "
               "and may change at any point in the future.", Warning, 2)
 
+
 class ContainerNetwork():
     props = {}
 
@@ -142,6 +143,9 @@
             Creates a new Container instance.
         """
 
+        if os.geteuid() != 0:
+            raise Exception("Running as non-root.")
+
         _lxc.Container.__init__(self, name)
         self.network = ContainerNetworkList(self)
 
@@ -358,6 +362,15 @@
             self.clear_config_item(key)
             return False
 
+    def wait(self, state, timeout = -1):
+        """
+            Wait for the container to reach a given state or timeout.
+        """
+
+        if isinstance(state, str):
+            state = state.upper()
+
+        return _lxc.Container.wait(self, state, timeout)
 
 def list_containers(as_object=False):
     """
Index: ubuntu-lxc-bzr/src/python-lxc/test.py
===================================================================
--- ubuntu-lxc-bzr.orig/src/python-lxc/test.py	2012-09-13 10:24:54.319126672 -0400
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,28 +0,0 @@
-import lxc
-
-t1 = lxc.Container("test")
-print("Name set properly: %s" % (t1.name == "test"))
-print("Test config loaded properly: %s" % t1.load_config("/etc/lxc/lxc.conf"))
-print("Real config loaded properly: %s" % t1.load_config())
-print("Test config path: %s" % (t1.config_file_name == "/var/lib/lxc/test/config"))
-print("Set config item: %s" % t1.set_config_item("lxc.utsname", "blabla"))
-print("Container defined: %s" % (t1.defined))
-print("Started properly: %s" % t1.start())
-print("Container running: %s" % t1.wait("RUNNING"))
-print("Container state: %s" % t1.state)
-print("Container running: %s" % t1.running)
-print("Container init process: %s" % t1.init_pid)
-print("Freezing: %s" % t1.freeze())
-print("Container frozen: %s" % t1.wait("FROZEN"))
-print("Container state: %s" % t1.state)
-print("Unfreezing: %s" % t1.unfreeze())
-print("Container running: %s" % t1.wait("RUNNING"))
-print("Container state: %s" % t1.state)
-print("Stopped properly: %s" % t1.stop())
-print("Container state: %s" % t1.state)
-
-#print("Started properly: %s" % t1.start(useinit=True))
-#print("Container running: %s" % t1.wait("RUNNING"))
-#print("Container state: %s" % t1.state)
-#print("Stopped properly: %s" % t1.stop())
-#print("Container state: %s" % t1.state)
Index: ubuntu-lxc-bzr/src/python-lxc/examples/api_test.py
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ubuntu-lxc-bzr/src/python-lxc/examples/api_test.py	2012-09-13 10:35:10.649816049 -0400
@@ -0,0 +1,151 @@
+#!/usr/bin/python3
+#
+# api_test.py: Test/demo of the python3-lxc API
+#
+# (C) Copyright Canonical Ltd. 2012
+#
+# Authors:
+# Stéphane Graber <stgraber@ubuntu.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import warnings
+warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")
+
+import lxc
+import uuid
+import sys
+
+# Some constants
+LXC_PATH_LIB = "/var/lib/lxc"
+LXC_TEMPLATE = "ubuntu"
+
+# Let's pick a random name, avoiding clashes
+CONTAINER_NAME = str(uuid.uuid1())
+CLONE_NAME = str(uuid.uuid1())
+
+## Instantiate the container instance
+print("Getting instance for '%s'" % CONTAINER_NAME)
+container = lxc.Container(CONTAINER_NAME)
+
+# A few basic checks of the current state
+assert(container.config_file_name == "%s/%s/config" %
+            (LXC_PATH_LIB, CONTAINER_NAME))
+assert(container.defined == False)
+assert(container.init_pid == -1)
+assert(container.name == CONTAINER_NAME)
+assert(container.running == False)
+assert(container.state == "STOPPED")
+
+## Create a rootfs
+print("Creating rootfs using '%s'" % LXC_TEMPLATE)
+container.create(LXC_TEMPLATE)
+
+assert(container.defined == True)
+assert(container.name == CONTAINER_NAME
+        == container.get_config_item("lxc.utsname"))
+assert(container.name in lxc.list_containers())
+
+## Test the config
+print("Testing the configuration")
+capdrop = container.get_config_item("lxc.cap.drop")
+container.clear_config_item("lxc.cap.drop")
+container.set_config_item("lxc.cap.drop", capdrop[:-1])
+container.append_config_item("lxc.cap.drop", capdrop[-1])
+container.save_config()
+
+# A few basic checks of the current state
+assert(isinstance(capdrop, list))
+assert(capdrop == container.get_config_item("lxc.cap.drop"))
+
+## Test the networking
+print("Testing the networking")
+
+# A few basic checks of the current state
+assert("name" in container.get_keys("lxc.network.0"))
+assert(len(container.network) == 1)
+assert(container.network[0].hwaddr.startswith("00:16:3e"))
+
+## Starting the container
+print("Starting the container")
+container.start()
+container.wait("RUNNING", 3)
+
+# A few basic checks of the current state
+assert(container.init_pid > 1)
+assert(container.running == True)
+assert(container.state == "RUNNING")
+
+## Checking IP address
+print("Getting the IP addresses")
+ips = container.get_ips(timeout=10)
+container.attach("NETWORK|UTSNAME", "/sbin/ifconfig", "eth0")
+
+# A few basic checks of the current state
+assert(len(ips) > 0)
+
+## Freezing the container
+print("Freezing the container")
+container.freeze()
+container.wait("FROZEN", 3)
+
+# A few basic checks of the current state
+assert(container.init_pid > 1)
+assert(container.running == True)
+assert(container.state == "FROZEN")
+
+## Unfreezing the container
+print("Unfreezing the container")
+container.unfreeze()
+container.wait("RUNNING", 3)
+
+# A few basic checks of the current state
+assert(container.init_pid > 1)
+assert(container.running == True)
+assert(container.state == "RUNNING")
+
+if len(sys.argv) > 1 and sys.argv[1] == "--with-console":
+    ## Attaching to tty1
+    print("Attaching to tty1")
+    container.console(tty=1)
+
+## Shutting down the container
+print("Shutting down the container")
+container.shutdown(3)
+
+if container.running:
+    print("Stopping the container")
+    container.stop()
+    container.wait("STOPPED", 3)
+
+# A few basic checks of the current state
+assert(container.init_pid == -1)
+assert(container.running == False)
+assert(container.state == "STOPPED")
+
+## Cloning the container
+print("Cloning the container")
+clone = lxc.Container(CLONE_NAME)
+clone.clone(container)
+clone.start()
+clone.stop()
+clone.destroy()
+
+## Destroy the container
+print("Destroying the container")
+container.destroy()
+
+assert(container.defined == False)
Index: ubuntu-lxc-bzr/src/python-lxc/lxc.c
===================================================================
--- ubuntu-lxc-bzr.orig/src/python-lxc/lxc.c	2012-09-13 10:42:11.970961000 -0400
+++ ubuntu-lxc-bzr/src/python-lxc/lxc.c	2012-09-13 10:42:19.957799924 -0400
@@ -59,14 +59,6 @@
     return result;
 }
 
-void zombie_handler(int sig)
-{
-    signal(SIGCHLD,zombie_handler);
-    int status;
-
-    waitpid(-1, &status, WNOHANG);
-}
-
 static void
 Container_dealloc(Container* self)
 {
@@ -353,7 +345,6 @@
         }
     }
 
-    signal(SIGCHLD, zombie_handler);
     self->container->want_daemonize(self->container);
 
     if (self->container->start(self->container, init_useinit, init_args)) {
