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

🌱 Develop User-Friendly baremetalhost creation for Tilt interface #1483

Merged

Conversation

peppi-lotta
Copy link
Member

Signed-off-by: peppi-lotta [email protected]

Tilt improved for easier baremetalhost creation

What this PR does / why we need it:
Fixes #1478

@metal3-io-bot metal3-io-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 7, 2023
Copy link
Member

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of nits.


After Tilt is up it is possible to make baremetalhosts by pressing a button in the Tilt localhost interface (right upper corner). This button runs the content of file
```sh
tools/bmh_test/create_bmh.sh {NAME} {VBMC_PORT}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tools/bmh_test/create_bmh.sh {NAME} {VBMC_PORT}
tools/bmh_test/create_bmh.sh <NAME> <VBMC_PORT>

Usually mandatory parameters are marked with <> and optioanl parameters [] in documentation.

<bootp file='http://192.168.222.199:6180/boot.ipxe'/>
</dhcp>
</ip>
</network>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like missing linefeed at the end of file.


# Clear network
sudo virsh -c qemu:///system net-destroy bmo-test-network
sudo virsh -c qemu:///system net-undefine bmo-test-network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing linefeed at the end of file.

@@ -0,0 +1,100 @@
#!/bin/bash -x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#!/bin/bash -x
#!/usr/bin/env bash

If not executed in container, let user decide which bash he/she wants to use.

You also have set -x later, it is unnecessary here. Any options are better added as a separate line anyways, as in case of use executing this as bash ./script.sh, the -x would not take effect as shebang is not read.

# VBMC runing
# -------------------------------------------------------------------------------------------

set -xe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set -xe
set -eux

You generally want to use -eux, ie. also add failing for undefined variables.
If you'd also use pipes | in the script, you'd also want to add -o pipefail by default.


# Install virtinst
sudo apt update
sudo apt install virtinst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo apt install virtinst
sudo apt-get -y install virtinst

Same

virsh -c qemu:///system net-start bmo-test-network

# Install libvirt clients and daemon system, python3-pip and pip install vbmc
sudo apt-get install libvirt-clients libvirt-daemon-system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo apt-get install libvirt-clients libvirt-daemon-system
sudo apt-get -y install libvirt-clients libvirt-daemon-system


# Install libvirt clients and daemon system, python3-pip and pip install vbmc
sudo apt-get install libvirt-clients libvirt-daemon-system
sudo apt-get install python3-pip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sudo apt-get install python3-pip
sudo apt-get -y install python3-pip

This and other apt-get should be a single line instead of 4.

# Install libvirt clients and daemon system, python3-pip and pip install vbmc
sudo apt-get install libvirt-clients libvirt-daemon-system
sudo apt-get install python3-pip
pip install vbmc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pip install vbmc
pip install vbmc

pip installing stuff into the user's environment is not nice. How about creating virtualenv first?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this utilizes sudo many times, consider checking if user is not root, and failing, and documenting it that it needs to be run sudo ./run_local_bmh_test_setup.sh instead.

@dtantsur
Copy link
Member

dtantsur commented Dec 8, 2023

The virsh/vbmc code gets copied over and over again. There is metal3-dev-env, there is now code in test/e2e. Could you maybe find a common place, ideally in metal3-dev-env? Maybe split some playbooks out of it?

Also, I'd recommend using sushy-tools instead of vbmc.

@lentzi90
Copy link
Member

The virsh/vbmc code gets copied over and over again. There is metal3-dev-env, there is now code in test/e2e. Could you maybe find a common place, ideally in metal3-dev-env? Maybe split some playbooks out of it?

Also, I'd recommend using sushy-tools instead of vbmc.

I explicitly want to get rid of the need for metal3-dev-env for these things. If it was just providing the VMs and BareMetalHosts fine, but it does way too much, which makes it extremely hard to work with.
However, I agree that we should not replicate this all over the place. I hope we can have a common way to initialize the BMO e2e tests and this tilt/dev setup. In the long term I think we may end up writing a little go-tool for it. Similar to make-bm-worker and make-virt-host.

@peppi-lotta peppi-lotta force-pushed the feature/add-bmh-button-tilt-PEPPI branch from 1ce8422 to 993339b Compare December 11, 2023 07:51
Copy link
Member

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small nits.

# Set default values
NAME="${1:?}"
VBMC_PORT="${2:?}"
CONSUMER="${3}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, now that you have set -u, this will fail unless $3 and $4 are provided.

You want to have

Suggested change
CONSUMER="${3}"
CONSUMER="${3:-}"

So at least empty value is substituted, which works nicely with the [[ -n ... ]] which we have later, since it is checking undefined or empty value.

NAME="${1:?}"
VBMC_PORT="${2:?}"
CONSUMER="${3}"
CONSUMER_NAMESPACE="${4}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

set -euxo pipefail

# Check if the script is run as root
if [[ $UID != 0 ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ $UID != 0 ]]; then
if [[ ${EUID} != 0 ]]; then

You should be checking effective UID, ${EUID} as that cannot be faked.


# Check if the script is run as root
if [[ $UID != 0 ]]; then
echo "This script must be run as root"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "This script must be run as root"
echo "ERROR: This script must be run as root"

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress @peppi-lotta !
This will make it much more enjoyable to work with BMO once finished 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reuse hack/e2e/net.xml instead of adding this?

Comment on lines 6 to 13
VM_LIST=$(virsh -c qemu:///system list --all --name)

# Loop through the list and delete each virtual machine
for vm_name in ${VM_LIST}; do
kubectl delete baremetalhost "${vm_name}"
virsh -c qemu:///system destroy --domain "${vm_name}"
virsh -c qemu:///system undefine --domain "${vm_name}" --remove-all-storage
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too dangerous. We should at least filter the VMs based on some prefix. How about we add a prefix to all created VMs and also mention this in the tilt UI so it is clear? Then we can filter for VMs with that prefix here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to split this so that we have one script for creating the VM and one for applying the BMH? Then we could reuse the first script in ci-e2e.sh and save some duplication 🙂

@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Dec 12, 2023
@peppi-lotta peppi-lotta force-pushed the feature/add-bmh-button-tilt-PEPPI branch from 58ccde7 to 26ddbe5 Compare December 12, 2023 09:09
@metal3-io-bot metal3-io-bot removed the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Dec 12, 2023
@peppi-lotta
Copy link
Member Author

/test-centos-e2e-integration-main
/test-ubuntu-integration-main

@mquhuy
Copy link
Member

mquhuy commented Dec 14, 2023

/test-ubuntu-integration-main

@mquhuy
Copy link
Member

mquhuy commented Dec 14, 2023

A minor comment: This PR currently has 4 commits, but most of them either fix issues from previous ones, or merge another branch onto this one. Maybe consider squashing them all to one?

Copy link
Member

@mquhuy mquhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits


# Install virtinst, libvirt clients and daemon system
apt-get -y update
apt-get -y install virtinst libvirt-clients libvirt-daemon-system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we decided to only support Tilt in Ubuntu/Debian? If so, could you update the README with that information?

Tiltfile Outdated
icon_name='add_box',
text='Add New baremetalhost',
inputs=[
text_input('NAME', '"bmh-tes-" is automatically added to the begining of the name. This naming convention is later used to clean the local testing environment.'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. It should be "bmh-test-"

sudo tools/bmh_test/run_local_bmh_test_setup.sh
```

