diff --git a/devstack/lib/ironic b/devstack/lib/ironic index f622fde4dc..81b3089916 100644 --- a/devstack/lib/ironic +++ b/devstack/lib/ironic @@ -2641,6 +2641,12 @@ function configure_ngs_for_simulator { switch_pass="system_s3cret!" enable_pass="" ;; + sonic) + switch_type="netmiko_sonic" + trunk_port="Ethernet0" + switch_pass="YourPaSsWoRd" + enable_pass="" + ;; esac # NOTE(TheJulia) This is for a dell force10 switch, and it may need # to be broken up to be more in-line with per-type options. @@ -2684,6 +2690,9 @@ function create_network_simulator_vm { cisco_nexus9k) create_network_simulator_vm_cisco_nexus $2 $3 ;; + sonic) + create_network_simulator_vm_sonic $2 $3 + ;; esac } @@ -2944,6 +2953,65 @@ function create_network_simulator_vm_cisco_nexus { send_switch_config_line localhost 55001 "copy run start" } # End of Cisco Nexus 9k simulator setup +function create_network_simulator_vm_sonic { + local sonic_image=/opt/stack/sonic-vs.img + if [ ! -f $sonic_image ]; then + sonic_url=$(curl -s https://sonic.software/builds.json | jq -r '.["master"]["sonic-vs.img.gz"]["url"]') + wget -O $sonic_image.gz $sonic_url + gzip -d $sonic_image.gz + fi + cp $sonic_image $sonic_image.qcow2 + # For extra context: + # * 4GB of RAM + # * e1000 interfaces + # * virtio disk interface + # * boot_priority set to d + # First port is mapped to eth0. + # The VM will crash if the first interface is not present. + local emu_cmd="$IRONIC_VM_EMULATOR -enable-kvm -drive file=$sonic_image.qcow2,id=disk0,format=qcow2,if=none --device virtio-blk-pci,drive=disk0 -m 4096M -smp cpus=2 -display none -serial telnet:localhost:55001,server,nowait " + + # Base interfaces, attaches the trunk and the management interfaces. + emu_cmd+=" -device e1000,netdev=net0 -netdev tap,id=net0,ifname=$1,script=no,downscript=no -device e1000,netdev=net1 -netdev tap,id=net1,ifname=$2,script=no,downscript=no,sndbuf=1048576" + + # Get a list of links, cut everything *after* "@" since taps duplicate + # entries, limit to "sim-node" to match our nodes, and extract only + # the actual interface name. + local net_interface=2 + for i in $(ip link show up |cut -f1 -d "@" |grep "sim-node"|cut -f2 -d" "|cut -d":" -f1|sed s/sim/sw/g); do + emu_cmd+=" -device e1000,netdev=net$net_interface -netdev tap,id=net$net_interface,ifname=$i,sndbuf=1048576" + net_interface=$(( net_interface + 1)) + done + run_process ir-sw-sim "$emu_cmd" "root" "root" + # wait for the enable prompt + + wait_for_switch_prompt localhost 55001 80 10 "sonic login:" False + sleep 4 + + send_switch_config_line localhost 55001 admin + sleep 2 + send_switch_config_line localhost 55001 "YourPaSsWoRd" + sleep 10 + # SONiC doesn't provide a means for this configuration through the CLI + # https://github.com/sonic-net/SONiC/blob/master/doc/SONiC-User-Manual.md#31-configuring-management-interface-and-loopback-interface + send_switch_config_line localhost 55001 "sudo /sbin/ifconfig eth0 172.24.5.20/24" + send_switch_config_line localhost 55001 "sonic-cli" + send_switch_config_line localhost 55001 "configure terminal" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet0 10.0.0.0/31" + send_switch_config_line localhost 55001 "sudo config switchport mode trunk Ethernet0" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet4 10.0.0.2/31" + send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet4" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet8 10.0.0.4/31" + send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet8" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet12 10.0.0.6/31" + send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet12" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet16 10.0.0.8/31" + send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet16" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet20 10.0.0.10/31" + send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet20" + send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet24 10.0.0.12/31" + send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet24" +} # End of SONiC configuration + function wait_for_switch_prompt { local host=$1 local port=$2 @@ -2999,6 +3067,8 @@ function send_switch_config_line { # NOTE(TheJulia): *Always* strings the output, in case 0xFF can # break devstack's executor. echo "$cmd" | nc -w1 $host $port | strings + # Sleep briefy to allow the execution to occur and finish. + sleep 1 } function wait_for_nova_resources { @@ -3479,27 +3549,30 @@ function identify_port_for_switch { cisco_nexus9k) identify_cisco_nexus_port $vm_port ;; + sonic) + identify_sonic_port $vm_port + ;; esac } function identify_force10_port { case $1 in - ovs-node-0i1) + tap-node-0i1) echo -n "forty0/4" ;; - ovs-node-0i2) + tap-node-0i2) echo -n "forty0/8" ;; - ovs-node-1i1) + tap-node-1i1) echo -n "forty0/12" ;; - ovs-node-1i2) + tap-node-1i2) echo -n "forty0/16" ;; - ovs-node-2i1) + tap-node-2i1) echo -n "forty0/20" ;; - ovs-node-2i2) + tap-node-2i2) echo -n "forty0/24" ;; esac @@ -3507,22 +3580,22 @@ function identify_force10_port { function identify_force10_10_port { case $1 in - ovs-node-0i1) + tap-node-0i1) echo -n "ethernet1/1/2" ;; - ovs-node-0i2) + tap-node-0i2) echo -n "ethernet1/1/3" ;; - ovs-node-1i1) + tap-node-1i1) echo -n "ethernet1/1/4" ;; - ovs-node-1i2) + tap-node-1i2) echo -n "ethernet1/1/5" ;; - ovs-node-2i1) + tap-node-2i1) echo -n "ethernet1/1/6" ;; - ovs-node-2i2) + tap-node-2i2) echo -n "ethernet1/1/7" ;; esac @@ -3530,27 +3603,50 @@ function identify_force10_10_port { function identify_cisco_nexus_port { case $1 in - ovs-node-0i1) + tap-node-0i1) echo -n "ethernet1/2" ;; - ovs-node-0i2) + tap-node-0i2) echo -n "ethernet1/3" ;; - ovs-node-1i1) + tap-node-1i1) echo -n "ethernet1/4" ;; - ovs-node-1i2) + tap-node-1i2) echo -n "ethernet1/5" ;; - ovs-node-2i1) + tap-node-2i1) echo -n "ethernet1/6" ;; - ovs-node-2i2) + tap-node-2i2) echo -n "ethernet1/7" ;; esac } +function identify_sonic_port { + case $1 in + tap-node-0i1) + echo -n "Ethernet4" + ;; + tap-node-0i2) + echo -n "Ethernet8" + ;; + tap-node-1i1) + echo -n "Ethernet12" + ;; + tap-node-1i2) + echo -n "Ethernet16" + ;; + tap-node-2i1) + echo -n "Ethernet20" + ;; + tap-node-2i2) + echo -n "Ethernet24" + ;; + esac +} + function configure_iptables { # enable tftp natting for allowing connections to HOST_IP's tftp server diff --git a/devstack/tools/ironic/scripts/create-node.sh b/devstack/tools/ironic/scripts/create-node.sh index ba08bd972d..6949bde868 100755 --- a/devstack/tools/ironic/scripts/create-node.sh +++ b/devstack/tools/ironic/scripts/create-node.sh @@ -155,6 +155,6 @@ fi if [[ "${NET_SIMULATOR:-ovs}" == "ovs" ]]; then VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/ovs-/{print $5","$1}')|tr ' ' ';') else - VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/tap-/{print $5","$1}')|tr ' ' ';') + VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/tap-/{print $5","$3}')|tr ' ' ';') fi echo -n "$VM_MAC $VBMC_PORT $PDU_OUTLET"