Skip to content

Commit 470abed

Browse files
committed
refactor: split main driver file into focused modules
Resolves #24 - the main openstack.rb driver file had grown too large with too many concerns in a single class. Extract four new modules from Kitchen::Driver::Openstack: - Config (openstack/config.rb): server naming logic including config_server_name, default_name, and server_name_prefix - Networking (openstack/networking.rb): floating IP allocation and IP address resolution including attach_ip, attach_ip_from_pool, get_ip, get_public_private_ips, filter_ips, and parse_ips - ServerHelper (openstack/server_helper.rb): server creation and resource finders including create_server, init_configuration, optional_config, find_image, find_flavor, find_network, and find_matching - Helpers (openstack/helpers.rb): ohai hints, SSL validation, and server wait logic including add_ohai_hint, disable_ssl_validation, wait_for_server, and countdown The main openstack.rb retains the class definition, create/destroy lifecycle methods, Fog connection helpers, and default_config declarations. Additional changes: - Fix Style/ClassVars offenses by replacing class variables with constants (IP_POOL_LOCK in Networking, DEFAULT_CREATION_TIMEOUT in Volume) - Fix Style/FileRead by using File.read and updating the corresponding spec mock - Remove obsolete --chefstyle flag from Rakefile (no longer supported by newer RuboCop; .rubocop.yml already loads cookstyle via require) - Auto-correct all cookstyle offenses (string quoting, comment format, percent literal delimiters) - Add Lance Albertson as author and Oregon State University copyright Signed-off-by: Lance Albertson <lance@osuosl.org>
1 parent 2b35d09 commit 470abed

11 files changed

Lines changed: 509 additions & 363 deletions

File tree

Gemfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# frozen_string_literal: true
22

3-
source "https://rubygems.org"
3+
source 'https://rubygems.org'
44

55
# Specify your gem's dependencies in kitchen-openstack.gemspec
66
gemspec
77

88
group :test do
9-
gem "rake"
10-
gem "kitchen-inspec"
11-
gem "rspec", "~> 3.2"
12-
gem "countloc"
9+
gem 'rake'
10+
gem 'kitchen-inspec'
11+
gem 'rspec', '~> 3.2'
12+
gem 'countloc'
1313
end
1414

1515
group :debug do
16-
gem "pry"
16+
gem 'pry'
1717
end
1818

1919
group :cookstyle do
20-
gem "cookstyle"
20+
gem 'cookstyle'
2121
end

Rakefile

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
require "bundler/gem_tasks"
2-
require "rspec/core/rake_task"
1+
require 'bundler/gem_tasks'
2+
require 'rspec/core/rake_task'
33

44
RSpec::Core::RakeTask.new(:unit)
55

6-
desc "Run all test suites"
6+
desc 'Run all test suites'
77
task test: [:unit]
88

9-
desc "Display LOC stats"
9+
desc 'Display LOC stats'
1010
task :stats do
1111
puts "\n## Production Code Stats"
12-
sh "countloc -r lib"
12+
sh 'countloc -r lib'
1313
puts "\n## Test Code Stats"
14-
sh "countloc -r spec"
14+
sh 'countloc -r spec'
1515
end
1616

1717
begin
18-
require "cookstyle"
19-
require "rubocop/rake_task"
18+
require 'cookstyle'
19+
require 'rubocop/rake_task'
2020
RuboCop::RakeTask.new(:style) do |task|
21-
task.options += ["--chefstyle", "--display-cop-names", "--no-color"]
21+
task.options += ['--display-cop-names', '--no-color']
2222
end
2323
rescue LoadError
24-
puts "cookstyle is not available. gem install cookstyle to do style checking."
24+
puts 'cookstyle is not available. gem install cookstyle to do style checking.'
2525
end
2626

27-
desc "Run all quality tasks"
28-
task quality: %i{style stats}
27+
desc 'Run all quality tasks'
28+
task quality: %i(style stats)
2929

30-
task default: %i{test quality}
30+
task default: %i(test quality)

kitchen-openstack.gemspec

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# frozen_string_literal: true
22

3-
lib = File.expand_path("lib", __dir__)
3+
lib = File.expand_path('lib', __dir__)
44
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5-
require "kitchen/driver/openstack_version"
5+
require 'kitchen/driver/openstack_version'
66

77
Gem::Specification.new do |spec|
8-
spec.name = "kitchen-openstack"
8+
spec.name = 'kitchen-openstack'
99
spec.version = Kitchen::Driver::OPENSTACK_VERSION
10-
spec.authors = ["Jonathan Hartman", "JJ Asghar"]
11-
spec.email = ["j@p4nt5.com", "jj@chef.io"]
12-
spec.description = "A Test Kitchen OpenStack Nova driver"
10+
spec.authors = ['Jonathan Hartman', 'JJ Asghar']
11+
spec.email = ['j@p4nt5.com', 'jj@chef.io']
12+
spec.description = 'A Test Kitchen OpenStack Nova driver'
1313
spec.summary = spec.description
14-
spec.homepage = "https://github.com/test-kitchen/kitchen-openstack"
15-
spec.license = "Apache-2.0"
14+
spec.homepage = 'https://github.com/test-kitchen/kitchen-openstack'
15+
spec.license = 'Apache-2.0'
1616

17-
spec.files = Dir["LICENSE", "README.md", "lib/**/*"]
18-
spec.require_paths = ["lib"]
17+
spec.files = Dir['LICENSE', 'README.md', 'lib/**/*']
18+
spec.require_paths = ['lib']
1919

20-
spec.required_ruby_version = ">= 3.1"
20+
spec.required_ruby_version = '>= 3.1'
2121

22-
spec.add_dependency "test-kitchen", ">= 1.4.1", "< 5"
23-
spec.add_dependency "fog-openstack", "~> 1.0"
24-
spec.add_dependency "ohai"
22+
spec.add_dependency 'test-kitchen', '>= 1.4.1', '< 5'
23+
spec.add_dependency 'fog-openstack', '~> 1.0'
24+
spec.add_dependency 'ohai'
2525
end

0 commit comments

Comments
 (0)