diff --git a/README.md b/README.md index d35365e..338445c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/beaker-google.gemspec b/beaker-google.gemspec index abeb48e..556de64 100644 --- a/beaker-google.gemspec +++ b/beaker-google.gemspec @@ -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' diff --git a/lib/beaker/hypervisor/google_compute.rb b/lib/beaker/hypervisor/google_compute.rb index 18b9b2b..551d7cf 100644 --- a/lib/beaker/hypervisor/google_compute.rb +++ b/lib/beaker/hypervisor/google_compute.rb @@ -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 diff --git a/lib/beaker/hypervisor/google_compute_helper.rb b/lib/beaker/hypervisor/google_compute_helper.rb index ac83151..52ccf43 100644 --- a/lib/beaker/hypervisor/google_compute_helper.rb +++ b/lib/beaker/hypervisor/google_compute_helper.rb @@ -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, @@ -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