Skip to content

Commit

Permalink
Add patch to workaround 1.9.1 bug
Browse files Browse the repository at this point in the history
Modified Vagrant source under MIT license
  • Loading branch information
Karl Isenberg committed Dec 13, 2016
1 parent 0130f00 commit 101238d
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 11 deletions.
8 changes: 7 additions & 1 deletion LICENSE
Expand Up @@ -198,4 +198,10 @@
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.
limitations under the License.


BUNDLED DEPENDENCIES:

This product bundles portions of modified Vagrant source code.
Vagrant is available under the MIT license. For details, see patch/.
28 changes: 19 additions & 9 deletions Vagrantfile
Expand Up @@ -215,20 +215,30 @@ end
## One Time Setup
##############################################

if Vagrant::VERSION == '1.8.5'
UI.error 'Unsupported Vagrant Version: 1.8.5', bold:true
UI.error 'For more info, visit https://github.com/dcos/dcos-vagrant/blob/master/docs/troubleshooting.md#ssh-authentication-failure'
def error_known_good_versions
UI.error 'Latest known-working versions: Vagrant 1.9.1, VirtualBox 5.1.10'
UI.error ''
end

Vagrant.require_version '>= 1.8.4', '!= 1.8.5'

if Vagrant::VERSION == '1.8.6'
# Monkey patch for network interface detection bug in Vagrant 1.8.6
# https://github.com/mitchellh/vagrant/issues/7876
require_relative 'lib/linux_network_interfaces'
# Monkey patches and known-bad Vagrant versions
case Vagrant::VERSION
when '1.9.1'
require_relative 'patch/redhat_change_host_name_1.9.1'
require_relative 'patch/redhat_configure_networks_1.9.1'
when '1.8.7'
UI.error 'Unsupported Vagrant Version: 1.8.7', bold:true
UI.error 'For more info, see https://github.com/mitchellh/vagrant/issues/7969'
error_known_good_versions
when '1.8.6'
require_relative 'patch/linux_network_interfaces_1.8.6'
when '1.8.5'
UI.error 'Unsupported Vagrant Version: 1.8.5', bold:true
UI.error 'For more info, see https://github.com/mitchellh/vagrant/issues/7610'
error_known_good_versions
end

Vagrant.require_version '>= 1.8.4', '!= 1.8.5', '!= 1.8.7'

begin

UI.info 'Validating Plugins...'
Expand Down
22 changes: 22 additions & 0 deletions patch/LICENSE
@@ -0,0 +1,22 @@
The MIT License

Copyright (c) 2016 Mesosphere
Copyright (c) 2010-2016 Mitchell Hashimoto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -1,5 +1,7 @@
# Monkey patch for network interface detection bug in Vagrant 1.8.6
# https://github.com/mitchellh/vagrant/issues/7876
#
# This file is a Derivative Work of Vagrant source, covered by the MIT license.

require Vagrant.source_root.join('plugins/guests/linux/cap/network_interfaces.rb')

Expand Down Expand Up @@ -54,4 +56,4 @@ def self.network_interfaces(machine, path = "/sbin/ip")
end
end

Vagrant::UI::Colored.new.info 'Vagrant Patch Loaded: GuestLinux network_interfaces'
Vagrant::UI::Colored.new.info 'Vagrant Patch Loaded: GuestLinux network_interfaces (1.8.6)'
51 changes: 51 additions & 0 deletions patch/redhat_change_host_name_1.9.1.rb
@@ -0,0 +1,51 @@
# Monkey patch for network interface detection bug in Vagrant 1.9.1
# https://github.com/mitchellh/vagrant/issues/8115
#
# This file is a Derivative Work of Vagrant source, covered by the MIT license.

require Vagrant.source_root.join('plugins/guests/redhat/cap/change_host_name.rb')

module VagrantPlugins
module GuestRedHat
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
comm = machine.communicate

if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split('.', 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Update sysconfig
sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network
# Update DNS
sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{basename}\"/' /etc/sysconfig/network-scripts/ifcfg-*
# Set the hostname - use hostnamectl if available
echo '#{name}' > /etc/hostname
if command -v hostnamectl; then
hostnamectl set-hostname --static '#{name}'
hostnamectl set-hostname --transient '#{name}'
else
hostname -F /etc/hostname
fi
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
# Restart network
service network restart
EOH
end
end
end
end
end
end

Vagrant::UI::Colored.new.info 'Vagrant Patch Loaded: GuestRedHat change_host_name (1.9.1)'
66 changes: 66 additions & 0 deletions patch/redhat_configure_networks_1.9.1.rb
@@ -0,0 +1,66 @@
# Monkey patch for network interface detection bug in Vagrant 1.9.1
# https://github.com/mitchellh/vagrant/issues/8115
#
# This file is a Derivative Work of Vagrant source, covered by the MIT license.

require Vagrant.source_root.join('plugins/guests/redhat/cap/configure_networks.rb')

module VagrantPlugins
module GuestRedHat
module Cap
class ConfigureNetworks
include Vagrant::Util

def self.configure_networks(machine, networks)
comm = machine.communicate

network_scripts_dir = machine.guest.capability(:network_scripts_dir)

commands = []
interfaces = machine.guest.capability(:network_interfaces)

networks.each.with_index do |network, i|
network[:device] = interfaces[network[:interface]]

# Render a new configuration
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
options: network,
)

# Upload the new configuration
remote_path = "/tmp/vagrant-network-entry-#{network[:device]}-#{Time.now.to_i}-#{i}"
Tempfile.open("vagrant-redhat-configure-networks") do |f|
f.binmode
f.write(entry)
f.fsync
f.close
machine.communicate.upload(f.path, remote_path)
end

# Add the new interface and bring it back up
final_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}"
commands << <<-EOH.gsub(/^ {14}/, '')
# Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown '#{network[:device]}'
# Move new config into place
mv -f '#{remote_path}' '#{final_path}'
# attempt to force network manager to reload configurations
nmcli c reload || true
EOH
end

commands << <<-EOH.gsub(/^ {12}/, '')
# Restart network
service network restart
EOH

comm.sudo(commands.join("\n"))
end
end
end
end
end

Vagrant::UI::Colored.new.info 'Vagrant Patch Loaded: GuestRedHat configure_networks (1.9.1)'

0 comments on commit 101238d

Please sign in to comment.