Skip to content

Commit

Permalink
Merge branch 'main' into configure-firewall
Browse files Browse the repository at this point in the history
  • Loading branch information
jaevans authored Oct 19, 2023
2 parents e5428d3 + 2dffbec commit 08d96b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ The internal firewall allows all communication between hosts in the node set, wh

The external firewall allows outside communication from the internet into the hosts in the test. Due to constrains of the Beaker system, the firewall accepts any source IP (`0.0.0.0/0`) and the SSH port (`22/tcp`) is always allowed. Other ports may be added by using the `gce_ports` configuration option or the `BEAKER_gce_ports` environment variable as a comma separated list of `port/proto` values where `port` is the port number or range, and proto is one of `tcp`, `udp`, `icmp`, `esp`, `ah`, `ipip`, or `sctp`. The port number is only used for `tcp`, `udp`, and `sctp` protocols. Any value, such as `-1` can be used for the other protocols.

VM Instances created during this process will by default use the automatically-generated instance name as the hostname in the VM OS. Set the `BEAKER_set_gce_hostname` environment variable to `1` to override this behavior and configure the VM OS with the name defined in the nodeset as the hostname.

# Cleanup

In cases where the beaker process is killed before finishing, it may leave resources in GCP. These resources will need to be manually deleted.
Expand Down
2 changes: 1 addition & 1 deletion beaker-google.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
# Testing dependencies
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'rspec-its'
s.add_development_dependency 'fakefs', '~> 1.8'
s.add_development_dependency 'fakefs', '~> 2.4'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'pry', '~> 0.10'
Expand Down
2 changes: 1 addition & 1 deletion lib/beaker/hypervisor/google_compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def provision
host['vmhostname'] = unique_host_id

# add a new instance of the image
operation = @gce_helper.create_instance(host['vmhostname'], img, machine_type, boot_size)
operation = @gce_helper.create_instance(host['vmhostname'], img, machine_type, boot_size, host.name)
unless operation.error.nil?
raise "Unable to create Google Compute Instance #{host.name}: [#{operation.error.errors[0].code}] #{operation.error.errors[0].message}"
end
Expand Down
29 changes: 21 additions & 8 deletions lib/beaker/hypervisor/google_compute_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,14 @@ def create_disk(name, size, img = nil)
# @param [Integer] disk_size The size of the boot disk for the new instance. Must be equal to or
# greater than the image disk's size
#
# @param [String] hostname The custom hostname to set in the OS of the instance
#
# @return [Google::Apis::ComputeV1::Operation]
#
# @raise [Google::Apis::ServerError] An error occurred on the server and the request can be retried
# @raise [Google::Apis::ClientError] The request is invalid and should not be retried without modification
# @raise [Google::Apis::AuthorizationError] Authorization is required
def create_instance(name, img, machine_type, disk_size)
def create_instance(name, img, machine_type, disk_size, hostname)
initialize_params = ::Google::Apis::ComputeV1::AttachedDiskInitializeParams.new(
disk_size_gb: disk_size,
source_image: img.self_link,
Expand All @@ -517,13 +519,24 @@ def create_instance(name, img, machine_type, disk_size)
),
],
)
new_instance = ::Google::Apis::ComputeV1::Instance.new(
machine_type: machine_type.self_link,
name: name,
disks: [disk_params],
network_interfaces: [network_interface],
tags: tags,
)

instance_opts = {
:machine_type => machine_type.self_link,
:name => name,
:disks => [disk_params],
:network_interfaces => [network_interface],
:tags => tags,
}

# use custom hostname if specified
if hostname && ENV.fetch('BEAKER_set_gce_hostname', false)
# The google api requires an FQDN for the custom hostname
hostname.include?('.') ? valid_hostname = hostname : valid_hostname = hostname + '.beaker.test'
instance_opts[:hostname] = valid_hostname
end

new_instance = ::Google::Apis::ComputeV1::Instance.new(instance_opts)

operation = @compute.insert_instance(@options[:gce_project], @options[:gce_zone], new_instance)
@compute.wait_zone_operation(@options[:gce_project], @options[:gce_zone], operation.name)
end
Expand Down

0 comments on commit 08d96b3

Please sign in to comment.