Skip to content

Commit

Permalink
Merge pull request #561 from hjensas/03-standalone-ironic
Browse files Browse the repository at this point in the history
Allow deploying Standalone with ironic as the compute driver
  • Loading branch information
openshift-ci[bot] authored Oct 5, 2023
2 parents c1c1cfd + 8b43c1e commit b8b9776
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 241 deletions.
27 changes: 24 additions & 3 deletions devsetup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ CRC_DEFAULT_NETWORK_IP ?= 192.168.122.10
EDPM_COMPUTE_SUFFIX ?= 0
# EDPM_COMPUTE_ADDITIONAL_NETWORKS: JSON string - list of additional networks
# Examples:
# EDPM_COMPUTE_ADDITIONAL_NETWORKS='[{"type": "network", "name": "crc-bmaas"}]'
# cat << EOF
# [
# {
# "type": "network",
# "name": "crc-bmaas",
# "standalone_config": {
# "type": "linux_bridge",
# "name": "baremetal",
# "mtu": 1500,
# "ip_subnet": "172.20.1.0/24",
# "allocation_pools": [
# {
# "start": "172.20.1.4",
# "end": "172.20.1.250"
# }
# ]
# }
# }
# ]
# EOF
# EDPM_COMPUTE_ADDITIONAL_NETWORKS=$(jq -c addtional_nets.json)
EDPM_COMPUTE_ADDITIONAL_NETWORKS ?= '[]'
EDPM_TOTAL_NODES ?= 1
Expand Down Expand Up @@ -38,6 +57,8 @@ BM_NODE_COUNT ?=1
BM_ROOT_PASSWORD_SECRET ?=
BMH_NAMESPACE ?=openstack

STANDALONE_COMPUTE_DRIVER ?= libvirt

CLEANUP_DIR_CMD ?= rm -Rf

define vars
Expand Down Expand Up @@ -137,7 +158,7 @@ edpm_compute: ## Create EDPM compute VM
$(eval $(call vars))
scripts/gen-ansibleee-ssh-key.sh
if [ ${EDPM_TOTAL_NODES} -eq 1 ]; then \
scripts/gen-edpm-compute-node.sh ${EDPM_COMPUTE_SUFFIX} '${EDPM_COMPUTE_ADDITIONAL_NETWORKS}' ; \
scripts/gen-edpm-compute-node.sh ${EDPM_COMPUTE_SUFFIX} '${EDPM_COMPUTE_ADDITIONAL_NETWORKS}'; \
else \
for INDEX in $(shell seq 0 $$((${EDPM_TOTAL_NODES} -1))) ; do \
scripts/gen-edpm-compute-node.sh $$INDEX '${EDPM_COMPUTE_ADDITIONAL_NETWORKS}' ; \
Expand Down Expand Up @@ -177,7 +198,7 @@ standalone: export STANDALONE=true
standalone: export INTERFACE_MTU=${NETWORK_MTU}
standalone: edpm_compute ## Create standalone VM
$(eval $(call vars))
scripts/standalone.sh ${EDPM_COMPUTE_SUFFIX}
scripts/standalone.sh ${EDPM_COMPUTE_SUFFIX} ${STANDALONE_COMPUTE_DRIVER} '${EDPM_COMPUTE_ADDITIONAL_NETWORKS}'

.PHONY: standalone_cleanup
standalone_cleanup: export STANDALONE=true
Expand Down
42 changes: 42 additions & 0 deletions devsetup/scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Copyright 2023 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

#---
## Jinja2 template render function
# Parameter #1 is the Jinja2 template file
# Parameter #2 is the YAML/JSON file with Jinja2 variable definitions
#---
function jinja2_render {
local j2_template_file
local j2_vars
j2_template_file=$1
j2_vars_file=$2

/usr/bin/python3 -c "
import yaml
import jinja2
with open('$j2_vars_file', 'r') as f:
vars = yaml.safe_load(f.read())
with open('$j2_template_file', 'r') as f:
template = f.read()
j2_template = jinja2.Template(template)
print(j2_template.render(**vars))
"
}
78 changes: 65 additions & 13 deletions devsetup/scripts/standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
# License for the specific language governing permissions and limitations
# under the License.
set -ex

MY_TMP_DIR="$(mktemp -d)"
trap 'rm -rf -- "$MY_TMP_DIR"' EXIT

