-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Adjust network calls to hcloud 1.2 #30
base: master
Are you sure you want to change the base?
Conversation
This requires tonobo/hcloud-ruby#84 |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #30 +/- ##
==========================================
- Coverage 92.94% 88.50% -4.44%
==========================================
Files 3 3
Lines 85 87 +2
==========================================
- Hits 79 77 -2
- Misses 6 10 +4
☔ View full report in Codecov by Sentry. |
e26c3e8
to
286eb43
Compare
@@ -100,8 +100,8 @@ def create_server(host) | |||
action = @client.actions.find(action.id) | |||
server = @client.servers.find(server.id) | |||
end | |||
host[:ip] = server.public_net['ipv4']['ip'] | |||
host[:vmhostname] = server.public_net['ipv4']['dns_ptr'] | |||
host[:ip] = server.public_net['ipv4'].ip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mhm I'm not sure how to mock .ip
properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
irb(main):013:0> server.public_net['ipv4']
=> #<Hcloud::PrimaryIP:0xd5c {"assignee_id"=>38840073, "assignee_type"=>"server", "auto_delete"=>true, "blocked"=>false, "created"=>2023-11-01 15:10:39 UTC, "datacenter"=>#<Hcloud::Datacenter:0xd70 {"description"=>"Nuremberg 1 virtual DC 3", "id"=>2, "location"=>#<Hcloud::Location:0xd84 {"city"=>"Nuremberg", "country"=>"DE", "description"=>"Nuremberg DC Park 1", "id"=>2, "latitude"=>49.452102, "longitude"=>11.076665, "name"=>"nbg1", "network_zone"=>"eu-central"}>, "name"=>"nbg1-dc3", "server_types"=>{"available"=>[1, 3, 5, 7, 9, 22, 23, 24, 25, 26, 45, 93, 94, 95, 96, 97, 98, 99, 100, 101], "available_for_migration"=>[1, 3, 5, 7, 9, 22, 23, 24, 25, 26, 45, 93, 94, 95, 96, 97, 98, 99, 100, 101], "supported"=>[9, 7, 5, 3, 1, 22, 23, 24, 25, 26, 45, 93, 94, 95, 96, 97, 98, 99, 100, 101]}}>, "dns_ptr"=>[{"ip"=>"128.140.40.189", "dns_ptr"=>"static.189.40.140.128.clients.your-server.de"}], "id"=>42635150, "ip"=>"128.140.40.189", "labels"=>{}, "name"=>"primary_ip-42635150", "protection"=>{"delete"=>false}, "type"=>"ipv4"}>
irb(main):014:0> server.public_net['ipv4'].ip
=> "128.140.40.189"
irb(main):015:0> server.public_net['ipv4'].dns_ptr
=> [{"ip"=>"128.140.40.189", "dns_ptr"=>"static.189.40.140.128.clients.your-server.de"}]
irb(main):016:0> server.public_net['ipv4'].dns_ptr.first
=> {"ip"=>"128.140.40.189", "dns_ptr"=>"static.189.40.140.128.clients.your-server.de"}
irb(main):017:0>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
irb(main):015:0> server.public_net['ipv4'].dns_ptr.find { |hash| hash['ip'] == server.public_net['ipv4'].ip }
=> {"ip"=>"128.140.40.189", "dns_ptr"=>"static.189.40.140.128.clients.your-server.de"}
irb(main):016:0> server.public_net['ipv4'].dns_ptr.find { |hash| hash['ip'] == server.public_net['ipv4'].ip }['dns_ptr']
=> "static.189.40.140.128.clients.your-server.de"
irb(main):017:0>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd mock the client. So
let(:mock_client) { double(::Hcloud::Client) }
before do
allow(::Hcloud::Client).to receive(new).and_return(mock_client)
end
A tricky part is that you need to mock all responses on mock_client
then. It may be easier to create another helper method:
def self.create_hcloud_server(client, **kwargs)
action, server, _password, _next_action = client.servers.create(**kwargs)
while action.status == 'running'
sleep 5
action = client.actions.find(action.id)
server = client.servers.find(server.id)
end
server
end
Then you already reduce it a lot: you now can use:
result = Mock(...)
allow(Beaker::Hypervisor::Hcloud).to receive(create_hcloud_server).with(....).and_return(result)
And if you then look at create_hcloud_server
, you can also consider if this is also sufficient:
def create_hcloud_server(client, **kwargs)
action, server, _password, _next_action = client.servers.create(**kwargs)
while action.status == 'running'
sleep 5
action = client.actions.find(action.id)
end
client.servers.find(server.id)
end
It saves a find action on every call.
Some methods and their return values changed within the 1.2 release.
Some methods and their return values changed within the 1.2 release.