Files
ubicloud/spec/model/hetzner_host_spec.rb
Furkan Sahin 1c75bfdb8e Introduce Hetzner API support for IPv4
This PR integrates the IPv4 address creation for Hetzner with their provided
APIs. This way, we don't need to manually add the ip ranges, controlplane
figures out itself at the host creation time.

The API for ip addresses on Hetzner has a some bits need more explanation.
First of all bought IP addresses are billed/assigned to the servers. Doesn't
matter if it's a failover IP address or not, they are connected even if you
perform a reassignment. If we need to perform a proper failover and disconnect
all the relationship of the ip from the originating server, we have to open a
support ticket. So, we need to treat carefully and use the failover ip ranges
properly.

Failure scenarios;
1. In this PR, when we are looking for failover ip ranges for the vm_host, we pull
all the ips and look for the ones assigned to the created vm_host from the field
active_server_ip. There is also server_ip which means the ip address of the
server that the ip range is first bought for. We fail if that server is not in
our control with an error message.

2. In relation to above scenario, in case we discover an ip range that is created
before for another vm_host and we now discover that it's actually routed to the
new vm_host, we update the routed_to_host_id property of the address object. If
there is already a VM that's using an ip address from that range, that means
there is a bug because the range is now routed to a new vm_host and the vm ip4
setup is broken. In that case, we fail with an error message.
2023-06-19 13:12:05 +02:00

40 lines
819 B
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe HetznerHost do
subject(:hetzner_host) { described_class.new }
let(:vm_host) {
instance_double(
VmHost,
provider: HetznerHost::PROVIDER_NAME,
hetzner_host: hetzner_host
)
}
describe "connection_string" do
it "returns the connection string" do
expect(hetzner_host.connection_string).to eq "https://robot-ws.your-server.de"
end
end
describe "user" do
it "returns the user" do
expect(hetzner_host.user).to eq "user1"
end
end
describe "password" do
it "returns the password" do
expect(hetzner_host.password).to eq "pass"
end
end
describe "api" do
it "returns the api" do
expect(hetzner_host.api).to be_a Hosting::HetznerApis
end
end
end