The network, VBMC, virtual vbmc environment and virtual machines can be run down with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo "clean up" might be a better wording than "run down", at least I wouldn't understand that term.

@peppi-lotta peppi-lotta force-pushed the feature/add-bmh-button-tilt-PEPPI branch 2 times, most recently from d59909a to 943d3d0 Compare December 15, 2023 10:10
@peppi-lotta
Copy link
Member Author

/test-centos-e2e-integration-main
/test-ubuntu-integration-main

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice progress! I was able to test this locally and it worked! 🎉
A couple of comments below

tools/bmh_test/create_bmh.sh <NAME> <VBMC_PORT>
```

and adds the values given to the button as arguments. Controlplane host can be created with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but was a bit hard to understand I think. Or maybe I am using it wrong. 😅 Could you make it so the drop down where we add the value also has a button for creating?
Current flow:

  1. drop down and fill in values
  2. "go back" and press the +

What I was thinking is like in CAPI:

  1. drop down and fill in values
  2. below the values press "Create"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to find a way to make this work in the second way. For what I was able to find Tilt doesn't support adding buttons to the drop down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I was confusing myself. It looks different in different places apparently. The button is good 👍

Comment on lines 9 to 17
# Check if the script is run as root
if [[ $EUID != 0 ]]; then
echo "ERROR: This script must be run as root"
exit 1
fi

# Install virtinst, libvirt clients and daemon system
apt-get -y update
apt-get -y install virtinst libvirt-clients libvirt-daemon-system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather check that virt-install is available end error out if not. So instead of trying to install these things, explain to the developer what is needed and let them set it up as they want.
We can also skip the root requirement then.

@peppi-lotta
Copy link
Member Author

/test-ubuntu-integration-main
/test-centos-e2e-integration-main

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I was able to confirm that this is working nicely now!
Just one nit below

tools/bmh_test/run_local_bmh_test_setup.sh Outdated Show resolved Hide resolved
@peppi-lotta peppi-lotta force-pushed the feature/add-bmh-button-tilt-PEPPI branch from 266bb6c to 925c12c Compare December 21, 2023 10:26
@lentzi90
Copy link
Member

Looks like something happened when rebasing so now there are 2 commits 🤔
Maybe some merge conflict? Can you try fixing that and push again?
Other than that it looks great!

@peppi-lotta peppi-lotta force-pushed the feature/add-bmh-button-tilt-PEPPI branch from 925c12c to 79af5f8 Compare December 21, 2023 10:55
@peppi-lotta
Copy link
Member Author

/test-ubuntu-integration-main
/test-centos-e2e-integration-main

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 22, 2023
@maxrantil
Copy link

LGTM

Copy link
Member

@kashifest kashifest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
Nits only!
/hold

@@ -174,6 +174,32 @@ refer to
[the development setup guide of CAPM3](https://github.com/metal3-io/cluster-api-provider-metal3/blob/main/docs/dev-setup.md#tilt-for-dev-in-capm3)
and specially the [Baremetal Operator Integration](https://github.com/metal3-io/cluster-api-provider-metal3/blob/main/docs/dev-setup.md#including-baremetal-operator-and-ip-address-manager)

### Making (virtual) BareMetalHosts with Tilt interface

Virtinst, libvirt-clients, libvirt-daemon-system, and [Virtualbmc](https://pypi.org/project/virtualbmc/) are required to to create BareMetalHosts this way. The network and VBMC needed for making a BareMetalHosts can be initialized with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Virtinst, libvirt-clients, libvirt-daemon-system, and [Virtualbmc](https://pypi.org/project/virtualbmc/) are required to to create BareMetalHosts this way. The network and VBMC needed for making a BareMetalHosts can be initialized with
Virtinst, libvirt-clients, libvirt-daemon-system, and [Virtualbmc](https://pypi.org/project/virtualbmc/) are required to create BareMetalHosts this way. The network and VBMC needed for making a BareMetalHosts can be initialized with

tools/bmh_test/create_bmh.sh <NAME> <VBMC_PORT>
```

and adds the values given to the button as arguments. Controlplane host can be created with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now forgetting the convention of this but I think we should rather write ControlPlane instead of Controlplane but please check it.

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 8, 2024
@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kashifest

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 8, 2024
@lentzi90
Copy link
Member

@peppi-lotta do you want to fix the nits here or in a follow up? This looks good to merge just need to remove the hold

@peppi-lotta
Copy link
Member Author

@peppi-lotta do you want to fix the nits here or in a follow up? This looks good to merge just need to remove the hold

I'll do it on a follow up.

@lentzi90
Copy link
Member

/unhold

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 18, 2024
@lentzi90
Copy link
Member

/metal3-bmo-e2e-test

@metal3-io-bot metal3-io-bot merged commit 3f691c1 into metal3-io:main Jan 18, 2024
18 checks passed
@metal3-io-bot metal3-io-bot deleted the feature/add-bmh-button-tilt-PEPPI branch January 18, 2024 08:53
@adilGhaffarDev adilGhaffarDev changed the title ✨ Develop User-Friendly baremetalhost creation for Tilt interface 🌱 Develop User-Friendly baremetalhost creation for Tilt interface Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Develop User-Friendly baremetalhost creation for Tilt interface
8 participants