lib/testlab/provisioners/apt_cacher_ng.rb in testlab-0.5.2 vs lib/testlab/provisioners/apt_cacher_ng.rb in testlab-0.5.3

- old
+ new

@@ -22,16 +22,19 @@ # @param [TestLab::Node] node The node which we want to provision. # @return [Boolean] True if successful. def node(node) @ui.logger.debug { "AptCacherNG Provisioner: Node #{node.id}" } - node.ssh.exec(%(sudo apt-get -y install apt-cacher-ng)) - node.ssh.exec(%(sudo service apt-cacher-ng restart || sudo service apt-cacher-ng start)) - node.ssh.exec(%(echo 'Acquire::HTTP { Proxy "http://127.0.0.1:3142"; };' | sudo tee /etc/apt/apt.conf.d/00proxy)) - node.ssh.exec(%(sudo grep "^MIRROR" /etc/default/lxc || echo 'MIRROR="http://127.0.0.1:3142/archive.ubuntu.com/ubuntu"' | sudo tee -a /etc/default/lxc)) - node.ssh.exec(%(sudo service lxc restart || sudo service lxc start)) + script = <<-EOF +apt-get -y install apt-cacher-ng +service apt-cacher-ng restart || service apt-cacher-ng start +echo 'Acquire::HTTP { Proxy "http://127.0.0.1:3142"; };' | tee /etc/apt/apt.conf.d/00proxy +grep "^MIRROR" /etc/default/lxc || echo 'MIRROR="http://127.0.0.1:3142/archive.ubuntu.com/ubuntu"' | tee -a /etc/default/lxc && service lxc restart || service lxc start + EOF + node.ssh.bootstrap(script) + true end # AptCacherNG Provisioner Container Setup # @@ -43,19 +46,23 @@ # Ensure the container APT calls use apt-cacher-ng on the node gateway_ip = container.primary_interface.network.ip apt_conf_d_proxy_file = File.join(container.lxc.fs_root, "etc", "apt", "apt.conf.d", "00proxy") - container.node.ssh.exec(%(sudo mkdir -pv #{File.dirname(apt_conf_d_proxy_file)})) + script = <<-EOF +mkdir -pv #{File.dirname(apt_conf_d_proxy_file)} +echo 'Acquire::HTTP { Proxy "http://#{gateway_ip}:3142"; };' | tee #{apt_conf_d_proxy_file} + EOF - container.node.ssh.exec(%(echo 'Acquire::HTTP { Proxy "http://#{gateway_ip}:3142"; };' | sudo tee #{apt_conf_d_proxy_file})) container.config[:apt_cacher_exclude_hosts].each do |host| - container.node.ssh.exec(%(echo 'Acquire::HTTP::Proxy::#{host} "DIRECT";' | sudo tee -a #{apt_conf_d_proxy_file})) + script << %(echo 'Acquire::HTTP::Proxy::#{host} "DIRECT";' | tee -a #{apt_conf_d_proxy_file}\n) end # Fix the APT sources since LXC mudges them when using apt-cacher-ng apt_conf_sources_file = File.join(container.lxc.fs_root, "etc", "apt", "sources.list") - container.node.ssh.exec(%(sudo sed -i 's/127.0.0.1:3142\\///g' #{apt_conf_sources_file})) + script << %(sed -i 's/127.0.0.1:3142\\///g' #{apt_conf_sources_file}\n) + + container.node.ssh.bootstrap(script) end # AptCacherNG Provisioner Container Teardown # # This is a NO-OP currently.