Skip to content

Commit

Permalink
Add script to generate multiple fake nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mquhuy committed Mar 31, 2023
1 parent f00b635 commit 08e1c15
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
REGISTRY_NAME="registry"
REGISTRY_PORT="5000"
IMAGE_NAMES=(
"quay.io/metal3-io/sushy-tools"
"quay.io/metal3-io/ironic-python-agent"
# "quay.io/metal3-io/sushy-tools"
"quay.io/metal3-io/ironic-ipa-downloader"
"quay.io/metal3-io/ironic:latest"
"quay.io/metal3-io/ironic-client"
Expand All @@ -18,6 +19,8 @@ if ! podman ps | grep -q "$REGISTRY_NAME"; then
podman run -d -p "$REGISTRY_PORT":"$REGISTRY_PORT" --name "$REGISTRY_NAME" docker.io/library/registry:2.7.1
fi

podman pod create -n infra-pod || true
podman pod create -n ironic-pod || true
# Pull images, tag to local registry, and push to registry
for NAME in "${IMAGE_NAMES[@]}"; do
# Pull and tag the image
Expand All @@ -29,7 +32,9 @@ done

# Define variables for repeated values
IRONIC_IMAGE="127.0.0.1:5000/localimages/ironic:latest"
SUSHY_TOOLS_IMAGE="127.0.0.1:5000/localimages/sushy-tools"
# SUSHY_TOOLS_IMAGE="127.0.0.1:5000/localimages/sushy-tools"
# FAKEIPA_IMAGE="127.0.0.1:5000/localimages/fakeipa"
SUSHY_TOOLS_IMAGE="127.0.0.1:5000/localimages/fakeipa"
LIBVIRT_URI="qemu+ssh://root@192.168.111.1/system?&keyfile=/root/ssh/id_rsa_virt_power&no_verify=1&no_tty=1"
API_URL="http://172.22.0.2:6385"
CALLBACK_URL="http://172.22.0.2:5050/v1/continue"
Expand All @@ -54,6 +59,35 @@ podman run -d --net host --name httpd-infra \
-e LISTEN_ALL_INTERFACES=false \
--entrypoint /bin/runhttpd \
"$IRONIC_IMAGE"

macgen(){
openssl rand -hex 6 | sed 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1:\2:\3:\4:\5:\6/'
}

rm -f nodes.json
echo [] > nodes.json

for i in $(seq 1 ${NUM_NODES:-100}); do
uuid=$(uuidgen)
macaddr=$(macgen)
name="fake${i}"
jq --arg node_name "${name}" \
--arg uuid "${uuid}" \
--arg macaddr "${macaddr}" \
'{
"uuid": $uuid,
"name": $node_name,
"power_state": "Off",
"nics": [
{"mac": $macaddr, "ip": "172.0.0.100"}
]
}' nodes_template.json > node.json

jq -s '.[0] + [.[1] ]' nodes.json node.json > tmp.json
rm -f nodes.json
mv tmp.json nodes.json
done
rm node.json
# Set configuration options
cat <<EOF >/opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/conf.py
import collections
Expand All @@ -69,11 +103,12 @@ SUSHY_EMULATOR_FAKE_DRIVER = True
FAKE_IPA_API_URL = "${API_URL}"
FAKE_IPA_INSPECTION_CALLBACK_URL = "${CALLBACK_URL}"
FAKE_IPA_ADVERTISE_ADDRESS = Host(hostname="${ADVERTISE_HOST}", port="${ADVERTISE_PORT}")
SUSHY_EMULATOR_FAKE_SYSTEMS = $(cat nodes.json)
EOF

# Create an htpasswd file
cat <<EOF >/opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/htpasswd
admin:$2b${12}$/dVOBNatORwKpF.ss99KB.vESjfyONOxyH.UgRwNyZi1Xs/W2pGVS
cat <<'EOF' > /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/htpasswd
admin:$2b$12$/dVOBNatORwKpF.ss99KB.vESjfyONOxyH.UgRwNyZi1Xs/W2pGVS
EOF

# Generate ssh keys to use for virtual power and add them to authorized_keys
Expand All @@ -85,3 +120,10 @@ podman run -d --net host --name sushy-tools --pod infra-pod \
-v /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools:/root/sushy \
-v /root/.ssh:/root/ssh \
"${SUSHY_TOOLS_IMAGE}"

# Create and start a container for fake-ipa
podman run --entrypoint='["sushy-fake-ipa", "--config", "/root/sushy/conf.py"]' \
-d --net host --name fake-ipa --pod infra-pod \
-v /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools:/root/sushy \
-v /root/.ssh:/root/ssh \
"${SUSHY_TOOLS_IMAGE}"
12 changes: 0 additions & 12 deletions Support/Multitenancy/ironic-env/05-apply-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,3 @@ clouds:
EOF
sudo chmod a+x ironicclient.sh
sudo ln -sf "$PWD/ironicclient.sh" "/usr/local/bin/baremetal"

