Lines Matching full:container
19 from autotest_lib.site_utils.lxc import container as container_module
26 """Unit tests for the Container class."""
34 # 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())
71 container = lxc.Container.create_from_existing_dir(self.test_dir,
74 container.refresh_status()
78 with self.createContainer() as container:
79 # Create a container with an empty ID file.
80 id_path = os.path.join(container.container_path,
81 container.name,
85 # Verify that container creation doesn't raise exceptions.
86 test_container = lxc.Container.create_from_existing_dir(
87 self.test_dir, container.name)
94 the lxc container name."""
96 with self.createContainer(name=test_name) as container:
97 container.start(wait_for_network=True)
98 hostname = container.attach_run('hostname').stdout.strip()
102 """Verifies that the hostname can be set on a running container."""
103 with self.createContainer() as container:
105 container.start(wait_for_network=True)
106 container.set_hostname(expected_hostname)
107 hostname = container.attach_run('hostname -f').stdout.strip()
111 """Verifies that set_hostname on a stopped container raises an error.
114 original container name is not a valid RFC-952 hostname, e.g. if it has
118 the container to be running. To avoid confusion, setting the hostname
119 on a stopped container is disallowed.
123 with self.createContainer() as container:
125 # Ensure the container is not running
126 if container.is_running():
127 raise RuntimeError('Container should not be running.')
128 container.set_hostname('foobar')
131 """Verifies that cloning a container works as expected."""
132 clone = lxc.Container.clone(src=self.base_container,
137 # Throws an exception if the container is not valid.
143 """Verifies that cloning a container to an existing name will fail as
146 lxc.Container.clone(src=self.base_container,
151 lxc.Container.clone(src=self.base_container,
157 """Verifies that cloning a container with cleanup works properly."""
158 clone0 = lxc.Container.clone(src=self.base_container,
167 # Clone another container in place of the existing container.
168 clone1 = lxc.Container.clone(src=self.base_container,
177 """Verifies that installing the ssp in the container works."""
182 # Create a container, install the self-served ssp, then check that it is
183 # installed into the container correctly.
184 with self.createContainer() as container:
186 container.install_ssp(url)
187 container.start(wait_for_network=False)
191 # container.
194 return container.attach_run('cat %s' % path).stdout
206 """Verifies that installing a control file in the container works."""
208 with self.createContainer() as container:
209 container.install_control_file(tmpfile)
210 container.start(wait_for_network=False)
211 # Verify that the file is found in the container.
212 container.attach_run(
217 """Verifies that files are correctly copied into the container."""
223 with self.createContainer() as container:
226 container.copy(tmpfile.name, dst)
227 container.start(wait_for_network=False)
229 test_string = container.attach_run('cat %s' % dst).stdout
233 """Verifies that directories are correctly copied into the container."""
241 with self.createContainer() as container:
244 container.copy(tmpdir, dst)
245 container.start(wait_for_network=False)
248 test_string = container.attach_run('cat %s' % test_file).stdout
253 with lxc_utils.TempDir() as tmpdir, self.createContainer() as container:
255 container.mount_dir(tmpdir, dst, readonly=False)
256 container.start(wait_for_network=False)
259 self.verifyBindMount(container, dst, tmpdir)
260 container.attach_run('test -r %s -a -w %s' % (dst, dst))
264 with lxc_utils.TempDir() as tmpdir, self.createContainer() as container:
266 container.mount_dir(tmpdir, dst, readonly=True)
267 container.start(wait_for_network=False)
270 self.verifyBindMount(container, dst, tmpdir)
271 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)
284 """Verifies that container IDs correctly persist.
286 When a Container is instantiated on top of an existing container dir,
289 with self.createContainer() as container:
291 container.id = test_id
293 # Set up another container and verify that its ID matches.
294 test_container = lxc.Container.create_from_existing_dir(
295 container.container_path, container.name)
301 with self.createContainer() as container:
302 self.assertIsNone(container.id)
303 # Set an ID, clone the container, and verify the clone has no ID.
304 container.id = random_container_id()
305 clone = lxc.Container.clone(src=container,
306 new_name=container.name + '_clone',
308 self.assertIsNotNone(container.id)
313 """Creates a container from the base container, for testing.
317 @param name: An optional name for the new container.
321 container = lxc.Container.clone(src=self.base_container,
326 yield container
329 container.destroy()
331 def verifyBindMount(self, container, container_path, host_path): argument
332 """Verifies that a given path in a container is bind-mounted to a given
335 @param container: The Container instance to be tested.
336 @param container_path: The path in the container to compare.
339 container_inode = (container.attach_run('ls -id %s' % container_path)
342 # Compare the container and host inodes - they should match.
366 """Generate a random container ID for testing."""