export VIRSH_DEFAULT_CONNECT_URI=qemu:///system
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
EDPM_COMPUTE_SUFFIX=${1:-"0"}
COMPUTE_DRIVER=${2:-"libvirt"}
EDPM_COMPUTE_ADDITIONAL_NETWORKS=${3:-'[]'}
EDPM_COMPUTE_NAME=${EDPM_COMPUTE_NAME:-"edpm-compute-${EDPM_COMPUTE_SUFFIX}"}
EDPM_COMPUTE_NETWORK=${EDPM_COMPUTE_NETWORK:-default}
EDPM_COMPUTE_NETWORK_IP=$(virsh net-dumpxml ${EDPM_COMPUTE_NETWORK} | xmllint - --xpath 'string(/network/ip/@address)')
Expand All @@ -26,16 +32,18 @@ GATEWAY=${GATEWAY:-"${EDPM_COMPUTE_NETWORK_IP}"}
OUTPUT_DIR=${OUTPUT_DIR:-"${SCRIPTPATH}/../../out/edpm/"}
SSH_KEY_FILE=${SSH_KEY_FILE:-"${OUTPUT_DIR}/ansibleee-ssh-key-id_rsa"}
SSH_OPT="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $SSH_KEY_FILE"
REPO_SETUP_CMDS=${REPO_SETUP_CMDS:-"/tmp/standalone_repos"}
CMDS_FILE=${CMDS_FILE:-"/tmp/standalone_cmds"}
REPO_SETUP_CMDS=${REPO_SETUP_CMDS:-"${MY_TMP_DIR}/standalone_repos"}
CMDS_FILE=${CMDS_FILE:-"${MY_TMP_DIR}/standalone_cmds"}
SKIP_TRIPLEO_REPOS=${SKIP_TRIPLEO_REPOS:="false"}
CLEANUP_DIR_CMD=${CLEANUP_DIR_CMD:-"rm -Rf"}

if [[ ! -f $SSH_KEY_FILE ]]; then
echo "$SSH_KEY_FILE is missing"
exit 1
fi

source ${SCRIPTPATH}/common.sh


# Clock synchronization is important for both Ceph and OpenStack services, so both ceph deploy and tripleo deploy commands will make use of chrony to ensure the clock is properly in sync.
# We'll use the NTP_SERVER environmental variable to define the NTP server to use.
# If we are running alls these commands in a system inside the Red Hat network we should use the clock.corp.redhat.com server:
Expand All @@ -44,7 +52,7 @@ fi
# export NTP_SERVER=pool.ntp.org

if [[ ! -f $REPO_SETUP_CMDS ]]; then
cat <<EOF > $REPO_SETUP_CMDS
cat <<EOF > $REPO_SETUP_CMDS
set -ex
sudo dnf remove -y epel-release
sudo dnf update -y
Expand All @@ -65,7 +73,8 @@ else
HOST_PRIMARY_RESOLV_CONF_ENTRY=${HOST_PRIMARY_RESOLV_CONF_ENTRY:-$GATEWAY}
fi

cat <<EOF > $CMDS_FILE
if [[ ! -f $CMDS_FILE ]]; then
cat <<EOF > $CMDS_FILE
sudo dnf install -y podman python3-tripleoclient util-linux lvm2 cephadm
# Pin Podman to work around a Podman regression where env variables
Expand All @@ -81,6 +90,7 @@ export INTERFACE_MTU=${INTERFACE_MTU:-1500}
export NTP_SERVER=${NTP_SERVER:-"clock.corp.redhat.com"}
export EDPM_COMPUTE_CEPH_ENABLED=${EDPM_COMPUTE_CEPH_ENABLED:-true}
export CEPH_ARGS="${CEPH_ARGS:--e \$HOME/deployed_ceph.yaml -e /usr/share/openstack-tripleo-heat-templates/environments/cephadm/cephadm-rbd-only.yaml}"
export COMPUTE_DRIVER=${COMPUTE_DRIVER:-"libvirt"}
export IP=${IP}
export GATEWAY=${GATEWAY}
Expand All @@ -94,22 +104,67 @@ else
sed -i 's|quay.io/tripleowallaby$|quay.io/tripleowallabycentos9|' \$HOME/containers-prepare-parameters.yaml
fi
/tmp/network.sh
# Use os-net-config to add VLAN interfaces which connect edpm-compute-0 to the isolated networks configured by install_yamls.
sudo mkdir -p /etc/os-net-config
cat << __EOF__ | sudo tee /etc/cloud/cloud.cfg.d/99-edpm-disable-network-config.cfg
network:
config: disabled
__EOF__
sudo systemctl enable network
sudo cp /tmp/net_config.yaml /etc/os-net-config/config.yaml
sudo os-net-config -c /etc/os-net-config/config.yaml
#---
## Copying files
#---
# Use /tmp/net_config.yaml as the network config template for Standalone
# so that tripleo deploy don't change the config applied above.
sudo cp /tmp/net_config.yaml \$HOME/standalone_net_config.j2
sudo cp /tmp/network_data.yaml \$HOME/network_data.yaml
sudo cp /tmp/deployed_network.yaml \$HOME/deployed_network.yaml
sudo cp /tmp/Standalone.yaml \$HOME/Standalone.yaml
#----
[[ "\$EDPM_COMPUTE_CEPH_ENABLED" == "true" ]] && /tmp/ceph.sh
/tmp/openstack.sh
EOF
fi

