Project

General

Profile

Actions

Bug #8555

closed

Associate VMs results in an error

Added by Andrew Lau over 9 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Difficulty:
easy
Triaged:
Fixed in Releases:
Found in Releases:

Description

Hello,

Kudos for this awesome plugin, ran into one bug while testing it.

Running Foreman 1.7 (upgrade from 1.6), errors occurred in both 1.6 and 1.7 and using ruby193-rubygem-foreman_digitalocean-0.0.2-1.el6.noarch

When associating VMs, it will error with:

ActiveRecord::StatementInvalid
PGError: ERROR: operator does not exist: character varying = integer LINE 1: ...sts"."compute_resource_id" = 1 AND "hosts"."uuid" IN (335119... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. : SELECT COUNT FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."compute_resource_id" = 1 AND "hosts"."uuid" IN (3351196)
app/controllers/compute_resources_controller.rb:46:in `block in associate'
app/controllers/compute_resources_controller.rb:45:in `associate'
app/models/concerns/foreman/thread_session.rb:33:in `clear_thread'
lib/middleware/catch_json_parse_errors.rb:9:in `call'

Actions #1

Updated by Dominic Cleal over 9 years ago

If I'm reading that correctly, it looks like the DO "UUIDs" being retrieved are actually integers, not UUID strings?

Actions #2

Updated by Tommy McNeely over 9 years ago

  • Assignee set to Tommy McNeely
  • Difficulty set to easy

This also happens during host creation. The problem as noted seems to be that "uuid" is being returned as an int, and it needs to be a string. While I believe that is actually a problem in "core" code, we can work around it in the module.

Actions #3

Updated by Tommy McNeely over 9 years ago

Note that I tried the following based on a suggestion in the #foreman-dev channel

[vagrant@devforeman digitalocean]$ git diff
diff --git a/app/models/concerns/fog_extensions/digitalocean/server.rb b/app/models/concerns/fog_extensions/digitalocean/server.rb
index 5050637..712e2bb 100644
--- a/app/models/concerns/fog_extensions/digitalocean/server.rb
+++ b/app/models/concerns/fog_extensions/digitalocean/server.rb
@@ -3,6 +3,10 @@ module FogExtensions
     module Server
       extend ActiveSupport::Concern

+      def identity
+        super.to_s
+      end
+
       def vm_description
         flavor.try(:name)
       end

However, now it fails immediately on host creation, rather than after the VM is created and ready. It gives the error:

creating VM with the following options: {"name"=>"testvm06.test.example.com", "flavor_id"=>"66", "region_id"=>"4", "image_id"=>"7053293"}
Unhandled DigitalOcean error: Fog::Errors::Error:Resaving an existing object may create a duplicate
 /home/vagrant/.gem/ruby/1.9.1/gems/fog-1.25.0/lib/fog/digitalocean/models/compute/server.rb:118:in `save'
 /home/vagrant/.gem/ruby/1.9.1/gems/fog-core-1.25.0/lib/fog/core/collection.rb:50:in `create'
 /home/vagrant/foreman/app/models/compute_resource.rb:147:in `create_vm'
 /home/vagrant/foreman-digitalocean/app/models/foreman_digitalocean/digitalocean.rb:35:in `create_vm'
 /home/vagrant/foreman/app/models/concerns/orchestration/compute.rb:74:in `setCompute'
Actions #4

Updated by Dominic Cleal over 9 years ago

Maybe instead of redefining 'identity' you could add a new method which we'll use for retrieving the UUID.

def identity_to_s
  identity.to_s
end

And then change DO's provided_attributes method (https://github.com/theforeman/foreman-digitalocean/blob/master/app/models/foreman_digitalocean/digitalocean.rb#L16) to:

super.merge({ :uuid => :identity_to_s, :ip => :public_ip_address })
Actions #5

Updated by Tommy McNeely over 9 years ago

That looks like it might work. I have tested it in my development instance, but not on "postgres" yet... However, it looks good form the logs:

  Host::Managed Load (0.2ms)  SELECT "hosts".* FROM "hosts" WHERE "hosts"."uuid" = '3426805' LIMIT 1

Note the single quotes around the uuid number...

Once I figure out a "sane" way to test it against postgres I will submit the PR.

~tommy

Actions #6

Updated by Tommy McNeely over 9 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100
Actions

Also available in: Atom PDF