# Create ironic node

baremetal node create --driver redfish --driver-info \
redfish_address=http://192.168.111.1:8000 --driver-info \
redfish_system_id=/redfish/v1/Systems/27946b59-9e44-4fa7-8e91-f3527a1ef094 --driver-info \
redfish_username=admin --driver-info redfish_password=password \
--name default-node

# baremetal node manage $NODE_UUID
# get mac : virsh domiflist vmname
# baremetal port create 00:5c:52:31:3a:9c --node $NODE_UUID
62 changes: 62 additions & 0 deletions Support/Multitenancy/ironic-env/06-create-nodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# for node in $(jq -c '.[]' nodes.json); do
# uuid=$(echo ${node} | jq -r '.uuid')
# node_name=$(echo ${node} | jq -r '.name')
# baremetal node create --driver redfish --driver-info \
# redfish_address=http://192.168.111.1:8000 --driver-info \
# redfish_system_id=/redfish/v1/Systems/${uuid} --driver-info \
# redfish_username=admin --driver-info redfish_password=password \
# --uuid ${uuid} \
# --name ${node_name}
# done
#
# sleep 10
nodes=$(baremetal node list -f json)
n_nodes=$(echo ${nodes} | jq -c '.[]' | wc -l)
inspected_nodes=""
while true; do
nodes=$(baremetal node list -f json)
for row in $(echo $nodes | jq -c -r '.[] | @base64'); do
node=$(echo ${row} | base64 --decode)
node_name=$(echo ${node} | jq -r '.Name')
provisioning_state=$(echo ${node} | jq -r '."Provisioning State"')
if [[ $provisioning_state == "enroll" ]]; then
baremetal node manage ${node_name}
continue
fi
if [[ $provisioning_state == "verifying" ]]; then
continue
fi
power_state=$(echo ${node} | jq -r '."Power State"')
if [[ $power_state == "power off" ]]; then
baremetal node power on ${node_name}
continue
fi
if [[ $provisioning_state == "inspect wait" ]]; then
continue
fi
if [[ $provisioning_state == "manageable" ]]; then
inspection_info=$(baremetal node show $node_name -f json | jq -r '.inspection_finished_at')
if [[ $inspection_info == "null" ]]; then
baremetal node inspect ${node_name}
else
if [[ $inspected_nodes == *$node_name* ]]; then
continue
fi
inspected_nodes="${inspected_nodes} ${node_name}"
echo "${node_name} was inspected at ${inspection_info}"
if [[ $(echo $inspected_nodes | wc -w) == $n_nodes ]]; then
exit 0
fi
fi
fi
if [[ $provisioning_state == "inspect failed" ]]; then
inspected_nodes="${inspected_nodes} ${node_name}"
echo "Failed to inspect ${node_name}"
if [[ $(echo $inspected_nodes | wc -w) == $n_nodes ]]; then
exit 0
fi
fi
done
done
1 change: 1 addition & 0 deletions Support/Multitenancy/ironic-env/Init-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ sudo ./01-vm-setup.sh
sudo ./03-images-and-run-local-services.sh
./04-start-minikube.sh
./05-apply-manifests.sh
./06-create-nodes.sh
2 changes: 1 addition & 1 deletion Support/Multitenancy/ironic-env/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ minikube stop
minikube delete --all --purge

# Stop and delete containers
containers=("sushy-tools" "ironic-ipa-downloader" "ironic" "keepalived" "registry" "ironic-client")
containers=("sushy-tools" "ironic-ipa-downloader" "ironic" "keepalived" "registry" "ironic-client", "fake-ipa")
for container in "${containers[@]}"; do
echo "Deleting the container: $container"
sudo podman stop "$container" &>/dev/null
Expand Down
7 changes: 7 additions & 0 deletions Support/Multitenancy/ironic-env/get_ironic_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
#
NS="baremetal-operator-system"
podName=$(kubectl -n $NS get pod -o json | jq -r '.items | .[].metadata.name' | grep "ironic" )

rm -f ironic.log
kubectl -n $NS logs $podName -c ironic > ironic.log
8 changes: 8 additions & 0 deletions Support/Multitenancy/ironic-env/nodes_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"uuid": "foo-uuid",
"name": "foo-name",
"power_state": "Off",
"nics": [
{"mac": "foo-address", "ip": "172.0.0.100"}
]
}

0 comments on commit 08e1c15

Please sign in to comment.