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

Renderer fails when calling validate_import_vm #3

Merged
merged 1 commit into from Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,7 +31,7 @@ def import_vm(source_vm_id, target_params)
end

def validate_import_vm
api_version >= '4.0'
highest_supported_api_version && highest_supported_api_version >= '4'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find >= on Strings dangerous and strange.
Also highest_supported_api_version seems to return 3 (int) as a default....
Consider some of those conversions:

[3] pry(main)> 3 >= '4'
ArgumentError: comparison of Fixnum with String failed
from (pry):3:in `>='
[4] pry(main)> 3.to_i >= 4
=> false
[5] pry(main)> '3.0'.to_i
=> 3
[6] pry(main)> Integer('3.0')
ArgumentError: invalid value for Integer(): "3.0"
from (pry):6:in `Integer'
[7] pry(main)> '3.0beta'.to_i
=> 3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked the code and we seems to return a string

2.3.0 :001 > ems = ExtManagementSystem.last
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 5, connections: 1, in use: 1, waiting_in_queue: 0
ExtManagementSystem Load (0.4ms) SELECT "ext_management_systems".* FROM "ext_management_systems" ORDER BY "ext_management_systems"."id" DESC LIMIT $1 [["LIMIT", 1]]
ExtManagementSystem Inst Including Associations (6430.5ms - 1rows)
=> #<ManageIQ::Providers::Redhat::InfraManager id: 11, name: "ovirt", created_on: "2017-04-11 14:18:50", updated_on: "2017-04-11 14:19:15", guid: "c89c81a0-1ec1-11e7-b1c4-c85b76722276", zone_id: 1, type: "ManageIQ::Providers::Redhat::InfraManager", api_version: "4.2.0_master.", uid_ems: nil, host_default_vnc_port_start: nil, host_default_vnc_port_end: nil, provider_region: nil, last_refresh_error: nil, last_refresh_date: "2017-04-11 14:19:15", provider_id: nil, realm: nil, tenant_id: 1, project: nil, parent_ems_id: nil, subscription: nil, last_metrics_error: nil, last_metrics_update_date: nil, last_metrics_success_date: nil, tenant_mapping_enabled: nil>
2.3.0 :002 > ems.highest_supported_api_version
Authentication Load (0.7ms) SELECT "authentications".* FROM "authentications" WHERE "authentications"."resource_id" = $1 AND "authentications"."resource_type" = $2 [["resource_id", 11], ["resource_type", "ExtManagementSystem"]]
Authentication Inst Including Associations (105.1ms - 1rows)
Endpoint Load (0.3ms) SELECT "endpoints".* FROM "endpoints" WHERE "endpoints"."resource_id" = $1 AND "endpoints"."resource_type" = $2 [["resource_id", 11], ["resource_type", "ExtManagementSystem"]]
Endpoint Inst Including Associations (16.4ms - 2rows)
=> "4"

I understand that it looks strange but this is how the code works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok I just wonder why this returns Integer(3) ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@durandom good point, will change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here: #10

end

private
Expand Down
Expand Up @@ -54,4 +54,18 @@
)
end
end

context 'checks version during validation' do
let(:ems) { FactoryGirl.create(:ems_redhat) }

it 'validates successfully' do
allow(ems).to receive(:highest_supported_api_version).and_return('4')
expect(ems.validate_import_vm).to be_truthy
end

it 'validates before connecting' do
allow(ems).to receive(:highest_supported_api_version).and_return(nil)
expect(ems.validate_import_vm).to be_falsey
end
end
end