Skip to content

Commit

Permalink
Fix test-runner bootstrap failing if apt lock is already held
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Sep 2, 2024
1 parent 7430173 commit 4544ef4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
14 changes: 11 additions & 3 deletions test/scripts/ssh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ fi

setup_systemd

# Run apt with some arguments
robust_apt () {
# We don't want to fail due to the global apt lock being
# held, which happens sporadically. It is fine to wait for
# some time if it means that the test run can continue.
apt -o DPkg::Lock::Timeout=60 "$@"
}

function install_packages_apt {
echo "Installing required apt packages"
apt update
apt install -yf xvfb wireguard-tools curl
robust_apt update
robust_apt install -yf xvfb wireguard-tools curl
if ! which ping &>/dev/null; then
apt install -yf iputils-ping
robust_apt install -yf iputils-ping
fi
curl -fsSL https://get.docker.com | sh
}
Expand Down
32 changes: 20 additions & 12 deletions test/test-runner/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::process::Command;
pub async fn uninstall_app(env: HashMap<String, String>) -> Result<()> {
match get_distribution()? {
Distribution::Debian | Distribution::Ubuntu => {
uninstall_dpkg("mullvad-vpn", env, true).await
uninstall_apt("mullvad-vpn", env, true).await
}
Distribution::Fedora => uninstall_rpm("mullvad-vpn", env).await,
}
Expand Down Expand Up @@ -103,7 +103,7 @@ pub async fn install_package(package: Package) -> Result<()> {
#[cfg(target_os = "linux")]
pub async fn install_package(package: Package) -> Result<()> {
match get_distribution()? {
Distribution::Debian | Distribution::Ubuntu => install_dpkg(&package.path).await,
Distribution::Debian | Distribution::Ubuntu => install_apt(&package.path).await,
Distribution::Fedora => install_rpm(&package.path).await,
}
}
Expand All @@ -127,9 +127,13 @@ pub async fn install_package(package: Package) -> Result<()> {
}

#[cfg(target_os = "linux")]
async fn install_dpkg(path: &Path) -> Result<()> {
let mut cmd = Command::new("/usr/bin/dpkg");
cmd.arg("-i");
async fn install_apt(path: &Path) -> Result<()> {
let mut cmd = Command::new("/usr/bin/apt");
// We don't want to fail due to the global apt lock being
// held, which happens sporadically. Wait to acquire the lock
// instead.
cmd.args(["-o", "DPkg::Lock::Timeout=60"]);
cmd.arg("install");
cmd.arg(path.as_os_str());
cmd.kill_on_drop(true);
cmd.stdout(Stdio::piped());
Expand All @@ -139,19 +143,23 @@ async fn install_dpkg(path: &Path) -> Result<()> {
.wait_with_output()
.await
.map_err(|e| strip_error(Error::RunApp, e))
.and_then(|output| result_from_output("dpkg -i", output))
.and_then(|output| result_from_output("apt install", output))
}

#[cfg(target_os = "linux")]
async fn uninstall_dpkg(name: &str, env: HashMap<String, String>, purge: bool) -> Result<()> {
async fn uninstall_apt(name: &str, env: HashMap<String, String>, purge: bool) -> Result<()> {
let action;
let mut cmd = Command::new("/usr/bin/dpkg");
let mut cmd = Command::new("/usr/bin/apt");
// We don't want to fail due to the global apt lock being
// held, which happens sporadically. Wait to acquire the lock
// instead.
cmd.args(["-o", "DPkg::Lock::Timeout=60"]);
if purge {
action = "dpkg --purge";
cmd.args(["--purge", name]);
action = "apt purge";
cmd.args(["purge", name]);
} else {
action = "dpkg -r";
cmd.args(["-r", name]);
action = "apt remove";
cmd.args(["remove", name]);
}
cmd.envs(env);
cmd.kill_on_drop(true);
Expand Down

0 comments on commit 4544ef4

Please sign in to comment.