Browse Source

Proper Windows 7/8/10 support

This commit adds enchantments and proper support for Windows 7/8/10:
 * more verbose messages.
 * by default all network interfaces will be removed.
 * some code cleanup and regexp fixes.
 * added sleeps for some network operations.
 * proper support for windows full filenames.

Change-Id: Ic56f8d114bdaf83dd12b76dd6cc46eaa8d74da52
Closes-Bug: #1524558
Closes-Bug: #1496042
Maksim Malchuk 3 years ago
parent
commit
85e5cf4817

+ 1
- 0
actions/check-available-memory.sh View File

@@ -45,3 +45,4 @@ else
45 45
     exit 1
46 46
   fi
47 47
 fi
48
+echo "Done."

+ 1
- 0
actions/clean-previous-installation.sh View File

@@ -26,3 +26,4 @@ source ./functions/network.sh
26 26
 
27 27
 # Delete all VMs from the previous Mirantis OpenStack installation
28 28
 delete_vms_multiple $vm_name_prefix
29
+echo "Done."

+ 2
- 1
actions/create-interfaces.sh View File

@@ -25,12 +25,13 @@ source ./config.sh
25 25
 source ./functions/vm.sh
26 26
 source ./functions/network.sh
27 27
 
28
-# Delete host-only interfaces
28
+echo "Deleting old interfaces if exists..."
29 29
 if [[ "$rm_network" == "0" ]]; then
30 30
     delete_fuel_ifaces
31 31
 else
32 32
     delete_all_hostonly_interfaces
33 33
 fi
34
+echo
34 35
 
35 36
 # Create the required host-only interfaces
36 37
 for ip in $fuel_master_ips; do

+ 2
- 2
actions/master-node-create-and-install.sh View File

@@ -32,8 +32,8 @@ get_fuel_name_ifaces
32 32
 
33 33
 name="${vm_name_prefix}master"
34 34
 
35
+# Create master node VM
35 36
 create_vm $name "${host_nic_name[0]}" $vm_master_cpu_cores $vm_master_memory_mb $vm_master_disk_mb
36
-echo
37 37
 
38 38
 # Add additional NICs
39 39
 add_hostonly_adapter_to_vm $name 2 "${host_nic_name[1]}"
@@ -49,7 +49,7 @@ if [ ${headless} -eq 1 ]; then
49 49
   enable_vrde $name ${RDPport}
50 50
 fi
51 51
 
52
-if [ "$skipfuelmenu" = "yes" ]; then
52
+if [ "${skipfuelmenu}" = "yes" ]; then
53 53
   cmdline="$(grep 'append initrd' ../iso/isolinux/isolinux.cfg -m1 2> /dev/null | sed -e 's/^[ ]*append//')"
54 54
   cmdline="${cmdline:- initrd=initrd.img net.ifnames=0 biosdevname=0 ks=hd:sr0:/ks.cfg ip=10.20.0.2::10.20.0.1:255.255.255.0:fuel.domain.tld:eth0:off::: dns1=10.20.0.1 selinux=0}"
55 55
   boot_line="$(translate "$cmdline showmenu=no"$'\n')"

+ 1
- 1
actions/master-node-enable-internet.sh View File

@@ -1,4 +1,4 @@
1
-#!/bin/bash 
1
+#!/bin/bash
2 2
 
3 3
 #    Copyright 2013 Mirantis, Inc.
4 4
 #

+ 1
- 1
actions/prepare-environment.sh View File

@@ -140,4 +140,4 @@ esac
140 140
 echo "OK"
141 141
 
142 142
 # Report success
143
-echo "Setup is done."
143
+echo "Done."

+ 2
- 5
config.sh View File

@@ -26,13 +26,10 @@ pxe_path=`ls -1t drivers/*.*rom 2>/dev/null | head -1`
26 26
 # Every Mirantis OpenStack machine name will start from this prefix
27 27
 vm_name_prefix=fuel-
28 28
 
29
-# By default, all available network interfaces vboxnet won't be removed,
30
-# if their IP addresses don't match with fuel_master_ips (10.20.0.1 172.16.0.254
31
-# 172.16.1.1)
32
-# If you want to remove all existing vbox interfaces, then use rm_network=1
29
+# By default, all available vbox network interfaces will be removed.
33 30
 # 0 - don't remove all vbox networks. Remove only fuel networks if they exist
34 31
 # 1 - remove all vbox networks
35
-rm_network=0
32
+rm_network=1
36 33
 
37 34
 # Please add the IPs accordingly if you going to create non-default NICs number
