[lxc-devel] Fwd: [PATCH] python api_test: Drop use of @LXCPATH@

Serge Hallyn serge.hallyn at ubuntu.com
Fri Mar 1 17:46:17 UTC 2013


Quoting Stéphane Graber (stgraber at ubuntu.com):

> Date: Fri,  1 Mar 2013 11:16:43 -0500
> From: Stéphane Graber <stgraber at ubuntu.com>
> To: lxc-devel at lists.sourceforge.net
> Cc: Stéphane Graber <stgraber at ubuntu.com>
> Subject: [PATCH] python api_test: Drop use of @LXCPATH@
> 
> The python api test script was using @LXCPATH@ for one of its checks.
> Now that the lxcpath is exposed by the lxc python module directly, this
> can be dropped and api_test.py can now become a simple python file without
> needing pre-processing by autoconf.
> 
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Excellent, thanks.

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  .gitignore                             |   1 -
>  configure.ac                           |   1 -
>  src/python-lxc/examples/api_test.py    | 157 ++++++++++++++++++++++++++++++++
>  src/python-lxc/examples/api_test.py.in | 158 ---------------------------------
>  4 files changed, 157 insertions(+), 160 deletions(-)
>  create mode 100644 src/python-lxc/examples/api_test.py
>  delete mode 100644 src/python-lxc/examples/api_test.py.in
> 
> diff --git a/.gitignore b/.gitignore
> index e5bc505..bef5cd1 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -66,7 +66,6 @@ src/lxc/lxc-wait
>  src/lxc/legacy/lxc-ls
>  
>  src/python-lxc/build/
> -src/python-lxc/examples/api_test.py
>  src/python-lxc/lxc/__init__.py
>  src/python-lxc/lxc/__pycache__/
>  
> diff --git a/configure.ac b/configure.ac
> index 88959ff..792aae8 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -384,7 +384,6 @@ AC_CONFIG_FILES([
>  
>  	src/python-lxc/Makefile
>  	src/python-lxc/lxc/__init__.py
> -	src/python-lxc/examples/api_test.py
>  
>  	src/lua-lxc/Makefile
>  
> diff --git a/src/python-lxc/examples/api_test.py b/src/python-lxc/examples/api_test.py
> new file mode 100644
> index 0000000..367bb7a
> --- /dev/null
> +++ b/src/python-lxc/examples/api_test.py
> @@ -0,0 +1,157 @@
> +#!/usr/bin/python3
> +#
> +# api_test.py: Test/demo of the python3-lxc API
> +#
> +# (C) Copyright Canonical Ltd. 2012
> +#
> +# Authors:
> +# Stéphane Graber <stgraber at 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_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.default_config_path, CONTAINER_NAME))
> +assert(not container.defined)
> +assert(container.init_pid == -1)
> +assert(container.name == CONTAINER_NAME)
> +assert(not container.running)
> +assert(container.state == "STOPPED")
> +
> +## Create a rootfs
> +print("Creating rootfs using '%s'" % LXC_TEMPLATE)
> +container.create(LXC_TEMPLATE)
> +
> +assert(container.defined)
> +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)
> +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)
> +
> +## Testing cgroups a bit
> +print("Testing cgroup API")
> +max_mem = container.get_cgroup_item("memory.max_usage_in_bytes")
> +current_limit = container.get_cgroup_item("memory.limit_in_bytes")
> +assert(container.set_cgroup_item("memory.limit_in_bytes", max_mem))
> +assert(container.get_cgroup_item("memory.limit_in_bytes") != current_limit)
> +
> +## 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)
> +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)
> +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(not container.running)
> +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(not container.defined)
> diff --git a/src/python-lxc/examples/api_test.py.in b/src/python-lxc/examples/api_test.py.in
> deleted file mode 100644
> index 7711291..0000000
> --- a/src/python-lxc/examples/api_test.py.in
> +++ /dev/null
> @@ -1,158 +0,0 @@
> -#!/usr/bin/python3
> -#
> -# api_test.py: Test/demo of the python3-lxc API
> -#
> -# (C) Copyright Canonical Ltd. 2012
> -#
> -# Authors:
> -# Stéphane Graber <stgraber at 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 = "@LXCPATH@"
> -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(not container.defined)
> -assert(container.init_pid == -1)
> -assert(container.name == CONTAINER_NAME)
> -assert(not container.running)
> -assert(container.state == "STOPPED")
> -
> -## Create a rootfs
> -print("Creating rootfs using '%s'" % LXC_TEMPLATE)
> -container.create(LXC_TEMPLATE)
> -
> -assert(container.defined)
> -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)
> -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)
> -
> -## Testing cgroups a bit
> -print("Testing cgroup API")
> -max_mem = container.get_cgroup_item("memory.max_usage_in_bytes")
> -current_limit = container.get_cgroup_item("memory.limit_in_bytes")
> -assert(container.set_cgroup_item("memory.limit_in_bytes", max_mem))
> -assert(container.get_cgroup_item("memory.limit_in_bytes") != current_limit)
> -
> -## 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)
> -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)
> -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(not container.running)
> -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(not container.defined)
> -- 
> 1.8.1.2
> 







More information about the lxc-devel mailing list