Browse Source

Fix PATH issue for VirtualBox on Windows

The support to deploy on a remote machine is broke the
default behaviour on the Windows OS, so now it always
needs to set the $PATH manually before using the scripts.

Also, the new functionality didn't work on the remote
Windows machine because the scripts change the $PATH on
the local system only.

This commit adds some more checks and fixes the local
$PATH setup. It didn't check remote system requirements
so deploy on a remote machine still have some problems.
Added several messages in the scripts.

Also this commit contain increased timeouts to fix
failures during network interfaces add/change operations
on some Windows systems.

Change-Id: If5dadc1ece3931f42eac423aae4d7016d45c2040
Closes-Bug: #1534129
Partial-Bug: #1491925
Maksim Malchuk 3 years ago
parent
commit
5cdbcc30d1
12 changed files with 165 additions and 57 deletions
  1. 11
    0
      README.md
  2. 1
    1
      actions/create-interfaces.sh
  3. 1
    1
      actions/delete-interfaces.sh
  4. 16
    6
      actions/prepare-environment.sh
  5. 12
    11
      clean.sh
  6. 4
    1
      config.sh
  7. 15
    12
      functions/network.sh
  8. 56
    12
      functions/shell.sh
  9. 16
    1
      functions/translate.sh
  10. 5
    10
      launch.sh
  11. 14
    1
      launch_16GB.sh
  12. 14
    1
      launch_8GB.sh

+ 11
- 0
README.md View File

@@ -7,6 +7,8 @@ Requirements
7 7
 - VirtualBox with VirtualBox Extension Pack
8 8
 - procps
9 9
 - expect
10
+- openssh-client
11
+- xxd
10 12
 - Cygwin for Windows host PC
11 13
 - Enable VT-x/AMD-V acceleration option on your hardware for 64-bits guests
12 14
 
@@ -17,6 +19,9 @@ In order to successfully run Mirantis OpenStack under VirtualBox, you need to:
17 19
 - download the official release (.iso) and place it under 'iso/' directory
18 20
 - run "./launch.sh" (or "./launch\_8GB.sh" or "./launch\_16GB.sh" according to your system resources). It will automatically pick up the iso and spin up master node and slave nodes
19 21
 
22
+If you run this script under Cygwin, you may have to add path to VirtualBox directory to your PATH.
23
+Usually it is enough to run: export PATH=$PATH:/cygdrive/c/Program Files/Oracle/VirtualBox
24
+
20 25
 If there are any errors, the script will report them and abort.
21 26
 
22 27
 If you want to change settings (number of OpenStack nodes, CPU, RAM, HDD), please refer to "config.sh".
@@ -31,3 +36,9 @@ The variable REMOTE_PORT allows to specify custom port for ssh.
31 36
 # or
32 37
  REMOTE_HOST=user@user.mos.mirantis.net REMOTE_PORT=23 ./launch_8GB.sh
