Lines Matching full:container
18 from autotest_lib.site_utils.lxc import container as container_module
25 """Unit tests for the Container class."""
33 # Check if a base container exists on this machine and download one if
57 # Make a container that just points to the base container.
58 container = lxc.Container.create_from_existing_dir(
62 # the on-disk container is valid.
63 self.assertFalse(container.is_running())
72 container = lxc.Container.create_from_existing_dir(self.test_dir,
75 container.refresh_status()
80 with self.createContainer() as container:
81 # Create a container with an empty ID file.
82 id_path = os.path.join(container.container_path,
83 container.name,
87 # Verify that container creation doesn't raise exceptions.
88 test_container = lxc.Container.create_from_existing_dir(
89 self.test_dir, container.name)
97 the lxc container name."""
99 with self.createContainer(name=test_name) as container:
100 container.start(wait_for_network=True)
101 hostname = container.attach_run('hostname').stdout.strip()
106 """Verifies that the hostname can be set on a running container."""
107 with self.createContainer() as container:
109 container.start(wait_for_network=True)
110 container.set_hostname(expected_hostname)
111 hostname = container.attach_run('hostname -f').stdout.strip()
116 """Verifies that set_hostname on a stopped container raises an error.
119 original container name is not a valid RFC-952 hostname, e.g. if it has
123 the container to be running. To avoid confusion, setting the hostname
124 on a stopped container is disallowed.
128 with self.createContainer() as container:
130 # Ensure the container is not running
131 if container.is_running():
132 raise RuntimeError('Container should not be running.')
133 container.set_hostname('foobar')
137 """Verifies that cloning a container works as expected."""
138 clone = lxc.Container.clone(src=self.base_container,
143 # Throws an exception if the container is not valid.
150 """Verifies that cloning a container to an existing name will fail as
153 lxc.Container.clone(src=self.base_container,
158 lxc.Container.clone(src=self.base_container,
165 """Verifies that cloning a container with cleanup works properly."""
166 clone0 = lxc.Container.clone(src=self.base_container,
175 # Clone another container in place of the existing container.
176 clone1 = lxc.Container.clone(src=self.base_container,
186 """Verifies that installing the ssp in the container works."""
191 # Create a container, install the self-served ssp, then check that it is
192 # installed into the container correctly.
193 with self.createContainer() as container:
195 container.install_ssp(url)
196 container.start(wait_for_network=False)
200 # container.
201 cat = lambda path: container.attach_run('cat %s' % path).stdout
213 """Verifies that installing a control file in the container works."""
215 with self.createContainer() as container:
216 container.install_control_file(tmpfile)
217 container.start(wait_for_network=False)
218 # Verify that the file is found in the container.
219 container.attach_run(
225 """Verifies that files are correctly copied into the container."""
231 with self.createContainer() as container:
234 container.copy(tmpfile.name, dst)
235 container.start(wait_for_network=False)
237 test_string = container.attach_run('cat %s' % dst).stdout
242 """Verifies that directories are correctly copied into the container."""
250 with self.createContainer() as container:
253 container.copy(tmpdir, dst)
254 container.start(wait_for_network=False)
257 test_string = container.attach_run('cat %s' % test_file).stdout
263 with lxc_utils.TempDir() as tmpdir, self.createContainer() as container:
265 container.mount_dir(tmpdir, dst, readonly=False)
266 container.start(wait_for_network=False)
269 self.verifyBindMount(container, dst, tmpdir)
270 container.attach_run('test -r %s -a -w %s' % (dst, dst))
275 with lxc_utils.TempDir() as tmpdir, self.createContainer() as container:
277 container.mount_dir(tmpdir, dst, readonly=True)
278 container.start(wait_for_network=False)
281 self.verifyBindMount(container, dst, tmpdir)
282 container.attach_run('test -r %s -a ! -w %s' % (dst, dst))
287 with lxc_utils.TempDir() as tmpdir, self.createContainer() as container:
289 container.mount_dir(tmpdir, dst, readonly=True)
290 container.start(wait_for_network=False)
293 self.verifyBindMount(container, dst, tmpdir)
297 """Verifies that container IDs correctly persist.
299 When a Container is instantiated on top of an existing container dir,
302 with self.createContainer() as container:
304 container.id = test_id
306 # Set up another container and verify that its ID matches.
307 test_container = lxc.Container.create_from_existing_dir(
308 container.container_path, container.name)
315 with self.createContainer() as container:
316 self.assertIsNone(container.id)
317 # Set an ID, clone the container, and verify the clone has no ID.
318 container.id = random_container_id()
319 clone = lxc.Container.clone(src=container,
320 new_name=container.name + '_clone',
322 self.assertIsNotNone(container.id)
328 """Creates a container from the base container, for testing.
332 @param name: An optional name for the new container.
336 container = lxc.Container.clone(src=self.base_container,
341 yield container
344 container.destroy()
347 def verifyBindMount(self, container, container_path, host_path): argument
348 """Verifies that a given path in a container is bind-mounted to a given
351 @param container: The Container instance to be tested.
352 @param container_path: The path in the container to compare.
355 container_inode = (container.attach_run('ls -id %s' % container_path)
358 # Compare the container and host inodes - they should match.
384 """Generate a random container ID for testing."""