diff --git a/README.md b/README.md index 431bf30..55720dc 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,20 @@ If your vms require config drive. config_drive: true ``` +### scheduler\_hints + +If you wish to pass any scheduler hints. + +``` + scheduler_hints: + group: b0f6f534-3a02-4dfa-9165-605446799cc0 + query: >- + ["or", + ["=", "$host", "cmp123.example.com"], + ["=", "$host", "cmp456.example.com"] + ] +``` + ### network\_ref **Deprecated** A list of network names to create instances with. diff --git a/kitchen-openstack.gemspec b/kitchen-openstack.gemspec index dc17be8..371ca0c 100644 --- a/kitchen-openstack.gemspec +++ b/kitchen-openstack.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "kitchen/driver/openstack_version" diff --git a/lib/kitchen/driver/openstack.rb b/lib/kitchen/driver/openstack.rb index 6538499..af1f215 100755 --- a/lib/kitchen/driver/openstack.rb +++ b/lib/kitchen/driver/openstack.rb @@ -200,6 +200,10 @@ def create_server server_def[c] = optional_config(c) if config[c] end + if config[:scheduler_hints] + server_def[:os_scheduler_hints] = optional_config(:scheduler_hints) + end + # Can't use the Fog bootstrap and/or setup methods here; they require a # public IP address that can't be guaranteed to exist across all # OpenStack deployments (e.g. TryStack ARM only has private IPs). @@ -224,6 +228,8 @@ def optional_config(c) config[c] if config[c].is_a?(Array) when :user_data File.open(config[c], &:read) if File.exist?(config[c]) + when :scheduler_hints + config[c] if config[c].is_a?(Hash) else config[c] end diff --git a/spec/kitchen/driver/openstack_spec.rb b/spec/kitchen/driver/openstack_spec.rb index 8c5089d..55f151b 100755 --- a/spec/kitchen/driver/openstack_spec.rb +++ b/spec/kitchen/driver/openstack_spec.rb @@ -534,6 +534,35 @@ end end + context "scheduler_hints specified" do + let(:config) do + { + server_name: "hello", + image_ref: "111", + flavor_ref: "1", + scheduler_hints: { + group: "3df3519e-0e22-4d14-8c6a-afd8e4467b4b", + }, + } + end + let(:data) do + { + group: "3df3519e-0e22-4d14-8c6a-afd8e4467b4b", + } + end + + it "passes scheduler_hints contents" do + expect(servers).to receive(:create).with( + name: "hello", + image_ref: "111", + flavor_ref: "1", + availability_zone: nil, + os_scheduler_hints: data + ) + driver.send(:create_server) + end + end + context "image_id specified" do let(:config) do {