33 38
 ```
39
+
40
+TODO
41
+----
42
+
43
+- add the ability to use Boot ROM during the remote deploy
44
+- add the new (even smaller) Boot ROM with iPXE HTTP enabled

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

@@ -26,7 +26,7 @@ source ./functions/vm.sh
26 26
 source ./functions/network.sh
27 27
 
28 28
 echo "Deleting old interfaces if exists..."
29
-if [[ "$rm_network" == "0" ]]; then
29
+if [[ "${rm_network}" == "0" ]]; then
30 30
     delete_fuel_ifaces
31 31
 else
32 32
     delete_all_hostonly_interfaces

+ 1
- 1
actions/delete-interfaces.sh View File

@@ -24,7 +24,7 @@ source ./functions/vm.sh
24 24
 source ./functions/network.sh
25 25
 
26 26
 # Delete host-only interfaces
27
-if [[ "$rm_network" == "0" ]]; then
27
+if [[ "${rm_network}" == "0" ]]; then
28 28
     delete_fuel_ifaces
29 29
 else
30 30
     delete_all_hostonly_interfaces

+ 16
- 6
actions/prepare-environment.sh View File

@@ -18,6 +18,7 @@
18 18
 #
19 19
 # This script performs initial check and configuration of the host system. It:
20 20
 #   - verifies that all available command-line tools are present on the host system
21
+#   - accepts one parameter value ('launch' or 'clean') which indicates how it is should be used
21 22
 #
22 23
 # We are avoiding using 'which' because of http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
23 24
 #
@@ -61,8 +62,6 @@ else
61 62
 fi
62 63
 
63 64
 # Check for VirtualBox
64
-echo "If you run this script under Cygwin, you may have to add path to VirtualBox directory to your PATH. "
65
-echo "Usually it is enough to run \"export PATH=\$PATH:\"/cygdrive/c/Program Files/Oracle/VirtualBox\" "
66 65
 echo -n "Checking for \"VBoxManage\"... "
67 66
 execute type VBoxManage >/dev/null 2>&1
68 67
 if [ $? -eq 1 ]; then
@@ -80,16 +79,25 @@ if [ "$extpacks" -le 0 ]; then
80 79
 fi
81 80
 echo "OK"
82 81
 
82
+# execute some checks only in the 'launch' mode
83
+if [ $1 == "launch" ]; then
84
+
83 85
 # Check for VirtualBox iPXE firmware
84 86
 echo -n "Checking for VirtualBox iPXE firmware..."
85 87
 if [ -z $pxe_path ]; then
86 88
     echo "SKIP"
87
-    echo "VirtualBox iPXE firmware is not found. Used standard firmware from the VirtualBox Extension Pack."
88
-    execute VBoxManage setextradata global VBoxInternal/Devices/pcbios/0/Config/LanBootRom
89
+    if [ -z "$REMOTE_HOST" ]; then
90
+        echo "VirtualBox iPXE firmware is not found. Used standard firmware from the VirtualBox Extension Pack."
91
+        execute VBoxManage setextradata global VBoxInternal/Devices/pcbios/0/Config/LanBootRom
92
+    fi
89 93
 else
90
-    execute VBoxManage setextradata global VBoxInternal/Devices/pcbios/0/Config/LanBootRom "$(pwd)/$pxe_path" 2>/dev/null
91 94
     echo "OK"
92
-    echo "Going to use iPXE boot firmware file $pxe_path"
95
+    if [ -z "$REMOTE_HOST" ]; then
96
+        execute VBoxManage setextradata global VBoxInternal/Devices/pcbios/0/Config/LanBootRom "$(pwd)/$pxe_path" 2>/dev/null
97
+        echo "Going to use iPXE boot firmware file $pxe_path"
98
+    else
99
+        echo "The iPXE boot on the remote system should be configured manually."
100
+    fi
93 101
 fi
94 102
 
95 103
 # Check for ISO image to be available
@@ -104,6 +112,8 @@ echo "Going to use Mirantis OpenStack ISO file $iso_path"
104 112
 # Copy ISO to host
105 113
 copy_if_required $iso_path
106 114
 
115
+fi # end 'launch' mode check
116
+
107 117
 # Check if SSH is installed. Cygwin does not install SSH by default.
108 118
 echo -n "Checking if SSH client installed... "
109 119
 execute type ssh >/dev/null 2>&1

+ 12
- 11
clean.sh View File

@@ -16,19 +16,20 @@
16 16
 
17 17
 source ./functions/shell.sh
18 18
 
19
+# Check remote host/port settings
20
+check_remote_settings
21
+
19 22
 # Add VirtualBox directory to PATH
20
-case "$(execute uname)" in
21
-    CYGWIN*)
22
-        vbox_path_registry=`execute cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
23
-        vbox_path=`execute cygpath "$vbox_path_registry"| sed -e 's%/$%%'`
24
-        export PATH=$PATH:$vbox_path
25
-      ;;
26
-    *)
27
-      ;;
28
-esac
23
+add_virtualbox_path
29 24
 
30 25
 # Shutdown installation and clean environment
31
-./actions/prepare-environment.sh || exit 1
26
+echo "Prepare the host system..."
27
+./actions/prepare-environment.sh clean || exit 1
28
+echo
29
+
30
+echo "Сlean previous installation if exists..."
32 31
 ./actions/clean-previous-installation.sh || exit 1
33
-./actions/delete-interfaces.sh || exit 1
32
+echo
34 33
 
34
+echo "Deleting old interfaces if exists..."
35
+./actions/delete-interfaces.sh || exit 1

