modified to correct the labconfig.yaml and reserver more ip.
[joid.git] / ci / 03-maasdeploy.sh
index d74214b..3004e0a 100755 (executable)
@@ -2,7 +2,25 @@
 #placeholder for deployment script.
 set -ex
 
-source tools.sh
+source common/tools.sh
+
+
+usage() {
+  # no xtrace output
+  { set +x; } 2> /dev/null
+
+  echo "OPNFV JOID deployer of the MAAS (Metal as a Service) infrastructure."
+  echo "Usage: $0 custom <path_to_labconfig>"
+  echo "       $0 virtual"
+  exit ${1-0}
+}
+
+# Print usage help message if requested
+if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]
+then
+    usage;
+fi
+
 
 virtinstall=0
 labname=$1
@@ -27,40 +45,30 @@ NODE_ARC="$NODE_ARCHES/generic"
 
 # Install the packages needed
 echo_info "Installing and upgrading required packages"
+#sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5EDB1B62EC4926EA
+sudo apt-get update -y || true
 sudo apt-get install software-properties-common -y
 sudo apt-add-repository ppa:juju/stable -y
 sudo apt-add-repository ppa:maas/stable -y
-sudo apt-add-repository cloud-archive:ocata -y
-sudo apt-get update -y
+sudo apt-add-repository cloud-archive:pike -y
+if [ "aarch64" == "$NODE_ARCTYPE" ]; then
+sudo add-apt-repository ppa:ubuntu-cloud-archive/pike-staging -y
+fi
+sudo apt-get update -y || true
 #sudo apt-get dist-upgrade -y
+
 sudo apt-get install bridge-utils openssh-server bzr git virtinst qemu-kvm libvirt-bin \
              maas maas-region-controller juju python-pip python-psutil python-openstackclient \
              python-congressclient gsutil charm-tools pastebinit python-jinja2 sshpass \
-             openssh-server vlan ipmitool jq expect snap -y
+             openssh-server vlan ipmitool jq expect snap -y --allow-unauthenticated
 
-#sudo apt-get install snap -y
-#sudo snap install maas --classic
-#sudo snap install juju --classic
+if [ "aarch64" == "$NODE_ARCTYPE" ]; then
+    sudo apt-get install qemu qemu-efi qemu-system-aarch64 -y --allow-unauthenticated
+fi
 
 sudo -H pip install --upgrade pip
 
 
-usage() {
-  # no xtrace output
-  { set +x; } 2> /dev/null
-
-  echo "OPNFV JOID deployer of the MAAS (Metal as a Service) infrastructure."
-  echo "Usage: $0 custom <path_to_labconfig>"
-  echo "       $0 virtual"
-  exit ${1-0}
-}
-
-if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]
-then
-    usage;
-fi
-
-
 #
 # Config preparation
 #
@@ -219,14 +227,6 @@ fi
 sudo cat ~maas/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
 sudo cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
 
-#
-# MAAS deploy
-#
-
-installmaas(){
-    sudo apt-get install maas maas-region-controller -y
-}
-
 #
 # MAAS config
 # https://insights.ubuntu.com/2016/01/23/maas-setup-deploying-openstack-on-maas-1-9-with-juju/
