Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem With Fog::Compute::Google::InstanceGroups.add_instance Deprecation Warning #308

Closed
seanmalloy opened this issue Mar 8, 2018 · 4 comments
Assignees

Comments

@seanmalloy
Copy link
Contributor

I am using the latest code from the master branch. Git commit is c42060f.

I receive the below warning when adding a GCE instance to an unmanaged instance group.

[fog][DEPRECATION] Fog::Compute::Google::InstanceGroups.add_instance is deprecated, use Fog::Compute::Google::InstanceGroup.add_instance instead (["/home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/fog-google-c42060f42df5/lib/fog/compute/google/models/instance_groups.rb:40:in `add_instance'"])

I would like to not get this deprecation error, so I update my code to use env[:google_compute].instance_group.add_instance instead of env[:google_compute].instance_groups.add_instance. Then I get the below NoMethodError exception.

NoMethodError: undefined method `instance_group' for #<Fog::Compute::Google::Real:0x0000560f42c13890>
Did you mean?  instance_groups
               instance_of?
  /home/sean/projects/vagrant-google/lib/vagrant-google/action/assign_instance_groups.rb:59:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/lib/vagrant-google/action/run_instance.rb:216:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/lib/vagrant-google/action/warn_ssh_keys.rb:28:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/lib/vagrant-google/action/warn_networks.rb:28:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/lib/vagrant-google/action/sync_folders.rb:33:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builtin/provision.rb:80:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builder.rb:116:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/runner.rb:66:in `block in run'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/util/busy.rb:19:in `busy'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/runner.rb:66:in `run'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builtin/call.rb:53:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/lib/vagrant-google/action/connect_google.rb:47:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builtin/box_check_outdated.rb:79:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builtin/handle_box.rb:56:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/warden.rb:34:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/builder.rb:116:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/runner.rb:66:in `block in run'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/util/busy.rb:19:in `busy'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/action/runner.rb:66:in `run'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/machine.rb:227:in `action_raw'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/machine.rb:202:in `block in action'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/environment.rb:592:in `lock'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/machine.rb:188:in `call'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/machine.rb:188:in `action'
  /home/sean/projects/vagrant-google/vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04fdab961e25/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'

Looking through the code in the below file I do not see an add_instance method, but I do see a method named add_instances.

https://github.com/fog/fog-google/blob/master/lib/fog/compute/google/models/instance_group.rb#L36

It appears that the deprecation warning provides the wrong method name, and also that the class Fog::Compute::Google::InstanceGroup does not exist? I'm thinking this is a bug introduced in the 1.0 release or I am doing something wrong.

Here is the specific code I used to get these errors.

https://github.com/KohlsTechnology/vagrant-google/blob/update-fog-google/lib/vagrant-google/action/assign_instance_groups.rb#L59-L63

I'm willing to submit a pull request to fix this if it is a bug, but I think I would need someone to point me in the right direction. Since this file exists lib/fog/compute/google/models/instance_group.rb I do not understand why the stack trace is happening.

@seanmalloy
Copy link
Contributor Author

I was able to get rid of the deprecation warning by using the below method instead.

https://github.com/fog/fog-google/blob/master/lib/fog/compute/google/requests/add_instance_group_instances.rb#L11

I'll leave this issue open as I think there is still a chance that this could be a bug. Let me now what you think.

@icco
Copy link
Member

icco commented Mar 9, 2018

@Temikus might know what's up here with more detail, but I'll give a pass at what I think is going on.

  • Yes this is a bug, add_instance should exist for InstanceGroup.
  • To get an InstanceGroup, you wanna call get on the InstanceGroups to get the singular item.

For now (until a add_instance is written), the following should work:

env[:google_compute].instance_groups.get(instance_group_name, zone).add_instances([instance_name])

@Temikus
Copy link
Member

Temikus commented Mar 22, 2018

Sorry for the late response, I've been pretty much out of GitHub for the past 3 months for personal reasons.

@seanmalloy Thanks for raising this.

I've mimicked the AddInstances from the api, however, semantically, it's probably would've been better to keep add_instance alias, instead of reworking the method.

@icco - Should I just add an alias then?

@Temikus Temikus self-assigned this Mar 22, 2018
@icco
Copy link
Member

icco commented Mar 22, 2018

@Temikus I think it needs to be a little more than an alias. Probably something like

def add_instance instance_id
   add_instances [instance_id]
end

Temikus added a commit to Temikus/fog-google that referenced this issue Mar 26, 2018
Adding add_instance back to the model, seems I forgot to port it
from the collection earlier.

Fixes fog#308
Temikus added a commit to Temikus/fog-google that referenced this issue Mar 26, 2018
Adding add_instance back to the model, seems I forgot to port it
from the collection earlier.

Fixes fog#308
@icco icco closed this as completed in #314 Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants