lib/testlab/container/actions.rb in testlab-0.4.16 vs lib/testlab/container/actions.rb in testlab-0.5.0
- old
+ new
@@ -18,28 +18,22 @@
build_lxc_config(self.lxc.config)
self.lxc.create(*create_args)
- # TODO: This needs to really go somewhere else:
- home_dir = ((self.node.user == "root") ? %(/root) : %(/home/#{self.node.user}))
- container_home_dir = File.join(self.lxc.fs_root, "/home/ubuntu")
+ # Ensure the container APT calls use apt-cacher-ng on the node
+ gateway_ip = self.primary_interface.network.ip
+ apt_conf_d_proxy_file = File.join(self.lxc.fs_root, "etc", "apt", "apt.conf.d", "02proxy")
+ self.node.ssh.exec(%(sudo mkdir -pv #{File.dirname(apt_conf_d_proxy_file)}))
+ self.node.ssh.exec(%(echo 'Acquire::http { Proxy "http://#{gateway_ip}:3142"; };' | sudo tee #{apt_conf_d_proxy_file}))
- home_authkeys = File.join(home_dir, ".ssh", "authorized_keys")
- container_authkeys = File.join(container_home_dir, ".ssh", "authorized_keys")
- container_authkeys2 = File.join(container_home_dir, ".ssh", "authorized_keys2")
+ # Fix the APT sources since LXC mudges them when using apt-cacher-ng
+ apt_conf_sources_file = File.join(self.lxc.fs_root, "etc", "apt", "sources.list")
+ self.node.ssh.exec(%(sudo sed -i 's/127.0.0.1:3142\\///g' #{apt_conf_sources_file}))
- authkeys = {
- home_authkeys => container_authkeys,
- home_authkeys => container_authkeys2
- }
-
- self.node.ssh.exec(%(mkdir -pv #{File.join(container_home_dir, %(.ssh))}))
- authkeys.each do |source, destination|
- self.node.ssh.exec(%(sudo cp -v #{source} #{destination}))
- self.node.ssh.exec(%(sudo chown -v 1000:1000 #{destination}))
- self.node.ssh.exec(%(sudo chmod -v 644 #{destination}))
+ self.users.each do |u|
+ u.create
end
end
true
@@ -79,11 +73,13 @@
self.lxc.start(%(--daemon))
self.lxc.wait(:running)
(self.lxc.state != :running) and raise ContainerError, "The container failed to online!"
- # TODO: This needs to really go somewhere else:
- self.lxc.attach(%(-- /bin/bash -c 'grep "sudo\tALL=\(ALL:ALL\) ALL" /etc/sudoers && sed -i "s/sudo\tALL=\(ALL:ALL\) ALL/sudo\tALL=\(ALL:ALL\) NOPASSWD: ALL/" /etc/sudoers'))
+ self.users.each do |u|
+ u.up
+ end
+
end
true
end