Skip to content

Commit a2499aa

Browse files
committed
fix: switch linting from cookstyle to chefstyle
Update Rakefile to use 'cookstyle --chefstyle' instead of RuboCop::RakeTask with the unsupported --chefstyle flag. The --chefstyle flag is handled by the cookstyle binary, not by RuboCop directly. Remove the require directive from .rubocop.yml since --chefstyle handles config loading internally. Auto-correct all chefstyle offenses (double-quoted strings, %i{} delimiters). Signed-off-by: Lance Albertson <lance@osuosl.org>
1 parent 470abed commit a2499aa

9 files changed

Lines changed: 67 additions & 70 deletions

File tree

.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
require:
3-
- cookstyle
4-
52
AllCops:
63
TargetRubyVersion: 3.1
74
Include:

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ end
1616

1717
begin
1818
require 'cookstyle'
19-
require 'rubocop/rake_task'
20-
RuboCop::RakeTask.new(:style) do |task|
21-
task.options += ['--display-cop-names', '--no-color']
19+
desc 'Run cookstyle with chefstyle rules'
20+
task :style do
21+
sh 'cookstyle --chefstyle --display-cop-names'
2222
end
2323
rescue LoadError
2424
puts 'cookstyle is not available. gem install cookstyle to do style checking.'

lib/kitchen/driver/openstack.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
# See the License for the specific language governing permissions and
2222
# limitations under the License.
2323

24-
require 'kitchen'
25-
require 'fog/openstack'
26-
require 'yaml'
27-
require_relative 'openstack_version'
28-
require_relative 'openstack/config'
29-
require_relative 'openstack/helpers'
30-
require_relative 'openstack/networking'
31-
require_relative 'openstack/server_helper'
32-
require_relative 'openstack/volume'
24+
require "kitchen"
25+
require "fog/openstack"
26+
require "yaml"
27+
require_relative "openstack_version"
28+
require_relative "openstack/config"
29+
require_relative "openstack/helpers"
30+
require_relative "openstack/networking"
31+
require_relative "openstack/server_helper"
32+
require_relative "openstack/volume"
3333

3434
module Kitchen
3535
module Driver
@@ -46,7 +46,7 @@ class Openstack < Kitchen::Driver::Base
4646
default_config :server_name, nil
4747
default_config :server_name_prefix, nil
4848
default_config :key_name, nil
49-
default_config :port, '22'
49+
default_config :port, "22"
5050
default_config :use_ipv6, false
5151
default_config :openstack_project_name, nil
5252
default_config :openstack_region, nil
@@ -110,13 +110,13 @@ def destroy(state)
110110

111111
unless server.nil?
112112
if config[:floating_ip_pool] && config[:allocate_floating_ip]
113-
info 'Retrieve the floating IP'
113+
info "Retrieve the floating IP"
114114
pub, priv = get_public_private_ips(server)
115115
pub, = parse_ips(pub, priv)
116116
pub_ip = pub[config[:public_ip_order].to_i] || nil
117117
if pub_ip
118118
info "Retrieve the ID of floating IP <#{pub_ip}>"
119-
floating_ip_id = network.list_floating_ips(floating_ip_address: pub_ip).body['floatingips'][0]['id']
119+
floating_ip_id = network.list_floating_ips(floating_ip_address: pub_ip).body["floatingips"][0]["id"]
120120
network.delete_floating_ip(floating_ip_id)
121121
info "OpenStack Floating IP <#{pub_ip}> released."
122122
end
@@ -141,17 +141,17 @@ def openstack_server
141141
end
142142

143143
def required_server_settings
144-
%i(openstack_username openstack_api_key openstack_auth_url openstack_domain_id)
144+
%i{openstack_username openstack_api_key openstack_auth_url openstack_domain_id}
145145
end
146146

147147
def optional_server_settings
148148
Fog::OpenStack::Compute.recognized.select do |k|
149-
k.to_s.start_with?('openstack')
149+
k.to_s.start_with?("openstack")
150150
end - required_server_settings
151151
end
152152