+ 4
- 1
config.sh View File

@@ -42,10 +42,11 @@ fuel_master_ips="10.20.0.1 172.16.0.254 172.16.1.1"
42 42
 # Network mask for fuel interfaces
43 43
 mask="255.255.255.0"
44 44
 
45
-# Determining the type of operating system and adding CPU core to the master node
45
+# Determining the type of operating system, set global variables and adding CPU core to the master node
46 46
   case "$(execute uname)" in
47 47
     Linux)
48 48
       os_type="linux"
49
+      net_sleep="2s"
49 50
       if [ "$(execute nproc)" -gt "1" ]; then
50 51
         vm_master_cpu_cores=2
51 52
       else
@@ -54,6 +55,7 @@ mask="255.255.255.0"
54 55
     ;;
55 56
     Darwin)
56 57
       os_type="darwin"
58
+      net_sleep="2s"
57 59
       mac_nproc=`execute sysctl -a | grep machdep.cpu.thread_count | sed 's/^machdep.cpu.thread_count\:[ \t]*//'`
58 60
       if [ "$mac_nproc" -gt "1" ]; then
59 61
         vm_master_cpu_cores=2
@@ -63,6 +65,7 @@ mask="255.255.255.0"
63 65
     ;;
64 66
     CYGWIN*)
65 67
       os_type="cygwin"
68
+      net_sleep="12s"
66 69
       if [ "$(execute nproc)" -gt "1" ]; then
67 70
         vm_master_cpu_cores=2
68 71
       else

+ 15
- 12
functions/network.sh View File