while [[ $(ssh -o BatchMode=yes -o ConnectTimeout=5 $SSH_OPT root@$IP echo ok) != "ok" ]]; do
true
done

# Render Jinja2 files
J2_VARS_FILE=$(mktemp --suffix=".yaml" --tmpdir="${MY_TMP_DIR}")
cat << EOF > ${J2_VARS_FILE}
---
additional_networks: ${EDPM_COMPUTE_ADDITIONAL_NETWORKS}
ctlplane_cidr: 24
ctlplane_ip: ${IP}
ctlplane_subnet: ${IP%.*}.0/24
ctlplane_vip: ${IP%.*}.99
ip_address_suffix: ${IP_ADRESS_SUFFIX}
interface_mtu: ${INTERFACE_MTU:-1500}
gateway_ip: ${GATEWAY}
dns_server: ${HOST_PRIMARY_RESOLV_CONF_ENTRY}
compute_driver: ${COMPUTE_DRIVER}
EOF

jinja2_render standalone/network_data.j2 "${J2_VARS_FILE}" > ${MY_TMP_DIR}/network_data.yaml
jinja2_render standalone/deployed_network.j2 "${J2_VARS_FILE}" > ${MY_TMP_DIR}/deployed_network.yaml
jinja2_render standalone/net_config.j2 "${J2_VARS_FILE}" > ${MY_TMP_DIR}/net_config.yaml
jinja2_render standalone/role.j2 "${J2_VARS_FILE}" > ${MY_TMP_DIR}/Standalone.yaml

# Copying files
scp $SSH_OPT $REPO_SETUP_CMDS root@$IP:/tmp/repo-setup.sh
scp $SSH_OPT $CMDS_FILE root@$IP:/tmp/standalone-deploy.sh
scp $SSH_OPT standalone/standalone.j2 root@$IP:/tmp/standalone.j2
scp $SSH_OPT standalone/network_data.yaml root@$IP:/tmp/network_data.yaml
scp $SSH_OPT standalone/deployed_network.yaml root@$IP:/tmp/deployed_network.yaml
scp $SSH_OPT standalone/network.sh root@$IP:/tmp/network.sh
scp $SSH_OPT ${MY_TMP_DIR}/net_config.yaml root@$IP:/tmp/net_config.yaml
scp $SSH_OPT ${MY_TMP_DIR}/network_data.yaml root@$IP:/tmp/network_data.yaml
scp $SSH_OPT ${MY_TMP_DIR}/deployed_network.yaml root@$IP:/tmp/deployed_network.yaml
scp $SSH_OPT ${MY_TMP_DIR}/Standalone.yaml root@$IP:/tmp/Standalone.yaml
scp $SSH_OPT standalone/ceph.sh root@$IP:/tmp/ceph.sh
scp $SSH_OPT standalone/openstack.sh root@$IP:/tmp/openstack.sh
[ -f $HOME/.ssh/id_ecdsa.pub ] || \
Expand All @@ -128,6 +183,3 @@ if [[ -z ${SKIP_TRIPLEO_REPOS} || ${SKIP_TRIPLEO_REPOS} == "false" ]]; then
fi
ssh $SSH_OPT root@$IP "bash /tmp/standalone-deploy.sh"
ssh $SSH_OPT root@$IP "rm -f /tmp/standalone-deploy.sh"