153153
def connection_options
154-
%i(read_timeout write_timeout connect_timeout)
154+
%i{read_timeout write_timeout connect_timeout}
155155
end
156156

157157
def network

lib/kitchen/driver/openstack/config.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def config_server_name
4949
# Total: 63
5050
def default_name
5151
[
52-
instance.name.gsub(/\W/, '')[0..14],
53-
((Etc.getpwuid ? Etc.getpwuid.name : Etc.getlogin) || 'nologin').gsub(/\W/, '')[0..14],
54-
Socket.gethostname.gsub(/\W/, '')[0..22],
52+
instance.name.gsub(/\W/, "")[0..14],
53+
((Etc.getpwuid ? Etc.getpwuid.name : Etc.getlogin) || "nologin").gsub(/\W/, "")[0..14],
54+
Socket.gethostname.gsub(/\W/, "")[0..22],
5555
Array.new(7) { rand(36).to_s(36) }.join,
56-
].join('-')
56+
].join("-")
5757
end
5858

5959
def server_name_prefix(server_name_prefix)
@@ -67,18 +67,18 @@ def server_name_prefix(server_name_prefix)
6767
# Max: 63
6868
#
6969
if server_name_prefix.length > 54
70-
warn 'Server name prefix too long, truncated to 54 characters'
70+
warn "Server name prefix too long, truncated to 54 characters"
7171
server_name_prefix = server_name_prefix[0..53]
7272
end
7373

74-
server_name_prefix.gsub!(/\W/, '')
74+
server_name_prefix.gsub!(/\W/, "")
7575

7676
if server_name_prefix.empty?
77-
warn 'Server name prefix empty or invalid; using fully generated name'
77+
warn "Server name prefix empty or invalid; using fully generated name"
7878
default_name
7979
else
80-
random_suffix = ('a'..'z').to_a.sample(8).join
81-
server_name_prefix + '-' + random_suffix
80+
random_suffix = ("a".."z").to_a.sample(8).join
81+
server_name_prefix + "-" + random_suffix
8282
end
8383
end
8484
end

lib/kitchen/driver/openstack/helpers.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# See the License for the specific language governing permissions and
2222
# limitations under the License.
2323

24-
require 'ohai' unless defined?(Ohai::System)
24+
require "ohai" unless defined?(Ohai::System)
2525

2626
module Kitchen
2727
module Driver
@@ -32,14 +32,14 @@ module Helpers
3232

