lib/testlab/container/actions.rb in testlab-0.4.2 vs lib/testlab/container/actions.rb in testlab-0.4.3

- old
+ new

@@ -18,28 +18,37 @@ self.release ||= "precise" self.arch ||= detect_arch self.lxc.config.clear - self.lxc.config['lxc.utsname'] = self.id + self.lxc.config['lxc.utsname'] = self.fqdn self.lxc.config['lxc.arch'] = self.arch self.lxc.config.networks = build_lxc_network_conf(self.interfaces) self.lxc.config.save 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") - home_authkeys = File.join(home_dir, %(.ssh), %(authorized_keys)) - container_authkeys = File.join(container_home_dir, %(.ssh), %(authorized_keys)) + 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") + authkeys = { + home_authkeys => container_authkeys, + home_authkeys => container_authkeys2 + } + self.node.ssh.exec(%(mkdir -pv #{File.join(container_home_dir, %(.ssh))})) - self.node.ssh.exec(%(sudo cp -v #{home_authkeys} #{container_authkeys})) - self.node.ssh.exec(%(sudo chown -v 1000:1000 #{container_authkeys})) - self.node.ssh.exec(%(sudo chmod -v 644 #{container_authkeys})) + 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})) + end + end true end @@ -73,10 +82,10 @@ 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.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')) end true end