diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b7175b0 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@test-kitchen/maintainers diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7062856 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +--- +version: 2 +updates: + - package-ecosystem: bundler + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..042bc85 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,9 @@ +--- +name: 'Lint, Unit & Integration Tests' + +'on': + pull_request: + +jobs: + lint-unit: + uses: test-kitchen/.github/.github/workflows/lint-unit.yml@main diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..d47a1b2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,32 @@ +--- +name: release-please + +"on": + push: + branches: [main] + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{ secrets.PORTER_GITHUB_TOKEN }} + + - name: Checkout + uses: actions/checkout@v4 + if: ${{ steps.release.outputs.release_created }} + + - name: Build and publish to GitHub Package + uses: actionshub/publish-gem-to-github@main + if: ${{ steps.release.outputs.release_created }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + owner: ${{ secrets.OWNER }} + + - name: Build and publish to RubyGems + uses: actionshub/publish-gem-to-rubygems@main + if: ${{ steps.release.outputs.release_created }} + with: + token: ${{ secrets.RUBYGEMS_API_KEY }} diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..138cbf8 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,8 @@ +--- +default: true +MD004: false +MD007: false +MD012: false +MD013: false +MD024: false +MD039: false diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..5fdd883 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "1.1.0" +} diff --git a/.rubocop.yml b/.rubocop.yml index 91258ec..8fd406e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,14 +1,11 @@ -Metrics/AbcSize: - Max: 50 -Metrics/ClassLength: - Max: 300 -Metrics/LineLength: - Max: 130 -Metrics/MethodLength: - Max: 25 -Style/Documentation: - Enabled: false -Style/SignalException: - Enabled: false -Style/SpaceInsideBrackets: - Enabled: false +--- +require: + - chefstyle + +AllCops: + TargetRubyVersion: 3.1 + Include: + - "**/*.rb" + Exclude: + - "vendor/**/*" + - "spec/**/*" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f11c445..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: ruby -cache: bundler -sudo: false - -rvm: -- 2.0.0 -- 2.1 -- 2.2 - -branches: - only: - - master - -notifications: - slack: - on_success: change - on_failure: always - rooms: - secure: "z33TKM67IPl+SUP9YZzZ3bl5384xrF8lm/PEdPmL9cGVJDLxN6VVo3hfwz//NlavS0Dfth4Y1Cb2c4cWqixpLNKaxcVZqulDx4ap13y1sSAmsN072hH5nsgHiF4NaqomUY0ytSudS3NOVUiXddGMALwZI0iinU3jKPKMXEy+ttwyd1Agetc7ZuNxEVf941jzaMrnyrHEU6DQnrfG5eR76XAB6fJaiMdFkfGN9d703prQzKF8YBL+5gNqtS9B4yaJbZ60RTiWPjU2lmPeLkWAohJwohbhRd2c5AbSsDTC6ZqcmHWCeI6emrWW9BqMT6atbgIyDkPYBbuWi5yyzGTAlYQC5RpaHlgK/Y5LlsxN05SHA059x1iC20s9E5F6TbQ08o3Yv2480tq9XEOTyJUPN5OFGLLlHGWTNpzfJBdRtPI44mw94ZMIowaPtpeEUIL5B6WfMIuM63wOkX1gBicv3LXAwYTKPyeNGH2ZTNVFc1EeRwgcaxhJaY73RJ9uKT8b09J1qteAKNuCVhuW4MXwDkYmJr8N/sZXLTrl+nwDYMSf+RxjMCsx7Z1C4rg9OuOT4M4vl/L72zoq3pwy2ZMOpPgYasyJtRzPRwKwYrw2UZ0iApWDyON/NXzFR0GK8jpCgoCnwjTRvAw7PpkNhJdIB1hFhqUsQCeQPALip3cAOMI=" diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b79e2..1a8aad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,19 @@ # kitchen-vcair Changelog ## Release: 1.1.0 / 2015-12-17 + * [pr#2](https://github.com/chef-partners/kitchen-vcair/pull/2) Added better error handling to resource fetchers for when the configured resource (image, network, catalog, etc.) does not exist. ## Release: 1.0.0 / 2015-08-21 + * Initial public release * Refactor by Chef Partner Engineering to match style of other VMware plugins * Support for vCloud Air OnDemand ## Release: 0.1.1 / 2015-06-04 + * Destroy working * Password updates * Documentation updates diff --git a/Gemfile b/Gemfile index 5d91b6f..0dd8be2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,18 @@ -# Encoding: UTF-8 - source 'https://rubygems.org' # Specify your gem's dependencies in kitchen-rackspace.gemspec gemspec + +group :test do + gem "rake" + gem "kitchen-inspec" + gem "rspec", "~> 3.2" +end + +group :debug do + gem "pry" +end + +group :chefstyle do + gem "chefstyle", "2.2.3" +end diff --git a/README.md b/README.md index d4c0867..82a793b 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,15 @@ gem 'kitchen-vcair' And then execute: - $ bundle +`bundle` Or install it yourself as: - $ gem install kitchen-vcair +`gem install kitchen-vcair` Or even better, install it via ChefDK: - $ chef gem install kitchen-vcair +`chef gem install kitchen-vcair` ## Usage @@ -168,9 +168,7 @@ License:: Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -``` -http://www.apache.org/licenses/LICENSE-2.0 -``` + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, @@ -181,7 +179,7 @@ and limitations under the License. We'd love to hear from you if this doesn't perform in the manner you expect. Please log a GitHub issue, or even better, submit a Pull Request with a fix! -1. Fork it ( https://github.com/chef-partners/kitchen-vcair/fork ) +1. Fork it () 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) diff --git a/Rakefile b/Rakefile index 3cb9c2f..71cfd2b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,19 @@ -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' -require 'rubocop/rake_task' +require "bundler/gem_tasks" -RSpec::Core::RakeTask.new(:spec) +require "rspec/core/rake_task" +desc "Run all specs in spec directory" +RSpec::Core::RakeTask.new(:test) do |t| + t.pattern = "spec/**/*_spec.rb" +end -task default: [ :spec ] +begin + require "chefstyle" + require "rubocop/rake_task" + RuboCop::RakeTask.new(:style) do |task| + task.options += ["--display-cop-names", "--no-color"] + end +rescue LoadError + puts "chefstyle is not available. (sudo) gem install chefstyle to do style checking." +end + +task default: %i{test style} diff --git a/kitchen-vcair.gemspec b/kitchen-vcair.gemspec index 4070194..780c44d 100644 --- a/kitchen-vcair.gemspec +++ b/kitchen-vcair.gemspec @@ -19,13 +19,8 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = %w(lib) - spec.required_ruby_version = '>= 2.0.0' + spec.required_ruby_version = '>= 3.1' - spec.add_dependency 'test-kitchen', '~> 1.4', '>= 1.4.1' - spec.add_dependency 'fog', '~> 1.33' - - spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rspec', '~> 3.2' - spec.add_development_dependency 'rubocop', '~> 0.49' - spec.add_development_dependency 'pry', '~> 0.10' + spec.add_dependency 'test-kitchen', ">= 1.1", "< 4.0" + spec.add_dependency 'fog', "~> 1.38.0" end diff --git a/lib/kitchen/driver/vcair.rb b/lib/kitchen/driver/vcair.rb index e419e38..2c7c7d0 100644 --- a/lib/kitchen/driver/vcair.rb +++ b/lib/kitchen/driver/vcair.rb @@ -1,4 +1,3 @@ -# Encoding: UTF-8 # # Authors:: Chris McClimans () # Authors:: Taylor Carpenter () @@ -18,9 +17,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'fog' -require 'kitchen' -require 'securerandom' +require "fog" +require "kitchen" +require "securerandom" unless defined?(SecureRandom) module Kitchen module Driver @@ -28,7 +27,7 @@ class Vcair < Kitchen::Driver::Base attr_accessor :vapp_id default_config :wait_for, 600 - default_config :vcair_api_path, '/api' + default_config :vcair_api_path, "/api" default_config :catalog_id, nil default_config :catalog_name, nil default_config :image_id, nil @@ -52,7 +51,7 @@ def initialize(config) end def name - 'vCloudAir' + "vCloudAir" end def create(state) @@ -83,13 +82,13 @@ def destroy(state) return end - info('Powering off the vApp...') + info("Powering off the vApp...") vapp.power_off - info('Undeploying the vApp...') + info("Undeploying the vApp...") vapp.undeploy - info('Deleting the vApp...') + info("Deleting the vApp...") vapp.destroy info("vApp <#{state[:vapp_id]}> destroyed.") @@ -111,25 +110,25 @@ def create_server(state) info("vApp ID #{vapp_id} created.") - info('Validating the vApp...') + info("Validating the vApp...") unless validate_vapp destroy(state) return end - info('Updating the VM customization...') + info("Updating the VM customization...") update_customization - info('Adjusting VM hardware...') + info("Adjusting VM hardware...") adjust_hardware - info('Attaching it to the network...') + info("Attaching it to the network...") attach_network - info('Tagging the VM...') + info("Tagging the VM...") tag_vm - info('Powering on the VM...') + info("Powering on the VM...") power_on end @@ -147,9 +146,9 @@ def attach_network_payload needsCustomization: true, NetworkConnectionIndex: 0, IsConnected: true, - IpAddressAllocationMode: 'POOL' - } - ] + IpAddressAllocationMode: "POOL", + }, + ], } end @@ -159,7 +158,7 @@ def attach_network end def tag_vm - vm.tags.create('created-by', 'test-kitchen') + vm.tags.create("created-by", "test-kitchen") end def power_on @@ -175,18 +174,18 @@ def wait_for_server(state) end def vcloud_username - [ config[:vcair_username], config[:vcair_org] ].join('@') + [ config[:vcair_username], config[:vcair_org] ].join("@") end def fog_server_def { - provider: 'vclouddirector', + provider: "vclouddirector", vcloud_director_username: vcloud_username, vcloud_director_password: config[:vcair_password], vcloud_director_host: config[:vcair_api_host], vcloud_director_api_version: config[:vcair_api_version], vcloud_director_show_progress: false, - path: config[:vcair_api_path] + path: config[:vcair_api_path], } end @@ -197,7 +196,8 @@ def image catalog.catalog_items.get_by_name(config[:image_name]) end - raise 'Unable to find image - check your image_id or image_name' if image.nil? + raise "Unable to find image - check your image_id or image_name" if image.nil? + image end @@ -208,7 +208,8 @@ def catalog org.catalogs.get_by_name(config[:catalog_name]) end - raise 'Unable to find catalog - check your catalog_id or catalog_name' if catalog.nil? + raise "Unable to find catalog - check your catalog_id or catalog_name" if catalog.nil? + catalog end @@ -219,7 +220,8 @@ def vdc org.vdcs.get_by_name(config[:vdc_name]) end - raise 'Unable to find VDC - check your vdc_id or vdc_name' if vdc.nil? + raise "Unable to find VDC - check your vdc_id or vdc_name" if vdc.nil? + vdc end @@ -230,7 +232,8 @@ def network org.networks.get_by_name(config[:network_name]) end - raise 'Unable to find network - check your network_id or network_name' if network.nil? + raise "Unable to find network - check your network_id or network_name" if network.nil? + network end @@ -247,28 +250,28 @@ def generate_node_name # We need the name to be 15 chars or less to play nicely # with windows, so we're generating a 12-char random # string prefixed with "tk-" - 'tk-' + SecureRandom.hex(6) + "tk-" + SecureRandom.hex(6) end def instantiate_config { vdc_id: vdc.id, network_id: network.id, - description: node_description + description: node_description, } end def print_error_and_exit(message) error(message) - fail message + raise message end def validate! - %w(vdc catalog image network).each do |param| + %w{vdc catalog image network}.each do |param| validate_parameter_pair!(param) end - [ :org, :vdc, :catalog, :image, :network].each do |method| + %i{org vdc catalog image network}.each do |method| validate_method!(method) end @@ -277,8 +280,8 @@ def validate! end def validate_parameter_pair!(param) - id_key = param + '_id' - name_key = param + '_name' + id_key = param + "_id" + name_key = param + "_name" print_error_and_exit("No #{param} found. You must specify #{id_key} or #{name_key}.") if config[id_key.to_sym].nil? && config[name_key.to_sym].nil? @@ -293,7 +296,7 @@ def validate_method!(method) def validate_computer_name! # regex proudly modified after stealing from: # http://stackoverflow.com/questions/2063213/regular-expression-for-validating-dns-label-host-name - print_error_and_exit('Node name is not valid - must be 15 characters or less, and be a valid Windows node name') unless + print_error_and_exit("Node name is not valid - must be 15 characters or less, and be a valid Windows node name") unless node_name =~ /^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,15}(? 1 - error('vApp created, but contained more than one VM') + error("vApp created, but contained more than one VM") return false end diff --git a/lib/kitchen/driver/vcair_version.rb b/lib/kitchen/driver/vcair_version.rb index f0468c3..73d4a3e 100644 --- a/lib/kitchen/driver/vcair_version.rb +++ b/lib/kitchen/driver/vcair_version.rb @@ -1,4 +1,3 @@ -# Encoding: UTF-8 # # Authors:: Chris McClimans () # Authors:: Taylor Carpenter () @@ -20,6 +19,6 @@ module Kitchen module Driver - VCAIR_VERSION = '1.1.0'.freeze + VCAIR_VERSION = "1.1.0".freeze end end diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..bf100b7 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,12 @@ +{ + "packages": { + ".": { + "package-name": "kitchen-vcair", + "changelog-path": "CHANGELOG.md", + "release-type": "ruby", + "include-component-in-tag": false, + "version-file": "lib/kitchen/driver/vcair_version.rb" + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/spec/vcair_spec.rb b/spec/kitchen/driver/vcair_spec.rb similarity index 99% rename from spec/vcair_spec.rb rename to spec/kitchen/driver/vcair_spec.rb index c6aba73..a4d28a4 100644 --- a/spec/vcair_spec.rb +++ b/spec/kitchen/driver/vcair_spec.rb @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' +require_relative "../../spec_helper" require 'excon' require 'kitchen/driver/vcair' require 'kitchen/provisioner/dummy' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b1ce97f..623f43c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,3 @@ -# Encoding: UTF-8 # # Authors:: Chef Partner Engineering () # Copyright:: Copyright (c) 2015 Chef Software, Inc. @@ -15,3 +14,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +require "rake" +require "rspec" +require "logger" +require "stringio" unless defined?(StringIO) +require "kitchen" + +require_relative "../lib/kitchen/driver/vcair" +RSpec.configure do |config| + config.run_all_when_everything_filtered = true + config.filter_run(:focus) + config.order = "random" +end