@@ -234,9 +234,7 @@ installmaas(){
 #
 configuremaas(){
     #reconfigure maas with correct MAAS address.
-    #Below code is needed as MAAS have issue in commissioning without restart.
-    #sudo ./maas-reconfigure-region.sh $MAAS_IP
-    sleep 30
+
     sudo maas-rack config --region-url http://$MAAS_IP:5240/MAAS
 
     sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com --password=ubuntu || true
@@ -253,6 +251,10 @@ configuremaas(){
         maas $PROFILE tags create name=$tag || true
     done
 
+    #below tag would be used to enable huge pages for DPDK and SRIOV enablement in Ubuntu kernel via MAAS
+    maas $PROFILE tags create name='opnfv-dpdk' comment='OPNFV DPDK enablement' \
+         kernel_opts='hugepagesz=2M hugepages=1024 hugepagesz=1G hugepages=20 default_hugepagesz=1G intel_iommu=on'
+
     #create the required spaces.
     maas $PROFILE space update 0 name=default || true
     for space in admin-api internal-api public-api \
@@ -371,6 +373,27 @@ setupspacenetwork(){
                 PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
                 maas $PROFILE vlan update $NET_FABRIC_ID $NET_FABRIC_VID dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
             fi
+        elif ([ $type == "public" ] || [ $type == "osapi" ]); then
+            # If we have a network, we create reserve IPS for public IP range
+            if ([ $NET_FABRIC_ID ]); then
+                # Set ranges
+                SUBNET_PREFIX=${SPACE_CIDR::-5}
+                IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
+                IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
+                maas $PROFILE ipranges create type=reserved \
+                     start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
+                     comment='This is a reserved range' || true
+            fi
+        else
+            if ([ $NET_FABRIC_ID ]); then
+                # Set ranges
+                SUBNET_PREFIX=${SPACE_CIDR::-5}
+                IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
+                IP_RES_RANGE_HIGH="$SUBNET_PREFIX.5"
+                maas $PROFILE ipranges create type=reserved \
+                     start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
+                     comment='This is a reserved range' || true
+            fi
         fi
     done
 }
@@ -379,11 +402,15 @@ addnodes(){
     API_KEY=`sudo maas-region apikey --username=ubuntu`
     maas login $PROFILE $API_SERVERMAAS $API_KEY
 
+    maas $PROFILE maas set-config name=default_min_hwe_kernel value=hwe-16.04-edge || true
+
     # make sure there is no machine entry in maas
     for m in $(maas $PROFILE machines read | jq -r '.[].system_id')
     do
         maas $PROFILE machine delete $m
     done
+    podno=$(maas $PROFILE pods read | jq -r ".[]".id)
+    maas $PROFILE pod delete $podno || true
 
     # if we have a virshurl configuration we use it, else we use local
     VIRSHURL=$(cat labconfig.json | jq -r '.opnfv.virshurl')
@@ -433,8 +460,8 @@ addnodes(){
 
     virt-install --connect $VIRSHURL --name bootstrap --ram 4098 --cpu $CPU_MODEL --vcpus 2 \
                  --disk size=20,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
-                 $netw --boot network,hd,menu=off --noautoconsole \
-                 --print-xml | tee bootstrap
+                 $netw --boot network,hd,menu=off --video virtio --noautoconsole --autostart \
+                 --accelerate --print-xml | tee bootstrap
 
     if [ "$virtinstall" -eq 1 ]; then
         bootstrapmac=`grep  "mac address" bootstrap | head -1 | cut -d '"' -f 2`
@@ -446,6 +473,7 @@ addnodes(){
         done
     fi
     virsh -c $VIRSHURL define --file bootstrap
+
     rm -f bootstrap
 
     sleep 60
@@ -468,10 +496,12 @@ addnodes(){
 
             virt-install --connect $VIRSHURL --name $NODE_NAME --ram 8192 --cpu $CPU_MODEL --vcpus 4 \
                      --disk size=120,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
-                     $netw $netw --boot network,hd,menu=off --noautoconsole --print-xml | tee $NODE_NAME
+                     $netw $netw --boot network,hd,menu=off --video virtio --noautoconsole --autostart \
+                     --accelerate --print-xml | tee $NODE_NAME
 
             nodemac=`grep  "mac address" $NODE_NAME | head -1 | cut -d '"' -f 2`
             virsh -c $VIRSHURL define --file $NODE_NAME
+
             rm -f $NODE_NAME
             maas $PROFILE machines create autodetect_nodegroup='yes' name=$NODE_NAME \
                 tags='control compute' hostname=$NODE_NAME power_type='virsh' mac_addresses=$nodemac \
@@ -542,9 +572,10 @@ sleep 30
 
 setupspacenetwork
 
-#just make sure rack controller has been synced and import only
-# just whether images have been imported or not.
-sudo ./maas-reconfigure-region.sh $MAAS_IP
+sudo sed -i 's/localhost/'$MAAS_IP'/g' /etc/maas/rackd.conf
+sudo service maas-rackd restart
+sudo service maas-regiond restart
+
 sleep 120
 
 # Let's add the nodes now. Currently works only for virtual deployment.
@@ -610,6 +641,7 @@ if [ -e ./labconfig.json ]; then
                 'data')     IF_MODE='AUTO' ;;
                 'public')   IF_MODE='AUTO' ;;
                 'storage')  IF_MODE='AUTO' ;;
+                'osapi')    IF_MODE='AUTO' ;;
                 'floating') IF_MODE='link_up' ;;
                 *) SUBNET_CIDR='null'; IF_MODE='null'; echo_info "      >>> Unknown SPACE" ;;
             esac
@@ -628,8 +660,12 @@ if [ -e ./labconfig.json ]; then
             if ([ $IF_VLAN ] && [ "$IF_VLAN" != "null" ]); then
                 echo_info "      >>> Configuring VLAN $IF_VLAN"
                 VLANID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".id)
-                FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
-                INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
+                if ([ $VLANID ] && [ "$VLANID" != "null" ]); then
+                    FABRICID=$(maas $PROFILE subnets read | jq ".[].vlan | select(.vid==$IF_VLAN)".fabric_id)
+                    if ([ $FABRICID ] && [ "$FABRICID" != "null" ]); then
+                        INTERFACE=$(maas $PROFILE interfaces read $NODE_SYS_ID | jq ".[] | select(.vlan.fabric_id==$FABRICID)".id)
+                    fi
+                fi
                 if [[ -z $INTERFACE ]]; then
                     # parent interface is not set because it does not have a SUBNET_CIDR
                     PARENT_VLANID=$(maas $PROFILE fabrics read | jq ".[].vlans[] | select(.fabric_id==$FABRICID and .name==\"untagged\")".id)
@@ -673,12 +709,8 @@ if [ -e ./labconfig.json ]; then
 fi
 
 # Add the cloud and controller credentials for MAAS for that lab.
-jujuver=`juju --version`
-
-if [[ "$jujuver" > "2" ]]; then
-    addcloud
-    addcredential
-fi
+addcloud
+addcredential
 
 #
 # End of scripts