${CLEANUP_DIR_CMD} $CMDS_FILE
${CLEANUP_DIR_CMD} $REPO_SETUP_CMDS
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,43 @@ parameter_defaults:
NodePortMap:
standalone:
ctlplane:
ip_address: CTLPLANE_IP
ip_subnet: CTLPLANE_SUBNET.1/24
ip_address_uri: CTLPLANE_IP
ip_address: {{ ctlplane_ip }}
ip_subnet: {{ ctlplane_subnet }}
ip_address_uri: {{ ctlplane_ip }}
storage:
ip_address: 172.18.0.100
ip_address: 172.18.0.{{ ip_address_suffix }}
ip_subnet: 172.18.0.1/24
ip_address_uri: 172.18.0.100
ip_address_uri: 172.18.0.{{ ip_address_suffix }}
storage_mgmt:
ip_address: 172.20.0.100
ip_address: 172.20.0.{{ ip_address_suffix }}
ip_subnet: 172.20.0.1/24
ip_address_uri: 172.20.0.100
ip_address_uri: 172.20.0.{{ ip_address_suffix }}
internal_api:
ip_address: 172.17.0.100
ip_address: 172.17.0.{{ ip_address_suffix }}
ip_subnet: 172.17.0.1/24
ip_address_uri: 172.17.0.100
ip_address_uri: 172.17.0.{{ ip_address_suffix }}
tenant:
ip_address: 172.19.0.100
ip_address: 172.19.0.{{ ip_address_suffix }}
ip_subnet: 172.19.0.1/24
ip_address_uri: 172.19.0.100
ip_address_uri: 172.19.0.{{ ip_address_suffix }}
external:
ip_address: 172.21.0.100
ip_address: 172.21.0.{{ ip_address_suffix }}
ip_subnet: 172.21.0.1/24
ip_address_uri: 172.21.0.100
ip_address_uri: 172.21.0.{{ ip_address_suffix }}
{%- for network in additional_networks if network.standalone_config %}
{%- set net = network.standalone_config %}
{{ net.name.lower() }}:
ip_address: {{ net.ip_subnet.split('/')[0].split('.')[:-1] | join('.') + '.' + ip_address_suffix | string }}
ip_subnet: {{ net.ip_subnet }}
ip_address_uri: {{ net.ip_subnet.split('/')[0].split('.')[:-1] | join('.') + '.' + ip_address_suffix | string }}
{%- endfor %}
ControlPlaneVipData:
fixed_ips:
- ip_address: CTLPLANE_VIP
- ip_address: {{ ctlplane_vip }}
name: control_virtual_ip
network:
tags:
- CTLPLANE_SUBNET.0/24
- {{ ctlplane_subnet }}
subnets:
- ip_version: 4
VipPortMap:
Expand All @@ -64,6 +71,13 @@ parameter_defaults:
ip_address: 172.21.0.2
ip_address_uri: 172.21.0.2
ip_subnet: 172.21.0.2/24
{%- for network in additional_networks if network.standalone_config and network.standalone_config.vip %}
{%- set net = network.standalone_config %}
{{ net.name.lower() }}:
ip_address: {{ net.ip_subnet.split('/')[0].split('.')[:-1] | join('.') + '.2' }}
ip_address_uri: {{ net.ip_subnet.split('/')[0].split('.')[:-1] | join('.') + '.2' }}
ip_subnet: {{ net.ip_subnet }}
{%- endfor %}
DeployedNetworkEnvironment:
net_cidr_map:
storage:
Expand All @@ -76,12 +90,21 @@ parameter_defaults:
- 172.19.0.0/24
external:
- 172.21.0.0/24
{%- for network in additional_networks if network.standalone_config %}
{%- set net = network.standalone_config %}
{{ net.name.lower() }}:
- {{ net.ip_subnet }}
{%- endfor %}
net_ip_version_map:
storage: 4
storage_mgmt: 4
internal_api: 4
tenant: 4
external: 4
{%- for network in additional_networks if network.standalone_config %}
{%- set net = network.standalone_config %}
{{ net.name.lower() }}: 4
{%- endfor %}
net_attributes_map:
storage:
network:
Expand Down Expand Up @@ -173,3 +196,23 @@ parameter_defaults:
host_routes: []
ip_version: 4
name: external_subnet
{%- for network in additional_networks if network.standalone_config %}
{%- set net = network.standalone_config %}
{{ net.name.lower() }}:
network:
dns_domain: {{ net.name.lower() }}.mydomain.tld.
mtu: {{ net.mtu | default(1500) }}
name: {{ net.name.lower() }}
tags:
- tripleo_network_name={{ net.name }}
- tripleo_net_idx=0
- tripleo_vip={{ net.vip | string | lower }}
subnets:
{{ net.name.lower() }}_subnet:
cidr: {{ net.ip_subnet }}
dns_nameservers: {{ net.dns_nameservers | default([]) }}
gateway_ip: {{ net.gateway_ip | default('null') }}
host_routes: {{ net.host_routes | default([]) }}
ip_version: 4
name: {{ net.name.lower() }}_subnet
{%- endfor %}
Loading

0 comments on commit b8b9776

Please sign in to comment.