38 35
 # 10.20.0.1/24   - Mirantis OpenStack Admin network

+ 25
- 26
functions/network.sh View File

@@ -19,7 +19,8 @@
19 19
 source ./functions/shell.sh
20 20
 
21 21
 get_hostonly_interfaces() {
22
-  echo -e `execute VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
22
+  local ifaces=`execute VBoxManage list hostonlyifs | egrep '^Name' | sed 's/^Name\:\s*//' | uniq | tr "\\n" ","`
23
+  echo -e "${ifaces}"
23 24
 }
24 25
 
25 26
 get_fuel_ifaces() {
@@ -32,7 +33,7 @@ get_fuel_ifaces() {
32 33
     fuel_networks+="$fuel_network "
33 34
   done
34 35
   for ip in $fuel_networks; do
35
-    fuel_iface=`execute VBoxManage list hostonlyifs | grep -B5 $ip | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
36
+    fuel_iface=`execute VBoxManage list hostonlyifs | egrep -B3 $ip | egrep '^Name' | sed 's/^Name\:\s*//' | uniq | tr "\\n" ","`
36 37
     fuel_ifaces+="$fuel_iface"
37 38
   done
38 39
   echo $fuel_ifaces
@@ -64,7 +65,7 @@ is_hostonly_interface_present() {
64 65
       ;;
65 66
   esac
66 67
   # Call VBoxManage directly instead of function, due to changed IFS
67
-  local found_iface=(`execute VBoxManage list hostonlyifs | grep -E "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
68
+  local found_iface=(`execute VBoxManage list hostonlyifs | egrep "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
68 69
   # Change default divider back
69 70
   case "$(execute uname)" in
70 71
     CYGWIN*)
@@ -86,26 +87,21 @@ check_if_iface_settings_applied() {
86 87
   ip=$2
87 88
   mask=$3
88 89
   echo "Verifying interface $name has IP $ip and mask $mask properly set."
89
-  # Please leave 12 spaces in place - these are placed intentionally
90
+  OIFS=$IFS
90 91
   case "$(execute uname)" in
91 92
     CYGWIN*)
92
-      OIFS=$IFS
93 93
       IFS=","
94 94
       ;;
95 95
     *)
96
-      ;;
97
-    esac
98
-  local new_name=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name:            $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
99
-  case "$(execute uname)" in
100
-    CYGWIN*)
101 96
       IFS=$OIFS
102 97
       ;;
103
-    *)
104
-      ;;
105 98
   esac
106
-  local new_ip=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name:            $name\$" | awk '/IPAddress:/ {print $2}'`)
107
-  local new_mask=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name:            $name\$" | awk '/NetworkMask:/ {print $2}'`)
108
-  local new_dhcp=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name:            $name\$" | awk '/DHCP:/ {print $2}'`)
99
+  local new_name=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
100
+  IFS=$OIFS
101
+  sleep 2s
102
+  local new_ip=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/IPAddress:/ { print $2 }'`)
103
+  local new_mask=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/NetworkMask:/ { print $2 }'`)
104
+  local new_dhcp=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/DHCP:/ { print $2 }'`)
109 105
   # First verify if we checking correct interface
110 106
   if [[ "$name" != "$new_name" ]]; then
111 107
     echo "Checking $name but found settings for $new_name"