3333
def add_ohai_hint(state)
3434
if bourne_shell?
35-
info 'Adding OpenStack hint for ohai'
35+
info "Adding OpenStack hint for ohai"
3636
mkdir_cmd = "sudo mkdir -p #{hints_path}"
3737
touch_cmd = "sudo bash -c 'echo {} > #{hints_path}/openstack.json'"
3838
instance.transport.connection(state).execute(
3939
"#{mkdir_cmd} && #{touch_cmd}"
4040
)
4141
elsif windows_os?
42-
info 'Adding OpenStack hint for ohai'
42+
info "Adding OpenStack hint for ohai"
4343
touch_cmd = "New-Item #{hints_path}\\openstack.json"
4444
touch_cmd_args = "-Value '{}' -Force -Type file"
4545
instance.transport.connection(state).execute(
@@ -53,7 +53,7 @@ def hints_path
5353
end
5454

5555
def disable_ssl_validation
56-
require 'excon' unless defined?(Excon)
56+
require "excon" unless defined?(Excon)
5757
Excon.defaults[:ssl_verify_peer] = false
5858
end
5959

@@ -62,7 +62,7 @@ def wait_for_server(state)
6262
info "Sleeping for #{config[:server_wait]} seconds to let your server start up..."
6363
countdown(config[:server_wait])
6464
end
65-
info 'Waiting for server to be ready...'
65+
info "Waiting for server to be ready..."
6666
instance.transport.connection(state).wait_until_ready
6767
rescue
6868
error "Server #{state[:hostname]} (#{state[:server_id]}) not reachable. Destroying server..."
@@ -73,7 +73,7 @@ def wait_for_server(state)
7373
def countdown(seconds)
7474
date1 = Time.now + seconds
7575
while Time.now < date1
76-
Kernel.print '.'
76+
Kernel.print "."
7777
sleep 10
7878
end
7979
end

lib/kitchen/driver/openstack/networking.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# See the License for the specific language governing permissions and
2222
# limitations under the License.
2323

24-
require 'ipaddr' unless defined?(IPAddr)
24+
require "ipaddr" unless defined?(IPAddr)
2525

2626
module Kitchen
2727
module Driver
@@ -37,11 +37,11 @@ def attach_ip_from_pool(server, pool)
3737
info "Attaching floating IP from <#{pool}> pool"
3838
if config[:allocate_floating_ip]
3939
network_id = network
40-
.list_networks(
40+
.list_networks(
4141
name: pool
42-
).body['networks'][0]['id']
42+
).body["networks"][0]["id"]
4343
resp = network.create_floating_ip(network_id)
44-
ip = resp.body['floatingip']['floating_ip_address']
44+
ip = resp.body["floatingip"]["floating_ip_address"]
4545
info "Created floating IP <#{ip}> from <#{pool}> pool"
4646
config[:floating_ip] = ip
4747
else
@@ -70,8 +70,8 @@ def get_public_private_ips(server)
7070
rescue Fog::OpenStack::Compute::NotFound, Excon::Errors::Forbidden
7171
# See Fog issue: https://github.com/fog/fog/issues/2160
7272
addrs = server.addresses
73-
addrs['public'] && pub = addrs['public'].map { |i| i['addr'] }
74-
addrs['private'] && priv = addrs['private'].map { |i| i['addr'] }
73+
addrs["public"] && pub = addrs["public"].map { |i| i["addr"] }
74+
addrs["private"] && priv = addrs["private"].map { |i| i["addr"] }
7575
end
7676
[pub, priv]
7777
end
@@ -83,33 +83,33 @@ def get_ip(server)
8383
end
8484

8585
# make sure we have the latest info
86-
info 'Waiting for network information to be available...'
86+
info "Waiting for network information to be available..."
8787
begin
8888
w = server.wait_for { !addresses.empty? }
8989
debug "Waited #{w[:duration]} seconds for network information."
9090
rescue Fog::Errors::TimeoutError
91-
raise ActionFailed, 'Could not get network information (timed out)'
91+
raise ActionFailed, "Could not get network information (timed out)"
9292
end
9393

9494
# should also work for private networks
9595
if config[:openstack_network_name]
9696
debug "Using configured net: #{config[:openstack_network_name]}"
97-
return filter_ips(server.addresses[config[:openstack_network_name]]).first['addr']
97+
return filter_ips(server.addresses[config[:openstack_network_name]]).first["addr"]
9898
end
9999

100100
pub, priv = get_public_private_ips(server)
101101
priv = server.ip_addresses if Array(pub).empty? && Array(priv).empty?
102102
pub, priv = parse_ips(pub, priv)
103103
pub[config[:public_ip_order].to_i] ||
104104
priv[config[:private_ip_order].to_i] ||
105-
raise(ActionFailed, 'Could not find an IP')
105+
raise(ActionFailed, "Could not find an IP")
106106
end
107107

108108
def filter_ips(addresses)
109109
if config[:use_ipv6]
110-
addresses.select { |i| IPAddr.new(i['addr']).ipv6? }
110+
addresses.select { |i| IPAddr.new(i["addr"]).ipv6? }
111111
else
112-
addresses.select { |i| IPAddr.new(i['addr']).ipv4? }
112+
addresses.select { |i| IPAddr.new(i["addr"]).ipv4? }
113113
end
114114
end
115115

lib/kitchen/driver/openstack/server_helper.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,36 @@ module ServerHelper
3030

3131
def create_server
3232
server_def = init_configuration
33-
raise(ActionFailed, 'Cannot specify both network_ref and network_id') if config[:network_id] && config[:network_ref]
33+
raise(ActionFailed, "Cannot specify both network_ref and network_id") if config[:network_id] && config[:network_ref]
3434

3535
if config[:network_id]
3636
networks = [].push(config[:network_id])
3737
server_def[:nics] = networks.flatten.map do |net_id|
38-
{ 'net_id' => net_id }
38+
{ "net_id" => net_id }
3939
end
4040
elsif config[:network_ref]
4141
networks = [].push(config[:network_ref])
4242
server_def[:nics] = networks.flatten.map do |net|
43-
{ 'net_id' => find_network(net).id }
43+
{ "net_id" => find_network(net).id }
4444
end
4545
end
4646

4747
if config[:block_device_mapping]
4848
server_def[:block_device_mapping] = get_bdm(config)
4949
end
5050

51-
%i(
51+
%i{
5252
security_groups
5353
key_name
5454
user_data
5555
config_drive
5656
metadata
57-
).each do |c|
57+
}.each do |c|
5858
server_def[c] = optional_config(c) if config[c]
5959
end
6060

6161
if config[:cloud_config]
62-
raise(ActionFailed, 'Cannot specify both cloud_config and user_data') if config[:user_data]
62+
raise(ActionFailed, "Cannot specify both cloud_config and user_data") if config[:user_data]
6363

6464
server_def[:user_data] = YAML.dump(Kitchen::Util.stringified_hash(config[:cloud_config])).gsub(/^---\n/, "#cloud-config\n")
6565
end
@@ -71,8 +71,8 @@ def create_server
7171
end
7272

7373
def init_configuration
74-
raise(ActionFailed, 'Cannot specify both image_ref and image_id') if config[:image_id] && config[:image_ref]
75-
raise(ActionFailed, 'Cannot specify both flavor_ref and flavor_id') if config[:flavor_id] && config[:flavor_ref]
74+
raise(ActionFailed, "Cannot specify both image_ref and image_id") if config[:image_id] && config[:image_ref]
75+
raise(ActionFailed, "Cannot specify both flavor_ref and flavor_id") if config[:flavor_id] && config[:flavor_ref]
7676

7777
{
7878
name: config[:server_name],
@@ -95,31 +95,31 @@ def optional_config(c)
9595

9696
def find_image(image_ref)
9797
image = find_matching(compute.images, image_ref)
98-
raise(ActionFailed, 'Image not found') unless image
98+
raise(ActionFailed, "Image not found") unless image
9999

100100
debug "Selected image: #{image.id} #{image.name}"
101101
image
102102
end
103103

104104
def find_flavor(flavor_ref)
105105
flavor = find_matching(compute.flavors, flavor_ref)
106-
raise(ActionFailed, 'Flavor not found') unless flavor
106+
raise(ActionFailed, "Flavor not found") unless flavor
107107

108108
debug "Selected flavor: #{flavor.id} #{flavor.name}"
109109
flavor
110110
end
111111

112112
def find_network(network_ref)
113113
net = find_matching(network.networks.all, network_ref)
114-
raise(ActionFailed, 'Network not found') unless net
114+
raise(ActionFailed, "Network not found") unless net
115115

116116
debug "Selected net: #{net.id} #{net.name}"
117117
net
118118
end
119119

120120
def find_matching(collection, name)
121121
name = name.to_s
122-
if name.start_with?('/') && name.end_with?('/')
122+
if name.start_with?("/") && name.end_with?("/")
123123
regex = Regexp.new(name[1...-1])
124124
# check for regex name match
125125
collection.each { |single| return single if regex&.match?(single.name) }

0 commit comments

Comments
 (0)