Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few fixes to scripts to simulate a Gimlet on commodity machines #957

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions package/src/bin/omicron-package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,18 @@ fn remove_all_unless_already_removed<P: AsRef<Path>>(path: P) -> Result<()> {
Ok(())
}

fn remove_all_except_databases<P: AsRef<Path>>(path: P) -> Result<()> {
const TO_KEEP: [&str; 2] = ["clickhouse", "cockroachdb"];
fn remove_all_except<P: AsRef<Path>>(path: P, to_keep: &[&str]) -> Result<()> {
let dir = match path.as_ref().read_dir() {
Ok(dir) => dir,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(()),
Err(e) => bail!(e),
};
for entry in dir {
let entry = entry?;
if !TO_KEEP.contains(&&*(entry.file_name().to_string_lossy())) {
if to_keep.contains(&&*(entry.file_name().to_string_lossy())) {
println!(" Keeping: '{}'", entry.path().to_string_lossy());
} else {
println!(" Removing: '{}'", entry.path().to_string_lossy());
if entry.metadata()?.is_dir() {
remove_all_unless_already_removed(entry.path())?;
} else {
Expand All @@ -452,9 +454,16 @@ fn do_uninstall(
println!("Uninstalling all packages");
uninstall_all_packages(config);
println!("Removing artifacts in: {}", artifact_dir.to_string_lossy());
remove_all_except_databases(artifact_dir)?;
println!("Removing: {}", install_dir.to_string_lossy());
remove_all_unless_already_removed(install_dir)?;

const ARTIFACTS_TO_KEEP: &[&str] = &["clickhouse", "cockroachdb", "xde"];
remove_all_except(artifact_dir, ARTIFACTS_TO_KEEP)?;

println!(
"Removing installed objects in: {}",
install_dir.to_string_lossy()
);
const INSTALLED_OBJECTS_TO_KEEP: &[&str] = &["opte"];
remove_all_except(install_dir, INSTALLED_OBJECTS_TO_KEEP)?;
Ok(())
}

Expand Down
47 changes: 26 additions & 21 deletions tools/create_virtual_hardware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,46 @@ function ensure_zpools {
done
}

# Return the name of a VNIC link if it exists, or the empty string if not.
#
# Arguments:
# $1: The name of the VNIC to look for
function get_vnic_name_if_exists {
NAME="$(dladm show-vnic -p -o LINK "$1")"
if [[ "$?" -eq 0 ]]; then
echo "$NAME"
else
echo ""
fi
}

# Create VNICs to represent the Chelsio physical links
#
# Arguments:
# $1: Optional name of the physical link to use. If not provided, use the
# first physical link available on the machine.
function ensure_simulated_chelsios {
local PHYSICAL_LINK="$1"
VNIC_NAMES=("vioif0" "vioif1")
VNIC_NAMES=("net0" "net1")
for VNIC in "${VNIC_NAMES[@]}"; do
if [[ -z "$(dladm show-vnic -p -o LINK "$VNIC")" ]]; then
if [[ -z "$(get_vnic_name_if_exists "$VNIC")" ]]; then
dladm create-vnic -t -l "$PHYSICAL_LINK" "$VNIC"
fi
success "VNIC $VNIC exists"
if [[ -z "$(ipadm show-addr -p -o ADDR "$VNIC/v6")" ]]; then
ipadm create-addr -t -T addrconf "$VNIC/v6"
fi
success "IP address $VNIC/v6 exists"
done

# Create an address on the underlay network
UNDERLAY_ADDR="lo0/underlay"
if [[ -z "$(ipadm show-addr -p -o ADDR "$UNDERLAY_ADDR")" ]]; then
ipadm create-addr -t -T static -a fd00:1::1/64 lo0/underlay
fi
success "IP address $UNDERLAY_ADDR exists"
}

function ensure_xde_driver {
# Always remove the driver first. There seems to be a bug in the driver,
# preventing it from showing up in `modinfo` on boot, even if it's actually
# installed.
if [[ -z "$(modinfo | grep xde)" ]]; then
rem_drv xde
add_drv xde
# Return the IP address for the provided addrobj name, or the empty string if it
# does not exist.
#
# Arguments:
# $1: The name of the addrobj
function get_ip_addr_if_exists {
ADDR="$(ipadm show-addr -p -o ADDR "$1")"
if [[ "$?" -eq 0 ]]; then
echo "$ADDR"
else
echo ""
bnaecker marked this conversation as resolved.
Show resolved Hide resolved
fi
}

Expand All @@ -97,4 +103,3 @@ function ensure_run_as_root {
ensure_run_as_root
ensure_zpools
ensure_simulated_chelsios "$PHYSICAL_LINK"
ensure_xde_driver
19 changes: 2 additions & 17 deletions tools/destroy_virtual_hardware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ function success {
echo -e "\e[1;36m$1\e[0m"
}

function try_uninstall_xde {
RC=0
if ! [[ -z "$(modinfo | grep xde)" ]]; then
rem_drv xde
RC=$?
fi

if [[ $RC -eq 0 ]]; then
success "XDE kernel module uninstalled"
else
warn "Failed to uninstall XDE kernel module"
fi
}

function try_remove_address {
local ADDRESS="$1"
RC=0
Expand Down Expand Up @@ -71,9 +57,8 @@ function try_remove_vnic {

function try_remove_vnics {
try_remove_address "lo0/underlay"
VNIC_LINKS=("vioif0" "vioif1")
VNIC_LINKS=("net0" "net1")
for LINK in "${VNIC_LINKS[@]}"; do
try_remove_address "$LINK/v6"
try_remove_vnic "$LINK"
done
}
Expand All @@ -94,5 +79,5 @@ function try_destroy_zpools {
done
}

try_uninstall_xde && try_remove_vnics
try_remove_vnics
try_destroy_zpools
71 changes: 40 additions & 31 deletions tools/install_opte.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "${SOURCE_DIR}/.."
OMICRON_TOP="$PWD"
OUT_DIR="$OMICRON_TOP/out"
mkdir -p "$OUT_DIR"
XDE_DIR="$OUT_DIR/xde"
mkdir -p "$XDE_DIR"

# Compute the SHA256 of the path in $1, returning just the sum
function file_sha {
Expand All @@ -30,7 +31,7 @@ function file_sha {
function download_and_check_sha {
local URL="$1"
local FILENAME="$(basename "$URL")"
local OUT_PATH="$OUT_DIR/$FILENAME"
local OUT_PATH="$XDE_DIR/$FILENAME"
local SHA="$2"

# Check if the file already exists, with the expected SHA
Expand All @@ -52,36 +53,44 @@ function sha_from_url {
curl -L "$SHA_URL" 2> /dev/null | cut -d ' ' -f 1
}

OPTE_P5P_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G0MRWX9Y0X46HBEJBW245DJY/PM097Agvf89uKmVRZ890z6saoeLp6RCcVsbYRa5PDv9DnLDT/01G0MRX6GMBV34CNANABXZXX25/01G0MSFZZWPFEQBW7JRS7ST99G/opte-0.1.58.p5p"
OPTE_P5P_SHA_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G0MRWX9Y0X46HBEJBW245DJY/PM097Agvf89uKmVRZ890z6saoeLp6RCcVsbYRa5PDv9DnLDT/01G0MRX6GMBV34CNANABXZXX25/01G0MSG01CGP6TH9THNY39G88Z/opte-0.1.58.p5p.sha256"
OPTE_P5P_REPO_PATH="$OUT_DIR/$(basename "$OPTE_P5P_URL")"
XDE_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G0DM53XR4E008D6ET5T8DXP6/wBWo0Jsg1AG19toIyAY23xAWhzmuNKmAsF6tL18ypZODNuHK/01G0DM5DMQHF5B89VGHZ05Z4E0/01G0DMHNYQ1NS7DBX8VG3JPAP0/xde"
XDE_SHA_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G0DM53XR4E008D6ET5T8DXP6/wBWo0Jsg1AG19toIyAY23xAWhzmuNKmAsF6tL18ypZODNuHK/01G0DM5DMQHF5B89VGHZ05Z4E0/01G0DMHP47353961S3ETXBSD2T/xde.sha256"
# Add a pkg repo by path. This will also run `pkg update`, handling the case
# gracefully where there are no updates required
function add_pkg_repo_and_update {
local REPO_PATH="$1"
pkg set-publisher -p "$REPO_PATH" --search-first
RC=0
pkg update || RC=$?;
if [[ "$RC" -eq 0 ]] || [[ "$RC" -eq 4 ]]; then
return 0
else
return "$RC"
fi
bnaecker marked this conversation as resolved.
Show resolved Hide resolved
}

download_and_check_sha "$OPTE_P5P_URL" "$(sha_from_url "$OPTE_P5P_SHA_URL")"
XDE_SHA="$(sha_from_url "$XDE_SHA_URL")"
download_and_check_sha "$XDE_URL" "$XDE_SHA"
# The `helios-netdev` provides the XDE kernel driver and the `opteadm` userland
# tool for interacting with it.
HELIOS_NETDEV_REPO_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G11AT7E4XV9J1J54GE2YDJT6/CB4WF4BVgnbvf5NI573z9osAV2LNIKogPtWJ5sfW2cNxUYQO/01G11ATFVTWAC2HSNV148PQ4ER/01G11B5MPQRBX3Q5EF45YDAW6Q/opte-0.1.60.p5p"
HELIOS_NETDEV_REPO_SHA_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G11AT7E4XV9J1J54GE2YDJT6/CB4WF4BVgnbvf5NI573z9osAV2LNIKogPtWJ5sfW2cNxUYQO/01G11ATFVTWAC2HSNV148PQ4ER/01G11B5MR60H4N13NJKGWEEA69/opte-0.1.60.p5p.sha256"
HELIOS_NETDEV_REPO_PATH="$XDE_DIR/$(basename "$HELIOS_NETDEV_REPO_URL")"

# Move the XDE driver into it the expected location to allow operating on it
# with `add_drv` and `rem_drv`
DRIVER_DIR="/kernel/drv/amd64"
XDE_FILENAME="$(basename "$XDE_URL")"
XDE_PATH="$DRIVER_DIR/$XDE_FILENAME"
if ! [[ -f "$XDE_PATH" ]] || [[ "$XDE_SHA" != "$(file_sha "$XDE_PATH")" ]]; then
echo "Replacing XDE driver"
mv -f "$OUT_DIR/$XDE_FILENAME" "$XDE_PATH"
else
echo "XDE driver already exists with correct SHA"
fi
# The XDE repo provides a full OS/Net incorporation, with updated kernel bits
# that the `xde` kernel module and OPTE rely on.
XDE_REPO_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G0ZKH44GQF88GB0GQBG9TQGW/7eOYj8L8E4MLrtvdTgGMyMu5qjYTRheV250bEvh2OkBrggX4/01G0ZKHBQ33K40S5ABZMRNWS5P/01G0ZYDDRXQ3Y4E5SG9QX8N9FK/repo.p5p"
XDE_REPO_SHA_URL="https://buildomat.eng.oxide.computer/wg/0/artefact/01G0ZKH44GQF88GB0GQBG9TQGW/7eOYj8L8E4MLrtvdTgGMyMu5qjYTRheV250bEvh2OkBrggX4/01G0ZKHBQ33K40S5ABZMRNWS5P/01G0ZYDJDMJAYHFV9Z6XVE30X5/repo.p5p.sha256"
XDE_REPO_PATH="$XDE_DIR/$(basename "$XDE_REPO_URL")"

# Add the OPTE P5P package repository (at the top of the search order) and
# update the OS packages. This may require a reboot.
pkg set-publisher -p "$OPTE_P5P_REPO_PATH" --search-first
# Download and verify the package repositorieies
download_and_check_sha "$HELIOS_NETDEV_REPO_URL" "$(sha_from_url "$HELIOS_NETDEV_REPO_SHA_URL")"
download_and_check_sha "$XDE_REPO_URL" "$(sha_from_url "$XDE_REPO_SHA_URL")"

# Set the `helios-dev` repo as non-sticky, meaning that packages that were
# originally provided by it may be updated by another repository, if that repo
# provides newer versions of the packages.
pkg set-publisher --non-sticky helios-dev
RC=0
pkg update || RC=$?;
if [[ "$RC" -eq 0 ]] || [[ "$RC" -eq 4 ]]; then
exit 0
else
exit "$RC"
fi

# Add the OPTE and XDE repositories and update packages.
add_pkg_repo_and_update "$HELIOS_NETDEV_REPO_PATH"
add_pkg_repo_and_update "$XDE_REPO_PATH"

# Actually install the xde kernel module and opteadm tool
pkg install driver/network/opte