@@ -130,7 +126,7 @@ check_if_iface_settings_applied() {
130 126
 create_hostonly_interfaces() {
131 127
   # Creating host-only interface
132 128
   local ip=$1
133
-  echo "Creating host-only interface"
129
+  echo "Creating host-only interface..."
134 130
   local id=`execute VBoxManage hostonlyif create | sed "s/'/_/g" | cut -d "_" -f2 | sed "s/^_//" | sed "s/_$//"`
135 131
   # If it does not exist after creation, let's abort
136 132
   if ! is_hostonly_interface_present "$id"; then
@@ -143,14 +139,12 @@ create_hostonly_interfaces() {
143 139
   echo "Disabling DHCP server on interface: $name..."
144 140
   # These magic 1 second sleeps around DHCP config are required under Windows/Cygwin
145 141
   # due to VBoxSvc COM server accepts next request before previous one is actually finished.
146
-  sleep 1s
142
+  sleep 2s
147 143
   execute VBoxManage dhcpserver remove --ifname "$name" 2>/dev/null
148
-  sleep 1s
144
+  sleep 2s
149 145
   # Set up IP address and network mask
150 146
   echo "Configuring IP address $ip and network mask $mask on interface: $name..."
151
-  set -x
152 147
   execute VBoxManage hostonlyif ipconfig "$id" --ip $ip --netmask $mask
153
-  set +x
154 148
   # Check what we have created actually.
155 149
   # Sometimes VBox occasionally fails to apply settings to the last IFace under Windows
156 150
   if !(check_if_iface_settings_applied "$id" $ip $mask); then
@@ -161,6 +155,7 @@ create_hostonly_interfaces() {
161 155
     echo "Aborting."
162 156
     exit 1
163 157
   fi
158
+  echo
164 159
 }
165 160
 
166 161
 # Checking that the interface has been removed
@@ -187,18 +182,22 @@ delete_fuel_ifaces() {
187 182
       check_removed_iface "$interface"
188 183
     done
189 184
   fi
185
+  echo "Done."
190 186
 }
191 187
 
192 188
 delete_all_hostonly_interfaces() {
193 189
   # All the hostonly interfaces will be removed
194 190
   local all_hostonly_interfaces=$(get_hostonly_interfaces)
195 191
   # Checking that the running virtual machines don't use removable host-only interfaces
196
-  check_running_vms "$all_hostonly_interfaces"
197
-  OIFS=$IFS;IFS=",";list=(`execute VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`);IFS=$OIFS
192
+  check_running_vms $all_hostonly_interfaces
193
+  OIFS=$IFS
194
+  IFS=","
198 195
   # Delete every single hostonly interface in the system
199
-  for interface in "${list[@]}"; do
200
-    echo "Deleting host-only interface: $interface..."
201
-    execute VBoxManage hostonlyif remove "$interface"
202
-    check_removed_iface "$interface"
196
+  for interface in $all_hostonly_interfaces; do
197
+    IFS=$OIFS
198
+    echo "Deleting host-only interface: ${interface}..."
199
+    execute VBoxManage hostonlyif remove "${interface}"
200
+    check_removed_iface "${interface}"
203 201
   done
202
+  echo "Done."
204 203
 }

+ 0
- 0
functions/shell.sh View File


+ 0
- 0
functions/translate.sh View File


+ 35
- 34
functions/vm.sh View File

@@ -19,7 +19,7 @@
19 19
 source ./functions/shell.sh
20 20
 
21 21
 get_vm_base_path() {
22
-    echo `execute VBoxManage list systemproperties | grep '^Default machine folder' | sed 's/^Default machine folder\:[ \t]*//'`
22
+    echo `execute VBoxManage list systemproperties | egrep '^Default machine folder' | sed 's/^Default machine folder\:\s*//'`
23 23
 }
24 24
 
25 25
 get_vms_running() {
@@ -36,7 +36,7 @@ is_vm_running() {
36 36
 
37 37
     # Check that the list of running VMs contains the given VM
38 38
     for name_in_list in $list; do
39
-        if [[ "$name_in_list" == "$name" ]]; then
39
+        if [[ "${name_in_list}" == "${name}" ]]; then
40 40
             return 0
41 41
         fi
42 42
     done
@@ -48,7 +48,7 @@ is_vm_present() {
48 48
     list=$(get_vms_present)
49 49
 
50 50
     for name_in_list in $list; do
51
-        if [[ "$name_in_list" == "$name" ]]; then
51
+        if [[ "${name_in_list}" == "${name}" ]]; then
52 52
             return 0
53 53
         fi
54 54
     done
@@ -62,14 +62,14 @@ check_running_vms() {
62 62
   local list_running_vms=$(execute VBoxManage list runningvms | sed 's/\" {/\",{/g')
63 63
   for vm_name in $list_running_vms; do
64 64
     vm_name=$(echo $vm_name | grep "\"" | sed 's/"//g')
65
-    vm_names+="$vm_name,"
65
+    vm_names+="${vm_name},"
66 66
   done
67 67
   for i in $vm_names; do
68 68
     for j in $hostonly_interfaces; do
69
-      running_vm=`execute VBoxManage showvminfo $i | grep "$j"`
69
+      running_vm=`execute VBoxManage showvminfo $i | grep "${j}"`
70 70
       if [[ $? -eq 0 ]]; then
71
-        echo "The \"$i\" VM uses host-only interface \"$j\" and it cannot be removed...."
72
-        echo "You should turn off the \"$i\" virtual machine, run the script again and then the host-only interface will be deleted. Aborting..."
71
+        echo "The \"${i}\" VM uses host-only interface \"${j}\" and it cannot be removed...."
72
+        echo "You should turn off the \"${i}\" virtual machine, run the script again and then the host-only interface will be deleted. Aborting..."
73 73
         exit 1
74 74
       fi
75 75
     done
@@ -86,9 +86,9 @@ create_vm() {
86 86
     os='RedHat_64'
87 87
 
88 88
     # There is a chance that some files are left from previous VM instance
89
-    vm_base_path=$(get_vm_base_path)
90
-    vm_path="$vm_base_path/$name/"
91
-    execute rm -rf "$vm_path"
89
+    vm_base_path=$(get_vm_base_path | sed 's/\\/\\\\/g')
90
+    vm_path="${vm_base_path}/${name}/"
91
+    execute rm -rf "${vm_path}"
92 92
 
93 93
     # Create virtual machine with the right name and type (assuming CentOS)
94 94
     execute VBoxManage createvm --name $name --ostype $os --register
@@ -99,7 +99,7 @@ create_vm() {
99 99
     execute VBoxManage modifyvm $name --rtcuseutc on --memory $memory_mb --cpus $cpu_cores --vram 16
100 100
 
101 101
     # Configure main network interface for management/PXE network
102
-    add_hostonly_adapter_to_vm $name 1 "$nic"
102
+    add_hostonly_adapter_to_vm $name 1 "${nic}"
103 103
     execute VBoxManage modifyvm $name --boot1 disk --boot2 dvd --boot3 net --boot4 none
104 104
 
105 105
     # Configure storage controllers
@@ -117,10 +117,10 @@ add_hostonly_adapter_to_vm() {
117 117
     name=$1
118 118
     id=$2
119 119
     nic=$3
120
-    echo "Adding hostonly adapter to $name and bridging with host NIC $nic..."
120
+    echo "Adding hostonly adapter to ${name} and bridging with host NIC ${nic}..."
121 121
 
122 122
     # Add Intel PRO/1000 MT Desktop (82540EM) card to VM. The card is 1Gbps.
123
-    execute VBoxManage modifyvm $name --nic${id} hostonly --hostonlyadapter${id} "$nic" --nictype${id} 82540EM \
123
+    execute VBoxManage modifyvm $name --nic${id} hostonly --hostonlyadapter${id} "${nic}" --nictype${id} 82540EM \
124 124
                         --cableconnected${id} on --macaddress${id} auto
125 125
     execute VBoxManage modifyvm  $name  --nicpromisc${id} allow-all
126 126
 }
@@ -129,13 +129,12 @@ add_nat_adapter_to_vm() {
129 129
     name=$1
130 130
     id=$2
131 131
     nat_network=$3
132
-    echo "Adding NAT adapter to $name for outbound network access through the host system..."
132
+    echo "Adding NAT adapter to ${name} for outbound network access through the host system..."
133 133
 
134 134
     # Add Intel PRO/1000 MT Desktop (82540EM) card to VM. The card is 1Gbps.
135 135
     execute VBoxManage modifyvm $name --nic${id} nat --nictype${id} 82540EM \
136 136
                         --cableconnected${id} on --macaddress${id} auto --natnet${id} "${nat_network}"
137 137
     execute VBoxManage modifyvm  $name  --nicpromisc${id} allow-all
138
-    execute VBoxManage controlvm $name setlinkstate${id} on
139 138
 }
140 139
 
141 140
 add_disk_to_vm() {
@@ -143,46 +142,48 @@ add_disk_to_vm() {
143 142
     port=$2
144 143
     disk_mb=$3
145 144
 
146
-    echo "Adding disk to $vm_name, with size $disk_mb Mb..."
145
+    echo "Adding disk to ${vm_name}, with size ${disk_mb} Mb..."
147 146
 
148
-    vm_disk_path="$(get_vm_base_path)/$vm_name/"
149
-    disk_name="${vm_name}_${port}"
150
-    disk_filename="${disk_name}.vdi"
151
-    execute VBoxManage createhd --filename "$vm_disk_path/$disk_filename" --size $disk_mb --format VDI
152
-    execute VBoxManage storageattach $vm_name --storagectl 'SATA' --port $port --device 0 --type hdd --medium "$vm_disk_path/$disk_filename"
147
+    vm_base_path=$(get_vm_base_path | sed 's/\\/\\\\/g')
148
+    vm_disk_path="${vm_base_path}/${vm_name}"
149
+    vm_disk_file="${vm_disk_path}/${vm_name}_${port}.vdi"
153 150
 
154
-    # Add serial numbers of disks to slave nodes
155
-    echo "Adding serial numbers of disks to $vm_name..."
156
-    execute VBoxManage setextradata $vm_name "VBoxInternal/Devices/ahci/0/Config/Port$port/SerialNumber" "VBOX-MIRANTIS-VHD$port"
151
+    execute VBoxManage createhd --filename "${vm_disk_file}" --size $disk_mb --format VDI
152
+    execute VBoxManage storageattach $vm_name --storagectl 'SATA' --port $port --device 0 --type hdd --medium "${vm_disk_file}"
157 153
 
154
+    # Add serial numbers of disks to slave nodes
155
+    echo "Adding serial numbers of disks to ${vm_name}..."
156
+    execute VBoxManage setextradata $vm_name "VBoxInternal/Devices/ahci/0/Config/Port${port}/SerialNumber" "VBOX-MIRANTIS-VHD${port}"
158 157
 }
159 158
 
160 159
 delete_vm() {
161 160
     name=$1
162
-    vm_base_path=$(get_vm_base_path)
163
-    vm_path="$vm_base_path/$name/"
161
+
162
+    vm_base_path=$(get_vm_base_path | sed 's/\\/\\\\/g')
163
+    vm_path="${vm_base_path}/${name}/"
164 164
 
165 165
     # Power off VM, if it's running
166 166
     count=0
167 167
     while is_vm_running $name; do
168
-        echo "Stopping Virtual Machine $name..."
168
+        echo "Stopping Virtual Machine ${name}..."
169 169
         execute VBoxManage controlvm $name poweroff
170
-        if [[ "$count" != 5 ]]; then
170
+        if [[ "${count}" != 5 ]]; then
171 171
             count=$((count+1))
172 172
             sleep 5
173 173
         else
174
-            echo "VirtualBox cannot stop VM $name... Exiting"
174
+            echo "VirtualBox cannot stop VM ${name}... Exiting"
175 175
             exit 1
176 176
         fi
177 177
     done
178 178
 
179
-    echo "Deleting existing virtual machine $name..."
179
+    echo "Deleting existing virtual machine ${name}..."
180 180
     while is_vm_present $name
181 181
     do
182 182
         execute VBoxManage unregistervm $name --delete
183 183
     done
184
+
184 185
     # Virtualbox does not fully delete VM file structure, so we need to delete the corresponding directory with files as well
185
-    execute rm -rf "$vm_path"
186
+    execute rm -rf "${vm_path}"
186 187
 }
187 188
 
188 189
 delete_vms_multiple() {
@@ -192,7 +193,7 @@ delete_vms_multiple() {
192 193
     # Loop over the list of VMs and delete them, if its name matches the given refix
193 194
     for name in $list; do
194 195
         if [[ $name == $name_prefix* ]]; then
195
-            echo "Found existing VM: $name. Deleting it..."
196
+            echo "Found existing VM: ${name}. Deleting it..."
196 197
             delete_vm $name
197 198
         fi
198 199
     done
@@ -208,7 +209,7 @@ start_vm() {
208 209
         execute VBoxManage startvm $name
209 210
     fi
210 211
 
211
-    if [ -n "$boot_line" ]; then
212
+    if [ -n "${boot_line}" ]; then
212 213
         sleep 3
213 214
         # Pressing/releasing escape key
214 215
         execute VBoxManage controlvm ${name} keyboardputscancode 01 81
@@ -225,7 +226,7 @@ mount_iso_to_vm() {
225 226
     iso_path=$2
226 227
 
227 228
     # Mount ISO to the VM
228
-    execute VBoxManage storageattach $name --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium "$iso_path"
229
+    execute VBoxManage storageattach $name --storagectl 'IDE' --port 0 --device 0 --type dvddrive --medium "${iso_path}"
229 230
 }
230 231
 
231 232
 enable_network_boot_for_vm() {

+ 6
- 3
launch.sh View File

@@ -27,14 +27,17 @@ case "$(execute uname)" in
27 27
       ;;
28 28
 esac
29 29
 
30
-# Prepare the host system
30
+echo "Prepare the host system..."
31 31
 ./actions/prepare-environment.sh || exit 1
32
+echo
32 33
 
33
-# Check available memory on the host system
34
+echo "Check available memory on the host system..."
34 35
 ./actions/check-available-memory.sh || exit 1
36
+echo
35 37
 
36
-# Сlean previous installation if exists
38
+echo "Сlean previous installation if exists..."
37 39
 ./actions/clean-previous-installation.sh || exit 1
40
+echo
38 41
 
39 42
 # Сreate host-only interfaces
40 43
 ./actions/create-interfaces.sh || exit 1

Loading…
Cancel
Save