From 6288641bd733e0257f0529affa3a2a73a5362c87 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 29 Sep 2016 15:06:43 -0700 Subject: [PATCH 01/10] Add issue template Signed-off-by: Tim Smith --- .github/ISSUE_TEMPLATE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..f229e13f --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,21 @@ +# Version: + +[Version of the project installed] + +# Environment: [Details about the environment such as the Operating System, cookbook details, etc...] + +# Scenario: + +[What you are trying to achieve and you can't?] + +# Steps to Reproduce: + +[If you are filing an issue what are the things we need to do in order to repro your problem?] + +# Expected Result: + +[What are you expecting to happen as the consequence of above reproduction steps?] + +# Actual Result: + +[What actually happens after the reproduction steps?] From 209545cae3aa3f457a0b272453571b9a8dd0d8cf Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 29 Sep 2016 15:06:57 -0700 Subject: [PATCH 02/10] Update copyright Signed-off-by: Tim Smith --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 8c0bf59d..0f1f75f1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ # Author:: Kaustubh Deorukhkar () -# Copyright:: Copyright (c) 2013 Chef Software, Inc. +# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc. require 'bundler' require 'bundler/setup' From 0f6ac9352b918f5415f1eede39d499fe139e13d6 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 29 Sep 2016 15:07:09 -0700 Subject: [PATCH 03/10] Require Chef 12 Signed-off-by: Tim Smith --- knife-openstack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knife-openstack.gemspec b/knife-openstack.gemspec index 744bb8ec..7d6cc531 100644 --- a/knife-openstack.gemspec +++ b/knife-openstack.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.add_dependency 'fog', '~> 1.23' - s.add_dependency 'chef', '>= 11' + s.add_dependency 'chef', '>= 12' s.add_dependency 'knife-cloud', '~> 1.2.0' %w(bundler rubocop rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem } From d7ce5edafc583281b97dd7da18409fb2220998c2 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 29 Sep 2016 15:07:22 -0700 Subject: [PATCH 04/10] Test on the latest Ruby 2.2 Signed-off-by: Tim Smith --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e0e3f581..8c2b6843 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: ruby cache: bundler sudo: false rvm: -- 2.2.3 +- 2.2.5 - 2.3.1 -script: bundle exec rake spec -notifications: - irc: - - "chat.freenode.net#openstack-chef" +branches: + only: + - master +script: bundle exec rake spec \ No newline at end of file From 20b2b9017bcf6a2094dd576ba12c93fad717197a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 29 Sep 2016 15:07:32 -0700 Subject: [PATCH 05/10] Use Chefstyle not Rubocop Signed-off-by: Tim Smith --- knife-openstack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knife-openstack.gemspec b/knife-openstack.gemspec index 7d6cc531..72150cac 100644 --- a/knife-openstack.gemspec +++ b/knife-openstack.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |s| s.add_dependency 'chef', '>= 12' s.add_dependency 'knife-cloud', '~> 1.2.0' - %w(bundler rubocop rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem } + %w(bundler chefstyle rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem } end From 056c703dd489d73274900ea13c522f56d68eb223 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 29 Sep 2016 15:33:27 -0700 Subject: [PATCH 06/10] Use chefstyle in Rake and resolve all warnings Signed-off-by: Tim Smith --- .travis.yml | 8 +- Gemfile | 6 +- Rakefile | 11 +- knife-openstack.gemspec | 32 +- .../cloud/openstack_server_create_options.rb | 70 +-- lib/chef/knife/cloud/openstack_service.rb | 12 +- .../knife/cloud/openstack_service_options.rb | 34 +- lib/chef/knife/openstack_flavor_list.rb | 20 +- .../knife/openstack_floating_ip_allocate.rb | 24 +- .../knife/openstack_floating_ip_associate.rb | 16 +- .../openstack_floating_ip_disassociate.rb | 16 +- lib/chef/knife/openstack_floating_ip_list.rb | 18 +- .../knife/openstack_floating_ip_release.rb | 12 +- lib/chef/knife/openstack_group_list.rb | 24 +- lib/chef/knife/openstack_helpers.rb | 14 +- lib/chef/knife/openstack_image_list.rb | 26 +- lib/chef/knife/openstack_network_list.rb | 18 +- lib/chef/knife/openstack_server_create.rb | 112 ++-- lib/chef/knife/openstack_server_delete.rb | 12 +- lib/chef/knife/openstack_server_list.rb | 30 +- lib/chef/knife/openstack_server_show.rb | 32 +- lib/chef/knife/openstack_volume_list.rb | 18 +- lib/knife-openstack/version.rb | 4 +- spec/functional/flavor_list_func_spec.rb | 24 +- spec/functional/floating_ip_list_func_spec.rb | 26 +- spec/functional/group_list_func_spec.rb | 56 +- spec/functional/image_list_func_spec.rb | 28 +- spec/functional/network_list_func_spec.rb | 24 +- spec/functional/server_create_func_spec.rb | 56 +- spec/functional/server_delete_func_spec.rb | 34 +- spec/functional/server_list_func_spec.rb | 84 +-- spec/functional/server_show_func_spec.rb | 12 +- spec/functional/volume_list_func_spec.rb | 22 +- spec/integration/cleanup.rb | 10 +- spec/integration/openstack_spec.rb | 572 +++++++++--------- spec/spec_context.rb | 18 +- spec/spec_helper.rb | 74 +-- spec/unit/openstack_flavor_list_spec.rb | 10 +- .../openstack_floating_ip_allocate_spec.rb | 26 +- .../openstack_floating_ip_associate_spec.rb | 20 +- ...openstack_floating_ip_disassociate_spec.rb | 22 +- spec/unit/openstack_floating_ip_list_spec.rb | 10 +- .../openstack_floating_ip_release_spec.rb | 24 +- spec/unit/openstack_group_list_spec.rb | 20 +- spec/unit/openstack_image_list_spec.rb | 10 +- spec/unit/openstack_network_list_spec.rb | 14 +- spec/unit/openstack_server_create_spec.rb | 260 ++++---- spec/unit/openstack_server_delete_spec.rb | 14 +- spec/unit/openstack_server_list_spec.rb | 10 +- spec/unit/openstack_server_show_spec.rb | 18 +- spec/unit/openstack_service_spec.rb | 50 +- spec/unit/openstack_volume_list_spec.rb | 10 +- 52 files changed, 1064 insertions(+), 1063 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c2b6843..15d8bc06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: ruby cache: bundler sudo: false rvm: -- 2.2.5 -- 2.3.1 + - 2.2.5 + - 2.3.1 branches: only: - - master -script: bundle exec rake spec \ No newline at end of file + - master +script: bundle exec rake diff --git a/Gemfile b/Gemfile index 9b1e655f..7ae2b1f0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,9 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in knife-openstack.gemspec gemspec group :development do - gem 'guard-rspec' - gem 'mixlib-shellout' + gem "guard-rspec" + gem "mixlib-shellout" end diff --git a/Rakefile b/Rakefile index 0f1f75f1..7c20cd0f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,12 @@ # Author:: Kaustubh Deorukhkar () # Copyright:: Copyright (c) 2013-2016 Chef Software, Inc. -require 'bundler' -require 'bundler/setup' -require 'bundler/gem_tasks' -require 'rubocop/rake_task' -require 'rspec/core/rake_task' +require "bundler" +require "bundler/setup" +require "bundler/gem_tasks" +require "chefstyle" +require "rubocop/rake_task" +require "rspec/core/rake_task" RuboCop::RakeTask.new diff --git a/knife-openstack.gemspec b/knife-openstack.gemspec index 72150cac..448701a4 100644 --- a/knife-openstack.gemspec +++ b/knife-openstack.gemspec @@ -1,29 +1,29 @@ # -*- encoding: utf-8 -*- -$LOAD_PATH.push File.expand_path('../lib', __FILE__) -require 'knife-openstack/version' +$LOAD_PATH.push File.expand_path("../lib", __FILE__) +require "knife-openstack/version" Gem::Specification.new do |s| - s.name = 'knife-openstack' + s.name = "knife-openstack" s.version = Knife::OpenStack::VERSION - s.version = "#{s.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS'] + s.version = "#{s.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV["TRAVIS"] s.platform = Gem::Platform::RUBY s.has_rdoc = true - s.extra_rdoc_files = ['README.md', 'LICENSE'] - s.authors = ['JJ Asghar'] - s.email = ['jj@chef.io'] - s.homepage = 'https://github.com/chef/knife-openstack' - s.summary = 'A Chef knife plugin for OpenStack clouds.' - s.description = 'A Chef knife plugin for OpenStack clouds.' - s.license = 'Apache-2.0' + s.extra_rdoc_files = ["README.md", "LICENSE"] + s.authors = ["JJ Asghar"] + s.email = ["jj@chef.io"] + s.homepage = "https://github.com/chef/knife-openstack" + s.summary = "A Chef knife plugin for OpenStack clouds." + s.description = "A Chef knife plugin for OpenStack clouds." + s.license = "Apache-2.0" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } - s.require_paths = ['lib'] + s.require_paths = ["lib"] - s.add_dependency 'fog', '~> 1.23' - s.add_dependency 'chef', '>= 12' - s.add_dependency 'knife-cloud', '~> 1.2.0' + s.add_dependency "fog", "~> 1.23" + s.add_dependency "chef", ">= 12" + s.add_dependency "knife-cloud", "~> 1.2.0" - %w(bundler chefstyle rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem } + %w{bundler chefstyle rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter}.each { |gem| s.add_development_dependency gem } end diff --git a/lib/chef/knife/cloud/openstack_server_create_options.rb b/lib/chef/knife/cloud/openstack_server_create_options.rb index 0e863258..91927cbd 100644 --- a/lib/chef/knife/cloud/openstack_server_create_options.rb +++ b/lib/chef/knife/cloud/openstack_server_create_options.rb @@ -1,5 +1,5 @@ -require 'chef/knife/cloud/server/create_options' +require "chef/knife/cloud/server/create_options" class Chef class Knife @@ -11,72 +11,72 @@ def self.included(includer) # Openstack Server create params. option :private_network, - long: '--openstack-private-network', - description: 'Use the private IP for bootstrapping rather than the public IP', + long: "--openstack-private-network", + description: "Use the private IP for bootstrapping rather than the public IP", boolean: true, default: false option :openstack_floating_ip, - short: '-a [IP]', - long: '--openstack-floating-ip [IP]', - default: '-1', - description: 'Request to associate a floating IP address to the new OpenStack node. Assumes IPs have been allocated to the project. Specific IP is optional.' + short: "-a [IP]", + long: "--openstack-floating-ip [IP]", + default: "-1", + description: "Request to associate a floating IP address to the new OpenStack node. Assumes IPs have been allocated to the project. Specific IP is optional." option :openstack_volumes, - long: '--openstack-volumes VOLUME1,VOLUME2,VOLUME3', - description: 'Comma separated list of the UUID(s) of the volume(s) to attach to the server', - proc: proc { |volumes| volumes.split(',') } + long: "--openstack-volumes VOLUME1,VOLUME2,VOLUME3", + description: "Comma separated list of the UUID(s) of the volume(s) to attach to the server", + proc: proc { |volumes| volumes.split(",") } option :openstack_scheduler_hints, - long: '--scheduler-hints HINTS', - description: 'A scheduler group hint to OpenStack', + long: "--scheduler-hints HINTS", + description: "A scheduler group hint to OpenStack", proc: proc { |i| Chef::Config[:knife][:openstack_scheduler_hints] = i } option :openstack_security_groups, - short: '-G X,Y,Z', - long: '--openstack-groups X,Y,Z', - description: 'The security groups for this server', - default: ['default'], - proc: proc { |groups| groups.split(',') } + short: "-G X,Y,Z", + long: "--openstack-groups X,Y,Z", + description: "The security groups for this server", + default: ["default"], + proc: proc { |groups| groups.split(",") } option :openstack_ssh_key_id, - short: '-S KEY', - long: '--openstack-ssh-key-id KEY', - description: 'The OpenStack SSH keypair id', + short: "-S KEY", + long: "--openstack-ssh-key-id KEY", + description: "The OpenStack SSH keypair id", proc: proc { |key| Chef::Config[:knife][:openstack_ssh_key_id] = key } option :user_data, - long: '--user-data USER_DATA', - description: 'The file path containing user data information for this server', + long: "--user-data USER_DATA", + description: "The file path containing user data information for this server", proc: proc { |user_data| open(user_data, &:read) } option :bootstrap_network, - long: '--bootstrap-network NAME', - default: 'public', + long: "--bootstrap-network NAME", + default: "public", description: "Specify network for bootstrapping. Default is 'public'." option :network, - long: '--no-network', + long: "--no-network", boolean: true, default: true, description: "Use first available network for bootstrapping if 'public' and 'private' are unavailable." option :network_ids, - long: '--network-ids NETWORK_ID_1,NETWORK_ID_2,NETWORK_ID_3', - description: 'Comma separated list of the UUID(s) of the network(s) for the server to attach', - proc: proc { |networks| networks.split(',') } + long: "--network-ids NETWORK_ID_1,NETWORK_ID_2,NETWORK_ID_3", + description: "Comma separated list of the UUID(s) of the network(s) for the server to attach", + proc: proc { |networks| networks.split(",") } option :availability_zone, - short: '-Z ZONE_NAME', - long: '--availability-zone ZONE_NAME', - description: 'The availability zone for this server', + short: "-Z ZONE_NAME", + long: "--availability-zone ZONE_NAME", + description: "The availability zone for this server", proc: proc { |z| Chef::Config[:knife][:availability_zone] = z } option :metadata, - short: '-M X=1', - long: '--metadata X=1', - description: 'Metadata information for this server (may pass multiple times)', - proc: proc { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!(data.split('=')[0] => data.split('=')[1]) } + short: "-M X=1", + long: "--metadata X=1", + description: "Metadata information for this server (may pass multiple times)", + proc: proc { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!(data.split("=")[0] => data.split("=")[1]) } end end end diff --git a/lib/chef/knife/cloud/openstack_service.rb b/lib/chef/knife/cloud/openstack_service.rb index 5dd2171a..a2f041d9 100644 --- a/lib/chef/knife/cloud/openstack_service.rb +++ b/lib/chef/knife/cloud/openstack_service.rb @@ -4,7 +4,7 @@ # Copyright:: Copyright (c) 2013 Chef Software, Inc. # -require 'chef/knife/cloud/fog/service' +require "chef/knife/cloud/fog/service" class Chef class Knife @@ -35,7 +35,7 @@ def get_server(search_term) if servers.length > 1 error_message = "Multiple server matches found for '#{search_term}', use an instance_id to be more specific." ui.fatal(error_message) - fail CloudExceptions::ValidationError, error_message + raise CloudExceptions::ValidationError, error_message else servers.first end @@ -47,10 +47,10 @@ def get_server(search_term) def get_auth_params load_fog_gem params = { - provider: 'OpenStack', + provider: "OpenStack", connection_options: { - ssl_verify_peer: !Chef::Config[:knife][:openstack_insecure] - } + ssl_verify_peer: !Chef::Config[:knife][:openstack_insecure], + }, } ( @@ -58,7 +58,7 @@ def get_auth_params Fog::Compute::OpenStack.recognized - [:openstack_api_key] ).each do |k| - next unless k.to_s.start_with?('openstack') + next unless k.to_s.start_with?("openstack") params[k] = Chef::Config[:knife][k] end params[:openstack_api_key] = Chef::Config[:knife][:openstack_password] || Chef::Config[:knife][:openstack_api_key] diff --git a/lib/chef/knife/cloud/openstack_service_options.rb b/lib/chef/knife/cloud/openstack_service_options.rb index 50892416..eb767267 100644 --- a/lib/chef/knife/cloud/openstack_service_options.rb +++ b/lib/chef/knife/cloud/openstack_service_options.rb @@ -1,4 +1,4 @@ -require 'chef/knife/cloud/fog/options' +require "chef/knife/cloud/fog/options" class Chef class Knife class Cloud @@ -8,41 +8,41 @@ def self.included(includer) include FogOptions # Openstack Connection params. option :openstack_username, - short: '-A USERNAME', - long: '--openstack-username KEY', - description: 'Your OpenStack Username', + short: "-A USERNAME", + long: "--openstack-username KEY", + description: "Your OpenStack Username", proc: proc { |key| Chef::Config[:knife][:openstack_username] = key } option :openstack_password, - short: '-K SECRET', - long: '--openstack-password SECRET', - description: 'Your OpenStack Password', + short: "-K SECRET", + long: "--openstack-password SECRET", + description: "Your OpenStack Password", proc: proc { |key| Chef::Config[:knife][:openstack_password] = key } option :openstack_tenant, - short: '-T NAME', - long: '--openstack-tenant NAME', - description: 'Your OpenStack Tenant NAME', + short: "-T NAME", + long: "--openstack-tenant NAME", + description: "Your OpenStack Tenant NAME", proc: proc { |key| Chef::Config[:knife][:openstack_tenant] = key } option :openstack_auth_url, - long: '--openstack-api-endpoint ENDPOINT', - description: 'Your OpenStack API endpoint', + long: "--openstack-api-endpoint ENDPOINT", + description: "Your OpenStack API endpoint", proc: proc { |endpoint| Chef::Config[:knife][:openstack_auth_url] = endpoint } option :openstack_endpoint_type, - long: '--openstack-endpoint-type ENDPOINT_TYPE', - description: 'OpenStack endpoint type to use (publicURL, internalURL, adminURL)', + long: "--openstack-endpoint-type ENDPOINT_TYPE", + description: "OpenStack endpoint type to use (publicURL, internalURL, adminURL)", proc: proc { |type| Chef::Config[:knife][:openstack_endpoint_type] = type } option :openstack_insecure, - long: '--insecure', - description: 'Ignore SSL certificate on the Auth URL', + long: "--insecure", + description: "Ignore SSL certificate on the Auth URL", boolean: true, default: false, proc: proc { |key| Chef::Config[:knife][:openstack_insecure] = key } end - end + end end end end diff --git a/lib/chef/knife/openstack_flavor_list.rb b/lib/chef/knife/openstack_flavor_list.rb index 4510a0ec..94808310 100644 --- a/lib/chef/knife/openstack_flavor_list.rb +++ b/lib/chef/knife/openstack_flavor_list.rb @@ -1,9 +1,9 @@ # Author:: Prabhu Das () # Copyright:: Copyright (c) 2014 Chef Software, Inc. -require 'chef/knife/cloud/list_resource_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/list_resource_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" class Chef class Knife @@ -12,18 +12,18 @@ class OpenstackFlavorList < ResourceListCommand include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack flavor list (options)' + banner "knife openstack flavor list (options)" def before_exec_command # set columns_with_info map @columns_with_info = [ - { label: 'Name', key: 'name' }, - { label: 'ID', key: 'id' }, - { label: 'Virtual CPUs', key: 'vcpus' }, - { label: 'RAM', key: 'ram', value_callback: method(:ram_in_mb) }, - { label: 'Disk', key: 'disk', value_callback: method(:disk_in_gb) } + { label: "Name", key: "name" }, + { label: "ID", key: "id" }, + { label: "Virtual CPUs", key: "vcpus" }, + { label: "RAM", key: "ram", value_callback: method(:ram_in_mb) }, + { label: "Disk", key: "disk", value_callback: method(:disk_in_gb) }, ] - @sort_by_field = 'name' + @sort_by_field = "name" end def query_resource diff --git a/lib/chef/knife/openstack_floating_ip_allocate.rb b/lib/chef/knife/openstack_floating_ip_allocate.rb index 4e575868..9bc54374 100644 --- a/lib/chef/knife/openstack_floating_ip_allocate.rb +++ b/lib/chef/knife/openstack_floating_ip_allocate.rb @@ -1,9 +1,9 @@ # Author:: Vasundhara Jagdale () # Copyright:: Copyright (c) 2015 Chef Software, Inc. -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/command' +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/command" class Chef class Knife @@ -12,12 +12,12 @@ class OpenstackFloatingIpAllocate < Command include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack floating_ip allocate (options)' + banner "knife openstack floating_ip allocate (options)" option :pool, - short: '-p POOL', - long: '--pool POOL', - description: 'Floating IP pool to allocate from.', + short: "-p POOL", + long: "--pool POOL", + description: "Floating IP pool to allocate from.", proc: proc { |key| Chef::Config[:knife][:pool] = key } def execute_command @@ -25,11 +25,11 @@ def execute_command end def after_exec_command - @columns_with_info = [{ label: 'ID', value: @resource['floating_ip']['id'].to_s }, - { label: 'Instance ID', value: @resource['floating_ip']['instance_id'].to_s }, - { label: 'Floating IP', value: @resource['floating_ip']['ip'].to_s }, - { label: 'Fixed IP', value: @resource['floating_ip']['fixed_ip'].to_s }, - { label: 'Pool', value: @resource['floating_ip']['pool'].to_s } + @columns_with_info = [{ label: "ID", value: @resource["floating_ip"]["id"].to_s }, + { label: "Instance ID", value: @resource["floating_ip"]["instance_id"].to_s }, + { label: "Floating IP", value: @resource["floating_ip"]["ip"].to_s }, + { label: "Fixed IP", value: @resource["floating_ip"]["fixed_ip"].to_s }, + { label: "Pool", value: @resource["floating_ip"]["pool"].to_s }, ] @service.server_summary(nil, @columns_with_info) end diff --git a/lib/chef/knife/openstack_floating_ip_associate.rb b/lib/chef/knife/openstack_floating_ip_associate.rb index 5d0fe8d5..35bf4d79 100644 --- a/lib/chef/knife/openstack_floating_ip_associate.rb +++ b/lib/chef/knife/openstack_floating_ip_associate.rb @@ -1,10 +1,10 @@ # Author:: Vasundhara Jagdale () # Copyright:: Copyright (c) 2015 Chef Software, Inc. -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/openstack_service' -require 'chef/knife/cloud/command' +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/openstack_service" +require "chef/knife/cloud/command" class Chef class Knife @@ -13,11 +13,11 @@ class OpenstackFloatingIpAssociate < Command include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack floating_ip associate IP (options)' + banner "knife openstack floating_ip associate IP (options)" option :instance_id, - long: '--instance-id ID', - description: 'Instance id to associate it with.', + long: "--instance-id ID", + description: "Instance id to associate it with.", proc: proc { |key| Chef::Config[:knife][:instance_id] = key }, required: true @@ -25,7 +25,7 @@ def execute_command if @name_args[0] floating_ip = @name_args[0] else - ui.error 'Please provide Floating IP to associate with.' + ui.error "Please provide Floating IP to associate with." exit 1 end diff --git a/lib/chef/knife/openstack_floating_ip_disassociate.rb b/lib/chef/knife/openstack_floating_ip_disassociate.rb index 7dcca0be..4a4d7bf8 100644 --- a/lib/chef/knife/openstack_floating_ip_disassociate.rb +++ b/lib/chef/knife/openstack_floating_ip_disassociate.rb @@ -1,10 +1,10 @@ # Author:: Vasundhara Jagdale () # Copyright:: Copyright (c) 2015 Chef Software, Inc. -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/openstack_service' -require 'chef/knife/cloud/command' +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/openstack_service" +require "chef/knife/cloud/command" class Chef class Knife @@ -13,11 +13,11 @@ class OpenstackFloatingIpDisassociate < Command include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack floating_ip disassociate IP (options)' + banner "knife openstack floating_ip disassociate IP (options)" option :instance_id, - long: '--instance-id ID', - description: 'Instance id to disassociate with.', + long: "--instance-id ID", + description: "Instance id to disassociate with.", proc: proc { |key| Chef::Config[:knife][:instance_id] = key }, required: true @@ -25,7 +25,7 @@ def execute_command if @name_args[0] floating_ip = @name_args[0] else - ui.error 'Please provide Floating IP to disassociate.' + ui.error "Please provide Floating IP to disassociate." exit 1 end instance_id = locate_config_value(:instance_id) diff --git a/lib/chef/knife/openstack_floating_ip_list.rb b/lib/chef/knife/openstack_floating_ip_list.rb index 8e67aff6..7c1680c3 100644 --- a/lib/chef/knife/openstack_floating_ip_list.rb +++ b/lib/chef/knife/openstack_floating_ip_list.rb @@ -1,9 +1,9 @@ # Author:: Vasundhara Jagdale () # Copyright:: Copyright (c) 2015 Chef Software, Inc. -require 'chef/knife/cloud/list_resource_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/list_resource_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" class Chef class Knife @@ -12,16 +12,16 @@ class OpenstackFloatingIpList < ResourceListCommand include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack floating_ip list (options)' + banner "knife openstack floating_ip list (options)" def before_exec_command # set columns_with_info map @columns_with_info = [ - { label: 'ID', key: 'id' }, - { label: 'Instance ID', key: 'instance_id' }, - { label: 'IP Address', key: 'ip' }, - { label: 'Fixed IP', key: 'fixed_ip' }, - { label: 'Floating IP Pool', key: 'pool' } + { label: "ID", key: "id" }, + { label: "Instance ID", key: "instance_id" }, + { label: "IP Address", key: "ip" }, + { label: "Fixed IP", key: "fixed_ip" }, + { label: "Floating IP Pool", key: "pool" }, ] end diff --git a/lib/chef/knife/openstack_floating_ip_release.rb b/lib/chef/knife/openstack_floating_ip_release.rb index 507df628..da14d8d4 100644 --- a/lib/chef/knife/openstack_floating_ip_release.rb +++ b/lib/chef/knife/openstack_floating_ip_release.rb @@ -3,9 +3,9 @@ # Copyright:: Copyright (c) 2015 Chef Software, Inc. # -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/command' +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/command" class Chef class Knife @@ -14,16 +14,16 @@ class OpenstackFloatingIpRelease < Command include OpenstackServiceOptions include OpenstackHelpers - banner 'knife openstack floating_ip release ID [ID] (options)' + banner "knife openstack floating_ip release ID [ID] (options)" def execute_command if @name_args[0] response = service.release_address(@name_args[0]) if response && response.status == 202 - ui.info 'Floating IP released successfully.' + ui.info "Floating IP released successfully." end else - ui.error 'Please provide Floating IP to release.' + ui.error "Please provide Floating IP to release." exit 1 end end diff --git a/lib/chef/knife/openstack_group_list.rb b/lib/chef/knife/openstack_group_list.rb index fbad0246..5e40bc87 100644 --- a/lib/chef/knife/openstack_group_list.rb +++ b/lib/chef/knife/openstack_group_list.rb @@ -1,6 +1,6 @@ -require 'chef/knife/cloud/list_resource_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/list_resource_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" class Chef class Knife @@ -9,7 +9,7 @@ class OpenstackGroupList < ResourceListCommand include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack group list (options)' + banner "knife openstack group list (options)" def query_resource @service.connection.security_groups @@ -20,14 +20,14 @@ def query_resource end def list(security_groups) - if (config[:format] == 'summary') + if config[:format] == "summary" group_list = [ - ui.color('Name', :bold), - ui.color('Protocol', :bold), - ui.color('From', :bold), - ui.color('To', :bold), - ui.color('CIDR', :bold), - ui.color('Description', :bold) + ui.color("Name", :bold), + ui.color("Protocol", :bold), + ui.color("From", :bold), + ui.color("To", :bold), + ui.color("CIDR", :bold), + ui.color("Description", :bold), ] security_groups.sort_by(&:name).each do |group| group.security_group_rules.each do |rule| @@ -36,7 +36,7 @@ def list(security_groups) group_list << rule.ip_protocol group_list << rule.from_port.to_s group_list << rule.to_port.to_s - group_list << rule.ip_range['cidr'] + group_list << rule.ip_range["cidr"] group_list << group.description end end diff --git a/lib/chef/knife/openstack_helpers.rb b/lib/chef/knife/openstack_helpers.rb index 58a5628e..665927ad 100644 --- a/lib/chef/knife/openstack_helpers.rb +++ b/lib/chef/knife/openstack_helpers.rb @@ -1,19 +1,19 @@ -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/openstack_service_options" class Chef class Knife class Cloud module OpenstackHelpers def primary_private_ip_address(addresses) - primary_network_ip_address(addresses, 'private') + primary_network_ip_address(addresses, "private") end def primary_public_ip_address(addresses) - primary_network_ip_address(addresses, 'public') + primary_network_ip_address(addresses, "public") end def primary_network_ip_address(addresses, network_name) - addresses[network_name].last['addr'] if addresses[network_name] && !addresses[network_name].empty? + addresses[network_name].last["addr"] if addresses[network_name] && !addresses[network_name].empty? end def create_service_instance @@ -29,12 +29,12 @@ def instance_addresses(addresses) if addresses[addresses.keys[0]] && addresses[addresses.keys[0]].size > 0 ips = addresses[addresses.keys[0]] ips.each do |ip| - version = 'IPv6' if ip['version'] == 6 - version = 'IPv4' if ip['version'] == 4 + version = "IPv6" if ip["version"] == 6 + version = "IPv4" if ip["version"] == 4 info << "#{addresses.keys[0]}:#{version}: #{ip['addr']}" end end - info.join(' ') + info.join(" ") end end end diff --git a/lib/chef/knife/openstack_image_list.rb b/lib/chef/knife/openstack_image_list.rb index fd77af39..9adae2e0 100644 --- a/lib/chef/knife/openstack_image_list.rb +++ b/lib/chef/knife/openstack_image_list.rb @@ -1,9 +1,9 @@ # Author:: Prabhu Das () # Copyright:: Copyright (c) 2014 Chef Software, Inc. -require 'chef/knife/cloud/list_resource_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/list_resource_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" class Chef class Knife @@ -12,10 +12,10 @@ class OpenstackImageList < ResourceListCommand include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack image list (options)' + banner "knife openstack image list (options)" option :disable_filter, - long: '--disable-filter', + long: "--disable-filter", description: "Disable filtering of the image list. Currently filters names ending with 'initrd' or 'kernel'", boolean: true, default: false @@ -23,15 +23,15 @@ class OpenstackImageList < ResourceListCommand def before_exec_command # set resource_filters unless config[:disable_filter] - @resource_filters = [{ attribute: 'name', regex: /initrd$|kernel$|loader$|virtual$|vmlinuz$/ }] + @resource_filters = [{ attribute: "name", regex: /initrd$|kernel$|loader$|virtual$|vmlinuz$/ }] end # set columns_with_info map @columns_with_info = [ - { label: 'Name', key: 'name' }, - { label: 'ID', key: 'id' }, - { label: 'Snapshot', key: 'metadata', value_callback: method(:is_image_snapshot) } + { label: "Name", key: "name" }, + { label: "ID", key: "id" }, + { label: "Snapshot", key: "metadata", value_callback: method(:is_image_snapshot) }, ] - @sort_by_field = 'name' + @sort_by_field = "name" end def query_resource @@ -39,10 +39,10 @@ def query_resource end def is_image_snapshot(metadata) - snapshot = 'no' + snapshot = "no" metadata.each do |datum| - if (datum.key == 'image_type') && (datum.value == 'snapshot') - snapshot = 'yes' + if (datum.key == "image_type") && (datum.value == "snapshot") + snapshot = "yes" end end snapshot diff --git a/lib/chef/knife/openstack_network_list.rb b/lib/chef/knife/openstack_network_list.rb index 15563286..14368295 100644 --- a/lib/chef/knife/openstack_network_list.rb +++ b/lib/chef/knife/openstack_network_list.rb @@ -1,9 +1,9 @@ # Author:: Prabhu Das () # Copyright:: Copyright (c) 2014 Chef Software, Inc. -require 'chef/knife/cloud/list_resource_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/list_resource_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" class Chef class Knife @@ -12,17 +12,17 @@ class OpenstackNetworkList < ResourceListCommand include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack network list (options)' + banner "knife openstack network list (options)" def before_exec_command # set columns_with_info map @columns_with_info = [ - { label: 'Name', key: 'name' }, - { label: 'ID', key: 'id' }, - { label: 'Tenant', key: 'tenant_id' }, - { label: 'Shared', key: 'shared' } + { label: "Name", key: "name" }, + { label: "ID", key: "id" }, + { label: "Tenant", key: "tenant_id" }, + { label: "Shared", key: "shared" }, ] - @sort_by_field = 'name' + @sort_by_field = "name" end def query_resource diff --git a/lib/chef/knife/openstack_server_create.rb b/lib/chef/knife/openstack_server_create.rb index 71404995..7a13a060 100644 --- a/lib/chef/knife/openstack_server_create.rb +++ b/lib/chef/knife/openstack_server_create.rb @@ -18,12 +18,12 @@ # limitations under the License. # -require 'chef/knife/cloud/server/create_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_server_create_options' -require 'chef/knife/cloud/openstack_service' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/exceptions' +require "chef/knife/cloud/server/create_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_server_create_options" +require "chef/knife/cloud/openstack_service" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/exceptions" class Chef class Knife @@ -33,7 +33,7 @@ class OpenstackServerCreate < ServerCreateCommand include OpenstackServerCreateOptions include OpenstackServiceOptions - banner 'knife openstack server create (options)' + banner "knife openstack server create (options)" def before_exec_command super @@ -46,11 +46,11 @@ def before_exec_command :flavor_ref => service.get_flavor(locate_config_value(:flavor)).id, :security_groups => locate_config_value(:openstack_security_groups), :availability_zone => locate_config_value(:availability_zone), - 'os:scheduler_hints' => locate_config_value(:openstack_scheduler_hints), + "os:scheduler_hints" => locate_config_value(:openstack_scheduler_hints), :metadata => locate_config_value(:metadata), - :key_name => locate_config_value(:openstack_ssh_key_id) + :key_name => locate_config_value(:openstack_ssh_key_id), }, - server_create_timeout: locate_config_value(:server_create_timeout) + server_create_timeout: locate_config_value(:server_create_timeout), } unless locate_config_value(:openstack_volumes).nil? counter = 99 @@ -59,53 +59,53 @@ def before_exec_command { volume_id: vol, delete_on_termination: false, - device_name: '/dev/vd' + counter.chr, - volume_size: nil + device_name: "/dev/vd" + counter.chr, + volume_size: nil, } end end - @create_options[:server_def].merge!(user_data: locate_config_value(:user_data)) if locate_config_value(:user_data) - @create_options[:server_def].merge!(nics: locate_config_value(:network_ids).map { |nic| nic_id = { 'net_id' => nic } }) if locate_config_value(:network_ids) + @create_options[:server_def][:user_data] = locate_config_value(:user_data) if locate_config_value(:user_data) + @create_options[:server_def][:nics] = locate_config_value(:network_ids).map { |nic| nic_id = { "net_id" => nic } } if locate_config_value(:network_ids) Chef::Log.debug("Create server params - server_def = #{@create_options[:server_def]}") # set columns_with_info map @columns_with_info = [ - { label: 'Instance ID', key: 'id' }, - { label: 'Name', key: 'name' }, - { label: 'Public IP', key: 'addresses', value_callback: method(:primary_public_ip_address) }, - { label: 'Private IP', key: 'addresses', value_callback: method(:primary_private_ip_address) }, - { label: 'Flavor', key: 'flavor', value_callback: method(:get_id) }, - { label: 'Image', key: 'image', value_callback: method(:get_id) }, - { label: 'Keypair', key: 'key_name' }, - { label: 'State', key: 'state' }, - { label: 'Availability Zone', key: 'availability_zone' } + { label: "Instance ID", key: "id" }, + { label: "Name", key: "name" }, + { label: "Public IP", key: "addresses", value_callback: method(:primary_public_ip_address) }, + { label: "Private IP", key: "addresses", value_callback: method(:primary_private_ip_address) }, + { label: "Flavor", key: "flavor", value_callback: method(:get_id) }, + { label: "Image", key: "image", value_callback: method(:get_id) }, + { label: "Keypair", key: "key_name" }, + { label: "State", key: "state" }, + { label: "Availability Zone", key: "availability_zone" }, ] end def get_id(value) - value['id'] + value["id"] end # Setup the floating ip after server creation. def after_exec_command Chef::Log.debug("Addresses #{server.addresses}") - msg_pair('Public IP Address', primary_public_ip_address(server.addresses)) if primary_public_ip_address(server.addresses) - msg_pair('Private IP Address', primary_private_ip_address(server.addresses)) if primary_private_ip_address(server.addresses) + msg_pair("Public IP Address", primary_public_ip_address(server.addresses)) if primary_public_ip_address(server.addresses) + msg_pair("Private IP Address", primary_private_ip_address(server.addresses)) if primary_private_ip_address(server.addresses) floating_address = locate_config_value(:openstack_floating_ip) bind_ip = primary_network_ip_address(server.addresses, server.addresses.keys[0]) Chef::Log.debug("Floating IP Address requested #{floating_address}") - unless (floating_address == '-1') # no floating IP requested + unless floating_address == "-1" # no floating IP requested addresses = service.connection.addresses # floating requested without value if floating_address.nil? free_floating = addresses.find_index { |a| a.fixed_ip.nil? } begin if free_floating.nil? # no free floating IP found - error_message = 'Unable to assign a Floating IP from allocated IPs.' + error_message = "Unable to assign a Floating IP from allocated IPs." ui.fatal(error_message) - fail CloudExceptions::ServerSetupError, error_message + raise CloudExceptions::ServerSetupError, error_message else floating_address = addresses[free_floating].ip end @@ -116,22 +116,22 @@ def after_exec_command end # Pull the port_id for the associate_floating_ip - port_id = @service.network.list_ports[:body]['ports'].find { |x| x['fixed_ips'][0]['ip_address'] == bind_ip }['id'] - fixed_ip_address = service.network.list_ports[:body]['ports'].find { |x| x['id'] == port_id }['fixed_ips'][0]['ip_address'] + port_id = @service.network.list_ports[:body]["ports"].find { |x| x["fixed_ips"][0]["ip_address"] == bind_ip }["id"] + fixed_ip_address = service.network.list_ports[:body]["ports"].find { |x| x["id"] == port_id }["fixed_ips"][0]["ip_address"] floating_ip_id = get_floating_ip_id(floating_address) # Associate the floating ip via the neutron/network api @service.network.associate_floating_ip(floating_ip_id, port_id, fixed_ip_address: fixed_ip_address) # a bit of a hack, but server.reload takes a long time - (server.addresses['public'] ||= []) << { 'version' => 4, 'addr' => floating_address } - msg_pair('Floating IP Address', floating_address) + (server.addresses["public"] ||= []) << { "version" => 4, "addr" => floating_address } + msg_pair("Floating IP Address", floating_address) end Chef::Log.debug("Addresses #{server.addresses}") Chef::Log.debug("Public IP Address actual: #{primary_public_ip_address(server.addresses)}") if primary_public_ip_address(server.addresses) - msg_pair('Private IP Address', primary_private_ip_address(server.addresses)) if primary_private_ip_address(server.addresses) + msg_pair("Private IP Address", primary_private_ip_address(server.addresses)) if primary_private_ip_address(server.addresses) super end @@ -144,13 +144,13 @@ def before_bootstrap # The bootstrap network is always initialised to 'public' when a network name isn't specified. Therefore, # only set the bootstrap network to 'private' if still initialised to public and nothing was specified for # the private network name. - config[:bootstrap_network] = 'private' if config[:private_network] && config[:bootstrap_network] == 'public' + config[:bootstrap_network] = "private" if config[:private_network] && config[:bootstrap_network] == "public" # Which IP address to bootstrap unless config[:network] # --no-network bootstrap_ip_address = primary_public_ip_address(server.addresses) || - primary_private_ip_address(server.addresses) || - server.addresses.first[1][0]['addr'] + primary_private_ip_address(server.addresses) || + server.addresses.first[1][0]["addr"] Chef::Log.debug("No Bootstrap Network: #{config[:bootstrap_network]}") else bootstrap_ip_address = primary_network_ip_address(server.addresses, config[:bootstrap_network]) @@ -159,14 +159,14 @@ def before_bootstrap Chef::Log.debug("Bootstrap IP Address: #{bootstrap_ip_address}") if bootstrap_ip_address.nil? - error_message = 'No IP address available for bootstrapping.' + error_message = "No IP address available for bootstrapping." ui.error(error_message) - fail CloudExceptions::BootstrapError, error_message + raise CloudExceptions::BootstrapError, error_message end config[:bootstrap_ip_address] = bootstrap_ip_address config[:hints] ||= {} - config[:hints]['openstack'] ||= {} + config[:hints]["openstack"] ||= {} end def validate_params! @@ -175,17 +175,17 @@ def validate_params! errors = [] - if locate_config_value(:bootstrap_protocol) == 'winrm' + if locate_config_value(:bootstrap_protocol) == "winrm" if locate_config_value(:winrm_password).nil? - errors << 'You must provide Winrm Password.' + errors << "You must provide Winrm Password." end - elsif locate_config_value(:bootstrap_protocol) != 'ssh' - errors << 'You must provide a valid bootstrap protocol. options [ssh/winrm]. For linux type images, options [ssh]' + elsif locate_config_value(:bootstrap_protocol) != "ssh" + errors << "You must provide a valid bootstrap protocol. options [ssh/winrm]. For linux type images, options [ssh]" end - errors << 'You must provide --image-os-type option [windows/linux]' unless %w(windows linux).include?(locate_config_value(:image_os_type)) - error_message = '' - fail CloudExceptions::ValidationError, error_message if errors.each { |e| ui.error(e); error_message = "#{error_message} #{e}." }.any? + errors << "You must provide --image-os-type option [windows/linux]" unless %w{windows linux}.include?(locate_config_value(:image_os_type)) + error_message = "" + raise CloudExceptions::ValidationError, error_message if errors.each { |e| ui.error(e); error_message = "#{error_message} #{e}." }.any? end def is_image_valid? @@ -199,7 +199,7 @@ def is_flavor_valid? def is_floating_ip_valid? address = locate_config_value(:openstack_floating_ip) - return true if address == '-1' # no floating IP requested + return true if address == "-1" # no floating IP requested addresses = service.connection.addresses return false if addresses.empty? # no floating IPs @@ -222,20 +222,20 @@ def is_floating_ip_valid? def post_connection_validations errors = [] - errors << 'You have not provided a valid image ID. Please note the options for this value are -I or --image.' unless is_image_valid? - errors << 'You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor.' unless is_flavor_valid? - errors << 'You have either requested an invalid floating IP address or none are available.' unless is_floating_ip_valid? - error_message = '' - fail CloudExceptions::ValidationError, error_message if errors.each { |e| ui.error(e); error_message = "#{error_message} #{e}." }.any? + errors << "You have not provided a valid image ID. Please note the options for this value are -I or --image." unless is_image_valid? + errors << "You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor." unless is_flavor_valid? + errors << "You have either requested an invalid floating IP address or none are available." unless is_floating_ip_valid? + error_message = "" + raise CloudExceptions::ValidationError, error_message if errors.each { |e| ui.error(e); error_message = "#{error_message} #{e}." }.any? end def get_floating_ip_id(floating_address) # required for this method to work floating_ip_id = -1 # Figure out the id for the port that the floating ip you requested - @service.network.list_floating_ips[:body]['floatingips'].each do |x| - if x['floating_ip_address'] == floating_address - floating_ip_id = x['id'] + @service.network.list_floating_ips[:body]["floatingips"].each do |x| + if x["floating_ip_address"] == floating_address + floating_ip_id = x["id"] end end floating_ip_id diff --git a/lib/chef/knife/openstack_server_delete.rb b/lib/chef/knife/openstack_server_delete.rb index 0c7b04f5..79bbdc8e 100644 --- a/lib/chef/knife/openstack_server_delete.rb +++ b/lib/chef/knife/openstack_server_delete.rb @@ -4,11 +4,11 @@ # Copyright:: Copyright (c) 2013 Chef Software, Inc. # -require 'chef/knife/cloud/server/delete_options' -require 'chef/knife/cloud/server/delete_command' -require 'chef/knife/cloud/openstack_service' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/openstack_helpers' +require "chef/knife/cloud/server/delete_options" +require "chef/knife/cloud/server/delete_command" +require "chef/knife/cloud/openstack_service" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/openstack_helpers" class Chef class Knife @@ -18,7 +18,7 @@ class OpenstackServerDelete < ServerDeleteCommand include OpenstackServiceOptions include OpenstackHelpers - banner 'knife openstack server delete INSTANCEID [INSTANCEID] (options)' + banner "knife openstack server delete INSTANCEID [INSTANCEID] (options)" end end end diff --git a/lib/chef/knife/openstack_server_list.rb b/lib/chef/knife/openstack_server_list.rb index 2e3b4ef8..c189f1d4 100644 --- a/lib/chef/knife/openstack_server_list.rb +++ b/lib/chef/knife/openstack_server_list.rb @@ -19,10 +19,10 @@ # limitations under the License. # -require 'chef/knife/cloud/server/list_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/server/list_options' +require "chef/knife/cloud/server/list_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/server/list_options" class Chef class Knife @@ -32,21 +32,21 @@ class OpenstackServerList < ServerListCommand include OpenstackServiceOptions include ServerListOptions - banner 'knife openstack server list (options)' + banner "knife openstack server list (options)" def before_exec_command # set columns_with_info map @columns_with_info = [ - { label: 'Name', key: 'name' }, - { label: 'Instance ID', key: 'id' }, - { label: 'Addresses', key: 'addresses', value_callback: method(:addresses) }, - { label: 'Flavor', key: 'flavor', value_callback: method(:get_id) }, - { label: 'Image', key: 'image', value_callback: method(:get_id) }, - { label: 'Keypair', key: 'key_name' }, - { label: 'State', key: 'state' }, - { label: 'Availability Zone', key: 'availability_zone' } + { label: "Name", key: "name" }, + { label: "Instance ID", key: "id" }, + { label: "Addresses", key: "addresses", value_callback: method(:addresses) }, + { label: "Flavor", key: "flavor", value_callback: method(:get_id) }, + { label: "Image", key: "image", value_callback: method(:get_id) }, + { label: "Keypair", key: "key_name" }, + { label: "State", key: "state" }, + { label: "Availability Zone", key: "availability_zone" }, ] - @sort_by_field = 'name' + @sort_by_field = "name" super end @@ -55,7 +55,7 @@ def addresses(addresses) end def get_id(value) - value['id'] + value["id"] end end end diff --git a/lib/chef/knife/openstack_server_show.rb b/lib/chef/knife/openstack_server_show.rb index 4576455c..bb2bf10a 100644 --- a/lib/chef/knife/openstack_server_show.rb +++ b/lib/chef/knife/openstack_server_show.rb @@ -15,12 +15,12 @@ # limitations under the License. # -require 'chef/knife/cloud/server/show_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/server/show_options' -require 'chef/knife/cloud/openstack_service' -require 'chef/knife/cloud/openstack_service_options' -require 'chef/knife/cloud/exceptions' +require "chef/knife/cloud/server/show_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/server/show_options" +require "chef/knife/cloud/openstack_service" +require "chef/knife/cloud/openstack_service_options" +require "chef/knife/cloud/exceptions" class Chef class Knife @@ -30,25 +30,25 @@ class OpenstackServerShow < ServerShowCommand include OpenstackServiceOptions include ServerShowOptions - banner 'knife openstack server show (options)' + banner "knife openstack server show (options)" def before_exec_command # set columns_with_info map @columns_with_info = [ - { label: 'Instance ID', key: 'id' }, - { label: 'Name', key: 'name' }, - { label: 'Addresses', key: 'addresses', value_callback: method(:instance_addresses) }, - { label: 'Flavor', key: 'flavor', value_callback: method(:get_id) }, - { label: 'Image', key: 'image', value_callback: method(:get_id) }, - { label: 'Keypair', key: 'key_name' }, - { label: 'State', key: 'state' }, - { label: 'Availability Zone', key: 'availability_zone' } + { label: "Instance ID", key: "id" }, + { label: "Name", key: "name" }, + { label: "Addresses", key: "addresses", value_callback: method(:instance_addresses) }, + { label: "Flavor", key: "flavor", value_callback: method(:get_id) }, + { label: "Image", key: "image", value_callback: method(:get_id) }, + { label: "Keypair", key: "key_name" }, + { label: "State", key: "state" }, + { label: "Availability Zone", key: "availability_zone" }, ] super end def get_id(value) - value['id'] + value["id"] end end end diff --git a/lib/chef/knife/openstack_volume_list.rb b/lib/chef/knife/openstack_volume_list.rb index 53477445..e12e4666 100644 --- a/lib/chef/knife/openstack_volume_list.rb +++ b/lib/chef/knife/openstack_volume_list.rb @@ -18,9 +18,9 @@ # limitations under the License. # -require 'chef/knife/cloud/list_resource_command' -require 'chef/knife/openstack_helpers' -require 'chef/knife/cloud/openstack_service_options' +require "chef/knife/cloud/list_resource_command" +require "chef/knife/openstack_helpers" +require "chef/knife/cloud/openstack_service_options" class Chef class Knife @@ -29,7 +29,7 @@ class OpenstackVolumeList < ResourceListCommand include OpenstackHelpers include OpenstackServiceOptions - banner 'knife openstack volume list (options)' + banner "knife openstack volume list (options)" def query_resource @service.connection.volumes @@ -41,11 +41,11 @@ def query_resource def list(volumes) volume_list = [ - ui.color('Name', :bold), - ui.color('ID', :bold), - ui.color('Status', :bold), - ui.color('Size', :bold), - ui.color('Description', :bold) + ui.color("Name", :bold), + ui.color("ID", :bold), + ui.color("Status", :bold), + ui.color("Size", :bold), + ui.color("Description", :bold), ] begin volumes.sort_by(&:name).each do |volume| diff --git a/lib/knife-openstack/version.rb b/lib/knife-openstack/version.rb index 58383627..d718749f 100644 --- a/lib/knife-openstack/version.rb +++ b/lib/knife-openstack/version.rb @@ -1,6 +1,6 @@ module Knife module OpenStack - VERSION = '1.3.2' - MAJOR, MINOR, TINY = VERSION.split('.') + VERSION = "1.3.2" + MAJOR, MINOR, TINY = VERSION.split(".") end end diff --git a/spec/functional/flavor_list_func_spec.rb b/spec/functional/flavor_list_func_spec.rb index b0b95c83..36371915 100644 --- a/spec/functional/flavor_list_func_spec.rb +++ b/spec/functional/flavor_list_func_spec.rb @@ -16,30 +16,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_flavor_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_flavor_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackFlavorList do let (:instance) { Chef::Knife::Cloud::OpenstackFlavorList.new } - context 'functionality' do + context "functionality" do before do - resources = [TestResource.new(id: 'resource-1', name: 'm1.tiny', vcpus: '1', ram: 512, disk: 0), - TestResource.new(id: 'resource-2', name: 'm1-xlarge-bigdisk', vcpus: '8', ram: 16_384, disk: 50) + resources = [TestResource.new(id: "resource-1", name: "m1.tiny", vcpus: "1", ram: 512, disk: 0), + TestResource.new(id: "resource-2", name: "m1-xlarge-bigdisk", vcpus: "8", ram: 16_384, disk: 50), ] allow(instance).to receive(:query_resource).and_return(resources) allow(instance).to receive(:puts) allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new) allow(instance).to receive(:validate!) - instance.config[:format] = 'summary' + instance.config[:format] = "summary" end - it 'lists formatted list of resources' do - expect(instance.ui).to receive(:list).with(['Name', 'ID', 'Virtual CPUs', 'RAM', 'Disk', - 'm1-xlarge-bigdisk', 'resource-2', '8', '16384 MB', '50 GB', - 'm1.tiny', 'resource-1', '1', '512 MB', '0 GB'], :uneven_columns_across, 5) + it "lists formatted list of resources" do + expect(instance.ui).to receive(:list).with(["Name", "ID", "Virtual CPUs", "RAM", "Disk", + "m1-xlarge-bigdisk", "resource-2", "8", "16384 MB", "50 GB", + "m1.tiny", "resource-1", "1", "512 MB", "0 GB"], :uneven_columns_across, 5) instance.run end end diff --git a/spec/functional/floating_ip_list_func_spec.rb b/spec/functional/floating_ip_list_func_spec.rb index 2a3a1a79..a13ab014 100644 --- a/spec/functional/floating_ip_list_func_spec.rb +++ b/spec/functional/floating_ip_list_func_spec.rb @@ -15,32 +15,32 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_floating_ip_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_floating_ip_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackFloatingIpList do let (:instance) { Chef::Knife::Cloud::OpenstackFloatingIpList.new } - context 'functionality' do + context "functionality" do before do - resources = [TestResource.new('id' => 'floatingip1', 'instance_id' => 'daed9e86-4b69-4242-993a-926a39352783', 'ip' => '173.236.251.98', 'fixed_ip' => '', 'pool' => 'test-pool' + resources = [TestResource.new("id" => "floatingip1", "instance_id" => "daed9e86-4b69-4242-993a-926a39352783", "ip" => "173.236.251.98", "fixed_ip" => "", "pool" => "test-pool" + ), + TestResource.new("id" => "floatingip2", "instance_id" => "", "ip" => "67.205.60.122", "fixed_ip" => "10.10.10.1", "pool" => "test-pool" ), - TestResource.new('id' => 'floatingip2', 'instance_id' => '', 'ip' => '67.205.60.122', 'fixed_ip' => '10.10.10.1', 'pool' => 'test-pool' - ) ] allow(instance).to receive(:query_resource).and_return(resources) allow(instance).to receive(:puts) allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new) allow(instance).to receive(:validate!) - instance.config[:format] = 'summary' + instance.config[:format] = "summary" end - it 'lists formatted list of resources' do - expect(instance.ui).to receive(:list).with(['ID', 'Instance ID', 'IP Address', 'Fixed IP', 'Floating IP Pool', - 'floatingip1', 'daed9e86-4b69-4242-993a-926a39352783', '173.236.251.98', '', 'test-pool', - 'floatingip2', '', '67.205.60.122', '10.10.10.1', 'test-pool'], :uneven_columns_across, 5) + it "lists formatted list of resources" do + expect(instance.ui).to receive(:list).with(["ID", "Instance ID", "IP Address", "Fixed IP", "Floating IP Pool", + "floatingip1", "daed9e86-4b69-4242-993a-926a39352783", "173.236.251.98", "", "test-pool", + "floatingip2", "", "67.205.60.122", "10.10.10.1", "test-pool"], :uneven_columns_across, 5) instance.run end end diff --git a/spec/functional/group_list_func_spec.rb b/spec/functional/group_list_func_spec.rb index 41e9a287..7e2cd544 100644 --- a/spec/functional/group_list_func_spec.rb +++ b/spec/functional/group_list_func_spec.rb @@ -17,47 +17,47 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_group_list' -require 'chef/knife/cloud/openstack_service' +require "spec_helper" +require "chef/knife/openstack_group_list" +require "chef/knife/cloud/openstack_service" describe Chef::Knife::Cloud::OpenstackGroupList do let (:instance) { Chef::Knife::Cloud::OpenstackGroupList.new } - context 'functionality' do + context "functionality" do before do - resources = [TestResource.new('name' => 'Unrestricted', - 'description' => 'All ports open', - 'security_group_rules' => [TestResource.new('from_port' => 1, - 'group' => {}, - 'ip_protocol' => 'tcp', - 'to_port' => 636, - 'parent_group_id' => 14, - 'ip_range' => { 'cidr' => '0.0.0.0/0' }, - 'id' => 1) + resources = [TestResource.new("name" => "Unrestricted", + "description" => "All ports open", + "security_group_rules" => [TestResource.new("from_port" => 1, + "group" => {}, + "ip_protocol" => "tcp", + "to_port" => 636, + "parent_group_id" => 14, + "ip_range" => { "cidr" => "0.0.0.0/0" }, + "id" => 1), + ]), + TestResource.new("name" => "WindowsDomain", + "description" => "Allows common protocols useful in a Windows domain", + "security_group_rules" => [TestResource.new("from_port" => 22, + "group" => {}, + "ip_protocol" => "tcp", + "to_port" => 636, + "parent_group_id" => 14, + "ip_range" => { "cidr" => "0.0.0.0/0" }, + "id" => 2), ]), - TestResource.new('name' => 'WindowsDomain', - 'description' => 'Allows common protocols useful in a Windows domain', - 'security_group_rules' => [TestResource.new('from_port' => 22, - 'group' => {}, - 'ip_protocol' => 'tcp', - 'to_port' => 636, - 'parent_group_id' => 14, - 'ip_range' => { 'cidr' => '0.0.0.0/0' }, - 'id' => 2) - ]) ] allow(instance).to receive(:query_resource).and_return(resources) allow(instance).to receive(:puts) allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new) allow(instance).to receive(:validate!) - instance.config[:format] = 'summary' + instance.config[:format] = "summary" end - it 'lists formatted list of resources' do - expect(instance.ui).to receive(:list).with(['Name', 'Protocol', 'From', 'To', 'CIDR', 'Description', - 'Unrestricted', 'tcp', '1', '636', '0.0.0.0/0', 'All ports open', - 'WindowsDomain', 'tcp', '22', '636', '0.0.0.0/0', 'Allows common protocols useful in a Windows domain'], :uneven_columns_across, 6) + it "lists formatted list of resources" do + expect(instance.ui).to receive(:list).with(["Name", "Protocol", "From", "To", "CIDR", "Description", + "Unrestricted", "tcp", "1", "636", "0.0.0.0/0", "All ports open", + "WindowsDomain", "tcp", "22", "636", "0.0.0.0/0", "Allows common protocols useful in a Windows domain"], :uneven_columns_across, 6) instance.run end end diff --git a/spec/functional/image_list_func_spec.rb b/spec/functional/image_list_func_spec.rb index 5f4d6784..768ed891 100644 --- a/spec/functional/image_list_func_spec.rb +++ b/spec/functional/image_list_func_spec.rb @@ -16,36 +16,36 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_image_list' -require 'chef/knife/cloud/openstack_service' +require "spec_helper" +require "chef/knife/openstack_image_list" +require "chef/knife/cloud/openstack_service" describe Chef::Knife::Cloud::OpenstackImageList do let (:instance) { Chef::Knife::Cloud::OpenstackImageList.new } - context 'functionality' do + context "functionality" do before do - resources = [TestResource.new(id: 'resource-1', name: 'image01', metadata: {}), - TestResource.new(id: 'resource-2', name: 'initrd', metadata: {}) + resources = [TestResource.new(id: "resource-1", name: "image01", metadata: {}), + TestResource.new(id: "resource-2", name: "initrd", metadata: {}), ] allow(instance).to receive(:query_resource).and_return(resources) allow(instance).to receive(:puts) allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new) allow(instance).to receive(:validate!) - instance.config[:format] = 'summary' + instance.config[:format] = "summary" end - it 'displays formatted list of images, filtered by default' do - expect(instance.ui).to receive(:list).with(['Name', 'ID', 'Snapshot', - 'image01', 'resource-1', 'no'], :uneven_columns_across, 3) + it "displays formatted list of images, filtered by default" do + expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot", + "image01", "resource-1", "no"], :uneven_columns_across, 3) instance.run end - it 'lists all images when disable_filter = true' do + it "lists all images when disable_filter = true" do instance.config[:disable_filter] = true - expect(instance.ui).to receive(:list).with(['Name', 'ID', 'Snapshot', - 'image01', 'resource-1', 'no', - 'initrd', 'resource-2', 'no'], :uneven_columns_across, 3) + expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot", + "image01", "resource-1", "no", + "initrd", "resource-2", "no"], :uneven_columns_across, 3) instance.run end end diff --git a/spec/functional/network_list_func_spec.rb b/spec/functional/network_list_func_spec.rb index eaf28772..31796aeb 100644 --- a/spec/functional/network_list_func_spec.rb +++ b/spec/functional/network_list_func_spec.rb @@ -15,30 +15,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_network_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_network_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackNetworkList do let (:instance) { Chef::Knife::Cloud::OpenstackNetworkList.new } - context 'functionality' do + context "functionality" do before do - resources = [TestResource.new(id: 'resource-1', name: 'external', tenant_id: '1', shared: true), - TestResource.new(id: 'resource-2', name: 'internal', tenant_id: '2', shared: false) + resources = [TestResource.new(id: "resource-1", name: "external", tenant_id: "1", shared: true), + TestResource.new(id: "resource-2", name: "internal", tenant_id: "2", shared: false), ] allow(instance).to receive(:query_resource).and_return(resources) allow(instance).to receive(:puts) allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new) allow(instance).to receive(:validate!) - instance.config[:format] = 'summary' + instance.config[:format] = "summary" end - it 'lists formatted list of network resources' do - expect(instance.ui).to receive(:list).with(['Name', 'ID', 'Tenant', 'Shared', - 'external', 'resource-1', '1', 'true', - 'internal', 'resource-2', '2', 'false'], :uneven_columns_across, 4) + it "lists formatted list of network resources" do + expect(instance.ui).to receive(:list).with(["Name", "ID", "Tenant", "Shared", + "external", "resource-1", "1", "true", + "internal", "resource-2", "2", "false"], :uneven_columns_across, 4) instance.run end end diff --git a/spec/functional/server_create_func_spec.rb b/spec/functional/server_create_func_spec.rb index 3477d238..a4b870a6 100644 --- a/spec/functional/server_create_func_spec.rb +++ b/spec/functional/server_create_func_spec.rb @@ -19,17 +19,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path("../../spec_helper", __FILE__) describe Chef::Knife::Cloud::OpenstackServerCreate do before do @knife_openstack_create = Chef::Knife::Cloud::OpenstackServerCreate.new { - image: 'image', - openstack_username: 'openstack_username', - openstack_password: 'openstack_password', - openstack_auth_url: 'openstack_auth_url', - server_create_timeout: 1000 + image: "image", + openstack_username: "openstack_username", + openstack_password: "openstack_password", + openstack_auth_url: "openstack_auth_url", + server_create_timeout: 1000, }.each do |key, value| Chef::Config[:knife][key] = value end @@ -38,26 +38,26 @@ allow(@openstack_service).to receive(:msg_pair) allow(@openstack_service).to receive(:print) image = Object.new - allow(image).to receive(:id).and_return('image_id') + allow(image).to receive(:id).and_return("image_id") allow(@openstack_service).to receive(:get_image).and_return(image) flavor = Object.new - allow(flavor).to receive(:id).and_return('flavor_id') + allow(flavor).to receive(:id).and_return("flavor_id") allow(@openstack_service).to receive(:get_flavor).and_return(flavor) allow(@knife_openstack_create).to receive(:create_service_instance).and_return(@openstack_service) allow(@knife_openstack_create).to receive(:puts) @new_openstack_server = double - @openstack_server_attribs = { name: 'Mock Server', - id: 'id-123456', - key_name: 'key_name', - flavor: 'flavor_id', - image: 'image_id', + @openstack_server_attribs = { name: "Mock Server", + id: "id-123456", + key_name: "key_name", + flavor: "flavor_id", + image: "image_id", addresses: { - 'public' => [{ 'addr' => '75.101.253.10' }], - 'private' => [{ 'addr' => '10.251.75.20' }] + "public" => [{ "addr" => "75.101.253.10" }], + "private" => [{ "addr" => "10.251.75.20" }], }, - password: 'password' + password: "password", } @openstack_server_attribs.each_pair do |attrib, value| @@ -65,25 +65,25 @@ end end - describe 'run' do + describe "run" do before(:each) do allow(@knife_openstack_create).to receive(:validate_params!) allow(Fog::Compute::OpenStack).to receive_message_chain(:new, :servers, :create).and_return(@new_openstack_server) - @knife_openstack_create.config[:openstack_floating_ip] = '-1' + @knife_openstack_create.config[:openstack_floating_ip] = "-1" allow(@new_openstack_server).to receive(:wait_for) end - context 'for Linux' do + context "for Linux" do before do - @config = { openstack_floating_ip: '-1', bootstrap_ip_address: '75.101.253.10', ssh_password: 'password', hints: { "openstack" => {} }} - @knife_openstack_create.config[:distro] = 'chef-full' + @config = { openstack_floating_ip: "-1", bootstrap_ip_address: "75.101.253.10", ssh_password: "password", hints: { "openstack" => {} } } + @knife_openstack_create.config[:distro] = "chef-full" @bootstrapper = Chef::Knife::Cloud::Bootstrapper.new(@config) @ssh_bootstrap_protocol = Chef::Knife::Cloud::SshBootstrapProtocol.new(@config) @unix_distribution = Chef::Knife::Cloud::UnixDistribution.new(@config) allow(@ssh_bootstrap_protocol).to receive(:send_bootstrap_command) end - it 'Creates an OpenStack instance and bootstraps it' do + it "Creates an OpenStack instance and bootstraps it" do expect(Chef::Knife::Cloud::Bootstrapper).to receive(:new).with(@config).and_return(@bootstrapper) allow(@bootstrapper).to receive(:bootstrap).and_call_original expect(@bootstrapper).to receive(:create_bootstrap_protocol).and_return(@ssh_bootstrap_protocol) @@ -93,17 +93,17 @@ end end - context 'for Windows' do + context "for Windows" do before do - @config = { openstack_floating_ip: '-1', image_os_type: 'windows', bootstrap_ip_address: '75.101.253.10', bootstrap_protocol: 'winrm', ssh_password: 'password', hints: { "openstack" => {} } } - @knife_openstack_create.config[:image_os_type] = 'windows' - @knife_openstack_create.config[:bootstrap_protocol] = 'winrm' - @knife_openstack_create.config[:distro] = 'windows-chef-client-msi' + @config = { openstack_floating_ip: "-1", image_os_type: "windows", bootstrap_ip_address: "75.101.253.10", bootstrap_protocol: "winrm", ssh_password: "password", hints: { "openstack" => {} } } + @knife_openstack_create.config[:image_os_type] = "windows" + @knife_openstack_create.config[:bootstrap_protocol] = "winrm" + @knife_openstack_create.config[:distro] = "windows-chef-client-msi" @bootstrapper = Chef::Knife::Cloud::Bootstrapper.new(@config) @winrm_bootstrap_protocol = Chef::Knife::Cloud::WinrmBootstrapProtocol.new(@config) @windows_distribution = Chef::Knife::Cloud::WindowsDistribution.new(@config) end - it 'Creates an OpenStack instance for Windows and bootstraps it' do + it "Creates an OpenStack instance for Windows and bootstraps it" do expect(Chef::Knife::Cloud::Bootstrapper).to receive(:new).with(@config).and_return(@bootstrapper) allow(@bootstrapper).to receive(:bootstrap).and_call_original expect(@bootstrapper).to receive(:create_bootstrap_protocol).and_return(@winrm_bootstrap_protocol) diff --git a/spec/functional/server_delete_func_spec.rb b/spec/functional/server_delete_func_spec.rb index bb27c358..0b9746e1 100644 --- a/spec/functional/server_delete_func_spec.rb +++ b/spec/functional/server_delete_func_spec.rb @@ -17,9 +17,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path('../../spec_helper', __FILE__) -require 'chef/knife/openstack_server_delete' -require 'chef/knife/cloud/openstack_service' +require File.expand_path("../../spec_helper", __FILE__) +require "chef/knife/openstack_server_delete" +require "chef/knife/cloud/openstack_service" describe Chef::Knife::Cloud::OpenstackServerDelete do before do @@ -28,9 +28,9 @@ @chef_client = double(Chef::ApiClient) @knife_openstack_delete = Chef::Knife::Cloud::OpenstackServerDelete.new { - openstack_username: 'openstack_username', - openstack_password: 'openstack_password', - openstack_auth_url: 'openstack_auth_url' + openstack_username: "openstack_username", + openstack_password: "openstack_password", + openstack_auth_url: "openstack_auth_url", }.each do |key, value| Chef::Config[:knife][key] = value end @@ -42,24 +42,24 @@ allow(@knife_openstack_delete.ui).to receive(:confirm) @openstack_servers = double @running_openstack_server = double - @openstack_server_attribs = { name: 'Mock Server', - id: 'id-123456', - flavor: 'flavor_id', - image: 'image_id', + @openstack_server_attribs = { name: "Mock Server", + id: "id-123456", + flavor: "flavor_id", + image: "image_id", addresses: { - 'public' => [{ 'addr' => '75.101.253.10' }], - 'private' => [{ 'addr' => '10.251.75.20' }] - } + "public" => [{ "addr" => "75.101.253.10" }], + "private" => [{ "addr" => "10.251.75.20" }], + }, } @openstack_server_attribs.each_pair do |attrib, value| allow(@running_openstack_server).to receive(attrib).and_return(value) end - @knife_openstack_delete.name_args = ['test001'] + @knife_openstack_delete.name_args = ["test001"] end - describe 'run' do - it 'deletes an OpenStack instance.' do + describe "run" do + it "deletes an OpenStack instance." do expect(@openstack_servers).to receive(:get).and_return(@running_openstack_server) expect(@openstack_connection).to receive(:servers).and_return(@openstack_servers) expect(Fog::Compute::OpenStack).to receive(:new).and_return(@openstack_connection) @@ -67,7 +67,7 @@ @knife_openstack_delete.run end - it 'deletes the instance along with the node and client on the chef-server when --purge is given as an option.' do + it "deletes the instance along with the node and client on the chef-server when --purge is given as an option." do @knife_openstack_delete.config[:purge] = true expect(Chef::Node).to receive(:load).and_return(@chef_node) expect(@chef_node).to receive(:destroy) diff --git a/spec/functional/server_list_func_spec.rb b/spec/functional/server_list_func_spec.rb index cd71a9f8..6cca7140 100644 --- a/spec/functional/server_list_func_spec.rb +++ b/spec/functional/server_list_func_spec.rb @@ -18,78 +18,78 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_server_list' -require 'chef/knife/cloud/openstack_service' +require "spec_helper" +require "chef/knife/openstack_server_list" +require "chef/knife/cloud/openstack_service" describe Chef::Knife::Cloud::OpenstackServerList do let (:instance) { Chef::Knife::Cloud::OpenstackServerList.new } - context 'functionality' do + context "functionality" do before do - @resources = [TestResource.new(id: 'resource-1', name: 'ubuntu01', availability_zone: 'test zone', addresses: { 'public' => [{ 'version' => 4, 'addr' => '172.31.6.132' }], 'private' => [{ 'version' => 4, 'addr' => '172.31.6.133' }] }, flavor: { 'id' => '1' }, image: { 'id' => 'image1' }, key_name: 'keypair', state: 'ACTIVE'), - TestResource.new(id: 'resource-2', name: 'windows2008', availability_zone: 'test zone', addresses: { 'public' => [{ 'version' => 4, 'addr' => '172.31.6.132' }] }, flavor: { 'id' => 'id2' }, image: { 'id' => 'image2' }, key_name: 'keypair', state: 'ACTIVE'), - TestResource.new(id: 'resource-3-err', name: 'windows2008', availability_zone: 'test zone', addresses: { 'public' => [], 'private' => [] }, flavor: { 'id' => 'id2' }, image: { 'id' => 'image2' }, key_name: 'keypair', state: 'ERROR') + @resources = [TestResource.new(id: "resource-1", name: "ubuntu01", availability_zone: "test zone", addresses: { "public" => [{ "version" => 4, "addr" => "172.31.6.132" }], "private" => [{ "version" => 4, "addr" => "172.31.6.133" }] }, flavor: { "id" => "1" }, image: { "id" => "image1" }, key_name: "keypair", state: "ACTIVE"), + TestResource.new(id: "resource-2", name: "windows2008", availability_zone: "test zone", addresses: { "public" => [{ "version" => 4, "addr" => "172.31.6.132" }] }, flavor: { "id" => "id2" }, image: { "id" => "image2" }, key_name: "keypair", state: "ACTIVE"), + TestResource.new(id: "resource-3-err", name: "windows2008", availability_zone: "test zone", addresses: { "public" => [], "private" => [] }, flavor: { "id" => "id2" }, image: { "id" => "image2" }, key_name: "keypair", state: "ERROR"), ] allow(instance).to receive(:query_resource).and_return(@resources) allow(instance).to receive(:puts) allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::FogService.new) allow(instance).to receive(:validate!) - instance.config[:format] = 'summary' + instance.config[:format] = "summary" end - it 'lists formatted list of resources' do - expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Addresses', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone', - 'ubuntu01', 'resource-1', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', - 'windows2008', 'resource-2', 'public:IPv4: 172.31.6.132', 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', - 'windows2008', 'resource-3-err', '', 'id2', 'image2', 'keypair', 'ERROR', 'test zone'], :uneven_columns_across, 8) + it "lists formatted list of resources" do + expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone", + "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", + "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone", + "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone"], :uneven_columns_across, 8) instance.run end - context 'when chef-data and chef-node-attribute set' do + context "when chef-data and chef-node-attribute set" do before(:each) do - @resources.push(TestResource.new(id: 'server-4', name: 'server-4', availability_zone: 'test zone', addresses: { 'public' => [{ 'version' => 4, 'addr' => '172.31.6.132' }], 'private' => [{ 'version' => 4, 'addr' => '172.31.6.133' }] }, flavor: { 'id' => '1' }, image: { 'id' => 'image1' }, key_name: 'keypair', state: 'ACTIVE')) - @node = TestResource.new(id: 'server-4', name: 'server-4', chef_environment: '_default', fqdn: 'testfqdnnode.us', run_list: [], tags: [], platform: 'ubuntu', platform_family: 'debian') - allow(Chef::Node).to receive(:list).and_return('server-4' => @node) + @resources.push(TestResource.new(id: "server-4", name: "server-4", availability_zone: "test zone", addresses: { "public" => [{ "version" => 4, "addr" => "172.31.6.132" }], "private" => [{ "version" => 4, "addr" => "172.31.6.133" }] }, flavor: { "id" => "1" }, image: { "id" => "image1" }, key_name: "keypair", state: "ACTIVE")) + @node = TestResource.new(id: "server-4", name: "server-4", chef_environment: "_default", fqdn: "testfqdnnode.us", run_list: [], tags: [], platform: "ubuntu", platform_family: "debian") + allow(Chef::Node).to receive(:list).and_return("server-4" => @node) instance.config[:chef_data] = true end - it 'lists formatted list of resources on chef data option set' do - expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Addresses', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone', 'Chef Node Name', 'Environment', 'FQDN', 'Runlist', 'Tags', 'Platform', - 'server-4', 'server-4', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', 'server-4', '_default', 'testfqdnnode.us', '[]', '[]', 'ubuntu', - 'ubuntu01', 'resource-1', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '', - 'windows2008', 'resource-2', 'public:IPv4: 172.31.6.132', 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '', - 'windows2008', 'resource-3-err', '', 'id2', 'image2', 'keypair', 'ERROR', 'test zone', '', '', '', '', '', ''], :uneven_columns_across, 14) + it "lists formatted list of resources on chef data option set" do + expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", + "server-4", "server-4", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu", + "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", + "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", + "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", ""], :uneven_columns_across, 14) instance.run end - it 'lists formatted list of resources on chef-data and chef-node-attribute option set' do - instance.config[:chef_node_attribute] = 'platform_family' - expect(@node).to receive(:attribute?).with('platform_family').and_return(true) - expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Addresses', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone', 'Chef Node Name', 'Environment', 'FQDN', 'Runlist', 'Tags', 'Platform', 'platform_family', - 'server-4', 'server-4', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', 'server-4', '_default', 'testfqdnnode.us', '[]', '[]', 'ubuntu', 'debian', - 'ubuntu01', 'resource-1', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '', '', - 'windows2008', 'resource-2', 'public:IPv4: 172.31.6.132', 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', '', '', '', '', '', '', '', - 'windows2008', 'resource-3-err', '', 'id2', 'image2', 'keypair', 'ERROR', 'test zone', '', '', '', '', '', '', ''], :uneven_columns_across, 15) + it "lists formatted list of resources on chef-data and chef-node-attribute option set" do + instance.config[:chef_node_attribute] = "platform_family" + expect(@node).to receive(:attribute?).with("platform_family").and_return(true) + expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "platform_family", + "server-4", "server-4", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu", "debian", + "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "", + "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "", + "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", "", ""], :uneven_columns_across, 15) instance.run end - it 'raise error on invalid chef-node-attribute set' do - instance.config[:chef_node_attribute] = 'invalid_attribute' + it "raise error on invalid chef-node-attribute set" do + instance.config[:chef_node_attribute] = "invalid_attribute" expect(instance.ui).to receive(:fatal) - expect(@node).to receive(:attribute?).with('invalid_attribute').and_return(false) - expect(instance.ui).to receive(:error).with('The Node does not have a invalid_attribute attribute.') + expect(@node).to receive(:attribute?).with("invalid_attribute").and_return(false) + expect(instance.ui).to receive(:error).with("The Node does not have a invalid_attribute attribute.") expect { instance.run }.to raise_error end - it 'not display chef-data on chef-node-attribute set but chef-data option missing' do + it "not display chef-data on chef-node-attribute set but chef-data option missing" do instance.config[:chef_data] = false - instance.config[:chef_node_attribute] = 'platform_family' - expect(instance.ui).to receive(:list).with(['Name', 'Instance ID', 'Addresses', 'Flavor', 'Image', 'Keypair', 'State', 'Availability Zone', - 'server-4', 'server-4', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', - 'ubuntu01', 'resource-1', 'public:IPv4: 172.31.6.132', '1', 'image1', 'keypair', 'ACTIVE', 'test zone', - 'windows2008', 'resource-2', 'public:IPv4: 172.31.6.132', 'id2', 'image2', 'keypair', 'ACTIVE', 'test zone', - 'windows2008', 'resource-3-err', '', 'id2', 'image2', 'keypair', 'ERROR', 'test zone'], :uneven_columns_across, 8) + instance.config[:chef_node_attribute] = "platform_family" + expect(instance.ui).to receive(:list).with(["Name", "Instance ID", "Addresses", "Flavor", "Image", "Keypair", "State", "Availability Zone", + "server-4", "server-4", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", + "ubuntu01", "resource-1", "public:IPv4: 172.31.6.132", "1", "image1", "keypair", "ACTIVE", "test zone", + "windows2008", "resource-2", "public:IPv4: 172.31.6.132", "id2", "image2", "keypair", "ACTIVE", "test zone", + "windows2008", "resource-3-err", "", "id2", "image2", "keypair", "ERROR", "test zone"], :uneven_columns_across, 8) instance.run end end diff --git a/spec/functional/server_show_func_spec.rb b/spec/functional/server_show_func_spec.rb index f4e8166d..f2e94eb6 100644 --- a/spec/functional/server_show_func_spec.rb +++ b/spec/functional/server_show_func_spec.rb @@ -15,15 +15,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_server_show' -require 'chef/knife/cloud/openstack_service' +require "spec_helper" +require "chef/knife/openstack_server_show" +require "chef/knife/cloud/openstack_service" describe Chef::Knife::Cloud::OpenstackServerShow do - context 'functionality' do + context "functionality" do before do @instance = Chef::Knife::Cloud::OpenstackServerShow.new - Chef::Config[:knife][:instance_id] = 'instance_id' + Chef::Config[:knife][:instance_id] = "instance_id" @openstack_service = Chef::Knife::Cloud::OpenstackService.new allow(@openstack_service).to receive(:msg_pair) allow(@openstack_service).to receive(:print) @@ -38,7 +38,7 @@ expect(@openstack_service).to receive(:server_summary) end - it 'runs server show successfully' do + it "runs server show successfully" do @instance.run end end diff --git a/spec/functional/volume_list_func_spec.rb b/spec/functional/volume_list_func_spec.rb index 64764ffc..8e33a95f 100644 --- a/spec/functional/volume_list_func_spec.rb +++ b/spec/functional/volume_list_func_spec.rb @@ -16,18 +16,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_volume_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_volume_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackVolumeList do let (:instance) { Chef::Knife::Cloud::OpenstackVolumeList.new } - context 'functionality' do + context "functionality" do before do - resources = [TestResource.new(id: 'volume-1', name: 'big-disk-volume', status: 'available', size: 1024, description: 'This is the big disk'), - TestResource.new(id: 'volume-2', name: 'little-disk-volume', status: 'in-use', size: 8, description: 'This is the little disk') + resources = [TestResource.new(id: "volume-1", name: "big-disk-volume", status: "available", size: 1024, description: "This is the big disk"), + TestResource.new(id: "volume-2", name: "little-disk-volume", status: "in-use", size: 8, description: "This is the little disk"), ] allow(instance).to receive(:query_resource).and_return(resources) allow(instance).to receive(:puts) @@ -35,10 +35,10 @@ allow(instance).to receive(:validate!) end - it 'lists formatted list of resources' do - expect(instance.ui).to receive(:list).with(['Name', 'ID', 'Status', 'Size', 'Description', - 'big-disk-volume', 'volume-1', 'available', '1024 GB', 'This is the big disk', - 'little-disk-volume', 'volume-2', 'in-use', '8 GB', 'This is the little disk'], :uneven_columns_across, 5) + it "lists formatted list of resources" do + expect(instance.ui).to receive(:list).with(["Name", "ID", "Status", "Size", "Description", + "big-disk-volume", "volume-1", "available", "1024 GB", "This is the big disk", + "little-disk-volume", "volume-2", "in-use", "8 GB", "This is the little disk"], :uneven_columns_across, 5) instance.run end end diff --git a/spec/integration/cleanup.rb b/spec/integration/cleanup.rb index 9d5a3d20..f6b45e99 100644 --- a/spec/integration/cleanup.rb +++ b/spec/integration/cleanup.rb @@ -15,19 +15,19 @@ # Author:: Siddheshwar More () -require 'mixlib/shellout' +require "mixlib/shellout" module CleanupTestResources def self.validate_params unset_env_var = [] # OPENSTACK_USERNAME, OPENSTACK_PASSWORD and OPENSTACK_AUTH_URL are mandatory params to run knife openstack commands. - %w(OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL).each do |os_env_var| + %w{OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL}.each do |os_env_var| unset_env_var << os_env_var if ENV[os_env_var].nil? end err_msg = "\nPlease set #{unset_env_var.join(', ')} environment" - err_msg = err_msg + (unset_env_var.length > 1 ? ' variables ' : ' variable ') + 'to cleanup test resources.' + err_msg = err_msg + (unset_env_var.length > 1 ? " variables " : " variable ") + "to cleanup test resources." unless unset_env_var.empty? puts err_msg exit 1 @@ -63,9 +63,9 @@ def self.cleanup_resources # We use "os-integration-test--" pattern for server name during integration tests run. So use "os-integration-test-" pattern to find out servers created during integration tests run. servers.each_line do |line| - if line.include?('os-integration-test-') || (line.include?('openstack-') && line.include?('opscode-ci-ssh')) + if line.include?("os-integration-test-") || (line.include?("openstack-") && line.include?("opscode-ci-ssh")) # Extract and add instance id of server to delete_resources list. - delete_resources << { 'id' => line.split(' ').first, 'name' => line.split(' ')[1] } + delete_resources << { "id" => line.split(" ").first, "name" => line.split(" ")[1] } end end diff --git a/spec/integration/openstack_spec.rb b/spec/integration/openstack_spec.rb index 315c99f6..abb610f0 100644 --- a/spec/integration/openstack_spec.rb +++ b/spec/integration/openstack_spec.rb @@ -17,7 +17,7 @@ # Author:: Ameya Varade () # Author:: Prabhu Das () -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") def append_openstack_creds(is_list_cmd = false) openstack_creds_cmd = " --openstack-username '#{ENV['OPENSTACK_USERNAME']}' --openstack-password '#{ENV['OPENSTACK_PASSWORD']}' --openstack-api-endpoint #{ENV['OPENSTACK_AUTH_URL']}" @@ -54,7 +54,7 @@ def get_winrm_credentials # get openstack active instance_id for knife openstack show command run def get_active_instance_id - server_list_output = run('knife openstack server list ' + append_openstack_creds(is_list_cmd = true)) + server_list_output = run("knife openstack server list " + append_openstack_creds(is_list_cmd = true)) # Check command exitstatus. Non zero exitstatus indicates command execution fails. if server_list_output.exitstatus != 0 puts "Please check Openstack user name, password and auth url are correct. Error: #{list_output.stderr}." @@ -64,20 +64,20 @@ def get_active_instance_id end servers.each_line do |line| - if line.include?('ACTIVE') - instance_id = line.split(' ').first + if line.include?("ACTIVE") + instance_id = line.split(" ").first return instance_id end end false end -describe 'knife-openstack integration test', if: is_config_present do +describe "knife-openstack integration test", if: is_config_present do include KnifeTestBed include RSpec::KnifeTestUtils before(:all) do - expect(run('gem build knife-openstack.gemspec').exitstatus).to be(0) + expect(run("gem build knife-openstack.gemspec").exitstatus).to be(0) expect(run("gem install #{get_gem_file_name}").exitstatus).to be(0) init_openstack_test end @@ -87,350 +87,350 @@ def get_active_instance_id cleanup_test_data end - describe 'display help for command' do - %w(flavor\ list server\ create server\ delete server\ list group\ list image\ list network\ list ).each do |command| + describe "display help for command" do + %w{flavor\ list server\ create server\ delete server\ list group\ list image\ list network\ list }.each do |command| context "when --help option used with #{command} command" do let(:command) { "knife openstack #{command} --help" } - run_cmd_check_stdout('--help') + run_cmd_check_stdout("--help") end end end - describe 'display server list' do - context 'when standard options specified' do - let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) } - run_cmd_check_status_and_output('succeed', 'Instance ID') + describe "display server list" do + context "when standard options specified" do + let(:command) { "knife openstack server list" + append_openstack_creds(is_list_cmd = true) } + run_cmd_check_status_and_output("succeed", "Instance ID") end - context 'when --chef-data CLI option specified' do - let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) + ' --chef-data' } - it { skip('setup a chef-zero on workspace node') } + context "when --chef-data CLI option specified" do + let(:command) { "knife openstack server list" + append_openstack_creds(is_list_cmd = true) + " --chef-data" } + it { skip("setup a chef-zero on workspace node") } end - context 'when --chef-data and valid --chef-node-attribute CLI option specified' do - let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) + ' --chef-data --chef-node-attribute platform_family' } - it { skip('setup a chef-zero on workspace node') } + context "when --chef-data and valid --chef-node-attribute CLI option specified" do + let(:command) { "knife openstack server list" + append_openstack_creds(is_list_cmd = true) + " --chef-data --chef-node-attribute platform_family" } + it { skip("setup a chef-zero on workspace node") } end - context 'when --chef-data and In valid --chef-node-attribute CLI option specified' do - let(:command) { 'knife openstack server list' + append_openstack_creds(is_list_cmd = true) + ' --chef-data --chef-node-attribute invalid' } - it { skip('setup a chef-zero on workspace node') } + context "when --chef-data and In valid --chef-node-attribute CLI option specified" do + let(:command) { "knife openstack server list" + append_openstack_creds(is_list_cmd = true) + " --chef-data --chef-node-attribute invalid" } + it { skip("setup a chef-zero on workspace node") } end end - describe 'display flavor list' do - context 'when standard options specified' do - let(:command) { 'knife openstack flavor list' + append_openstack_creds(is_list_cmd = true) } - run_cmd_check_status_and_output('succeed', 'ID') + describe "display flavor list" do + context "when standard options specified" do + let(:command) { "knife openstack flavor list" + append_openstack_creds(is_list_cmd = true) } + run_cmd_check_status_and_output("succeed", "ID") end end - describe 'display image list' do - context 'when standard options specified' do - let(:command) { 'knife openstack image list' + append_openstack_creds(is_list_cmd = true) } - run_cmd_check_status_and_output('succeed', 'ID') + describe "display image list" do + context "when standard options specified" do + let(:command) { "knife openstack image list" + append_openstack_creds(is_list_cmd = true) } + run_cmd_check_status_and_output("succeed", "ID") end end - describe 'display group list' do - context 'when standard options specified' do - let(:command) { 'knife openstack group list' + append_openstack_creds(is_list_cmd = true) } - run_cmd_check_status_and_output('succeed', 'Name') + describe "display group list" do + context "when standard options specified" do + let(:command) { "knife openstack group list" + append_openstack_creds(is_list_cmd = true) } + run_cmd_check_status_and_output("succeed", "Name") end end - describe 'display network list' do - context 'when standard options specified' do - let(:command) { 'knife openstack network list' + append_openstack_creds(is_list_cmd = true) } - it { skip 'Chef openstack setup not support this functionality' } + describe "display network list" do + context "when standard options specified" do + let(:command) { "knife openstack network list" + append_openstack_creds(is_list_cmd = true) } + it { skip "Chef openstack setup not support this functionality" } end end - describe 'server show' do - context 'with valid instance_id' do + describe "server show" do + context "with valid instance_id" do before(:each) do @instance_id = get_active_instance_id end let(:command) { "knife openstack server show #{@instance_id}" + append_openstack_creds(is_list_cmd = true) } - run_cmd_check_status_and_output('succeed', 'Instance ID') + run_cmd_check_status_and_output("succeed", "Instance ID") end - context 'with invalid instance_id' do - let(:command) { 'knife openstack server show invalid_instance_id' + append_openstack_creds(is_list_cmd = true) } + context "with invalid instance_id" do + let(:command) { "knife openstack server show invalid_instance_id" + append_openstack_creds(is_list_cmd = true) } - run_cmd_check_status_and_output('fail', "ERROR: Server doesn't exists for this invalid_instance_id instance id") + run_cmd_check_status_and_output("fail", "ERROR: Server doesn't exists for this invalid_instance_id instance id") end end - describe 'create and bootstrap Linux Server' do + describe "create and bootstrap Linux Server" do before(:each) { rm_known_host } - context 'when standard options specified' do - cmd_out = '' + context "when standard options specified" do + cmd_out = "" - before(:each) { create_node_name('linux') } + before(:each) { create_node_name("linux") } after { cmd_out = "#{cmd_output}" } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") - context 'delete server after create' do + context "delete server after create" do let(:command) { delete_instance_cmd(cmd_out) } - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") end end - context 'when standard options and chef node name prefix is default value(i.e openstack)' do - let(:command) { - 'knife openstack server create '\ + context "when standard options and chef node name prefix is default value(i.e openstack)" do + let(:command) do + "knife openstack server create "\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end after { run(delete_instance_cmd("#{cmd_output}")) } - run_cmd_check_status_and_output('succeed', 'Bootstrapping Chef on') + run_cmd_check_status_and_output("succeed", "Bootstrapping Chef on") end - context 'when standard options and chef node name prefix is user specified value' do - let(:command) { - 'knife openstack server create '\ + context "when standard options and chef node name prefix is user specified value" do + let(:command) do + "knife openstack server create "\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ - ' --chef-node-name-prefix os-integration-test-' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ + " --chef-node-name-prefix os-integration-test-" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end after { run(delete_instance_cmd("#{cmd_output}")) } - run_cmd_check_status_and_output('succeed', 'os-integration-test-') + run_cmd_check_status_and_output("succeed", "os-integration-test-") end - context 'when standard options and delete-server-on-failure specified' do - nodename = '' - before(:each) { create_node_name('linux') } + context "when standard options and delete-server-on-failure specified" do + nodename = "" + before(:each) { create_node_name("linux") } after { nodename = @name_node } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ - ' --delete-server-on-failure' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ + " --delete-server-on-failure" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") - context 'delete server by using name after create' do - let(:command) { "knife openstack server delete #{nodename} " + append_openstack_creds(is_list_cmd = true) + ' --yes' } - run_cmd_check_status_and_output('succeed', "#{@name_node}") + context "delete server by using name after create" do + let(:command) { "knife openstack server delete #{nodename} " + append_openstack_creds(is_list_cmd = true) + " --yes" } + run_cmd_check_status_and_output("succeed", "#{@name_node}") end end - context 'when delete-server-on-failure specified and bootstrap fails' do - before(:each) { create_node_name('linux') } + context "when delete-server-on-failure specified and bootstrap fails" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ - ' --delete-server-on-failure' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ + " --delete-server-on-failure" + get_ssh_credentials + - " --identity-file #{temp_dir}/incorrect_openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/incorrect_openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'FATAL: Authentication Failed during bootstrapping') + run_cmd_check_status_and_output("fail", "FATAL: Authentication Failed during bootstrapping") end - context 'when openstack credentials not specified' do - before(:each) { create_node_name('linux') } + context "when openstack credentials not specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem --sudo" - } + end - run_cmd_check_status_and_output('fail', "ERROR: You did not provide a valid 'Openstack Username' value") + run_cmd_check_status_and_output("fail", "ERROR: You did not provide a valid 'Openstack Username' value") end - context 'when ssh-password and identity-file parameters not specified' do - before(:each) { create_node_name('linux') } + context "when ssh-password and identity-file parameters not specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + - append_openstack_creds + ' --sudo' - } + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + + append_openstack_creds + " --sudo" + end - it { skip 'Chef openstack setup not support this functionality.' } + it { skip "Chef openstack setup not support this functionality." } end - context 'when standard options and invalid openstack security group specified' do - before(:each) { create_node_name('linux') } + context "when standard options and invalid openstack security group specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"\ - ' --openstack-groups invalid-invalid-1212' + append_openstack_creds + ' --sudo' - } + " --openstack-groups invalid-invalid-1212" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'Security group invalid-invalid-1212 not found') + run_cmd_check_status_and_output("fail", "Security group invalid-invalid-1212 not found") end - context 'when standard options and invalid image id specified' do - before(:each) { create_node_name('linux') } + context "when standard options and invalid image id specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{SecureRandom.hex(18)} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'ERROR: You have not provided a valid image ID. Please note the options for this value are -I or --image') + run_cmd_check_status_and_output("fail", "ERROR: You have not provided a valid image ID. Please note the options for this value are -I or --image") end - context 'when standard options and invalid flavor id specified' do - before(:each) { create_node_name('linux') } + context "when standard options and invalid flavor id specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_invalid_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'ERROR: You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor') + run_cmd_check_status_and_output("fail", "ERROR: You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor") end - context 'when standard options and invalid floating ip specified' do - before(:each) { create_node_name('linux') } + context "when standard options and invalid floating ip specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} --openstack-floating-ip #{@os_invalid_floating_ip} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'ERROR: You have either requested an invalid floating IP address or none are available') + run_cmd_check_status_and_output("fail", "ERROR: You have either requested an invalid floating IP address or none are available") end - context 'when invalid key_pair specified' do - before(:each) { create_node_name('linux') } + context "when invalid key_pair specified" do + before(:each) { create_node_name("linux") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' \ + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" \ " --ssh-user #{@os_ssh_user}"\ " --openstack-ssh-key-id #{SecureRandom.hex(6)}"\ - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'Invalid key_name provided') + run_cmd_check_status_and_output("fail", "Invalid key_name provided") end - context 'when incorrect openstack private_key.pem file is used' do + context "when incorrect openstack private_key.pem file is used" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' \ + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" \ " --ssh-user #{@os_ssh_user}"\ " --openstack-ssh-key-id #{@openstack_key_pair}"\ - " --identity-file #{temp_dir}/incorrect_openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/incorrect_openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('fail', 'FATAL: Authentication Failed during bootstrapping') + run_cmd_check_status_and_output("fail", "FATAL: Authentication Failed during bootstrapping") end - context 'when standard options and --openstack-private-network option specified' do + context "when standard options and --openstack-private-network option specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"\ - ' --openstack-private-network' + append_openstack_creds + ' --sudo' - } + " --openstack-private-network" + append_openstack_creds + " --sudo" + end - it { skip 'not yet supported' } + it { skip "not yet supported" } end - context 'when standard options and --openstack-floating-ip option specified' do + context "when standard options and --openstack-floating-ip option specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"\ - ' --openstack-floating-ip' + append_openstack_creds + ' --sudo' - } + " --openstack-floating-ip" + append_openstack_creds + " --sudo" + end - it { skip 'empty floating ip pool' } + it { skip "empty floating ip pool" } end - context 'when standard options and user data specified' do + context "when standard options and user data specified" do before(:each) do - create_node_name('linux') + create_node_name("linux") @user_data_file = create_sh_user_data_file end @@ -441,208 +441,208 @@ def get_active_instance_id run(delete_instance_cmd("#{cmd_output}")) end - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem" \ " --user-data #{@user_data_file.path}" + - append_openstack_creds + ' --sudo -VV' - } + append_openstack_creds + " --sudo -VV" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") end - context 'when standard options and no network option specified' do + context "when standard options and no network option specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ - ' --no-network' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ + " --no-network" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") end - context 'when standard options and openstack endpoint type option is specified' do + context "when standard options and openstack endpoint type option is specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ - ' --openstack-endpoint-type publicURL' + + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ + " --openstack-endpoint-type publicURL" + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") end - context 'when standard options and openstack metadata option is specified' do + context "when standard options and openstack metadata option is specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ " --metadata testdataone='testmetadata'" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"\ " --metadata testdatatwo='testmetadata'" + - append_openstack_creds + ' --sudo' - } + append_openstack_creds + " --sudo" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") end - context 'when standard options and openstack network-ids option is specified' do + context "when standard options and openstack network-ids option is specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ " --network-ids #{@os_network_ids} " + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - it { skip 'Chef openstack setup not support this functionality' } + it { skip "Chef openstack setup not support this functionality" } end - context 'when standard options and openstack availability-zone option is specified' do + context "when standard options and openstack availability-zone option is specified" do server_create_common_bfr_aftr - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_linux_image} -f #{@os_linux_flavor} "\ - ' --template-file ' + get_linux_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_linux_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ " --availability-zone #{@os_availability_zone} " + get_ssh_credentials + - " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + ' --sudo' - } + " --identity-file #{temp_dir}/openstack.pem" + append_openstack_creds + " --sudo" + end - it { skip 'Chef openstack setup not support this functionality' } + it { skip "Chef openstack setup not support this functionality" } end end - describe 'create and bootstrap Windows Server' do + describe "create and bootstrap Windows Server" do before(:each) { rm_known_host } - context 'when standard options specified' do - cmd_out = '' + context "when standard options specified" do + cmd_out = "" - before(:each) { create_node_name('windows') } + before(:each) { create_node_name("windows") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}" \ " -I #{@os_windows_image} " \ " -f #{@os_windows_flavor} " \ - ' --template-file ' + get_windows_msi_template_file_path + - ' --server-url http://localhost:8889' \ - ' --bootstrap-protocol winrm' \ - ' --yes --server-create-timeout 1800' + + " --template-file " + get_windows_msi_template_file_path + + " --server-url http://localhost:8889" \ + " --bootstrap-protocol winrm" \ + " --yes --server-create-timeout 1800" + get_winrm_credentials + append_openstack_creds_for_windows - } + end after { cmd_out = "#{cmd_output}" } - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") - context 'delete server after create' do + context "delete server after create" do let(:command) { delete_instance_cmd(cmd_out) } - run_cmd_check_status_and_output('succeed') + run_cmd_check_status_and_output("succeed") end end - context 'when invalid winrm user specified' do - server_create_common_bfr_aftr('windows') + context "when invalid winrm user specified" do + server_create_common_bfr_aftr("windows") - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}" \ " -I #{@os_windows_image} " \ " -f #{@os_windows_flavor} " \ - ' --template-file ' + get_windows_msi_template_file_path + - ' --server-url http://localhost:8889' \ - ' --bootstrap-protocol winrm' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_windows_msi_template_file_path + + " --server-url http://localhost:8889" \ + " --bootstrap-protocol winrm" \ + " --yes --server-create-timeout 1800" \ " --winrm-user #{SecureRandom.hex(6)}"\ " --winrm-password #{@os_winrm_password}" + append_openstack_creds_for_windows - } - it { skip 'Fails due to OC-9708 bug in knife-windows.' } + end + it { skip "Fails due to OC-9708 bug in knife-windows." } end - context 'when invalid winrm password specified' do - server_create_common_bfr_aftr('windows') + context "when invalid winrm password specified" do + server_create_common_bfr_aftr("windows") - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}" \ " -I #{@os_windows_image} " \ " -f #{@os_windows_flavor} " \ - ' --template-file ' + get_windows_msi_template_file_path + - ' --server-url http://localhost:8889' \ - ' --bootstrap-protocol winrm' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_windows_msi_template_file_path + + " --server-url http://localhost:8889" \ + " --bootstrap-protocol winrm" \ + " --yes --server-create-timeout 1800" \ " --winrm-user #{@os_winrm_user}"\ " --winrm-password #{SecureRandom.hex(6)}" + append_openstack_creds_for_windows - } + end after(:each) { run(delete_instance_cmd("#{cmd_output}")) } - it { skip 'Fails due to OC-9708 bug in knife-windows.' } + it { skip "Fails due to OC-9708 bug in knife-windows." } end - context 'when standard options ssh bootstrap and valid image-os-type protocol specified' do - server_create_common_bfr_aftr('windows') + context "when standard options ssh bootstrap and valid image-os-type protocol specified" do + server_create_common_bfr_aftr("windows") - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_windows_ssh_image}"\ " -f #{@os_windows_flavor} "\ - ' --template-file ' + get_windows_msi_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_windows_msi_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ " --identity-file #{temp_dir}/openstack.pem"\ - " --openstack-ssh-key-id #{@openstack_key_pair}" + get_ssh_credentials_for_windows_image + append_openstack_creds + ' --image-os-type windows' - } + " --openstack-ssh-key-id #{@openstack_key_pair}" + get_ssh_credentials_for_windows_image + append_openstack_creds + " --image-os-type windows" + end - run_cmd_check_status_and_output('succeed', "#{@name_node}") + run_cmd_check_status_and_output("succeed", "#{@name_node}") end - context 'when standard options ssh bootstrap and invalid image-os-type protocol specified' do - before(:each) { create_node_name('windows') } + context "when standard options ssh bootstrap and invalid image-os-type protocol specified" do + before(:each) { create_node_name("windows") } - let(:command) { + let(:command) do "knife openstack server create -N #{@name_node}"\ " -I #{@os_windows_ssh_image}"\ " -f #{@os_windows_flavor} "\ - ' --template-file ' + get_windows_msi_template_file_path + - ' --server-url http://localhost:8889' \ - ' --yes --server-create-timeout 1800' \ + " --template-file " + get_windows_msi_template_file_path + + " --server-url http://localhost:8889" \ + " --yes --server-create-timeout 1800" \ " --identity-file #{temp_dir}/openstack.pem"\ - " --openstack-ssh-key-id #{@openstack_key_pair}" + get_ssh_credentials_for_windows_image + append_openstack_creds + ' --image-os-type invalid' - } + " --openstack-ssh-key-id #{@openstack_key_pair}" + get_ssh_credentials_for_windows_image + append_openstack_creds + " --image-os-type invalid" + end - run_cmd_check_status_and_output('fail', 'ERROR: You must provide --image-os-type option [windows/linux]') + run_cmd_check_status_and_output("fail", "ERROR: You must provide --image-os-type option [windows/linux]") end end end diff --git a/spec/spec_context.rb b/spec/spec_context.rb index 367fbc4e..4bc1f9d1 100644 --- a/spec/spec_context.rb +++ b/spec/spec_context.rb @@ -15,12 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -shared_context '#validate!' do |instance| +shared_context "#validate!" do |instance| before(:each) do - Chef::Config[:knife][:openstack_username] = 'testuser' - Chef::Config[:knife][:openstack_password] = 'testpassword' - Chef::Config[:knife][:openstack_auth_url] = 'tsturl' - Chef::Config[:knife][:openstack_region] = 'test-region' + Chef::Config[:knife][:openstack_username] = "testuser" + Chef::Config[:knife][:openstack_password] = "testpassword" + Chef::Config[:knife][:openstack_auth_url] = "tsturl" + Chef::Config[:knife][:openstack_region] = "test-region" allow(instance).to receive(:exit) end @@ -31,23 +31,23 @@ Chef::Config[:knife].delete(:openstack_region) end - it 'validate openstack mandatory options' do + it "validate openstack mandatory options" do expect { instance.validate! }.to_not raise_error end - it 'raise error on openstack_username missing' do + it "raise error on openstack_username missing" do Chef::Config[:knife].delete(:openstack_username) expect(instance.ui).to receive(:error).with("You did not provide a valid 'Openstack Username' value.") expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) end - it 'raise error on openstack_password missing' do + it "raise error on openstack_password missing" do Chef::Config[:knife].delete(:openstack_password) expect(instance.ui).to receive(:error).with("You did not provide a valid 'Openstack Password' value.") expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) end - it 'raise error on openstack_auth_url missing' do + it "raise error on openstack_auth_url missing" do Chef::Config[:knife].delete(:openstack_auth_url) expect(instance.ui).to receive(:error).with("You did not provide a valid 'Openstack Auth Url' value.") expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 50cffffc..0ac1a84e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,31 +15,31 @@ # Author:: Siddheshwar More () -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) -require 'chef/knife/bootstrap' -require 'chef/knife/openstack_helpers' -require 'fog' -require 'chef/knife/winrm_base' -require 'chef/knife/bootstrap_windows_winrm' -require 'chef/knife/openstack_server_create' -require 'chef/knife/openstack_server_delete' -require 'chef/knife/bootstrap_windows_ssh' -require 'securerandom' -require 'knife-openstack/version' -require 'test/knife-utils/test_bed' -require 'resource_spec_helper' -require 'server_command_common_spec_helper' -require 'tempfile' -require 'spec_context' +$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) +require "chef/knife/bootstrap" +require "chef/knife/openstack_helpers" +require "fog" +require "chef/knife/winrm_base" +require "chef/knife/bootstrap_windows_winrm" +require "chef/knife/openstack_server_create" +require "chef/knife/openstack_server_delete" +require "chef/knife/bootstrap_windows_ssh" +require "securerandom" +require "knife-openstack/version" +require "test/knife-utils/test_bed" +require "resource_spec_helper" +require "server_command_common_spec_helper" +require "tempfile" +require "spec_context" def find_instance_id(instance_name, file) file.lines.each do |line| - return "#{line}".split(' ')[2].strip if line.include?("#{instance_name}") + return "#{line}".split(" ")[2].strip if line.include?("#{instance_name}") end end def is_config_present - unless ENV['RUN_INTEGRATION_TESTS'] + unless ENV["RUN_INTEGRATION_TESTS"] puts("\nPlease set RUN_INTEGRATION_TESTS environment variable to run integration tests") return false end @@ -47,9 +47,9 @@ def is_config_present unset_env_var = [] unset_config_options = [] is_config = true - config_file_exist = File.exist?(File.expand_path('../integration/config/environment.yml', __FILE__)) - openstack_config = YAML.load(File.read(File.expand_path('../integration/config/environment.yml', __FILE__))) if config_file_exist - %w(OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL OPENSTACK_TENANT).each do |os_env_var| + config_file_exist = File.exist?(File.expand_path("../integration/config/environment.yml", __FILE__)) + openstack_config = YAML.load(File.read(File.expand_path("../integration/config/environment.yml", __FILE__))) if config_file_exist + %w{OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL OPENSTACK_TENANT}.each do |os_env_var| if ENV[os_env_var].nil? unset_env_var << os_env_var is_config = false @@ -57,10 +57,10 @@ def is_config_present end err_msg = "\nPlease set #{unset_env_var.join(', ')} environment" - err_msg = err_msg + (unset_env_var.length > 1 ? ' variables ' : ' variable ') + 'for integration tests.' + err_msg = err_msg + (unset_env_var.length > 1 ? " variables " : " variable ") + "for integration tests." puts err_msg unless unset_env_var.empty? - %w(OS_SSH_USER OPENSTACK_PRI_KEY OPENSTACK_KEY_PAIR OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE).each do |os_config_opt| + %w{OS_SSH_USER OPENSTACK_PRI_KEY OPENSTACK_KEY_PAIR OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE}.each do |os_config_opt| option_value = ENV[os_config_opt] || (openstack_config[os_config_opt] if openstack_config) if option_value.nil? unset_config_options << os_config_opt @@ -69,53 +69,53 @@ def is_config_present end config_err_msg = "\nPlease set #{unset_config_options.join(', ')} config" - config_err_msg = config_err_msg + (unset_config_options.length > 1 ? ' options in ../spec/integration/config/environment.yml or as environment variables' : ' option in ../spec/integration/config/environment.yml or as environment variable') + ' for integration tests.' + config_err_msg = config_err_msg + (unset_config_options.length > 1 ? " options in ../spec/integration/config/environment.yml or as environment variables" : " option in ../spec/integration/config/environment.yml or as environment variable") + " for integration tests." puts config_err_msg unless unset_config_options.empty? is_config end def get_gem_file_name - 'knife-openstack-' + Knife::OpenStack::VERSION + '.gem' + "knife-openstack-" + Knife::OpenStack::VERSION + ".gem" end def delete_instance_cmd(stdout) - 'knife openstack server delete ' + find_instance_id('Instance ID', stdout) + - append_openstack_creds(is_list_cmd = true) + ' --yes' + "knife openstack server delete " + find_instance_id("Instance ID", stdout) + + append_openstack_creds(is_list_cmd = true) + " --yes" end def create_node_name(name) - @name_node = (name == 'linux') ? "os-integration-test-linux-#{SecureRandom.hex(4)}" : "os-integration-test-win-#{SecureRandom.hex(4)}" + @name_node = (name == "linux") ? "os-integration-test-linux-#{SecureRandom.hex(4)}" : "os-integration-test-win-#{SecureRandom.hex(4)}" end def init_openstack_test init_test begin - data_to_write = File.read(File.expand_path('../integration/config/incorrect_openstack.pem', __FILE__)) - File.open("#{temp_dir}/incorrect_openstack.pem", 'w') { |f| f.write(data_to_write) } + data_to_write = File.read(File.expand_path("../integration/config/incorrect_openstack.pem", __FILE__)) + File.open("#{temp_dir}/incorrect_openstack.pem", "w") { |f| f.write(data_to_write) } rescue - puts 'Error while creating file - incorrect_openstack.pem' + puts "Error while creating file - incorrect_openstack.pem" end - config_file_exist = File.exist?(File.expand_path('../integration/config/environment.yml', __FILE__)) - openstack_config = YAML.load(File.read(File.expand_path('../integration/config/environment.yml', __FILE__))) if config_file_exist + config_file_exist = File.exist?(File.expand_path("../integration/config/environment.yml", __FILE__)) + openstack_config = YAML.load(File.read(File.expand_path("../integration/config/environment.yml", __FILE__))) if config_file_exist - %w(OS_SSH_USER OPENSTACK_KEY_PAIR OPENSTACK_PRI_KEY OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE).each do |os_config_opt| + %w{OS_SSH_USER OPENSTACK_KEY_PAIR OPENSTACK_PRI_KEY OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE}.each do |os_config_opt| instance_variable_set("@#{os_config_opt.downcase}", (openstack_config[os_config_opt] if openstack_config) || ENV[os_config_opt]) end begin key_file_path = @openstack_pri_key key_file_exist = File.exist?(File.expand_path(key_file_path, __FILE__)) data_to_write = File.read(File.expand_path(key_file_path, __FILE__)) if key_file_exist - File.open("#{temp_dir}/openstack.pem", 'w') { |f| f.write(data_to_write) } + File.open("#{temp_dir}/openstack.pem", "w") { |f| f.write(data_to_write) } rescue - puts 'Error while creating file - openstack.pem' + puts "Error while creating file - openstack.pem" end end def create_sh_user_data_file - file = Tempfile.new(['test_user_data', '.sh']) + file = Tempfile.new(["test_user_data", ".sh"]) file.write("echo 'sample user data file created' >> #{Dir.tmpdir}/testuserdata.txt") file.rewind file diff --git a/spec/unit/openstack_flavor_list_spec.rb b/spec/unit/openstack_flavor_list_spec.rb index 8955a31a..54c01d35 100644 --- a/spec/unit/openstack_flavor_list_spec.rb +++ b/spec/unit/openstack_flavor_list_spec.rb @@ -17,13 +17,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_flavor_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_flavor_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackFlavorList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFlavorList.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackFlavorList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackFlavorList.new end diff --git a/spec/unit/openstack_floating_ip_allocate_spec.rb b/spec/unit/openstack_floating_ip_allocate_spec.rb index 6c35c947..ec5f19f0 100644 --- a/spec/unit/openstack_floating_ip_allocate_spec.rb +++ b/spec/unit/openstack_floating_ip_allocate_spec.rb @@ -15,39 +15,39 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_floating_ip_allocate' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_floating_ip_allocate" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackFloatingIpAllocate do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new before(:each) do @instance = Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new allow(@instance.ui).to receive(:error) end - describe 'create service instance' do - it 'return OpenstackService instance' do + describe "create service instance" do + it "return OpenstackService instance" do expect(@instance.create_service_instance).to be_an_instance_of(Chef::Knife::Cloud::OpenstackService) end end - describe 'allocate floating ip' do - it 'calls allocate address' do + describe "allocate floating ip" do + it "calls allocate address" do @instance.service = double expect(@instance.service).to receive(:allocate_address).and_return(true) @instance.execute_command end end - describe 'when user provides pool option ' do - it 'allocates floating ip in user specified pool' do - @instance = Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new(['--pool', 'test-pool']) + describe "when user provides pool option " do + it "allocates floating ip in user specified pool" do + @instance = Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new(["--pool", "test-pool"]) @instance.service = Chef::Knife::Cloud::Service.new - response = { floating_ip: { 'id' => 'test-id', 'instance_id' => 'test-instance-id', 'floating_ip' => '127.0.0.1', 'fixed_ip' => 'nil', 'pool' => 'test-pool' } } + response = { floating_ip: { "id" => "test-id", "instance_id" => "test-instance-id", "floating_ip" => "127.0.0.1", "fixed_ip" => "nil", "pool" => "test-pool" } } expect(@instance.service).to receive(:allocate_address).and_return(response) @instance.execute_command end diff --git a/spec/unit/openstack_floating_ip_associate_spec.rb b/spec/unit/openstack_floating_ip_associate_spec.rb index 33adb1b0..36fa7414 100644 --- a/spec/unit/openstack_floating_ip_associate_spec.rb +++ b/spec/unit/openstack_floating_ip_associate_spec.rb @@ -14,21 +14,21 @@ # 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 'spec_helper' -require 'chef/knife/openstack_floating_ip_associate' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' -require 'ostruct' +require "spec_helper" +require "chef/knife/openstack_floating_ip_associate" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" +require "ostruct" describe Chef::Knife::Cloud::OpenstackFloatingIpAssociate do before(:each) do - @instance = Chef::Knife::Cloud::OpenstackFloatingIpAssociate.new(['--instance-id', '23849038438240934n3294839248']) - @instance.name_args = ['127.0.0.1'] + @instance = Chef::Knife::Cloud::OpenstackFloatingIpAssociate.new(["--instance-id", "23849038438240934n3294839248"]) + @instance.name_args = ["127.0.0.1"] end - describe 'associate floating ip' do - it 'calls associate address' do - success_message = 'Floating IP 127.0.0.1 associated with Instance 23849038438240934n3294839248' + describe "associate floating ip" do + it "calls associate address" do + success_message = "Floating IP 127.0.0.1 associated with Instance 23849038438240934n3294839248" @instance.service = Chef::Knife::Cloud::Service.new response = OpenStruct.new(status: 202) expect(@instance.service).to receive(:associate_address).and_return(response) diff --git a/spec/unit/openstack_floating_ip_disassociate_spec.rb b/spec/unit/openstack_floating_ip_disassociate_spec.rb index 773167dd..4a8aca27 100644 --- a/spec/unit/openstack_floating_ip_disassociate_spec.rb +++ b/spec/unit/openstack_floating_ip_disassociate_spec.rb @@ -14,24 +14,24 @@ # 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 'spec_helper' -require 'chef/knife/openstack_floating_ip_disassociate' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' -require 'ostruct' +require "spec_helper" +require "chef/knife/openstack_floating_ip_disassociate" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" +require "ostruct" describe Chef::Knife::Cloud::OpenstackFloatingIpDisassociate do before(:each) do - @instance = Chef::Knife::Cloud::OpenstackFloatingIpDisassociate.new(['--instance-id', '23849038438240934n3294839248']) - @instance.name_args = ['127.0.0.1'] + @instance = Chef::Knife::Cloud::OpenstackFloatingIpDisassociate.new(["--instance-id", "23849038438240934n3294839248"]) + @instance.name_args = ["127.0.0.1"] end - describe 'associate floating ip' do - it 'calls associate address' do + describe "associate floating ip" do + it "calls associate address" do @instance.service = Chef::Knife::Cloud::Service.new response = OpenStruct.new(status: 202) - expect(@instance.service).to receive(:disassociate_address).with('23849038438240934n3294839248', '127.0.0.1').and_return(response) - expect(@instance.ui).to receive(:info).and_return('Floating IP 127.0.0.1 disassociated with Instance 23849038438240934n3294839248') + expect(@instance.service).to receive(:disassociate_address).with("23849038438240934n3294839248", "127.0.0.1").and_return(response) + expect(@instance.ui).to receive(:info).and_return("Floating IP 127.0.0.1 disassociated with Instance 23849038438240934n3294839248") @instance.execute_command end end diff --git a/spec/unit/openstack_floating_ip_list_spec.rb b/spec/unit/openstack_floating_ip_list_spec.rb index 874dceec..064bec0b 100644 --- a/spec/unit/openstack_floating_ip_list_spec.rb +++ b/spec/unit/openstack_floating_ip_list_spec.rb @@ -15,12 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_floating_ip_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_floating_ip_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackFloatingIpList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFloatingIpList.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackFloatingIpList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackFloatingIpList.new end diff --git a/spec/unit/openstack_floating_ip_release_spec.rb b/spec/unit/openstack_floating_ip_release_spec.rb index 418949b3..6f1f0ff3 100644 --- a/spec/unit/openstack_floating_ip_release_spec.rb +++ b/spec/unit/openstack_floating_ip_release_spec.rb @@ -14,34 +14,34 @@ # 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 'spec_helper' -require 'chef/knife/openstack_floating_ip_release' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_floating_ip_release" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackFloatingIpRelease do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFloatingIpRelease.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackFloatingIpRelease.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackFloatingIpRelease.new before(:each) do @instance = Chef::Knife::Cloud::OpenstackFloatingIpRelease.new allow(@instance.ui).to receive(:error) - @instance.name_args = ['23849038438240934n3294839248'] + @instance.name_args = ["23849038438240934n3294839248"] end - describe 'create service instance' do - it 'return OpenstackService instance' do + describe "create service instance" do + it "return OpenstackService instance" do expect(@instance.create_service_instance).to be_an_instance_of(Chef::Knife::Cloud::OpenstackService) end end - describe 'release floating ip' do - it 'calls release address' do - address_id = '23849038438240934n3294839248' + describe "release floating ip" do + it "calls release address" do + address_id = "23849038438240934n3294839248" @instance.service = double response = OpenStruct.new(status: 202) expect(@instance.service).to receive(:release_address).and_return(response) - expect(@instance.ui).to receive(:info).and_return('Floating IP released successfully.') + expect(@instance.ui).to receive(:info).and_return("Floating IP released successfully.") @instance.execute_command end end diff --git a/spec/unit/openstack_group_list_spec.rb b/spec/unit/openstack_group_list_spec.rb index a90b8526..9baa69b1 100644 --- a/spec/unit/openstack_group_list_spec.rb +++ b/spec/unit/openstack_group_list_spec.rb @@ -17,26 +17,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_group_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_group_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackGroupList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackGroupList.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackGroupList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackGroupList.new let (:instance) { Chef::Knife::Cloud::OpenstackGroupList.new } - context '#list' do + context "#list" do before(:each) do - @security_groups = [TestResource.new('name' => 'Unrestricted', 'description' => 'testdescription', 'security_group_rules' => [TestResource.new('from_port' => 636, 'group' => {}, 'ip_protocol' => 'tcp', 'to_port' => 636, 'parent_group_id' => 14, 'ip_range' => { 'cidr' => '0.0.0.0/0' }, 'id' => 183)])] - instance.config[:format] = 'summary' + @security_groups = [TestResource.new("name" => "Unrestricted", "description" => "testdescription", "security_group_rules" => [TestResource.new("from_port" => 636, "group" => {}, "ip_protocol" => "tcp", "to_port" => 636, "parent_group_id" => 14, "ip_range" => { "cidr" => "0.0.0.0/0" }, "id" => 183)])] + instance.config[:format] = "summary" end - it 'returns group list' do - expect(instance.ui).to receive(:list).with(['Name', 'Protocol', 'From', 'To', 'CIDR', 'Description', 'Unrestricted', 'tcp', '636', '636', '0.0.0.0/0', 'testdescription'], :uneven_columns_across, 6) + it "returns group list" do + expect(instance.ui).to receive(:list).with(["Name", "Protocol", "From", "To", "CIDR", "Description", "Unrestricted", "tcp", "636", "636", "0.0.0.0/0", "testdescription"], :uneven_columns_across, 6) instance.list(@security_groups) end end diff --git a/spec/unit/openstack_image_list_spec.rb b/spec/unit/openstack_image_list_spec.rb index 66030ef5..7b2cce76 100644 --- a/spec/unit/openstack_image_list_spec.rb +++ b/spec/unit/openstack_image_list_spec.rb @@ -17,15 +17,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_image_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_image_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackImageList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackImageList.new let (:instance) { Chef::Knife::Cloud::OpenstackImageList.new } - include_context '#validate!', Chef::Knife::Cloud::OpenstackImageList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackImageList.new end diff --git a/spec/unit/openstack_network_list_spec.rb b/spec/unit/openstack_network_list_spec.rb index 7d962681..37bcbc9e 100644 --- a/spec/unit/openstack_network_list_spec.rb +++ b/spec/unit/openstack_network_list_spec.rb @@ -16,20 +16,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_network_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_network_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackNetworkList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackNetworkList.new let (:instance) { Chef::Knife::Cloud::OpenstackNetworkList.new } - include_context '#validate!', Chef::Knife::Cloud::OpenstackNetworkList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackNetworkList.new - context 'query_resource' do - it 'returns the networks using the fog service.' do + context "query_resource" do + it "returns the networks using the fog service." do instance.service = double expect(instance.service).to receive(:list_networks) instance.query_resource diff --git a/spec/unit/openstack_server_create_spec.rb b/spec/unit/openstack_server_create_spec.rb index 94d0dfbc..95ca906d 100644 --- a/spec/unit/openstack_server_create_spec.rb +++ b/spec/unit/openstack_server_create_spec.rb @@ -18,10 +18,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path('../../spec_helper', __FILE__) -require 'chef/knife/openstack_server_create' -require 'support/shared_examples_for_servercreatecommand' -require 'support/shared_examples_for_command' +require File.expand_path("../../spec_helper", __FILE__) +require "chef/knife/openstack_server_create" +require "support/shared_examples_for_servercreatecommand" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackServerCreate do create_instance = Chef::Knife::Cloud::OpenstackServerCreate.new @@ -30,29 +30,29 @@ it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerCreate.new it_behaves_like Chef::Knife::Cloud::ServerCreateCommand, create_instance - describe '#create_service_instance' do + describe "#create_service_instance" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new end - it 'return OpenstackService instance' do + it "return OpenstackService instance" do expect(@instance.create_service_instance).to be_an_instance_of(Chef::Knife::Cloud::OpenstackService) end - it 'has custom_arguments as its option' do + it "has custom_arguments as its option" do expect(@instance.options.include? :custom_attributes).to be true end end - describe '#validate_params!' do + describe "#validate_params!" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new allow(@instance.ui).to receive(:error) - Chef::Config[:knife][:bootstrap_protocol] = 'ssh' - Chef::Config[:knife][:identity_file] = 'identity_file' - Chef::Config[:knife][:image_os_type] = 'linux' - Chef::Config[:knife][:openstack_ssh_key_id] = 'openstack_ssh_key' - Chef::Config[:knife][:openstack_region] = 'test-region' + Chef::Config[:knife][:bootstrap_protocol] = "ssh" + Chef::Config[:knife][:identity_file] = "identity_file" + Chef::Config[:knife][:image_os_type] = "linux" + Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key" + Chef::Config[:knife][:openstack_region] = "test-region" end after(:all) do @@ -63,24 +63,24 @@ Chef::Config[:knife].delete(:openstack_region) end - it 'run sucessfully on all params exist' do + it "run sucessfully on all params exist" do expect { @instance.validate_params! }.to_not raise_error end end - describe '#before_exec_command' do + describe "#before_exec_command" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new allow(@instance.ui).to receive(:error) - @instance.config[:chef_node_name] = 'chef_node_name' - Chef::Config[:knife][:image] = 'image' - Chef::Config[:knife][:flavor] = 'flavor' - Chef::Config[:knife][:openstack_security_groups] = 'openstack_security_groups' - Chef::Config[:knife][:server_create_timeout] = 'server_create_timeout' - Chef::Config[:knife][:openstack_ssh_key_id] = 'openstack_ssh_key' - Chef::Config[:knife][:network_ids] = 'test_network_id' + @instance.config[:chef_node_name] = "chef_node_name" + Chef::Config[:knife][:image] = "image" + Chef::Config[:knife][:flavor] = "flavor" + Chef::Config[:knife][:openstack_security_groups] = "openstack_security_groups" + Chef::Config[:knife][:server_create_timeout] = "server_create_timeout" + Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key" + Chef::Config[:knife][:network_ids] = "test_network_id" allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids]) - Chef::Config[:knife][:metadata] = 'foo=bar' + Chef::Config[:knife][:metadata] = "foo=bar" end after(:all) do @@ -92,10 +92,10 @@ Chef::Config[:knife].delete(:metadata) end - it 'set create_options' do + it "set create_options" do @instance.service = double - allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image')) - allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor')) + allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image")) + allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor")) expect(@instance.service).to receive(:create_server_dependencies) expect(@instance).to receive(:post_connection_validations) @instance.before_exec_command @@ -110,49 +110,49 @@ end it "doesn't set user data in server_def if user_data not specified" do - @instance.service = double('Chef::Knife::Cloud::OpenstackService', create_server_dependencies: nil) - allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image')) - allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor')) + @instance.service = double("Chef::Knife::Cloud::OpenstackService", create_server_dependencies: nil) + allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image")) + allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor")) expect(@instance).to receive(:post_connection_validations) @instance.before_exec_command expect(@instance.create_options[:server_def]).to_not include(:user_data) end - it 'sets user data' do + it "sets user data" do user_data = "echo 'hello world' >> /tmp/user_data.txt" Chef::Config[:knife][:user_data] = user_data - @instance.service = double('Chef::Knife::Cloud::OpenstackService', create_server_dependencies: nil) - allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image')) - allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor')) + @instance.service = double("Chef::Knife::Cloud::OpenstackService", create_server_dependencies: nil) + allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image")) + allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor")) expect(@instance).to receive(:post_connection_validations) @instance.before_exec_command expect(@instance.create_options[:server_def][:user_data]).to be == user_data end - context 'with multiple network_ids specified' do + context "with multiple network_ids specified" do before(:each) do @instance.service = double - allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image')) - allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor')) + allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image")) + allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor")) expect(@instance.service).to receive(:create_server_dependencies) - Chef::Config[:knife][:network_ids] = 'test_network_id1,test_network_id2' - allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids].split(',')) + Chef::Config[:knife][:network_ids] = "test_network_id1,test_network_id2" + allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids].split(",")) expect(@instance).to receive(:post_connection_validations) end - it 'creates the server_def with multiple nic_ids.' do + it "creates the server_def with multiple nic_ids." do @instance.before_exec_command - expect(@instance.create_options[:server_def][:nics]).to be == %w(test_network_id1 test_network_id2) + expect(@instance.create_options[:server_def][:nics]).to be == %w{test_network_id1 test_network_id2} end end - it 'ensures default value for metadata' do + it "ensures default value for metadata" do options = @instance.options expect(options[:metadata][:default]).to be_nil end end - describe '#after_exec_command' do + describe "#after_exec_command" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new allow(@instance).to receive(:msg_pair) @@ -164,136 +164,136 @@ it "don't set openstack_floating_ip on missing openstack_floating_ip option" do # default openstack_floating_ip is '-1' - Chef::Config[:knife][:openstack_floating_ip] = '-1' + Chef::Config[:knife][:openstack_floating_ip] = "-1" @instance.service = Chef::Knife::Cloud::Service.new @instance.server = double - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] }) + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.1.1" }] }) expect(@instance).to receive(:bootstrap) @instance.after_exec_command end - it 'set openstack_floating_ip on openstack_floating_ip option' do + it "set openstack_floating_ip on openstack_floating_ip option" do Chef::Config[:knife][:openstack_floating_ip] = nil @instance.service = Chef::Knife::Cloud::Service.new @instance.server = double @network = double - @ports = ['id' => 'test', - 'fixed_ips' => ['ip_address' => '127.0.1.1']] - allow(@network).to receive(:list_ports).and_return(body: { 'ports' => @ports }) - @floating_ips = ['id' => 'test', - 'fixed_ips' => ['ip_address' => '127.0.1.1']] - allow(@network).to receive(:list_floating_ips).and_return(body: { 'floatingips' => @floating_ips }) + @ports = ["id" => "test", + "fixed_ips" => ["ip_address" => "127.0.1.1"]] + allow(@network).to receive(:list_ports).and_return(body: { "ports" => @ports }) + @floating_ips = ["id" => "test", + "fixed_ips" => ["ip_address" => "127.0.1.1"]] + allow(@network).to receive(:list_floating_ips).and_return(body: { "floatingips" => @floating_ips }) allow(@network).to receive(:associate_floating_ip) allow(@instance.service).to receive(:network).and_return(@network) - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] }) + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.1.1" }] }) expect(@instance).to receive(:bootstrap) allow(@instance.service).to receive(:connection).and_return(double) free_floating = Object.new free_floating.define_singleton_method(:fixed_ip) { return nil } - free_floating.define_singleton_method(:ip) { return '127.0.0.1' } + free_floating.define_singleton_method(:ip) { return "127.0.0.1" } expect(@instance.service.connection).to receive(:addresses).and_return([free_floating]) @instance.after_exec_command end - it 'raise error on unavailability of free_floating ip' do + it "raise error on unavailability of free_floating ip" do Chef::Config[:knife][:openstack_floating_ip] = nil @instance.service = Chef::Knife::Cloud::Service.new allow(@instance.ui).to receive(:fatal) @instance.server = double - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] }) + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.1.1" }] }) expect(@instance).to_not receive(:bootstrap) allow(@instance.service).to receive(:connection).and_return(double) free_floating = Object.new - free_floating.define_singleton_method(:fixed_ip) { return '127.0.0.1' } + free_floating.define_singleton_method(:fixed_ip) { return "127.0.0.1" } expect(@instance.service.connection).to receive(:addresses).and_return([free_floating]) - expect { @instance.after_exec_command }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerSetupError, 'Unable to assign a Floating IP from allocated IPs.') + expect { @instance.after_exec_command }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerSetupError, "Unable to assign a Floating IP from allocated IPs.") end end - describe '#before_bootstrap' do + describe "#before_bootstrap" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new @instance.server = double # default bootstrap_network is public - @instance.config[:bootstrap_network] = 'public' + @instance.config[:bootstrap_network] = "public" # default no network is true @instance.config[:network] = true - Chef::Config[:knife][:ssh_password] = 'config_ssh_password' + Chef::Config[:knife][:ssh_password] = "config_ssh_password" end after(:each) do Chef::Config[:knife].delete(:ssh_password) end - context 'when no-network option specified' do + context "when no-network option specified" do before(:each) { @instance.config[:network] = false } - it 'set public ip as a bootstrap ip if both public and private ip available' do - allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.2' }] }) + it "set public ip as a bootstrap ip if both public and private ip available" do + allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }], "public" => [{ "version" => 4, "addr" => "127.0.0.2" }] }) @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.2' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2" end - it 'set private-ip as a bootstrap ip if private ip is available' do - allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) + it "set private-ip as a bootstrap ip if private ip is available" do + allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1" end - it 'set available ip as a bootstrap ip if no public, private ip available' do - allow(@instance.server).to receive(:addresses).and_return({ 1 => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) + it "set available ip as a bootstrap ip if no public, private ip available" do + allow(@instance.server).to receive(:addresses).and_return({ 1 => [{ "version" => 4, "addr" => "127.0.0.1" }] }) @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1" end end - it 'set bootstrap_ip' do - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) + it "set bootstrap_ip" do + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1" end - it 'set private-ip as a bootstrap-ip if private-network option set' do - allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.2' }] }) + it "set private-ip as a bootstrap-ip if private-network option set" do + allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }], "public" => [{ "version" => 4, "addr" => "127.0.0.2" }] }) @instance.config[:private_network] = true @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1" end - it 'raise error on nil bootstrap_ip' do + it "raise error on nil bootstrap_ip" do allow(@instance.ui).to receive(:error) - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => nil }] }) - expect { @instance.before_bootstrap }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, 'No IP address available for bootstrapping.') + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => nil }] }) + expect { @instance.before_bootstrap }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, "No IP address available for bootstrapping.") end - it 'set public ip as default bootstrap network is public' do - allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.2' }] }) + it "set public ip as default bootstrap network is public" do + allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }], "public" => [{ "version" => 4, "addr" => "127.0.0.2" }] }) @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.2' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2" end - it 'configures the bootstrap to use alternate network' do - allow(@instance.server).to receive(:addresses).and_return({ 'foo' => [{ 'version' => 1, 'addr' => '127.0.0.1' }], 'private' => [{ 'version' => 4, 'addr' => '127.0.0.2' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.3' }] }) - @instance.config[:bootstrap_network] = 'foo' + it "configures the bootstrap to use alternate network" do + allow(@instance.server).to receive(:addresses).and_return({ "foo" => [{ "version" => 1, "addr" => "127.0.0.1" }], "private" => [{ "version" => 4, "addr" => "127.0.0.2" }], "public" => [{ "version" => 4, "addr" => "127.0.0.3" }] }) + @instance.config[:bootstrap_network] = "foo" @instance.before_bootstrap - expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1' + expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1" end - it 'configures the bootstrap to use the server password' do - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) + it "configures the bootstrap to use the server password" do + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) Chef::Config[:knife].delete(:ssh_password) - server_password = 'adFRjk1089' + server_password = "adFRjk1089" allow(@instance.server).to receive(:password).and_return(server_password) @instance.before_bootstrap expect(@instance.config[:ssh_password]).to be == server_password end - it 'configures the bootstrap to use the config ssh password' do - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) - server_password = 'config_ssh_password' + it "configures the bootstrap to use the config ssh password" do + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) + server_password = "config_ssh_password" Chef::Config[:knife][:ssh_password] = server_password expect(@instance.server).to_not receive(:password) @instance.before_bootstrap @@ -301,60 +301,60 @@ end it "configures the default private bootstrap network to use 'private'" do - allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) + allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) @instance.config[:private_network] = true @instance.before_bootstrap - expect(@instance.config[:bootstrap_network]).to be == 'private' + expect(@instance.config[:bootstrap_network]).to be == "private" end - it 'configures the bootstrap to use alternate private network' do - allow(@instance.server).to receive(:addresses).and_return({ 'secure' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) - @instance.config[:bootstrap_network] = 'secure' + it "configures the bootstrap to use alternate private network" do + allow(@instance.server).to receive(:addresses).and_return({ "secure" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) + @instance.config[:bootstrap_network] = "secure" @instance.config[:private_network] = true @instance.before_bootstrap - expect(@instance.config[:bootstrap_network]).to be == 'secure' + expect(@instance.config[:bootstrap_network]).to be == "secure" end - it 'set openstack ohai hint' do - allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] }) + it "set openstack ohai hint" do + allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] }) @instance.before_bootstrap - expect(@instance.config[:hints]).to be == { 'openstack' => {} } + expect(@instance.config[:hints]).to be == { "openstack" => {} } end end - describe '#post_connection_validations' do + describe "#post_connection_validations" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new allow(@instance.ui).to receive(:error) end - it 'raise error on invalid image' do + it "raise error on invalid image" do allow(@instance).to receive(:is_flavor_valid?).and_return(true) allow(@instance).to receive(:is_floating_ip_valid?).and_return(true) expect(@instance).to receive(:is_image_valid?).and_return(false) - expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, ' You have not provided a valid image ID. Please note the options for this value are -I or --image..') + expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You have not provided a valid image ID. Please note the options for this value are -I or --image..") end - it 'raise error on invalid flavor' do + it "raise error on invalid flavor" do allow(@instance).to receive(:is_image_valid?).and_return(true) allow(@instance).to receive(:is_floating_ip_valid?).and_return(true) expect(@instance).to receive(:is_flavor_valid?).and_return(false) - expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, ' You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor..') + expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor..") end - it 'raise error on invalid floating IP' do + it "raise error on invalid floating IP" do allow(@instance).to receive(:is_flavor_valid?).and_return(true) allow(@instance).to receive(:is_image_valid?).and_return(true) expect(@instance).to receive(:is_floating_ip_valid?).and_return(false) - expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, ' You have either requested an invalid floating IP address or none are available..') + expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You have either requested an invalid floating IP address or none are available..") end end - describe '#is_floating_ip_valid?' do + describe "#is_floating_ip_valid?" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new # Default value - Chef::Config[:knife][:openstack_floating_ip] = '-1' + Chef::Config[:knife][:openstack_floating_ip] = "-1" @instance.service = double end @@ -362,18 +362,18 @@ Chef::Config[:knife].delete(:openstack_floating_ip) end - it 'returns true for default' do + it "returns true for default" do expect(@instance.is_floating_ip_valid?).to be true end - it 'returns false if no floating IPs' do + it "returns false if no floating IPs" do Chef::Config[:knife].delete(:openstack_floating_ip) expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([]) expect(@instance.is_floating_ip_valid?).to be false end - context 'when floating ip requested without value' do - it 'returns true if fixed_ip is nil' do + context "when floating ip requested without value" do + it "returns true if fixed_ip is nil" do Chef::Config[:knife][:openstack_floating_ip] = nil obj = Object.new obj.define_singleton_method(:fixed_ip) { nil } @@ -382,66 +382,66 @@ end end - context 'when floating ip requested with value' do - before { Chef::Config[:knife][:openstack_floating_ip] = '127.0.0.1' } + context "when floating ip requested with value" do + before { Chef::Config[:knife][:openstack_floating_ip] = "127.0.0.1" } after { Chef::Config[:knife].delete(:openstack_floating_ip) } - it 'returns true if requested floating IP is exist' do + it "returns true if requested floating IP is exist" do obj = Object.new - obj.define_singleton_method(:ip) { return '127.0.0.1' } + obj.define_singleton_method(:ip) { return "127.0.0.1" } expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj]) expect(@instance.is_floating_ip_valid?).to be true end - it 'returns false if requested floating IP does not exist' do + it "returns false if requested floating IP does not exist" do obj = Object.new - obj.define_singleton_method(:ip) { return '127.0.1.1' } + obj.define_singleton_method(:ip) { return "127.0.1.1" } expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj]) expect(@instance.is_floating_ip_valid?).to be false end end end - describe '#is_image_valid?' do + describe "#is_image_valid?" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new @instance.service = double - Chef::Config[:knife][:image] = 'image_id' + Chef::Config[:knife][:image] = "image_id" end after(:each) do Chef::Config[:knife].delete(:image) end - it 'returns false on invalid image' do + it "returns false on invalid image" do expect(@instance.service).to receive_message_chain(:get_image).and_return(nil) expect(@instance.is_image_valid?).to be false end - it 'returns true on valid image' do - expect(@instance.service).to receive_message_chain(:get_image).and_return('image') + it "returns true on valid image" do + expect(@instance.service).to receive_message_chain(:get_image).and_return("image") expect(@instance.is_image_valid?).to be true end end - describe '#is_flavor_valid?' do + describe "#is_flavor_valid?" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackServerCreate.new @instance.service = double - Chef::Config[:knife][:flavor] = 'flavor' + Chef::Config[:knife][:flavor] = "flavor" end after(:each) do Chef::Config[:knife].delete(:flavor) end - it 'returns false on invalid flavor' do + it "returns false on invalid flavor" do expect(@instance.service).to receive_message_chain(:get_flavor).and_return(nil) expect(@instance.is_flavor_valid?).to be false end - it 'returns true on valid flavor' do - expect(@instance.service).to receive_message_chain(:get_flavor).and_return('flavor') + it "returns true on valid flavor" do + expect(@instance.service).to receive_message_chain(:get_flavor).and_return("flavor") expect(@instance.is_flavor_valid?).to be true end end diff --git a/spec/unit/openstack_server_delete_spec.rb b/spec/unit/openstack_server_delete_spec.rb index 4fdd0480..6431cb5a 100644 --- a/spec/unit/openstack_server_delete_spec.rb +++ b/spec/unit/openstack_server_delete_spec.rb @@ -18,15 +18,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_server_delete' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_serverdeletecommand' +require "spec_helper" +require "chef/knife/openstack_server_delete" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_serverdeletecommand" describe Chef::Knife::Cloud::OpenstackServerDelete do it_behaves_like Chef::Knife::Cloud::ServerDeleteCommand, Chef::Knife::Cloud::OpenstackServerDelete.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackServerDelete.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackServerDelete.new let (:instance) { Chef::Knife::Cloud::OpenstackServerDelete.new } @@ -34,8 +34,8 @@ allow(instance).to receive(:exit) end - describe '#create_service_instance' do - it 'return OpenstackService instance' do + describe "#create_service_instance" do + it "return OpenstackService instance" do expect(instance.create_service_instance).to be_an_instance_of(Chef::Knife::Cloud::OpenstackService) end end diff --git a/spec/unit/openstack_server_list_spec.rb b/spec/unit/openstack_server_list_spec.rb index f57b2ded..6c1a85ed 100644 --- a/spec/unit/openstack_server_list_spec.rb +++ b/spec/unit/openstack_server_list_spec.rb @@ -17,15 +17,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_server_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_server_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackServerList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerList.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackServerList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackServerList.new let (:instance) { Chef::Knife::Cloud::OpenstackServerList.new } end diff --git a/spec/unit/openstack_server_show_spec.rb b/spec/unit/openstack_server_show_spec.rb index 98c3aa81..f405db9d 100644 --- a/spec/unit/openstack_server_show_spec.rb +++ b/spec/unit/openstack_server_show_spec.rb @@ -15,26 +15,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_server_show' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_server_show" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackServerShow do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerShow.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackServerShow.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackServerShow.new let (:instance) { Chef::Knife::Cloud::OpenstackServerShow.new } - context '#validate_params!' do + context "#validate_params!" do before(:each) do - Chef::Config[:knife][:instance_id] = 'instance_id' + Chef::Config[:knife][:instance_id] = "instance_id" end - it 'raise error on instance_id missing' do + it "raise error on instance_id missing" do Chef::Config[:knife].delete(:instance_id) - expect(instance.ui).to receive(:error).with('You must provide a valid Instance Id') + expect(instance.ui).to receive(:error).with("You must provide a valid Instance Id") expect { instance.validate_params! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) end end diff --git a/spec/unit/openstack_service_spec.rb b/spec/unit/openstack_service_spec.rb index 03c82ac1..71194335 100644 --- a/spec/unit/openstack_service_spec.rb +++ b/spec/unit/openstack_service_spec.rb @@ -17,13 +17,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/cloud/openstack_service' +require "spec_helper" +require "chef/knife/cloud/openstack_service" describe Chef::Knife::Cloud::OpenstackService do - describe '#add_api_endpoint' do + describe "#add_api_endpoint" do before(:each) do - @api_endpoint = 'https://test_openstack_api_endpoint' + @api_endpoint = "https://test_openstack_api_endpoint" Chef::Config[:knife][:api_endpoint] = @api_endpoint @instance = Chef::Knife::Cloud::OpenstackService.new end @@ -32,13 +32,13 @@ Chef::Config[:knife].delete(:api_endpoint) end - it 'sets the api_endpoint in auth params' do + it "sets the api_endpoint in auth params" do expect(@instance.instance_variable_get(:@auth_params)[:openstack_auth_url]).to be_nil @instance.add_api_endpoint expect(@instance.instance_variable_get(:@auth_params)[:openstack_auth_url]).to be == @api_endpoint end - it 'does not set the endpoint when --api-endpoint option is missing' do + it "does not set the endpoint when --api-endpoint option is missing" do Chef::Config[:knife][:api_endpoint] = nil expect(@instance.instance_variable_get(:@auth_params)[:openstack_auth_url]).to be_nil @instance.add_api_endpoint @@ -51,34 +51,34 @@ end end - describe '#get_server' do + describe "#get_server" do before(:each) do @instance = Chef::Knife::Cloud::OpenstackService.new allow(@instance).to receive_message_chain(:connection, :servers, :get) end - context 'when instance_id given' do - it 'return server' do - server_id = '123f456-123-453e-9c0c-12345a6789' + context "when instance_id given" do + it "return server" do + server_id = "123f456-123-453e-9c0c-12345a6789" expect(@instance.connection.servers).to receive(:get).and_return(server_id) expect(@instance.connection.servers).to_not receive(:all) expect(@instance.get_server(server_id)).to be == server_id end end - context 'when instance_name given' do + context "when instance_name given" do before(:each) do expect(@instance.connection.servers).to receive(:get).and_return(nil) end - let (:server_name) { 'testname' } + let (:server_name) { "testname" } - it 'return server' do + it "return server" do expect(@instance.connection.servers).to receive(:all).with(name: server_name).and_return([server_name]) expect(@instance.get_server(server_name)).to be == server_name end - it 'raise error if multiple server matches found for given instance name' do + it "raise error if multiple server matches found for given instance name" do error_message = "Multiple server matches found for '#{server_name}', use an instance_id to be more specific." expect(@instance.connection.servers).to receive(:all).with(name: server_name).and_return([server_name, server_name]) allow(@instance).to receive_message_chain(:ui, :fatal) @@ -87,39 +87,39 @@ end end - describe '#get_auth_params' do + describe "#get_auth_params" do let(:auth_params) do Chef::Knife::Cloud::OpenstackService.new.instance_variable_get(:@auth_params) end - it 'sets ssl_verify_peer to false when openstack_insecure is true' do + it "sets ssl_verify_peer to false when openstack_insecure is true" do Chef::Config[:knife][:openstack_insecure] = true expect(auth_params[:connection_options][:ssl_verify_peer]).to be false end - it 'only copies openstack options from Fog' do + it "only copies openstack options from Fog" do params = auth_params.keys - [:provider, :connection_options] - expect(params.all? { |p| p.to_s.start_with?('openstack') }).to be true + expect(params.all? { |p| p.to_s.start_with?("openstack") }).to be true end - context 'when openstack_password is set' do + context "when openstack_password is set" do before(:each) do - @expected = 'password' + @expected = "password" Chef::Config[:knife][:openstack_password] = @expected end - it 'sets openstack_api_key from openstack_password' do + it "sets openstack_api_key from openstack_password" do expect(auth_params[:openstack_api_key]).to be == @expected end - it 'prefers openstack_password over openstack_api_key' do - Chef::Config[:knife][:openstack_api_key] = 'unexpected' + it "prefers openstack_password over openstack_api_key" do + Chef::Config[:knife][:openstack_api_key] = "unexpected" expect(auth_params[:openstack_api_key]).to be == @expected end end - it 'uses openstack_api_key if openstack_password is not set' do - @expected = 'password' + it "uses openstack_api_key if openstack_password is not set" do + @expected = "password" Chef::Config[:knife][:openstack_api_key] = @expected expect(auth_params[:openstack_api_key]).to be == @expected end diff --git a/spec/unit/openstack_volume_list_spec.rb b/spec/unit/openstack_volume_list_spec.rb index 1eeb07d6..d13d67b3 100644 --- a/spec/unit/openstack_volume_list_spec.rb +++ b/spec/unit/openstack_volume_list_spec.rb @@ -17,13 +17,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' -require 'chef/knife/openstack_volume_list' -require 'chef/knife/cloud/openstack_service' -require 'support/shared_examples_for_command' +require "spec_helper" +require "chef/knife/openstack_volume_list" +require "chef/knife/cloud/openstack_service" +require "support/shared_examples_for_command" describe Chef::Knife::Cloud::OpenstackVolumeList do it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackVolumeList.new - include_context '#validate!', Chef::Knife::Cloud::OpenstackVolumeList.new + include_context "#validate!", Chef::Knife::Cloud::OpenstackVolumeList.new end From b2b0eec39c601aed83a83340553d82067bab5817 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 1 Oct 2016 20:27:43 -0700 Subject: [PATCH 07/10] Move dev deps to the Gemfile Signed-off-by: Tim Smith --- Gemfile | 6 ++++++ knife-openstack.gemspec | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 7ae2b1f0..26229cf6 100644 --- a/Gemfile +++ b/Gemfile @@ -6,4 +6,10 @@ gemspec group :development do gem "guard-rspec" gem "mixlib-shellout" + gem "rake", "~> 11.0" + gem "rspec", "~> 3.0" + gem "chefstyle" + gem "rspec-expectations" + gem "rspec-mocks" + gem "rspec_junit_formatter" end diff --git a/knife-openstack.gemspec b/knife-openstack.gemspec index 448701a4..14e2908a 100644 --- a/knife-openstack.gemspec +++ b/knife-openstack.gemspec @@ -24,6 +24,4 @@ Gem::Specification.new do |s| s.add_dependency "fog", "~> 1.23" s.add_dependency "chef", ">= 12" s.add_dependency "knife-cloud", "~> 1.2.0" - - %w{bundler chefstyle rake rspec-core rspec-expectations rspec-mocks rspec_junit_formatter}.each { |gem| s.add_development_dependency gem } end From d0cc17bf92e77b51b3995ce20ebe837a09796ebb Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 1 Oct 2016 20:29:35 -0700 Subject: [PATCH 08/10] Add requirements to the readme Signed-off-by: Tim Smith --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ddeaddf2..335c4e7e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ Please refer to the [CHANGELOG](CHANGELOG.md) for version history and known issu Note: Documentation needs to be updated in chef docs +## Requirements + +- Chef 12.0 higher +- Ruby 2.2.2 or higher + ## Installation If you're using [ChefDK](https://downloads.chef.io/chef-dk/), simply install the Gem: @@ -176,7 +181,7 @@ Author:: Chirag Jog ([chirag@clogeny.com](mailto:chirag@clogeny.com)) Author:: JJ Asghar ([jj@chef.io](mailto:jj@chef.io)) -Copyright:: Copyright (c) 2011-2015 Chef Software, Inc. +Copyright:: Copyright (c) 2011-2016 Chef Software, Inc. License:: Apache License, Version 2.0 From 8b30884d9e08cfd8059b397170a019cb3db41854 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 1 Oct 2016 20:41:22 -0700 Subject: [PATCH 09/10] Install docs for ChefDK only If you're using a Gemfile you know what to do. We shouldn't encourage that though. Signed-off-by: Tim Smith --- README.md | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 335c4e7e..86667c1f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Please refer to the [CHANGELOG](CHANGELOG.md) for version history and known issu - Documentation: - Source: - Issues: -- IRC: `#chef` and `#openstack-chef` on Freenode +- Slack: - Mailing list: Note: Documentation needs to be updated in chef docs @@ -21,33 +21,12 @@ Note: Documentation needs to be updated in chef docs ## Installation -If you're using [ChefDK](https://downloads.chef.io/chef-dk/), simply install the Gem: +Using [ChefDK](https://downloads.chef.io/chef-dk/), simply install the Gem: ```bash chef gem install knife-openstack ``` -If you're using bundler, simply add Chef and Knife OpenStack to your `Gemfile`: - -```ruby -gem 'chef' -gem 'knife-openstack' -``` - -If you are not using bundler, you can install the gem manually. Be sure you are running Chef 0.10.10 or higher, as earlier versions do not support plugins. - -```bash -$ gem install chef -``` - -This plugin is distributed as a Ruby Gem. To install it, run: - -```bash -$ gem install knife-openstack -``` - -Depending on your system's configuration, you may need to run this command with root privileges. - ## Configuration In order to communicate with an OpenStack API you will need to tell Knife your OpenStack Auth API endpoint, your Dashboard username and password (tenant is optional). The easiest way to accomplish this is to create these entries in your `knife.rb` file: From f7734a6b4467232888d69c1f1e3692f821cb92b8 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 1 Oct 2016 21:05:42 -0700 Subject: [PATCH 10/10] Add Ruby 2.2.2 dep to the Gemspec Signed-off-by: Tim Smith --- Gemfile | 2 +- knife-openstack.gemspec | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 26229cf6..60bb9236 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ group :development do gem "rake", "~> 11.0" gem "rspec", "~> 3.0" gem "chefstyle" - gem "rspec-expectations" + gem "rspec-expectations" gem "rspec-mocks" gem "rspec_junit_formatter" end diff --git a/knife-openstack.gemspec b/knife-openstack.gemspec index 14e2908a..29e7a927 100644 --- a/knife-openstack.gemspec +++ b/knife-openstack.gemspec @@ -21,6 +21,8 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ["lib"] + s.required_ruby_version = ">= 2.2.2" + s.add_dependency "fog", "~> 1.23" s.add_dependency "chef", ">= 12" s.add_dependency "knife-cloud", "~> 1.2.0"