@@ -67,7 +67,7 @@ is_hostonly_interface_present() {
67 67
   # Call VBoxManage directly instead of function, due to changed IFS
68 68
   local found_iface=(`execute VBoxManage list hostonlyifs | egrep "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
69 69
   # Change default divider back
70
-  case "$(execute uname)" in
70
+  case "$(uname)" in
71 71
     CYGWIN*)
72 72
       IFS=$OIFS
73 73
       ;;
@@ -87,18 +87,23 @@ check_if_iface_settings_applied() {
87 87
   ip=$2
88 88
   mask=$3
89 89
   echo "Verifying interface $name has IP $ip and mask $mask properly set."
90
-  OIFS=$IFS
91
-  case "$(execute uname)" in
90
+  case "$(uname)" in
92 91
     CYGWIN*)
92
+      OIFS=$IFS
93 93
       IFS=","
94 94
       ;;
95 95
     *)
96
-      IFS=$OIFS
97 96
       ;;
98 97
   esac
99 98
   local new_name=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
100
-  IFS=$OIFS
101
-  sleep 2s
99
+  case "$(uname)" in
100
+    CYGWIN*)
101
+      IFS=$OIFS
102
+      ;;
103
+    *)
104
+      ;;
105
+  esac
106
+  sleep ${net_sleep}
102 107
   local new_ip=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/IPAddress:/ { print $2 }'`)
103 108
   local new_mask=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/NetworkMask:/ { print $2 }'`)
104 109
   local new_dhcp=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: + $name\$" | awk '/DHCP:/ { print $2 }'`)
@@ -139,9 +144,9 @@ create_hostonly_interfaces() {
139 144
   echo "Disabling DHCP server on interface: $name..."
140 145
   # These magic 1 second sleeps around DHCP config are required under Windows/Cygwin
141 146
   # due to VBoxSvc COM server accepts next request before previous one is actually finished.
142
-  sleep 2s
147
+  sleep ${net_sleep}
143 148
   execute VBoxManage dhcpserver remove --ifname "$name" 2>/dev/null
144
-  sleep 2s
149
+  sleep ${net_sleep}
145 150
   # Set up IP address and network mask
146 151
   echo "Configuring IP address $ip and network mask $mask on interface: $name..."
147 152
   execute VBoxManage hostonlyif ipconfig "$id" --ip $ip --netmask $mask
@@ -173,15 +178,14 @@ delete_fuel_ifaces() {
173 178
   local fuel_ifaces=$(get_fuel_ifaces)
174 179
   if [ ! -z "$fuel_ifaces" ]; then
175 180
     check_running_vms "$fuel_ifaces"
176
-    OIFS=$IFS
177 181
     IFS=","
178 182
     for interface in $fuel_ifaces; do
179
-      IFS=$OIFS
180 183
       echo "Deleting host-only interface: $interface..."
181 184
       execute VBoxManage hostonlyif remove "$interface"
182 185
       check_removed_iface "$interface"
183 186
     done
184 187
   fi
188
+  unset IFS
185 189
   echo "Done."
186 190
 }
187 191
 
@@ -190,14 +194,13 @@ delete_all_hostonly_interfaces() {
190 194
   local all_hostonly_interfaces=$(get_hostonly_interfaces)
191 195
   # Checking that the running virtual machines don't use removable host-only interfaces
192 196
   check_running_vms $all_hostonly_interfaces
193
-  OIFS=$IFS
194 197
   IFS=","
195 198
   # Delete every single hostonly interface in the system
196 199
   for interface in $all_hostonly_interfaces; do
197
-    IFS=$OIFS
198 200
     echo "Deleting host-only interface: ${interface}..."
199 201
     execute VBoxManage hostonlyif remove "${interface}"
200 202
     check_removed_iface "${interface}"
201 203
   done
204
+  unset IFS
202 205
   echo "Done."
203 206
 }

+ 56
- 12
functions/shell.sh View File

@@ -18,15 +18,6 @@
18 18
 # Each command might be executed on the local machine or on the remote machine
19 19
 # depending on environment settings
20 20
 
21
-shell_ssh_options=""
22
-shell_scp_options=""
23
-
24
-if [ -n "$REMOTE_PORT" ]; then
25
-  shell_ssh_options="-p $REMOTE_PORT $shell_ssh_options"
26
-  shell_scp_options="-P $REMOTE_PORT $shell_scp_options"
27
-fi
28
-
29
-
30 21
 function execute() {
31 22
   #  use shell substitution pattern ${parameter/pattern/string}, to escape spaces in arguments.
32 23
   if [ -n "$REMOTE_HOST" ]; then
@@ -41,19 +32,20 @@ function execute() {
41 32
 function copy_if_required() {
42 33
   local source_path=$1
43 34
   if [ -n "$REMOTE_HOST" ]; then
44
-    if ! execute test -f $source_path; then
35
+    local local_size=`wc -c <${source_path} 2>/dev/null`
36
+    local remote_size=`execute wc -c <${source_path} 2>/dev/null`
37
+    if [ "${local_size}" != "${remote_size}" ]; then
45 38
       # the scripts always find iso in original path
46 39
       # reconstruct same path on remote machine
47 40
       local source_dir=$(dirname $source_path)
48 41
       echo "Copying $source_path to $REMOTE_HOST:$source_path..."
49 42
       execute mkdir -p $source_dir && copy $source_path $source_path || exit 1
50 43
     else
51
-      echo "Skip copying the file $source_path, it already exists on $REMOTE_HOST."
44
+      echo "Skip copying the file $source_path, same file already exists on $REMOTE_HOST."
52 45
     fi
53 46
   fi
54 47
 }
55 48
 
56
-
57 49
 function copy() {
58 50
   local src=$1
59 51
   local dst=$2
@@ -64,3 +56,55 @@ function copy() {
64 56
     cp $src $dst
65 57
   fi
66 58
 }
59
+
60
+# Add VirtualBox directory to PATH
61
+function add_virtualbox_path() {
62
+  case "$(execute uname 2>/dev/null)" in
63
+    CYGWIN*)
64
+      execute type VBoxManage &>/dev/null
65
+      if [ $? -eq 1 ]; then
66
+        if [ -n "$REMOTE_HOST" ]; then
67
+          echo "When using the \$REMOTE_HOST it's required to add path to VirtualBox directory"
68
+          echo "to your PATH on remote system globaly in the remote system settings. Aborting."
69
+          exit 1
70
+        else
71
+          # check 64bit Windows registry branch
72
+          if [ -f /proc/registry64/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir ]; then
73
+            vbox_path_registry=`cat /proc/registry64/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
74
+          # check 32bit Windows registry branch
75
+          elif [ -f /proc/registry32/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir ]; then
76
+            vbox_path_registry=`cat /proc/registry32/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
77
+          # check default Windows registry branch
78
+          elif [ -f /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir ]; then
79
+            vbox_path_registry=`cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
80
+          else
81
+            # default override if registry lookup fails
82
+            vbox_path_registry='C:\Program Files\Oracle\VirtualBox\'
83
+          fi
84
+          vbox_path=`cygpath "$vbox_path_registry"| sed -e 's%/$%%'`
85
+          export PATH=$PATH:$vbox_path
86
+        fi
87
+      fi
88
+      ;;
89
+    *)
90
+      ;;
91
+  esac
92
+}
93
+
94
+# Check remote host/port settings
95
+function check_remote_settings() {
96
+  if [ -n "$REMOTE_HOST" ]; then
97
+    echo
98
+    echo "WARNING! All the commands will be executed on the remote system: ${REMOTE_HOST}"
99
+    echo "WARNING! The remote system should be configured correctly. Please read the README.md file"
100
+    echo
101
+  fi
102
+  # configure ssh/scp options
103
+  if [ -n "$REMOTE_PORT" ]; then
104
+    shell_ssh_options="-p $REMOTE_PORT $shell_ssh_options"
105
+    shell_scp_options="-P $REMOTE_PORT $shell_scp_options"
106
+  else
107
+    shell_ssh_options=""
108
+    shell_scp_options=""
109
+  fi
110
+}

+ 16
- 1
functions/translate.sh View File

@@ -1,5 +1,20 @@
1 1
 #!/bin/bash -eu
2
-# AT translated set 2 encoder
2
+
3
+#    Copyright 2015 Mirantis, Inc.
4
+#
5
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+#    not use this file except in compliance with the License. You may obtain
7
+#    a copy of the License at
8
+#
9
+#         http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+#    Unless required by applicable law or agreed to in writing, software
12
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+#    License for the specific language governing permissions and limitations
15
+#    under the License.
16
+
17
+# This file contains the functions for AT translated set 2 encoder
3 18
 
4 19
 type xxd > /dev/null || exit 1
5 20
 

+ 5
- 10
launch.sh View File

@@ -16,19 +16,14 @@
16 16
 
17 17
 source ./functions/shell.sh
18 18
 
19
+# Check remote host/port settings
20
+check_remote_settings
21
+
19 22
 # Add VirtualBox directory to PATH
20
-case "$(execute uname)" in
21
-    CYGWIN*)
22
-        vbox_path_registry=`execute cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
23
-        vbox_path=`execute cygpath "$vbox_path_registry"| sed -e 's%/$%%'`
24
-        export PATH=$PATH:$vbox_path
25
-      ;;
26
-    *)
27
-      ;;
28
-esac
23
+add_virtualbox_path
29 24
 
30 25
 echo "Prepare the host system..."
31
-./actions/prepare-environment.sh || exit 1
26
+./actions/prepare-environment.sh launch || exit 1
32 27
 echo
33 28
 
34 29
 echo "Check available memory on the host system..."

+ 14
- 1
launch_16GB.sh View File

@@ -1,4 +1,17 @@
1 1
 #!/bin/bash
2 2
 
3
-CONFIG_FOR="16GB" ./launch.sh
3
+#    Copyright 2013 Mirantis, Inc.
4
+#
5
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+#    not use this file except in compliance with the License. You may obtain
7
+#    a copy of the License at
8
+#
9
+#         http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+#    Unless required by applicable law or agreed to in writing, software
12
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+#    License for the specific language governing permissions and limitations
15
+#    under the License.
4 16
 
17
+CONFIG_FOR="16GB" ./launch.sh

+ 14
- 1
launch_8GB.sh View File

@@ -1,4 +1,17 @@
1 1
 #!/bin/bash
2 2
 
3
-CONFIG_FOR="8GB" ./launch.sh
3
+#    Copyright 2013 Mirantis, Inc.
4
+#
5
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+#    not use this file except in compliance with the License. You may obtain
7
+#    a copy of the License at
8
+#
9
+#         http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+#    Unless required by applicable law or agreed to in writing, software
12
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+#    License for the specific language governing permissions and limitations
15
+#    under the License.
4 16
 
17
+CONFIG_FOR="8GB" ./launch.sh

Loading…
Cancel
Save