tmatilai / vagrant-proxyconf

Vagrant plugin that configures the virtual machine to use proxies
MIT License
531 stars 74 forks source link

Disable specific applications #93

Closed otahi closed 9 years ago

otahi commented 9 years ago

The implementation for #85 . I want to change like this.


Disabling the plugin

The plugin can be totally skipped by setting config.proxy.enabled to false or empty string (""). This can be useful to for example disable it for some provider. Specific applications can be skipped by setting config.proxy.enabled to a hash( like { svn: false }). This disabling keeps proxy configurations for applications on the guest. The configurations must be cleared before disabling if needed.

config.proxy.enabled         # => all applications enabled(default)
config.proxy.enabled = true  # => all applications enabled
config.proxy.enabled = { svn: false, docker: false }
                             # => specific applications disabled
config.proxy.enabled = ""    # => all applications disabled
config.proxy.enabled = false # => all applications disabled

Todos:

otahi commented 9 years ago

@tmatilai, I have implemented the function to disable specific applications. If you have any indications or advices, please give me. I just checked this function work on my vagrant with CentOS7 virtualbox instance. I will cover more instances.

@jperville, I am trying to solve #85. If possible, I want to ask you to check this function on your environment with Installing a pre-release version.


The unit test result for this function is as follows.

[otahi@otahiair vagrant-proxyconf]$ bundle exec rspec spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb

VagrantPlugins::ProxyConf::Action::ConfigureEnvProxy
  #config_name
    should eq "env_proxy"
  #disabled?
    when both config and proxy are enabled
      should eq false
    when config is enabled and config proxy is not enabled
      should eq true
    when config is enabled and config proxy is empty string
      should eq true
    when config is not enabled and proxy is enabled
      should eq true
    when both config and target proxy are enabled
      should eq false
    when config is enabled and target proxy target is not enabled
      should eq true
    when config is enabled and other proxy are not enabled
      should eq false

Finished in 0.0109 seconds (files took 0.4665 seconds to load)
8 examples, 0 failures
Coverage report generated for RSpec to /Users/otahi/git/vagrant-proxyconf/tmp/coverage. 3635 / 7140 LOC (50.91%) covered.
[Coveralls] Outside the Travis environment, not sending data.
[otahi@otahiair vagrant-proxyconf]$
jperville commented 9 years ago

I just tested the branch on my system with good success (at least to disable the docker proxy). I encountered an error with the git proxy (the /usr/bin/git config --system --unset-all http.proxy command exited with status 5) so I disabled the git proxy also.

Relevant output of vagrant plugin list:

vagrant-proxyconf (1.4.1.dev)
  - Version Constraint: 1.4.1.dev

Here is the configuration snippet in my Vagrantfile:

  if Vagrant.has_plugin?('vagrant-proxyconf')
    config.proxy.enabled = { docker: false, git: false }
  end

When booting the VM, the following proxies were configured:

==> default: Configuring proxy for Apt...
==> default: Configuring proxy for Chef provisioners...
==> default: Configuring proxy environment variables...

LGTM, thank you so much for this PR @otahi

otahi commented 9 years ago

@jperville Thank you for your testing. I'm happy to hear that. I will continue to test some kind of VMs.

tmatilai commented 9 years ago

Thanks to both of you!

otahi commented 9 years ago

@tmatilai , Thank you for your merging. But, I am doing test on some VMs.(CentOS 7, CentOS 6.5, Ubuntu 14.04) Now, I am thinking there some issues.

  1. chef is not affected because chef has separated call method.
  2. git fails on my VMs as @jperville said
==> centos6: Configuring proxy for Git...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/usr/bin/git config --system --unset-all http.proxy
tmatilai commented 9 years ago

@otahi OK. One issue is at least that config.enabled? is not called early enough in some cases. That checks the capability, in git's case if the binary is found.

otahi commented 9 years ago

@tmatilai , Thank you for your advice.

On the VM, git can be run but return 5. I am investigating.

[vagrant@vagrant-centos65 ~]$ sudo /usr/bin/git config --system --unset-all http.proxy ; echo $?
5
[vagrant@vagrant-centos65 ~]$
otahi commented 9 years ago

@tmatilai I understand git case. Git returns 5 if no configuration exists.

[vagrant@vagrant-centos65 ~]$ sudo /usr/bin/git config --system http.proxy test; echo $?
0
[vagrant@vagrant-centos65 ~]$ sudo /usr/bin/git config --system --unset-all http.proxy; echo $?
0
[vagrant@vagrant-centos65 ~]$ sudo /usr/bin/git config --system --unset-all http.proxy; echo $?
5
[vagrant@vagrant-centos65 ~]$

Now, I don't have enough time. I will do research tommorow JST. Thank you,

tmatilai commented 9 years ago

Ouch, that's a nasty catch in the git API... So that's a bug in the configure_git_proxy action. Never came up as no-one probably explicitly sets config.git_proxy.http = "" or so. Guess we could just ignore the errors when removing the configurations? This is anyway a bit out of scope for this PR.

But I still think that there is a bug here too. We shouldn't be unsetting the git proxy without config.git_proxy being touched.

otahi commented 9 years ago

I have tested on #96. It seems OK.