From e182f475d4bbe4344821b5d2637f9790d9941c3c Mon Sep 17 00:00:00 2001 From: Tensibai Date: Tue, 21 May 2019 20:48:50 +0200 Subject: [PATCH] Allow resources to use another partition than Common (#33) * Add generated delivery configuration Allow to specify partitions in resources. Fix tests to handle the partition change, add a test for partition. Anchor regexes to avoid matching a pool contained by another (pool-web vs pool-webservers for exemple) Strip slashes from partition to ensure coherence, fix the irule existence test * Last linting fix --- .delivery/build_cookbook/.kitchen.yml | 21 ++ .delivery/build_cookbook/Berksfile | 7 + .delivery/build_cookbook/LICENSE | 3 + .delivery/build_cookbook/README.md | 146 +++++++++++++ .delivery/build_cookbook/chefignore | 104 ++++++++++ .../data_bags/keys/delivery_builder_keys.json | 1 + .delivery/build_cookbook/metadata.rb | 8 + .delivery/build_cookbook/recipes/default.rb | 6 + .delivery/build_cookbook/recipes/deploy.rb | 6 + .../build_cookbook/recipes/functional.rb | 6 + .delivery/build_cookbook/recipes/lint.rb | 6 + .delivery/build_cookbook/recipes/provision.rb | 6 + .delivery/build_cookbook/recipes/publish.rb | 6 + .delivery/build_cookbook/recipes/quality.rb | 6 + .delivery/build_cookbook/recipes/security.rb | 6 + .delivery/build_cookbook/recipes/smoke.rb | 6 + .delivery/build_cookbook/recipes/syntax.rb | 6 + .delivery/build_cookbook/recipes/unit.rb | 6 + .../build_cookbook/secrets/fakey-mcfakerton | 0 .../test/fixtures/cookbooks/test/metadata.rb | 2 + .../cookbooks/test/recipes/default.rb | 9 + .delivery/config.json | 17 ++ .delivery/project.toml | 36 ++++ .gitignore | 1 + CHANGELOG.md | 2 + libraries/base_client.rb | 14 +- libraries/chef_f5.rb | 18 +- libraries/gem_helper.rb | 2 - libraries/irule.rb | 10 +- libraries/irule_diff.rb | 4 +- libraries/monitor.rb | 27 ++- libraries/vip.rb | 135 ++++++------ metadata.rb | 2 +- rakefile.rb | 2 +- resources/irule.rb | 12 +- resources/monitor.rb | 12 +- resources/pool.rb | 9 +- resources/vip.rb | 13 +- spec/unit/recipes/test_create_irule_spec.rb | 46 ++--- spec/unit/recipes/test_create_monitor_spec.rb | 112 +++++----- .../test_create_pool_add_action_spec.rb | 18 +- .../test_create_pool_all_services_spec.rb | 6 +- .../recipes/test_create_pool_no_host_spec.rb | 13 +- spec/unit/recipes/test_create_pool_spec.rb | 27 +-- .../test_create_vip_address_changed_spec.rb | 19 +- .../recipes/test_create_vip_all_ports_spec.rb | 29 +-- ...vip_enforced_firewall_policy_named_spec.rb | 48 +++-- ..._vip_enforced_firewall_policy_none_spec.rb | 28 ++- .../test_create_vip_http_profile_spec.rb | 37 ++-- .../recipes/test_create_vip_irules_spec.rb | 40 ++-- .../unit/recipes/test_create_vip_name_spec.rb | 14 +- .../test_create_vip_no_http_profile_spec.rb | 15 +- .../test_create_vip_none_http_profile_spec.rb | 17 +- .../test_create_vip_snat_pool_automap_spec.rb | 18 +- .../test_create_vip_snat_pool_named_spec.rb | 36 ++-- .../test_create_vip_snat_pool_none_spec.rb | 18 +- spec/unit/recipes/test_create_vip_spec.rb | 15 +- .../test_create_vip_ssl_profiles_spec.rb | 194 +++++++++--------- ...e_vip_staged_firewall_policy_named_spec.rb | 47 +++-- ...te_vip_staged_firewall_policy_none_spec.rb | 26 ++- .../test_manage_nodes_disabled_spec.rb | 60 +++--- .../recipes/test_manage_nodes_enabled_spec.rb | 55 ++--- spec/unit/recipes/test_other_lb_spec.rb | 3 +- .../unit/recipes/test_other_partition_spec.rb | 24 +++ .../f5_test/recipes/test_create_irule.rb | 4 +- .../f5_test/recipes/test_create_monitor.rb | 2 +- .../recipes/test_create_vip_snat_pool_none.rb | 2 +- .../f5_test/recipes/test_other_partition.rb | 7 + 68 files changed, 1054 insertions(+), 609 deletions(-) create mode 100644 .delivery/build_cookbook/.kitchen.yml create mode 100644 .delivery/build_cookbook/Berksfile create mode 100644 .delivery/build_cookbook/LICENSE create mode 100644 .delivery/build_cookbook/README.md create mode 100644 .delivery/build_cookbook/chefignore create mode 100644 .delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json create mode 100644 .delivery/build_cookbook/metadata.rb create mode 100644 .delivery/build_cookbook/recipes/default.rb create mode 100644 .delivery/build_cookbook/recipes/deploy.rb create mode 100644 .delivery/build_cookbook/recipes/functional.rb create mode 100644 .delivery/build_cookbook/recipes/lint.rb create mode 100644 .delivery/build_cookbook/recipes/provision.rb create mode 100644 .delivery/build_cookbook/recipes/publish.rb create mode 100644 .delivery/build_cookbook/recipes/quality.rb create mode 100644 .delivery/build_cookbook/recipes/security.rb create mode 100644 .delivery/build_cookbook/recipes/smoke.rb create mode 100644 .delivery/build_cookbook/recipes/syntax.rb create mode 100644 .delivery/build_cookbook/recipes/unit.rb create mode 100644 .delivery/build_cookbook/secrets/fakey-mcfakerton create mode 100644 .delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb create mode 100644 .delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb create mode 100644 .delivery/config.json create mode 100644 .delivery/project.toml create mode 100644 spec/unit/recipes/test_other_partition_spec.rb create mode 100644 test/fixtures/cookbooks/f5_test/recipes/test_other_partition.rb diff --git a/.delivery/build_cookbook/.kitchen.yml b/.delivery/build_cookbook/.kitchen.yml new file mode 100644 index 0000000..bc6e264 --- /dev/null +++ b/.delivery/build_cookbook/.kitchen.yml @@ -0,0 +1,21 @@ +--- +driver: + name: vagrant + synced_folders: + - [<%= File.join(ENV['PWD'], '..', '..')%>, '/tmp/repo-data'] + +provisioner: + name: chef_zero + encrypted_data_bag_secret_key_path: 'secrets/fakey-mcfakerton' + data_bags_path: './data_bags' + product_name: chefdk + +platforms: + - name: ubuntu-16.04 + - name: centos-7 + +suites: + - name: default + run_list: + - recipe[test] + attributes: diff --git a/.delivery/build_cookbook/Berksfile b/.delivery/build_cookbook/Berksfile new file mode 100644 index 0000000..61dab72 --- /dev/null +++ b/.delivery/build_cookbook/Berksfile @@ -0,0 +1,7 @@ +source 'https://supermarket.chef.io' + +metadata + +group :delivery do + cookbook 'test', path: './test/fixtures/cookbooks/test' +end diff --git a/.delivery/build_cookbook/LICENSE b/.delivery/build_cookbook/LICENSE new file mode 100644 index 0000000..10b5688 --- /dev/null +++ b/.delivery/build_cookbook/LICENSE @@ -0,0 +1,3 @@ +Copyright 2019 The Authors + +All rights reserved, do not redistribute. diff --git a/.delivery/build_cookbook/README.md b/.delivery/build_cookbook/README.md new file mode 100644 index 0000000..297af5a --- /dev/null +++ b/.delivery/build_cookbook/README.md @@ -0,0 +1,146 @@ +# build_cookbook + +A build cookbook for running the parent project through Chef Delivery + +This build cookbook should be customized to suit the needs of the parent project. Using this cookbook can be done outside of Chef Delivery, too. If the parent project is a Chef cookbook, we've detected that and "wrapped" [delivery-truck](https://github.com/chef-cookbooks/delivery-truck). That means it is a dependency, and each of its pipeline phase recipes is included in the appropriate phase recipes in this cookbook. If the parent project is not a cookbook, it's left as an exercise to the reader to customize the recipes as needed for each phase in the pipeline. + +## .delivery/config.json + +In the parent directory to this build_cookbook, the `config.json` can be modified as necessary. For example, phases can be skipped, publishing information can be added, and so on. Refer to customer support or the Chef Delivery documentation for assistance on what options are available for this configuration. + +## Test Kitchen - Local Verify Testing + +This cookbook also has a `.kitchen.yml` which can be used to create local build nodes with Test Kitchen to perform the verification phases, `unit`, `syntax`, and `lint`. When running `kitchen converge`, the instances will be set up like Chef Delivery "build nodes" with the [delivery_build cookbook](https://github.com/chef-cookbooks/delivery_build). The reason for this is to make sure that the same exact kind of nodes are used by this build cookbook are run on the local workstation as would run Delivery. It will run `delivery job verify PHASE` for the parent project. + +Modify the `.kitchen.yml` if necessary to change the platforms or other configuration to run the verify phases. After making changes in the parent project, `cd` into this directory (`.delivery/build_cookbook`), and run: + +``` +kitchen test +``` + +## Recipes + +Each of the recipes in this build_cookbook are run in the named phase during the Chef Delivery pipeline. The `unit`, `syntax`, and `lint` recipes are additionally run when using Test Kitchen for local testing as noted in the above section. + +## Making Changes - Cookbook Example + +When making changes in the parent project (that which lives in `../..` from this directory), or in the recipes in this build cookbook, there is a bespoke workflow for Chef Delivery. As an example, we'll discuss a Chef Cookbook as the parent. + +First, create a new branch for the changes. + +``` +git checkout -b testing-build-cookbook +``` + +Next, increment the version in the metadata.rb. This should be in the _parent_, not in this, the build_cookbook. If this is not done, the verify phase will fail. + +``` +% git diff + +-version '0.1.0' ++version '0.1.1' +``` + +The change we'll use for an example is to install the `zsh` package. Write a failing ChefSpec in the cookbook project's `spec/unit/recipes/default_spec.rb`. + +```ruby +require 'spec_helper' + +describe 'godzilla::default' do + context 'When all attributes are default, on Ubuntu 16.04' do + let(:chef_run) do + runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04') + runner.converge(described_recipe) + end + + it 'installs zsh' do + expect(chef_run).to install_package('zsh') + end + end +end +``` + +Commit the local changes as work in progress. The `delivery job` expects to use a clean git repository. + +``` +git add ../.. +git commit -m 'WIP: Testing changes' +``` + +From _this_ directory (`.delivery/build_cookbook`, relative to the parent cookbook project), run + +``` +cd .delivery/build_cookbook +kitchen converge +``` + +This will take some time at first, because the VMs need to be created, Chef installed, the Delivery CLI installed, etc. Later runs will be faster until they are destroyed. It will also fail on the first VM, as expected, because we wrote the test first. Now edit the parent cookbook project's default recipe to install `zsh`. + +``` +cd ../../ +$EDITOR/recipes/default.rb +``` + +It should look like this: + +``` +package 'zsh' +``` + +Create another commit. + +``` +git add . +git commit -m 'WIP: Install zsh in default recipe' +``` + +Now rerun kitchen from the build_cookbook. + +``` +cd .delivery/build_cookbook +kitchen converge +``` + +This will take awhile because it will now pass on the first VM, and then create the second VM. We should have warned you this was a good time for a coffee break. + +``` +Recipe: test::default + +- execute HOME=/home/vagrant delivery job verify unit --server localhost --ent test --org kitchen + * execute[HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen] action run + - execute HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen + + - execute HOME=/home/vagrant delivery job verify syntax --server localhost --ent test --org kitchen + +Running handlers: +Running handlers complete +Chef Client finished, 3/32 resources updated in 54.665445968 seconds +Finished converging (1m26.83s). +``` + +Victory is ours! Our verify phase passed on the build nodes. + +We are ready to run this through our Delivery pipeline. Simply run `delivery review` on the local system from the parent project, and it will open a browser window up to the change we just added. + +``` +cd ../.. +delivery review +``` + +## FAQ + +### Why don't I just run rspec and foodcritic/rubocop on my local system? + +An objection to the Test Kitchen approach is that it is much faster to run the unit, lint, and syntax commands for the project on the local system. That is totally true, and also totally valid. Do that for the really fast feedback loop. However, the dance we do with Test Kitchen brings a much higher degree of confidence in the changes we're making, that everything will run on the build nodes in Chef Delivery. We strongly encourage this approach before actually pushing the changes to Delivery. + +### Why do I have to make a commit every time? + +When running `delivery job`, it expects to merge the commit for the changeset against the clean master branch. If we don't save our progress by making a commit, our local changes aren't run through `delivery job` in the Test Kitchen build instances. We can always perform an interactive rebase, and modify the original changeset message in Delivery with `delivery review --edit`. The latter won't modify the git commits, only the changeset in Delivery. + +### What do I do next? + +Make changes in the cookbook project as required for organizational goals and needs. Modify the `build_cookbook` as necessary for the pipeline phases that the cookbook should go through. + +### What if I get stuck? + +Contact Chef Support, or your Chef Customer Success team and they will help you get unstuck. diff --git a/.delivery/build_cookbook/chefignore b/.delivery/build_cookbook/chefignore new file mode 100644 index 0000000..4439807 --- /dev/null +++ b/.delivery/build_cookbook/chefignore @@ -0,0 +1,104 @@ +# Put files/directories that should be ignored in this file when uploading +# to a chef-server or supermarket. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +examples/* +Guardfile +Procfile +.kitchen* +kitchen.yml* +.rubocop.yml +spec/* +Rakefile +.travis.yml +.foodcritic +.codeclimate.yml + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Bundler # +########### +vendor/* + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Cookbooks # +############# +CONTRIBUTING* +CHANGELOG* +TESTING* + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json b/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json new file mode 100644 index 0000000..af375ea --- /dev/null +++ b/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json @@ -0,0 +1 @@ +{"id": "delivery_builder_keys"} \ No newline at end of file diff --git a/.delivery/build_cookbook/metadata.rb b/.delivery/build_cookbook/metadata.rb new file mode 100644 index 0000000..3c92d5b --- /dev/null +++ b/.delivery/build_cookbook/metadata.rb @@ -0,0 +1,8 @@ +name 'build_cookbook' +maintainer 'The Authors' +maintainer_email 'you@example.com' +license 'all_rights' +version '0.1.0' +chef_version '>= 12.14' if respond_to?(:chef_version) + +depends 'delivery-truck' diff --git a/.delivery/build_cookbook/recipes/default.rb b/.delivery/build_cookbook/recipes/default.rb new file mode 100644 index 0000000..5bb9df3 --- /dev/null +++ b/.delivery/build_cookbook/recipes/default.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: default +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::default' diff --git a/.delivery/build_cookbook/recipes/deploy.rb b/.delivery/build_cookbook/recipes/deploy.rb new file mode 100644 index 0000000..43af83c --- /dev/null +++ b/.delivery/build_cookbook/recipes/deploy.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: deploy +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::deploy' diff --git a/.delivery/build_cookbook/recipes/functional.rb b/.delivery/build_cookbook/recipes/functional.rb new file mode 100644 index 0000000..66001fe --- /dev/null +++ b/.delivery/build_cookbook/recipes/functional.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: functional +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::functional' diff --git a/.delivery/build_cookbook/recipes/lint.rb b/.delivery/build_cookbook/recipes/lint.rb new file mode 100644 index 0000000..0188770 --- /dev/null +++ b/.delivery/build_cookbook/recipes/lint.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: lint +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::lint' diff --git a/.delivery/build_cookbook/recipes/provision.rb b/.delivery/build_cookbook/recipes/provision.rb new file mode 100644 index 0000000..ac44c47 --- /dev/null +++ b/.delivery/build_cookbook/recipes/provision.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: provision +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::provision' diff --git a/.delivery/build_cookbook/recipes/publish.rb b/.delivery/build_cookbook/recipes/publish.rb new file mode 100644 index 0000000..618b3f4 --- /dev/null +++ b/.delivery/build_cookbook/recipes/publish.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: publish +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::publish' diff --git a/.delivery/build_cookbook/recipes/quality.rb b/.delivery/build_cookbook/recipes/quality.rb new file mode 100644 index 0000000..7b2ad5d --- /dev/null +++ b/.delivery/build_cookbook/recipes/quality.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: quality +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::quality' diff --git a/.delivery/build_cookbook/recipes/security.rb b/.delivery/build_cookbook/recipes/security.rb new file mode 100644 index 0000000..00096dd --- /dev/null +++ b/.delivery/build_cookbook/recipes/security.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: security +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::security' diff --git a/.delivery/build_cookbook/recipes/smoke.rb b/.delivery/build_cookbook/recipes/smoke.rb new file mode 100644 index 0000000..332646f --- /dev/null +++ b/.delivery/build_cookbook/recipes/smoke.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: smoke +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::smoke' diff --git a/.delivery/build_cookbook/recipes/syntax.rb b/.delivery/build_cookbook/recipes/syntax.rb new file mode 100644 index 0000000..4052638 --- /dev/null +++ b/.delivery/build_cookbook/recipes/syntax.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: syntax +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::syntax' diff --git a/.delivery/build_cookbook/recipes/unit.rb b/.delivery/build_cookbook/recipes/unit.rb new file mode 100644 index 0000000..fde68b8 --- /dev/null +++ b/.delivery/build_cookbook/recipes/unit.rb @@ -0,0 +1,6 @@ +# +# Cookbook:: build_cookbook +# Recipe:: unit +# +# Copyright:: 2019, The Authors, All Rights Reserved. +include_recipe 'delivery-truck::unit' diff --git a/.delivery/build_cookbook/secrets/fakey-mcfakerton b/.delivery/build_cookbook/secrets/fakey-mcfakerton new file mode 100644 index 0000000..e69de29 diff --git a/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb b/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb new file mode 100644 index 0000000..1725039 --- /dev/null +++ b/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb @@ -0,0 +1,2 @@ +name 'test' +version '0.1.0' \ No newline at end of file diff --git a/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb b/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb new file mode 100644 index 0000000..2fd58de --- /dev/null +++ b/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +%w(unit lint syntax).each do |phase| + # TODO: This works on Linux/Unix. Not Windows. + execute "HOME=/home/vagrant delivery job verify #{phase} --server localhost --ent test --org kitchen" do + cwd '/tmp/repo-data' + user 'vagrant' + environment('GIT_DISCOVERY_ACROSS_FILESYSTEM' => '1') + end +end diff --git a/.delivery/config.json b/.delivery/config.json new file mode 100644 index 0000000..987952b --- /dev/null +++ b/.delivery/config.json @@ -0,0 +1,17 @@ +{ + "version": "2", + "build_cookbook": { + "name": "build_cookbook", + "path": ".delivery/build_cookbook" + }, + "delivery-truck": { + "lint": { + "enable_cookstyle": true + } + }, + "skip_phases": [], + "job_dispatch": { + "version": "v2" + }, + "dependencies": [] +} diff --git a/.delivery/project.toml b/.delivery/project.toml new file mode 100644 index 0000000..9f54c5e --- /dev/null +++ b/.delivery/project.toml @@ -0,0 +1,36 @@ +# Delivery Prototype for Local Phases Execution +# +# The purpose of this file is to prototype a new way to execute +# phases locally on your workstation. The delivery-cli will read +# this file and execute the command(s) that are configured for +# each phase. You can customize them by just modifying the phase +# key on this file. +# +# By default these phases are configured for Cookbook Workflow only +# +# As this is still a prototype we are not modifying the current +# config.json file and it will continue working as usual. + +[local_phases] +unit = "chef exec rspec spec/" +lint = "chef exec cookstyle" +# Foodcritic includes rules only appropriate for community cookbooks +# uploaded to Supermarket. We turn off any rules tagged "supermarket" +# by default. If you plan to share this cookbook you should remove +# '-t ~supermarket' below to enable supermarket rules. +syntax = "chef exec foodcritic . -t ~supermarket" +provision = "chef exec kitchen create" +deploy = "chef exec kitchen converge" +smoke = "chef exec kitchen verify" +# The functional phase is optional, you can define it by uncommenting +# the line below and running the command: `delivery local functional` +# functional = "" +cleanup = "chef exec kitchen destroy" + +# Remote project.toml file +# +# Specify a remote URI location for the `project.toml` file. +# This is useful for teams that wish to centrally manage the behavior +# of the `delivery local` command across many different projects. +# +# remote_file = "https://url/project.toml" diff --git a/.gitignore b/.gitignore index d907bef..6039006 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ test/integration/data_bags/ # build output metadata.json tmp/ +*.iml diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d63824..b2999e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +# 0.4.13 +Add handling the api_path to properly manage partitions. # 0.2.2 Bugfix for the last version diff --git a/libraries/base_client.rb b/libraries/base_client.rb index 8b6ab25..7376b82 100644 --- a/libraries/base_client.rb +++ b/libraries/base_client.rb @@ -1,41 +1,45 @@ module ChefF5 class BaseClient - - def initialize(node, resource, load_balancer) + def initialize(node, resource, load_balancer, partition = 'Common') @node = node @resource = resource @load_balancer = load_balancer + @partition = partition[%r{/?([^/]+)/?}, 1] # local module aliases reduce repetetive call chains + # rubocop:disable Naming/VariableName @ProfileContextType = F5::Icontrol::LocalLB::ProfileContextType @ProfileType = F5::Icontrol::LocalLB::ProfileType @EnabledStatus = F5::Icontrol::LocalLB::EnabledStatus @EnabledState = F5::Icontrol::Common::EnabledState + # rubocop:enable Naming/VariableName end private def strip_partition(key) - key.gsub(%r{^/Common/}, '') if key + key.gsub(%r{^/#{@partition}/}, '') if key end def with_partition(key) if key =~ %r{^/} || key.to_s.empty? key else - "/Common/#{key}" + "/#{@partition}/#{key}" end end def api @api ||= begin credentials = ChefF5::Credentials.new(@node, @resource).credentials_for(@load_balancer) - F5::Icontrol::API.new( + api = F5::Icontrol::API.new( nil, host: credentials[:host], username: credentials[:username], password: credentials[:password] ) + api.System.Session.set_active_folder(folder: "/#{@partition}") + api end end end diff --git a/libraries/chef_f5.rb b/libraries/chef_f5.rb index 205b98e..c6a3290 100644 --- a/libraries/chef_f5.rb +++ b/libraries/chef_f5.rb @@ -2,7 +2,7 @@ module ChefF5 class Client < BaseClient unless defined? LB_METHOD_TYPES - LB_METHOD_TYPES = %w[ + LB_METHOD_TYPES = %w( LB_METHOD_ROUND_ROBIN LB_METHOD_RATIO_MEMBER LB_METHOD_LEAST_CONNECTION_MEMBER @@ -24,7 +24,7 @@ class Client < BaseClient LB_METHOD_RATIO_SESSION LB_METHOD_RATIO_LEAST_CONNECTION_MEMBER LB_METHOD_RATIO_LEAST_CONNECTION_NODE_ADDRESS - ].freeze + ).freeze end def node_is_missing?(name) @@ -32,7 +32,7 @@ def node_is_missing?(name) return true if response[:item].nil? - Array(response[:item]).grep(/#{with_partition name}/).empty? + Array(response[:item]).grep(/#{with_partition name}$/).empty? end def node_is_enabled?(name) @@ -65,7 +65,7 @@ def pool_is_missing?(name) pools = response[:item] - Array(pools).grep(/#{with_partition name}/).empty? + Array(pools).grep(/#{with_partition name}$/).empty? end def pool_is_missing_node?(pool, node) @@ -76,7 +76,7 @@ def pool_is_missing_node?(pool, node) members = [members] if members.is_a? Hash - members.map { |m| m[:address] }.grep(/#{with_partition node}/).empty? + members.map { |m| m[:address] }.grep(/#{with_partition node}$/).empty? end def pool_is_missing_monitor?(pool, monitor) @@ -96,15 +96,15 @@ def add_monitor(pool, monitor) { pool_name: pool, monitor_rule: { monitor_templates: { - item: monitor + item: monitor, }, quorum: '0', # this value is overridden if an array of monitors # are passed in. Instead it is set to # `MONITOR_RULE_TYPE_AND_LIST` - type: 'MONITOR_RULE_TYPE_SINGLE' - } } - ] + type: 'MONITOR_RULE_TYPE_SINGLE', + } }, + ], }) end diff --git a/libraries/gem_helper.rb b/libraries/gem_helper.rb index acd04bd..e67d99a 100644 --- a/libraries/gem_helper.rb +++ b/libraries/gem_helper.rb @@ -1,6 +1,4 @@ require 'singleton' -require 'thread' - module ChefF5 class Autoload include Singleton diff --git a/libraries/irule.rb b/libraries/irule.rb index 1b37e2a..97cdb38 100644 --- a/libraries/irule.rb +++ b/libraries/irule.rb @@ -2,14 +2,12 @@ module ChefF5 class IRule < BaseClient - def is_missing?(name) + def missing?(name) !api.LocalLB.Rule.get_list[:item].include?(with_partition(name)) end def create(name, definition) - api.LocalLB.Rule.create(rules: { - item: [{ rule_name: with_partition(name), rule_definition: definition }] - }) + api.LocalLB.Rule.create(rules: { item: [{ rule_name: with_partition(name), rule_definition: definition }] }) end def definition_changed?(name, definition) @@ -18,9 +16,7 @@ def definition_changed?(name, definition) end def update_definition(name, definition) - api.LocalLB.Rule.modify_rule(rules: { - item: [{ rule_name: with_partition(name), rule_definition: definition }] - }) + api.LocalLB.Rule.modify_rule(rules: { item: [{ rule_name: with_partition(name), rule_definition: definition }] }) end def destroy(name) diff --git a/libraries/irule_diff.rb b/libraries/irule_diff.rb index 291d379..d0d86b2 100644 --- a/libraries/irule_diff.rb +++ b/libraries/irule_diff.rb @@ -35,9 +35,7 @@ def diff(target, current_hash) def next_priority(min, current_priority, used_priorities) i = min - while used_priorities.include?(i) && current_priority != i - i += 1 - end + i += 1 while used_priorities.include?(i) && current_priority != i i end end diff --git a/libraries/monitor.rb b/libraries/monitor.rb index 728f1d2..8386c8a 100644 --- a/libraries/monitor.rb +++ b/libraries/monitor.rb @@ -1,7 +1,7 @@ require_relative './base_client' module ChefF5 class Monitor < BaseClient - PROPERTY_NAMES = %w(STYPE_UNSET STYPE_SEND STYPE_GET STYPE_RECEIVE STYPE_USERNAME STYPE_PASSWORD STYPE_RUN STYPE_NEWSGROUP STYPE_DATABASE STYPE_DOMAIN STYPE_ARGUMENTS STYPE_FOLDER STYPE_BASE STYPE_FILTER STYPE_SECRET STYPE_METHOD STYPE_URL STYPE_COMMAND STYPE_METRICS STYPE_POST STYPE_USERAGENT STYPE_AGENT_TYPE STYPE_CPU_COEFFICIENT STYPE_CPU_THRESHOLD STYPE_MEMORY_COEFFICIENT STYPE_MEMORY_THRESHOLD STYPE_DISK_COEFFICIENT STYPE_DISK_THRESHOLD STYPE_SNMP_VERSION STYPE_COMMUNITY STYPE_SEND_PACKETS STYPE_TIMEOUT_PACKETS STYPE_RECEIVE_DRAIN STYPE_RECEIVE_ROW STYPE_RECEIVE_COLUMN STYPE_DEBUG STYPE_SECURITY STYPE_MODE STYPE_CIPHER_LIST STYPE_NAMESPACE STYPE_PARAMETER_NAME STYPE_PARAMETER_VALUE STYPE_PARAMETER_TYPE STYPE_RETURN_TYPE STYPE_RETURN_VALUE STYPE_SOAP_FAULT STYPE_SSL_OPTIONS STYPE_CLIENT_CERTIFICATE STYPE_PROTOCOL STYPE_MANDATORY_ATTRS STYPE_FILENAME STYPE_ACCOUNTING_NODE STYPE_ACCOUNTING_PORT STYPE_SERVER_ID STYPE_CALL_ID STYPE_SESSION_ID STYPE_FRAMED_ADDRESS STYPE_PROGRAM STYPE_VERSION STYPE_SERVER STYPE_SERVICE STYPE_GW_MONITOR_ADDRESS STYPE_GW_MONITOR_SERVICE STYPE_GW_MONITOR_INTERVAL STYPE_GW_MONITOR_PROTOCOL STYPE_DB_COUNT STYPE_REQUEST STYPE_HEADERS STYPE_FILTER_NEG STYPE_SERVER_IP STYPE_SNMP_PORT STYPE_POOL_NAME STYPE_NAS_IP STYPE_CLIENT_KEY STYPE_MAX_LOAD_AVERAGE STYPE_CONCURRENCY_LIMIT STYPE_FAILURES STYPE_FAILURE_INTERVAL STYPE_RESPONSE_TIME STYPE_RETRY_TIME STYPE_DIAMETER_ACCT_APPLICATION_ID STYPE_DIAMETER_AUTH_APPLICATION_ID STYPE_DIAMETER_ORIGIN_HOST STYPE_DIAMETER_ORIGIN_REALM STYPE_DIAMETER_HOST_IP_ADDRESS STYPE_DIAMETER_VENDOR_ID STYPE_DIAMETER_PRODUCT_NAME STYPE_DIAMETER_VENDOR_SPECIFIC_VENDOR_ID STYPE_DIAMETER_VENDOR_SPECIFIC_ACCT_APPLICATION_ID STYPE_DIAMETER_VENDOR_SPECIFIC_AUTH_APPLICATION_ID STYPE_RUN_V2 STYPE_CLIENT_CERTIFICATE_V2 STYPE_CLIENT_KEY_V2) unless defined?(PROPERTY_NAMES) + PROPERTY_NAMES = %w(STYPE_UNSET STYPE_SEND STYPE_GET STYPE_RECEIVE STYPE_USERNAME STYPE_PASSWORD STYPE_RUN STYPE_NEWSGROUP STYPE_DATABASE STYPE_DOMAIN STYPE_ARGUMENTS STYPE_FOLDER STYPE_BASE STYPE_FILTER STYPE_SECRET STYPE_METHOD STYPE_URL STYPE_COMMAND STYPE_METRICS STYPE_POST STYPE_USERAGENT STYPE_AGENT_TYPE STYPE_CPU_COEFFICIENT STYPE_CPU_THRESHOLD STYPE_MEMORY_COEFFICIENT STYPE_MEMORY_THRESHOLD STYPE_DISK_COEFFICIENT STYPE_DISK_THRESHOLD STYPE_SNMP_VERSION STYPE_COMMUNITY STYPE_SEND_PACKETS STYPE_TIMEOUT_PACKETS STYPE_RECEIVE_DRAIN STYPE_RECEIVE_ROW STYPE_RECEIVE_COLUMN STYPE_DEBUG STYPE_SECURITY STYPE_MODE STYPE_CIPHER_LIST STYPE_NAMESPACE STYPE_PARAMETER_NAME STYPE_PARAMETER_VALUE STYPE_PARAMETER_TYPE STYPE_RETURN_TYPE STYPE_RETURN_VALUE STYPE_SOAP_FAULT STYPE_SSL_OPTIONS STYPE_CLIENT_CERTIFICATE STYPE_PROTOCOL STYPE_MANDATORY_ATTRS STYPE_FILENAME STYPE_ACCOUNTING_NODE STYPE_ACCOUNTING_PORT STYPE_SERVER_ID STYPE_CALL_ID STYPE_SESSION_ID STYPE_FRAMED_ADDRESS STYPE_PROGRAM STYPE_VERSION STYPE_SERVER STYPE_SERVICE STYPE_GW_MONITOR_ADDRESS STYPE_GW_MONITOR_SERVICE STYPE_GW_MONITOR_INTERVAL STYPE_GW_MONITOR_PROTOCOL STYPE_DB_COUNT STYPE_REQUEST STYPE_HEADERS STYPE_FILTER_NEG STYPE_SERVER_IP STYPE_SNMP_PORT STYPE_POOL_NAME STYPE_NAS_IP STYPE_CLIENT_KEY STYPE_MAX_LOAD_AVERAGE STYPE_CONCURRENCY_LIMIT STYPE_FAILURES STYPE_FAILURE_INTERVAL STYPE_RESPONSE_TIME STYPE_RETRY_TIME STYPE_DIAMETER_ACCT_APPLICATION_ID STYPE_DIAMETER_AUTH_APPLICATION_ID STYPE_DIAMETER_ORIGIN_HOST STYPE_DIAMETER_ORIGIN_REALM STYPE_DIAMETER_HOST_IP_ADDRESS STYPE_DIAMETER_VENDOR_ID STYPE_DIAMETER_PRODUCT_NAME STYPE_DIAMETER_VENDOR_SPECIFIC_VENDOR_ID STYPE_DIAMETER_VENDOR_SPECIFIC_ACCT_APPLICATION_ID STYPE_DIAMETER_VENDOR_SPECIFIC_AUTH_APPLICATION_ID STYPE_RUN_V2 STYPE_CLIENT_CERTIFICATE_V2 STYPE_CLIENT_KEY_V2).freeze unless defined?(PROPERTY_NAMES) def monitor_is_missing?(name) response = api.LocalLB.Monitor.get_template_list @@ -17,12 +17,12 @@ def create_monitor(name, **attributes) address_type: address_type(dest_ip, dest_port), ipport: { address: dest_ip, - port: dest_port - } + port: dest_port, + }, } api.LocalLB.Monitor.create_template( - templates: { item: [{ template_name: with_partition(name), template_type: template_type }]}, - template_attributes: { item: [attributes]} + templates: { item: [{ template_name: with_partition(name), template_type: template_type }] }, + template_attributes: { item: [attributes] } ) end @@ -32,7 +32,7 @@ def delete_monitor(name) ) end - def common_attributes_changed?(name, dest_ip:, dest_port: ) + def common_attributes_changed?(name, dest_ip:, dest_port:) current = api.LocalLB.Monitor.get_template_destination(template_names: { item: [with_partition(name)] }) current_dest_ip = current[:item][:ipport][:address] current_dest_port = current[:item][:ipport][:port] @@ -42,11 +42,11 @@ def common_attributes_changed?(name, dest_ip:, dest_port: ) current_dest_type != address_type(dest_ip, dest_port) end - def update_common_attributes(name, dest_ip:, dest_port: ) + def update_common_attributes(name, dest_ip:, dest_port:) api.LocalLB.Monitor.set_template_destination( template_names: { item: [with_partition(name)] }, - destinations: { item: [{address_type: address_type(dest_ip, dest_port), - ipport: {address: dest_ip, port: dest_port }}]} + destinations: { item: [{ address_type: address_type(dest_ip, dest_port), + ipport: { address: dest_ip, port: dest_port } }] } ) end @@ -75,7 +75,7 @@ def update_string_properties(name, mismatches, properties) next unless mismatches.include? prop api.LocalLB.Monitor.set_template_string_property( template_names: { item: [with_partition(name)] }, - values: { item: [{type: prop, value: value}] }) + values: { item: [{ type: prop, value: value }] }) end end @@ -85,12 +85,11 @@ def address_type(dest_ip, dest_port) # The types are redundant so the case statement below covers all relevant # combinations. ip_0 = '0.0.0.0' - case - when dest_ip == ip_0 && dest_port == '0' + if dest_ip == ip_0 && dest_port == '0' 'ATYPE_STAR_ADDRESS_STAR_PORT' - when dest_ip != ip_0 && dest_port != '0' + elsif dest_ip != ip_0 && dest_port != '0' 'ATYPE_EXPLICIT_ADDRESS_EXPLICIT_PORT' - when dest_ip == ip_0 && dest_port != '0' + elsif dest_ip == ip_0 && dest_port != '0' 'ATYPE_STAR_ADDRESS_EXPLICIT_PORT' else 'ATYPE_UNSET' diff --git a/libraries/vip.rb b/libraries/vip.rb index a249daa..476af24 100644 --- a/libraries/vip.rb +++ b/libraries/vip.rb @@ -1,6 +1,6 @@ require_relative './base_client' require_relative './irule_diff' - +# rubocop:disable Naming/PredicateName module ChefF5 class VIP < BaseClient def vip_is_missing?(name) @@ -63,7 +63,7 @@ def address(vip) def update_address(vip, address, port) port = '0' if port == '*' api.LocalLB.VirtualServer.set_destination_v2(virtual_servers: { item: [with_partition(vip)] }, - destinations: { item: [{ address: address, port: port}]}) + destinations: { item: [{ address: address, port: port }] }) end def set_vip_pool(vip, pool) @@ -74,7 +74,7 @@ def set_vip_pool(vip, pool) end def has_client_ssl_profile?(vip, profile_name) - return has_profile?(vip, profile_name, + has_profile?(vip, profile_name, @ProfileType::PROFILE_TYPE_CLIENT_SSL.member, @ProfileContextType::PROFILE_CONTEXT_TYPE_CLIENT.member) end @@ -83,7 +83,7 @@ def has_any_http_profile?(vip) has_type_of_profile?(vip, @ProfileType::PROFILE_TYPE_HTTP.member, @ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member - ) + ) end def has_http_profile?(vip, profile_name) @@ -97,34 +97,34 @@ def set_http_profile(vip, profile_name, existing_profile = nil) api.LocalLB.VirtualServer.add_profile( virtual_servers: { item: [with_partition(vip)] }, profiles: { item: [ { item: [{ - profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member, - profile_name: with_partition(profile_name) - }] - }]}) + profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member, + profile_name: with_partition(profile_name), + }], + }] }) end def remove_http_profile(vip, profile_name) api.LocalLB.VirtualServer.remove_profile( virtual_servers: { item: [with_partition(vip)] }, profiles: { item: [ { item: [{ - profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member, - profile_name: with_partition(profile_name) - }] - }] + profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member, + profile_name: with_partition(profile_name), + }], + }], }) end def has_type_of_profile?(vip, profile_type, profile_context) - response = api.LocalLB.VirtualServer.get_profile({ - virtual_servers: { item: [with_partition(vip)] } - }) + response = api.LocalLB.VirtualServer.get_profile( + virtual_servers: { item: [with_partition(vip)] } + ) - return false unless response.length > 0 && - response[:item].length > 0 && - response[:item][:item].length > 0 + return false unless !response.empty? && + !response[:item].empty? && + !response[:item][:item].empty? vip_profiles = response[:item][:item] - vip_profiles = [ vip_profiles ] if (vip_profiles.respond_to?(:has_key?)) + vip_profiles = [ vip_profiles ] if vip_profiles.respond_to?(:has_key?) current_profiles = vip_profiles.select do |p| p[:profile_type] == profile_type && @@ -138,22 +138,22 @@ def has_type_of_profile?(vip, profile_type, profile_context) end def has_profile?(vip, profile_name, profile_type, profile_context) - response = api.LocalLB.VirtualServer.get_profile({ - virtual_servers: { item: [with_partition(vip)] } - }) + response = api.LocalLB.VirtualServer.get_profile( + virtual_servers: { item: [with_partition(vip)] } + ) - return false unless response.length > 0 && - response[:item].length > 0 && - response[:item][:item].length > 0 + return false unless !response.empty? && + !response[:item].empty? && + !response[:item][:item].empty? vip_profiles = response[:item][:item] - vip_profiles = [ vip_profiles ] if (vip_profiles.respond_to?(:has_key?)) + vip_profiles = [ vip_profiles ] if vip_profiles.respond_to?(:has_key?) current_profiles = vip_profiles.select do |p| - p[:profile_type] == profile_type && + p[:profile_type] == profile_type && p[:profile_context] == profile_context - end + end current_profiles.any? do |p| p[:profile_name] == with_partition(profile_name) @@ -164,15 +164,15 @@ def add_client_ssl_profile(vip, profile_name) api.LocalLB.VirtualServer.add_profile( virtual_servers: { item: [with_partition(vip)] }, profiles: { item: [ { item: [{ - profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: with_partition(profile_name) - }] - }] + profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: with_partition(profile_name), + }], + }], }) end def has_server_ssl_profile?(vip, profile_name) - return has_profile?(vip, profile_name, + has_profile?(vip, profile_name, @ProfileType::PROFILE_TYPE_SERVER_SSL.member, @ProfileContextType::PROFILE_CONTEXT_TYPE_SERVER.member) end @@ -181,10 +181,10 @@ def add_server_ssl_profile(vip, profile_name) api.LocalLB.VirtualServer.add_profile( virtual_servers: { item: [with_partition(vip)] }, profiles: { item: [ { item: [{ - profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: with_partition(profile_name) - }] - }] + profile_context: @ProfileContextType::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: with_partition(profile_name), + }], + }], }) end @@ -208,7 +208,7 @@ def get_snat_pool(vip) src_trans_type = src_trans_type_map.key(raw_src_trans_type) - raise "Unrecognized source translation type:"\ + raise 'Unrecognized source translation type:'\ " `#{raw_src_trans_type}`" unless src_trans_type src_trans_type @@ -218,24 +218,24 @@ def set_snat_pool(vip, snat_pool) case snat_pool when :none api.LocalLB.VirtualServer - .set_source_address_translation_none({ - virtual_servers: { item: [with_partition(vip)] } - }) + .set_source_address_translation_none( + virtual_servers: { item: [with_partition(vip)] } + ) when :automap api.LocalLB.VirtualServer - .set_source_address_translation_automap({ - virtual_servers: { item: [with_partition(vip)] } - }) + .set_source_address_translation_automap( + virtual_servers: { item: [with_partition(vip)] } + ) when :manual - raise "Cannot set the source address translation type to `manual`"\ - " ... what would that even mean?" + raise 'Cannot set the source address translation type to `manual`'\ + ' ... what would that even mean?' else # assume that the requested snat_pool is already defined on the F5 api.LocalLB.VirtualServer - .set_source_address_translation_snat_pool({ - virtual_servers: { item: [with_partition(vip)] }, - pools: { item: [with_partition(snat_pool)] } - }) + .set_source_address_translation_snat_pool( + virtual_servers: { item: [with_partition(vip)] }, + pools: { item: [with_partition(snat_pool)] } + ) end end @@ -248,19 +248,19 @@ def firewall_policy_missing?(name) end def vip_enforced_firewall_policy(vip) - response = api.LocalLB.VirtualServer.get_enforced_firewall_policy({ + response = api.LocalLB.VirtualServer.get_enforced_firewall_policy( virtual_servers: { item: [with_partition(vip)] } - }) + ) firewall_policy = strip_partition(response[:item]) - return firewall_policy.to_s.empty? ? :none : firewall_policy + firewall_policy.to_s.empty? ? :none : firewall_policy end def vip_staged_firewall_policy(vip) - response = api.LocalLB.VirtualServer.get_staged_firewall_policy({ + response = api.LocalLB.VirtualServer.get_staged_firewall_policy( virtual_servers: { item: [with_partition(vip)] } - }) + ) firewall_policy = strip_partition(response[:item]) - return firewall_policy.to_s.empty? ? :none : firewall_policy + firewall_policy.to_s.empty? ? :none : firewall_policy end def set_enforced_firewall_policy(vip, firewall_policy) @@ -280,13 +280,12 @@ def set_staged_firewall_policy(vip, firewall_policy) end def irules_changed?(vip, target_rules) - current = api.LocalLB.VirtualServer.get_rule(virtual_servers: { item: [with_partition(vip)]}) + current = api.LocalLB.VirtualServer.get_rule(virtual_servers: { item: [with_partition(vip)] }) current_value = current[:item][:item] - current_rules = case - when current_value.nil? + current_rules = if current_value.nil? {} - when current_value.is_a?(Hash) - {current_value[:rule_name] => current_value[:priority]} + elsif current_value.is_a?(Hash) + { current_value[:rule_name] => current_value[:priority] } else current_value.each_with_object({}) do |irule, out| out[irule[:rule_name]] = irule[:priority] @@ -306,9 +305,9 @@ def update_irules(vip, irules, added, changed, removed) end def remove_rule(vip, rule) - api.LocalLB.VirtualServer.remove_rule(virtual_servers: { item: [with_partition(vip)]}, - rules: { item: { item: [{ rule_name: with_partition(rule), priority: '0' }] }} - ) + api.LocalLB.VirtualServer.remove_rule(virtual_servers: { item: [with_partition(vip)] }, + rules: { item: { item: [{ rule_name: with_partition(rule), priority: '0' }] } } + ) end def update_rule(vip, rule_name, priority) @@ -317,9 +316,9 @@ def update_rule(vip, rule_name, priority) end def create_rule(vip, rule_name, priority) - api.LocalLB.VirtualServer.add_rule(virtual_servers: { item: [with_partition(vip)]}, - rules: { item: { item: [{ rule_name: with_partition(rule_name), priority: priority }]}} - ) + api.LocalLB.VirtualServer.add_rule(virtual_servers: { item: [with_partition(vip)] }, + rules: { item: { item: [{ rule_name: with_partition(rule_name), priority: priority }] } } + ) end end -end \ No newline at end of file +end diff --git a/metadata.rb b/metadata.rb index 67d64f4..5c40c7b 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'MIT' description 'Resources for managing an F5 BigIP load balancer' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.4.12' +version '0.4.13' %w(ubuntu debian redhat centos suse opensuse opensuseleap scientific oracle amazon windows).each do |os| supports os diff --git a/rakefile.rb b/rakefile.rb index 8f9c6cc..643d09d 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -17,7 +17,7 @@ namespace :run do task :unit do - #exec('bundle exec rake lint && bundle exec rspec -f d --color spec') + # exec('bundle exec rake lint && bundle exec rspec -f d --color spec') exec('bundle exec rspec -f d --color spec') end end diff --git a/resources/irule.rb b/resources/irule.rb index ac6a9a1..d031299 100644 --- a/resources/irule.rb +++ b/resources/irule.rb @@ -1,17 +1,16 @@ -property :name, String property :irule_name, [NilClass, String], default: nil property :definition, String property :load_balancer, String, regex: /.*/, default: 'default' property :lb_host, String property :lb_username, String property :lb_password, String +property :partition, String, default: 'Common' action :create do load_f5_gem actual_irule_name = new_resource.irule_name || new_resource.name - irule = ChefF5::IRule.new(node, new_resource, new_resource.load_balancer) - - if irule.is_missing?(actual_irule_name) + irule = ChefF5::IRule.new(node, new_resource, new_resource.load_balancer, new_resource.partition) + if irule.missing?(actual_irule_name) converge_by "Create IRule #{actual_irule_name}" do irule.create(actual_irule_name, new_resource.definition) return @@ -27,9 +26,9 @@ action :destroy do actual_irule_name = new_resource.irule_name || new_resource.name - irule = ChefF5::IRule.new(node, new_resource, new_resource.load_balancer) + irule = ChefF5::IRule.new(node, new_resource, new_resource.load_balancer, new_resource.partition) - unless irule.is_missing?(actual_irule_name) + unless irule.missing?(actual_irule_name) converge_by "Destroy IRule #{actual_irule_name}" do irule.destroy(name) end @@ -39,4 +38,3 @@ action_class do include ChefF5::GemHelper end - diff --git a/resources/monitor.rb b/resources/monitor.rb index a57e95b..6d92004 100644 --- a/resources/monitor.rb +++ b/resources/monitor.rb @@ -1,4 +1,3 @@ -property :name, String property :monitor_name, [NilClass, String], default: nil property :template_type, String, regex: /TTYPE_UNSET|TTYPE_ICMP|TTYPE_TCP|TTYPE_TCP_ECHO|TTYPE_EXTERNAL|TTYPE_HTTP|TTYPE_HTTPS|TTYPE_NNTP|TTYPE_FTP|TTYPE_POP3|TTYPE_SMTP|TTYPE_MSSQL|TTYPE_GATEWAY|TTYPE_IMAP|TTYPE_RADIUS|TTYPE_LDAP|TTYPE_WMI|TTYPE_SNMP_DCA|TTYPE_SNMP_DCA_BASE|TTYPE_REAL_SERVER|TTYPE_UDP|TTYPE_NONE|TTYPE_ORACLE|TTYPE_SOAP|TTYPE_GATEWAY_ICMP|TTYPE_SIP|TTYPE_TCP_HALF_OPEN|TTYPE_SCRIPTED|TTYPE_WAP|TTYPE_RPC|TTYPE_SMB|TTYPE_SASP|TTYPE_MODULE_SCORE|TTYPE_FIREPASS|TTYPE_INBAND|TTYPE_RADIUS_ACCOUNTING|TTYPE_DIAMETER|TTYPE_VIRTUAL_LOCATION|TTYPE_MYSQL|TTYPE_POSTGRESQL/ property :parent_template, String @@ -13,13 +12,12 @@ property :lb_host, String property :lb_username, String property :lb_password, String - - +property :partition, String, default: 'Common' action :create do load_f5_gem actual_monitor_name = new_resource.monitor_name || new_resource.name - monitor = ChefF5::Monitor.new(node, new_resource, new_resource.load_balancer) + monitor = ChefF5::Monitor.new(node, new_resource, new_resource.load_balancer, new_resource.partition) if monitor.monitor_is_missing?(actual_monitor_name) converge_by "Create monitor template #{actual_monitor_name}" do monitor.create_monitor(actual_monitor_name, **f5_attributes) @@ -28,7 +26,7 @@ changeable_attributes = { dest_ip: new_resource.dest_ip, - dest_port: new_resource.dest_port + dest_port: new_resource.dest_port, } if monitor.common_attributes_changed?(actual_monitor_name, **changeable_attributes) converge_by "Update common attributes on monitor template #{actual_monitor_name}" do @@ -60,7 +58,7 @@ action :destroy do load_f5_gem actual_monitor_name = new_resource.monitor_name || new_resource.name - monitor = ChefF5::Monitor.new(node, new_resource, new_resource.load_balancer) + monitor = ChefF5::Monitor.new(node, new_resource, new_resource.load_balancer, new_resource.partition) unless monitor.monitor_is_missing?(actual_monitor_name) converge_by "Deleting monitor template #{actual_monitor_name}" do monitor.delete_monitor(actual_monitor_name) @@ -79,7 +77,7 @@ def f5_attributes dest_ip: new_resource.dest_ip, dest_port: new_resource.dest_port, is_read_only: new_resource.read_only, - is_directly_usable: new_resource.directly_usable + is_directly_usable: new_resource.directly_usable, } end end diff --git a/resources/pool.rb b/resources/pool.rb index d1bfcba..0df947e 100644 --- a/resources/pool.rb +++ b/resources/pool.rb @@ -9,6 +9,7 @@ property :lb_host, String property :lb_username, String property :lb_password, String +property :partition, String, default: 'Common' property :enabled_status, [:manual, :enabled, :disabled], default: node['f5']['enabled_status'] create_node = proc do @@ -26,11 +27,11 @@ end if new_resource.enabled_status != :manual current_enabled_status = @f5.node_is_enabled?(new_resource.host) - if (new_resource.enabled_status == :disabled && current_enabled_status == true) + if new_resource.enabled_status == :disabled && current_enabled_status == true converge_by("Disabling '#{new_resource.host}' (was previously enabled)") do @f5.node_disable(new_resource.host) end - elsif (new_resource.enabled_status == :enabled && current_enabled_status == false) + elsif new_resource.enabled_status == :enabled && current_enabled_status == false converge_by("Enabling '#{new_resource.host}' (was previously disabled)") do @f5.node_enable(new_resource.host) end @@ -88,7 +89,7 @@ action :create do load_f5_gem - @f5 = ChefF5::Client.new(node, new_resource, new_resource.load_balancer) + @f5 = ChefF5::Client.new(node, new_resource, new_resource.load_balancer, new_resource.partition) instance_eval(&create_pool) @@ -97,7 +98,7 @@ action :add do load_f5_gem - @f5 = ChefF5::Client.new(node, new_resource, new_resource.load_balancer) + @f5 = ChefF5::Client.new(node, new_resource, new_resource.load_balancer, new_resource.partition) instance_eval(&create_node) end diff --git a/resources/vip.rb b/resources/vip.rb index 469e004..802e5ca 100644 --- a/resources/vip.rb +++ b/resources/vip.rb @@ -7,6 +7,7 @@ property :lb_host, String property :lb_username, String property :lb_password, String +property :partition, String, default: 'Common' property :client_ssl_profile, String property :server_ssl_profile, String property :snat_pool, [:manual, :none, :automap, String], default: :manual @@ -15,10 +16,10 @@ property :irules, Array, default: [] property :http_profile, [NilClass, String, Symbol], default: nil -IPv4 = %r{^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$} +IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ def resolve_ip(name) - if name =~ IPv4 + if name =~ IPV4 name else DNSLookup.new(name).address @@ -28,7 +29,7 @@ def resolve_ip(name) action :create do load_f5_gem actual_vip_name = new_resource.vip_name || new_resource.name - vip = ChefF5::VIP.new(node, new_resource, new_resource.load_balancer) + vip = ChefF5::VIP.new(node, new_resource, new_resource.load_balancer, new_resource.partition) ip = resolve_ip(new_resource.address) next if ip.nil? @@ -115,20 +116,20 @@ def resolve_ip(name) unless current_snat_pool == new_resource.snat_pool - converge_by("Change server source address translation from"\ + converge_by('Change server source address translation from'\ " '#{current_snat_pool}' to"\ " '#{new_resource.snat_pool}'") do vip.set_snat_pool(actual_vip_name, new_resource.snat_pool) - Chef::Log.info("Changed server source address translation from"\ + Chef::Log.info('Changed server source address translation from'\ " '#{current_snat_pool}' to"\ " '#{new_resource.snat_pool}'") end end end added, changed, removed, target = vip.irules_changed?(actual_vip_name, new_resource.irules) - unless [added, changed, removed].all? { |l| l.empty? } + unless [added, changed, removed].all?(&:empty?) msg = "Update IRules for #{actual_vip_name}; "\ "The following rules changed: #{changed.join ', '}."\ "The following rules have been added: #{added.to_a.join ', '}"\ diff --git a/spec/unit/recipes/test_create_irule_spec.rb b/spec/unit/recipes/test_create_irule_spec.rb index 3723d17..1790b76 100644 --- a/spec/unit/recipes/test_create_irule_spec.rb +++ b/spec/unit/recipes/test_create_irule_spec.rb @@ -1,60 +1,58 @@ require 'spec_helper' require 'f5/icontrol' + require_relative '../../../libraries/irule' require_relative '../../../libraries/credentials' require_relative '../../../libraries/gem_helper' describe 'f5_test::test_create_irule' do - let(:api) { double('F5::Icontrol') } + let(:api) { double('F5.Icontrol') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_irule']).converge(described_recipe) - } + end - let(:f5_rule) { double 'LocalLB.Rule' } + let(:f5_rule) { double('LocalLB.Rule') } - let(:rule_definition) { + let(:rule_definition) do <<-EOL -# For hosts that serve both http but attached to http and https vips, +# For hosts that serve both http but attached to http and https vips, # this lets them know if the request # originally came in on https when HTTP_REQUEST { HTTP::header insert HTTPS true } EOL - } + end before do allow(F5::Icontrol::API).to receive(:new) { api } allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') allow(api).to receive_message_chain('LocalLB.Rule') { f5_rule } + allow(api).to receive_message_chain('System.Session.set_active_folder') end context 'managing the irule' do context 'irule does not exist' do before do - allow_any_instance_of(ChefF5::IRule).to receive(:is_missing?).and_return(true) - allow(f5_rule).to receive(:create) + allow_any_instance_of(ChefF5::IRule).to receive(:missing?).and_return(true) end it 'creates the irule' do - expect(f5_rule).to receive(:create).with(hash_including( - rules: { item: [{ rule_name: '/Common/test-irule', rule_definition: rule_definition }]} - )) + expect(f5_rule).to receive(:create).with(hash_including(rules: { item: [{ rule_name: '/Common/test-irule', rule_definition: rule_definition }] })) chef_run end end context 'the irule does exists' do before do - allow_any_instance_of(ChefF5::IRule).to receive(:is_missing?).and_return(false) + allow_any_instance_of(ChefF5::IRule).to receive(:missing?).and_return(false) allow(f5_rule).to receive(:update_definition) allow(f5_rule).to receive(:query_rule) - .with(hash_including(rule_names: { item: ['/Common/test-irule']})) - .and_return({item: { - rule_name: '/Common/test-irule', rule_definition: rule_definition - }}) - + .with(hash_including(rule_names: { item: ['/Common/test-irule'] })) + .and_return(item: { + rule_name: '/Common/test-irule', rule_definition: rule_definition + }) end context 'and is the same' do it 'does not update attributes' do @@ -66,16 +64,16 @@ context 'the definition is different' do before do allow(f5_rule).to receive(:query_rule) - .with(hash_including(rule_names: { item: ['/Common/test-irule']})) - .and_return({item: { - rule_name: '/Common/test-irule', rule_definition: '' - }}) + .with(hash_including(rule_names: { item: ['/Common/test-irule'] })) + .and_return(item: { + rule_name: '/Common/test-irule', rule_definition: '' + }) end it 'updates the definition' do expect(f5_rule).to receive(:modify_rule) - .with(hash_including(rules: { - item: [{rule_name: '/Common/test-irule', rule_definition: rule_definition}]})) + .with(hash_including(rules: { + item: [{ rule_name: '/Common/test-irule', rule_definition: rule_definition }] })) chef_run end end diff --git a/spec/unit/recipes/test_create_monitor_spec.rb b/spec/unit/recipes/test_create_monitor_spec.rb index 047c58b..a8e328d 100644 --- a/spec/unit/recipes/test_create_monitor_spec.rb +++ b/spec/unit/recipes/test_create_monitor_spec.rb @@ -7,9 +7,9 @@ describe 'f5_test::test_create_monitor' do let(:api) { double('F5::Icontrol') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_monitor']).converge(described_recipe) - } + end let(:f5_monitor) { double 'LocalLB.Monitor' } @@ -18,6 +18,7 @@ allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') allow(api).to receive_message_chain('LocalLB.Monitor') { f5_monitor } + allow(api).to receive_message_chain('System.Session.set_active_folder') end context 'managing the monitor' do @@ -28,41 +29,41 @@ allow_any_instance_of(ChefF5::Monitor).to receive(:interval_changed?).and_return(false) allow(f5_monitor).to receive(:create_template) allow(f5_monitor).to receive(:get_template_string_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['STYPE_SEND']})) - .and_return({item: {value: 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n'}}) - .once - allow(f5_monitor).to receive(:get_template_string_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['STYPE_RECEIVE']})) - .and_return({item: {value: 'status.*DOWN' }}) - .once + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['STYPE_SEND'] })) + .and_return(item: { value: 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n' }) + .once + allow(f5_monitor).to receive(:get_template_string_property) + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['STYPE_RECEIVE'] })) + .and_return(item: { value: 'status.*DOWN' }) + .once - allow(f5_monitor).to receive(:get_template_destination) - .with(hash_including(template_names: { item: ['/Common/test-monitor']})) - .and_return({item: { - ipport: {address: '0.0.0.0', port: '0'}, - address_type: 'ATYPE_STAR_ADDRESS_STAR_PORT' - }}) + allow(f5_monitor).to receive(:get_template_destination) + .with(hash_including(template_names: { item: ['/Common/test-monitor'] })) + .and_return(item: { + ipport: { address: '0.0.0.0', port: '0' }, + address_type: 'ATYPE_STAR_ADDRESS_STAR_PORT', + }) end it 'creates the monitor' do expect(f5_monitor).to receive(:create_template).with(hash_including( - templates: { item: [{ template_name: '/Common/test-monitor', template_type: 'TTYPE_HTTP' }]}, - template_attributes: { item: [hash_including({ - parent_template: 'http', - interval: 5, - timeout: 10, - dest_ipport: { - address_type: 'ATYPE_STAR_ADDRESS_STAR_PORT', - ipport: { - address: '0.0.0.0', port: '0' - } - }, - is_read_only: false, - is_directly_usable: true - })]} + templates: { item: [{ template_name: '/Common/test-monitor', template_type: 'TTYPE_HTTP' }] }, + template_attributes: { item: [hash_including( + parent_template: 'http', + interval: 5, + timeout: 10, + dest_ipport: { + address_type: 'ATYPE_STAR_ADDRESS_STAR_PORT', + ipport: { + address: '0.0.0.0', port: '0' + }, + }, + is_read_only: false, + is_directly_usable: true + )] } )) expect(f5_monitor).to receive(:set_template_string_property) - .with(hash_including(template_names: {item: ['/Common/test-monitor']}, - values: {item: [{type: 'STYPE_RECEIVE', value: 'status.*UP'}]})) + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, + values: { item: [{ type: 'STYPE_RECEIVE', value: 'status.*UP' }] })) chef_run end @@ -73,25 +74,24 @@ allow_any_instance_of(ChefF5::Monitor).to receive(:monitor_is_missing?).and_return(false) allow(f5_monitor).to receive(:update_common_attributes) allow(f5_monitor).to receive(:get_template_destination) - .with(hash_including(template_names: { item: ['/Common/test-monitor']})) - .and_return({item: { - ipport: {address: '0.0.0.0', port: '0'}, - address_type: 'ATYPE_STAR_ADDRESS_STAR_PORT' - }}) - + .with(hash_including(template_names: { item: ['/Common/test-monitor'] })) + .and_return(item: { + ipport: { address: '0.0.0.0', port: '0' }, + address_type: 'ATYPE_STAR_ADDRESS_STAR_PORT', + }) end context 'and is the same' do before do allow_any_instance_of(ChefF5::Monitor).to receive(:timeout_changed?).and_return(false) allow_any_instance_of(ChefF5::Monitor).to receive(:interval_changed?).and_return(false) allow(f5_monitor).to receive(:get_template_string_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['STYPE_SEND']})) - .and_return({item: {value: 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n'}}) - .once + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['STYPE_SEND'] })) + .and_return(item: { value: 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n' }) + .once allow(f5_monitor).to receive(:get_template_string_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['STYPE_RECEIVE']})) - .and_return({item: {value: 'status.*UP' }}) - .once + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['STYPE_RECEIVE'] })) + .and_return(item: { value: 'status.*UP' }) + .once end it 'does not update attributes' do expect(f5_monitor).not_to receive(:update_common_attributes) @@ -104,20 +104,20 @@ allow_any_instance_of(ChefF5::Monitor).to receive(:timeout_changed?).and_return(false) allow_any_instance_of(ChefF5::Monitor).to receive(:interval_changed?).and_return(false) allow(f5_monitor).to receive(:get_template_string_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['STYPE_SEND']})) - .and_return({item: {value: 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n'}}) - .once + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['STYPE_SEND'] })) + .and_return(item: { value: 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n' }) + .once allow(f5_monitor).to receive(:get_template_string_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['STYPE_RECEIVE']})) - .and_return({item: {value: 'status.*DOWN' }}) - .once + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['STYPE_RECEIVE'] })) + .and_return(item: { value: 'status.*DOWN' }) + .once # allow(f5_monitor).to receive(:set_template_string_property) end it 'updates the string properties' do expect(f5_monitor).to receive(:set_template_string_property) - .with(hash_including(template_names: {item: ['/Common/test-monitor']}, - values: {item: [{type: 'STYPE_RECEIVE', value: 'status.*UP'}]})) + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, + values: { item: [{ type: 'STYPE_RECEIVE', value: 'status.*UP' }] })) chef_run end end @@ -126,15 +126,15 @@ allow_any_instance_of(ChefF5::Monitor).to receive(:string_properties_match?).and_return([]) allow_any_instance_of(ChefF5::Monitor).to receive(:interval_changed?).and_return(false) allow(f5_monitor).to receive(:get_template_integer_property) - .with(hash_including(template_names: { item: ['/Common/test-monitor']}, property_types: {item: ['ITYPE_TIMEOUT']})) - .and_return({item: {value: '5'}}) - .once + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, property_types: { item: ['ITYPE_TIMEOUT'] })) + .and_return(item: { value: '5' }) + .once end it 'updates the timeout' do expect(f5_monitor).to receive(:set_template_integer_property) - .with(hash_including(template_names: {item: ['/Common/test-monitor']}, - values: {item: [{type: 'ITYPE_TIMEOUT', value: '10'}]})) + .with(hash_including(template_names: { item: ['/Common/test-monitor'] }, + values: { item: [{ type: 'ITYPE_TIMEOUT', value: '10' }] })) chef_run end end diff --git a/spec/unit/recipes/test_create_pool_add_action_spec.rb b/spec/unit/recipes/test_create_pool_add_action_spec.rb index 4dad0cf..b5bf034 100644 --- a/spec/unit/recipes/test_create_pool_add_action_spec.rb +++ b/spec/unit/recipes/test_create_pool_add_action_spec.rb @@ -7,9 +7,9 @@ describe 'f5_test::test_create_pool_add_action' do let(:api) { double('F5::Icontrol') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) - } + end before do allow(F5::Icontrol::API).to receive(:new) { api } @@ -27,14 +27,14 @@ allow_any_instance_of(ChefF5::Client).to receive(:pool_is_missing_monitor?).and_return(false) allow(api).to receive_message_chain('LocalLB.NodeAddressV2') { node } allow(api).to receive_message_chain('LocalLB.Pool') { pool } - allow(pool).to receive(:get_member_ratio).and_return({:item=>{:item=>"1", :"@a:array_type"=>"y:long[1]"}, :"@s:type"=>"A:Array", :"@a:array_type"=>"y:long[][1]"}) - + allow(pool).to receive(:get_member_ratio).and_return(item: { item: '1', "@a:array_type": 'y:long[1]' }, "@s:type": 'A:Array', "@a:array_type": 'y:long[][1]') + allow(api).to receive_message_chain('System.Session.set_active_folder') end context 'the node exists' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/fauxhai.local', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/fauxhai.local', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -53,7 +53,7 @@ context 'the node does not exist' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/a', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/a', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -73,13 +73,13 @@ before do allow_any_instance_of(ChefF5::Client).to receive(:node_is_missing?).and_return(false) allow(pool).to receive(:get_member_ratio) { - { :item => { :item => '2', :"@a:array_type" => 'y:long[1]' }, :"@s:type" => 'A:Array', :"@a:array_type" => 'y:long[][1]' } + { item: { item: '2', "@a:array_type": 'y:long[1]' }, "@s:type": 'A:Array', "@a:array_type": 'y:long[][1]' } } end it 'update the pool member ratio' do expect(pool).to receive(:set_member_ratio).with(pool_names: { item: ['/Common/reallybasic'] }, - members: { item: { item: [{ address: 'fauxhai.local', port: 80 }]}}, - ratios: { item: { item: [1]}}) + members: { item: { item: [{ address: 'fauxhai.local', port: 80 }] } }, + ratios: { item: { item: [1] } }) chef_run end diff --git a/spec/unit/recipes/test_create_pool_all_services_spec.rb b/spec/unit/recipes/test_create_pool_all_services_spec.rb index 7dd19fc..8f1365f 100644 --- a/spec/unit/recipes/test_create_pool_all_services_spec.rb +++ b/spec/unit/recipes/test_create_pool_all_services_spec.rb @@ -8,14 +8,14 @@ let(:api) { double('F5::Icontrol') } let(:pool) { double('F5::Icontrol::LocalLB::Pool') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) - } + end before do allow(F5::Icontrol::API).to receive(:new) { api } allow(api).to receive_message_chain('LocalLB.Pool') { pool } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') end diff --git a/spec/unit/recipes/test_create_pool_no_host_spec.rb b/spec/unit/recipes/test_create_pool_no_host_spec.rb index aaf0979..1f92b8c 100644 --- a/spec/unit/recipes/test_create_pool_no_host_spec.rb +++ b/spec/unit/recipes/test_create_pool_no_host_spec.rb @@ -7,12 +7,13 @@ describe 'f5_test::test_create_pool_no_host' do let(:api) { double('F5::Icontrol') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) - } + end before do allow(F5::Icontrol::API).to receive(:new) { api } + allow(api).to receive_message_chain('System.Session.set_active_folder') allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') end @@ -28,7 +29,7 @@ context 'the pool does not exist' do before do allow(api).to receive_message_chain('LocalLB.Pool.get_list') { - { :item => ['/Common/test1', '/Common/mchan01'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/test1', '/Common/mchan01'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -47,7 +48,7 @@ before do allow(api).to receive_message_chain('LocalLB.Pool') { pool } allow(pool).to receive(:get_list) { - { :item => ['/Common/reallybasic', '/Common/mchan01'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/reallybasic', '/Common/mchan01'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -72,10 +73,10 @@ allow(api).to receive_message_chain('LocalLB.Pool') { pool } allow(api).to receive_message_chain('LocalLB.NodeAddressV2') { node } expect(node).to_not receive(:get_list) { - { :item => ['/Common/fauxhai.local', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/fauxhai.local', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } allow(pool).to receive(:get_monitor_association) { - { :item => { pool_name: '/Common/reallybasic', monitor_rule: { :type => 'MONITOR_RULE_TYPE_SINGLE', :quorum => '0', :monitor_templates => { :item => '/Common/test-monitor', :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[1]' }, :"@s:type" => 'iControl:LocalLB.MonitorRule' } }, :"@s:type" => 'A:Array', :"@a:array_type" => 'iControl:LocalLB.Pool.MonitorAssociation[1]' } + { item: { pool_name: '/Common/reallybasic', monitor_rule: { type: 'MONITOR_RULE_TYPE_SINGLE', quorum: '0', monitor_templates: { item: '/Common/test-monitor', "@s:type": 'A:Array', "@a:array_type": 'y:string[1]' }, "@s:type": 'iControl:LocalLB.MonitorRule' } }, "@s:type": 'A:Array', "@a:array_type": 'iControl:LocalLB.Pool.MonitorAssociation[1]' } } end context 'the monitor is already on assigned to the pool' do diff --git a/spec/unit/recipes/test_create_pool_spec.rb b/spec/unit/recipes/test_create_pool_spec.rb index 521e204..07b5469 100644 --- a/spec/unit/recipes/test_create_pool_spec.rb +++ b/spec/unit/recipes/test_create_pool_spec.rb @@ -7,12 +7,13 @@ describe 'f5_test::test_create_pool' do let(:api) { double('F5::Icontrol') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) - } + end before do allow(F5::Icontrol::API).to receive(:new) { api } + allow(api).to receive_message_chain('System.Session.set_active_folder') allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') end @@ -29,7 +30,7 @@ context 'the pool does not exist' do before do allow(api).to receive_message_chain('LocalLB.Pool.get_list') { - { :item => ['/Common/test1', '/Common/mchan01'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/test1', '/Common/mchan01'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -51,7 +52,7 @@ before do allow(api).to receive_message_chain('LocalLB.Pool') { pool } allow(pool).to receive(:get_list) { - { :item => ['/Common/reallybasic', '/Common/mchan01'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/reallybasic', '/Common/mchan01'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -80,7 +81,7 @@ context 'the node exists' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/fauxhai.local', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/fauxhai.local', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -98,7 +99,7 @@ context 'the node does not exist' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/a', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/a', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end @@ -127,10 +128,10 @@ allow(api).to receive_message_chain('LocalLB.Pool') { pool } allow(api).to receive_message_chain('LocalLB.NodeAddressV2') { node } expect(node).to receive(:get_list) { - { :item => ['/Common/fauxhai.local', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/fauxhai.local', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } allow(pool).to receive(:get_monitor_association) { - { :item => { pool_name: '/Common/reallybasic', monitor_rule: { :type => 'MONITOR_RULE_TYPE_SINGLE', :quorum => '0', :monitor_templates => { :item => '/Common/test-monitor', :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[1]' }, :"@s:type" => 'iControl:LocalLB.MonitorRule' } }, :"@s:type" => 'A:Array', :"@a:array_type" => 'iControl:LocalLB.Pool.MonitorAssociation[1]' } + { item: { pool_name: '/Common/reallybasic', monitor_rule: { type: 'MONITOR_RULE_TYPE_SINGLE', quorum: '0', monitor_templates: { item: '/Common/test-monitor', "@s:type": 'A:Array', "@a:array_type": 'y:string[1]' }, "@s:type": 'iControl:LocalLB.MonitorRule' } }, "@s:type": 'A:Array', "@a:array_type": 'iControl:LocalLB.Pool.MonitorAssociation[1]' } } end context 'the monitor is already on assigned to the pool' do @@ -165,8 +166,8 @@ allow_any_instance_of(ChefF5::Client).to receive(:pool_is_missing_monitor?).and_return(false) allow_any_instance_of(ChefF5::Client).to receive(:node_is_missing?).and_return(false) allow(pool).to receive(:get_lb_method) - .with(pool_names: { item: ['/Common/reallybasic'] }) - .and_return(:item=>'LB_METHOD_ROUND_ROBIN', :'@s:type' => 'A:Array', :'@a:array_type' => 'iControl:LocalLB.LBMethod[1]') + .with(pool_names: { item: ['/Common/reallybasic'] }) + .and_return(item: 'LB_METHOD_ROUND_ROBIN', '@s:type': 'A:Array', '@a:array_type': 'iControl:LocalLB.LBMethod[1]') end context 'the lb_method is already set' do it 'does not set the lb_method' do @@ -186,14 +187,14 @@ allow_any_instance_of(ChefF5::Client).to receive(:pool_is_missing_monitor?).and_return(false) allow_any_instance_of(ChefF5::Client).to receive(:node_is_missing?).and_return(false) allow(pool).to receive(:get_lb_method) - .with(pool_names: { item: ['/Common/reallybasic'] }) - .and_return(:item=>'LB_METHOD_PREDICTIVE_MEMBER', :'@s:type' => 'A:Array', :'@a:array_type' => 'iControl:LocalLB.LBMethod[1]') + .with(pool_names: { item: ['/Common/reallybasic'] }) + .and_return(item: 'LB_METHOD_PREDICTIVE_MEMBER', '@s:type': 'A:Array', '@a:array_type': 'iControl:LocalLB.LBMethod[1]') end it 'sets the lb_method' do expect(pool).to receive(:set_lb_method).with(pool_names: { item: ['/Common/reallybasic'] }, lb_methods: { item: ['LB_METHOD_ROUND_ROBIN'] } - ) + ) chef_run end end diff --git a/spec/unit/recipes/test_create_vip_address_changed_spec.rb b/spec/unit/recipes/test_create_vip_address_changed_spec.rb index 2aa7bf0..a46490f 100644 --- a/spec/unit/recipes/test_create_vip_address_changed_spec.rb +++ b/spec/unit/recipes/test_create_vip_address_changed_spec.rb @@ -17,14 +17,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -33,22 +33,23 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) end context 'when managing the vip' do before do # these vips have no profiles allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } allow(server_api).to receive(:get_list) { { item: ['/Common/myvip'] } } @@ -64,7 +65,7 @@ end it 'updates the address' do expect(server_api).to receive(:set_destination_v2).with(virtual_servers: { item: ['/Common/myvip'] }, - destinations: { item: [{address: '86.75.30.9', port: '0'}]}) + destinations: { item: [{ address: '86.75.30.9', port: '0' }] }) chef_run end end @@ -76,7 +77,7 @@ end it 'updates the address' do expect(server_api).to receive(:set_destination_v2).with(virtual_servers: { item: ['/Common/myvip'] }, - destinations: { item: [{address: '86.75.30.9', port: '0'}]}) + destinations: { item: [{ address: '86.75.30.9', port: '0' }] }) chef_run end end diff --git a/spec/unit/recipes/test_create_vip_all_ports_spec.rb b/spec/unit/recipes/test_create_vip_all_ports_spec.rb index 4962a86..8e5efee 100644 --- a/spec/unit/recipes/test_create_vip_all_ports_spec.rb +++ b/spec/unit/recipes/test_create_vip_all_ports_spec.rb @@ -17,14 +17,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -33,14 +33,14 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) end context 'when managing the vip' do before do # these vips have no profiles allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:get_destination_v2) { @@ -50,9 +50,10 @@ # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } end context 'and the vip does not exist' do @@ -72,10 +73,10 @@ expect(server_api).to receive(:create).with( definitions: { item: { - name: '/Common/myvip', - address: '86.75.30.9', - port: '0', - protocol: 'PROTOCOL_TCP' }, + name: '/Common/myvip', + address: '86.75.30.9', + port: '0', + protocol: 'PROTOCOL_TCP' }, }, wildmasks: { item: '255.255.255.255' }, resources: { @@ -88,9 +89,9 @@ item: [ item: { profile_context: 'PROFILE_CONTEXT_TYPE_ALL', - profile_name: 'http' - } - ] + profile_name: 'http', + }, + ], } ) diff --git a/spec/unit/recipes/test_create_vip_enforced_firewall_policy_named_spec.rb b/spec/unit/recipes/test_create_vip_enforced_firewall_policy_named_spec.rb index 6a11a59..e9d924b 100644 --- a/spec/unit/recipes/test_create_vip_enforced_firewall_policy_named_spec.rb +++ b/spec/unit/recipes/test_create_vip_enforced_firewall_policy_named_spec.rb @@ -18,14 +18,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) # these vips have no profiles allow(server_api).to receive(:get_profile) { { item: { item: [] } } @@ -75,13 +75,13 @@ end it 'adds the enforced firewall policy to the vip' do - expect(server_api).to receive(:get_enforced_firewall_policy).with({ + expect(server_api).to receive(:get_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_enforced_firewall_policy).with({ - virtual_servers: { item: ['/Common/myvip'] }, - policies: { item: [ '/Common/myfwpolicy-enforced' ] } - }) + ) + expect(server_api).to receive(:set_enforced_firewall_policy).with( + virtual_servers: { item: ['/Common/myvip'] }, + policies: { item: [ '/Common/myfwpolicy-enforced' ] } + ) chef_run end end @@ -97,15 +97,14 @@ end it 'fails to converge' do - expect(server_api).to receive(:get_enforced_firewall_policy).with({ + expect(server_api).to receive(:get_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect { + ) + expect do chef_run - }.to raise_error /Firewall policy myfwpolicy-enforced does not exist/ + end.to raise_error /Firewall policy myfwpolicy-enforced does not exist/ end end - end context 'when managing an existing vip' do @@ -135,13 +134,13 @@ end it 'adds the enforced firewall policy to the vip' do - expect(server_api).to receive(:get_enforced_firewall_policy).with({ + expect(server_api).to receive(:get_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_enforced_firewall_policy).with({ - virtual_servers: { item: ['/Common/myvip'] }, - policies: { item: [ '/Common/myfwpolicy-enforced' ] } - }) + ) + expect(server_api).to receive(:set_enforced_firewall_policy).with( + virtual_servers: { item: ['/Common/myvip'] }, + policies: { item: [ '/Common/myfwpolicy-enforced' ] } + ) chef_run end end @@ -157,14 +156,13 @@ end it 'fails to converge' do - expect(server_api).to receive(:get_enforced_firewall_policy).with({ + expect(server_api).to receive(:get_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect { + ) + expect do chef_run - }.to raise_error /Firewall policy myfwpolicy-enforced does not exist/ + end.to raise_error /Firewall policy myfwpolicy-enforced does not exist/ end end end - end diff --git a/spec/unit/recipes/test_create_vip_enforced_firewall_policy_none_spec.rb b/spec/unit/recipes/test_create_vip_enforced_firewall_policy_none_spec.rb index 718e7b8..c73fbe4 100644 --- a/spec/unit/recipes/test_create_vip_enforced_firewall_policy_none_spec.rb +++ b/spec/unit/recipes/test_create_vip_enforced_firewall_policy_none_spec.rb @@ -18,14 +18,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) # these vips have no profiles allow(server_api).to receive(:get_profile) { { item: { item: [] } } @@ -63,7 +63,6 @@ allow(server_api).to receive(:set_default_pool_name) end - context 'and the enforced firewall policy is set to empty' do before do allow(fw_policy_api).to receive(:get_list) { @@ -76,18 +75,16 @@ end it 'unsets the enforced firewall policy' do - expect(server_api).to receive(:get_enforced_firewall_policy).with({ + expect(server_api).to receive(:get_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_enforced_firewall_policy).with({ + ) + expect(server_api).to receive(:set_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] }, policies: { item: [ '' ] } - }) - chef_run + ) + chef_run end end - - end context 'when managing an existing vip' do @@ -117,16 +114,15 @@ end it 'unsets the enforced firewall policy' do - expect(server_api).to receive(:get_enforced_firewall_policy).with({ + expect(server_api).to receive(:get_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_enforced_firewall_policy).with({ + ) + expect(server_api).to receive(:set_enforced_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] }, policies: { item: [ '' ] } - }) + ) chef_run end end end - end diff --git a/spec/unit/recipes/test_create_vip_http_profile_spec.rb b/spec/unit/recipes/test_create_vip_http_profile_spec.rb index 084263d..0d54bef 100644 --- a/spec/unit/recipes/test_create_vip_http_profile_spec.rb +++ b/spec/unit/recipes/test_create_vip_http_profile_spec.rb @@ -17,14 +17,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -33,7 +33,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow_any_instance_of(ChefF5::VIP).to receive(:vip_default_pool) allow_any_instance_of(ChefF5::VIP).to receive(:set_vip_pool) allow(server_api).to receive(:get_list) { @@ -49,24 +49,25 @@ # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } end context 'and the http profile does not exist' do before do allow(server_api).to receive(:get_profile) { - { item: { item: { }}} + { item: { item: {} } } } end it 'sets the http profile' do expect(server_api).to receive(:add_profile).with( - hash_including(profiles: {item: [{item: [ - hash_including(profile_name: '/Common/http', - profile_context: F5::Icontrol::LocalLB::ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member - )]}]})) + hash_including(profiles: { item: [{ item: [ + hash_including(profile_name: '/Common/http', + profile_context: F5::Icontrol::LocalLB::ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member + )] }] })) chef_run end end @@ -74,7 +75,7 @@ context 'and the http profile is correct' do before do allow(server_api).to receive(:get_profile) { - { item: { item: {profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http'} }} + { item: { item: { profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http' } } } } end @@ -88,16 +89,16 @@ context 'and the http profile is different' do before do allow(server_api).to receive(:get_profile) { - { item: { item: {profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http-access'} }} + { item: { item: { profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http-access' } } } } end it 'sets the correct profile' do - expect(server_api).to receive(:remove_profile).with(hash_including(profiles: {item: [{item: [hash_including(profile_name: '/Common/http-access')]}]})) + expect(server_api).to receive(:remove_profile).with(hash_including(profiles: { item: [{ item: [hash_including(profile_name: '/Common/http-access')] }] })) expect(server_api).to receive(:add_profile).with( - hash_including(profiles: {item: [{item: [ - hash_including(profile_name: '/Common/http', - profile_context: F5::Icontrol::LocalLB::ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member - )]}]})) + hash_including(profiles: { item: [{ item: [ + hash_including(profile_name: '/Common/http', + profile_context: F5::Icontrol::LocalLB::ProfileContextType::PROFILE_CONTEXT_TYPE_ALL.member + )] }] })) chef_run end end diff --git a/spec/unit/recipes/test_create_vip_irules_spec.rb b/spec/unit/recipes/test_create_vip_irules_spec.rb index 341f2c1..52c4b1c 100644 --- a/spec/unit/recipes/test_create_vip_irules_spec.rb +++ b/spec/unit/recipes/test_create_vip_irules_spec.rb @@ -18,14 +18,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -43,37 +43,38 @@ before do # these vips have no profiles allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } allow(server_api).to receive(:get_list).and_return item: ['/Common/myvip'] end context 'and the VIP does not have irules before' do before do - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow_any_instance_of(ChefF5::VIP) .to receive(:vip_default_pool).and_return('reallybasic') end it 'creates the irules' do - expect(server_api).to receive(:add_rule).with(virtual_servers: { item: ['/Common/myvip']}, - rules: { item: { item: [{ rule_name: '/Common/test-irule', priority: '0' }]}}) - expect(server_api).to receive(:add_rule).with(virtual_servers: { item: ['/Common/myvip']}, - rules: { item: { item: [{ rule_name: '/Common/test-irule-2', priority: '1' }]}}) + expect(server_api).to receive(:add_rule).with(virtual_servers: { item: ['/Common/myvip'] }, + rules: { item: { item: [{ rule_name: '/Common/test-irule', priority: '0' }] } }) + expect(server_api).to receive(:add_rule).with(virtual_servers: { item: ['/Common/myvip'] }, + rules: { item: { item: [{ rule_name: '/Common/test-irule-2', priority: '1' }] } }) chef_run end end context 'and an IRule has been deleted' do before do - allow(server_api).to receive(:get_rule).and_return({item: {item: [{rule_name: '/Common/test-irule', priority: '0'}, {rule_name: '/Common/test-irule-2', priority: '1'}, {rule_name: '/Common/test-irule-3', priority: '2'}]}}) + allow(server_api).to receive(:get_rule).and_return(item: { item: [{ rule_name: '/Common/test-irule', priority: '0' }, { rule_name: '/Common/test-irule-2', priority: '1' }, { rule_name: '/Common/test-irule-3', priority: '2' }] }) allow_any_instance_of(ChefF5::VIP) .to receive(:vip_default_pool).and_return('reallybasic') end @@ -81,27 +82,26 @@ allow(server_api).to receive(:get_destination_v2) { { item: { address: '192.30.253.112', port: '80' } } } - expect(server_api).to receive(:remove_rule).with(virtual_servers: { item: ['/Common/myvip']}, - rules: { item: { item: [{ rule_name: '/Common/test-irule-3', priority: '0' }]}}) + expect(server_api).to receive(:remove_rule).with(virtual_servers: { item: ['/Common/myvip'] }, + rules: { item: { item: [{ rule_name: '/Common/test-irule-3', priority: '0' }] } }) chef_run end end context 'and the IRules have changed' do before do - allow(server_api).to receive(:get_rule).and_return({item: {item: [{rule_name: '/Common/test-irule', priority: '1'}, {rule_name: '/Common/test-irule-2', priority: '0'}]}}) + allow(server_api).to receive(:get_rule).and_return(item: { item: [{ rule_name: '/Common/test-irule', priority: '1' }, { rule_name: '/Common/test-irule-2', priority: '0' }] }) allow_any_instance_of(ChefF5::VIP) .to receive(:vip_default_pool).and_return('reallybasic') # allow_any_instance_of(ChefF5::VIP) # .to receive(:irules_changed?).and_return([[],[],[],{}]) end it 'updates the irules' do - expect(server_api).to receive(:remove_rule).with(virtual_servers: { item: ['/Common/myvip']}, - rules: { item: { item: [{ rule_name: '/Common/test-irule-2', priority: '0' }]}}) - expect(server_api).to receive(:add_rule).with(virtual_servers: { item: ['/Common/myvip']}, - rules: { item: { item: [{ rule_name: '/Common/test-irule-2', priority: '2' }]}}) + expect(server_api).to receive(:remove_rule).with(virtual_servers: { item: ['/Common/myvip'] }, + rules: { item: { item: [{ rule_name: '/Common/test-irule-2', priority: '0' }] } }) + expect(server_api).to receive(:add_rule).with(virtual_servers: { item: ['/Common/myvip'] }, + rules: { item: { item: [{ rule_name: '/Common/test-irule-2', priority: '2' }] } }) chef_run end end end end - diff --git a/spec/unit/recipes/test_create_vip_name_spec.rb b/spec/unit/recipes/test_create_vip_name_spec.rb index 31b4e4a..23f322d 100644 --- a/spec/unit/recipes/test_create_vip_name_spec.rb +++ b/spec/unit/recipes/test_create_vip_name_spec.rb @@ -18,14 +18,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -34,7 +34,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -50,9 +50,10 @@ # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } end context 'and the name hasnt been created yet' do @@ -119,4 +120,3 @@ end end end - diff --git a/spec/unit/recipes/test_create_vip_no_http_profile_spec.rb b/spec/unit/recipes/test_create_vip_no_http_profile_spec.rb index 0ea7976..e1acaf1 100644 --- a/spec/unit/recipes/test_create_vip_no_http_profile_spec.rb +++ b/spec/unit/recipes/test_create_vip_no_http_profile_spec.rb @@ -17,14 +17,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -33,7 +33,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -42,15 +42,16 @@ context 'when managing the vip' do before do allow(server_api).to receive(:get_profile) { - { item: { item: {profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http'} }} + { item: { item: { profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http' } } } } # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } end context 'and the vip has an http profile' do diff --git a/spec/unit/recipes/test_create_vip_none_http_profile_spec.rb b/spec/unit/recipes/test_create_vip_none_http_profile_spec.rb index cfdfe54..5625d2f 100644 --- a/spec/unit/recipes/test_create_vip_none_http_profile_spec.rb +++ b/spec/unit/recipes/test_create_vip_none_http_profile_spec.rb @@ -17,14 +17,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -33,7 +33,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -42,15 +42,16 @@ context 'when managing the vip' do before do allow(server_api).to receive(:get_profile) { - { item: { item: {profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http'} }} + { item: { item: { profile_type: 'PROFILE_TYPE_HTTP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/http' } } } } # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } end context 'and the vip has an http profile' do @@ -63,7 +64,7 @@ it 'deletes the http profile' do allow_any_instance_of(ChefF5::VIP).to receive(:vip_default_pool) allow_any_instance_of(ChefF5::VIP).to receive(:set_vip_pool) - expect(server_api).to receive(:remove_profile).with(hash_including(profiles: {item: [{item: [hash_including(profile_name: '/Common/http')]}]})) + expect(server_api).to receive(:remove_profile).with(hash_including(profiles: { item: [{ item: [hash_including(profile_name: '/Common/http')] }] })) chef_run end end diff --git a/spec/unit/recipes/test_create_vip_snat_pool_automap_spec.rb b/spec/unit/recipes/test_create_vip_snat_pool_automap_spec.rb index cb47649..d14d94b 100644 --- a/spec/unit/recipes/test_create_vip_snat_pool_automap_spec.rb +++ b/spec/unit/recipes/test_create_vip_snat_pool_automap_spec.rb @@ -8,9 +8,9 @@ describe 'f5_test::test_create_vip_snat_pool_automap' do let(:api) { double('F5::Icontrol') } let(:server_api) { double('F5::Icontrol::LocalLB::VirtualServer') } - let(:sat_type) { + let(:sat_type) do F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType - } + end let(:chef_run) do ChefSpec::SoloRunner.new( @@ -21,14 +21,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -62,12 +62,12 @@ before do allow(server_api) .to receive(:get_source_address_translation_type) { - { item: sat_type::SRC_TRANS_NONE.member } - } + { item: sat_type::SRC_TRANS_NONE.member } + } # must allow the client profile to be set allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:add_profile) end @@ -113,7 +113,7 @@ # must allow the client profile to be set allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:add_profile) end diff --git a/spec/unit/recipes/test_create_vip_snat_pool_named_spec.rb b/spec/unit/recipes/test_create_vip_snat_pool_named_spec.rb index 8ecf85f..2bdda90 100644 --- a/spec/unit/recipes/test_create_vip_snat_pool_named_spec.rb +++ b/spec/unit/recipes/test_create_vip_snat_pool_named_spec.rb @@ -8,9 +8,9 @@ describe 'f5_test::test_create_vip_snat_pool_named' do let(:api) { double('F5::Icontrol') } let(:server_api) { double('F5::Icontrol::LocalLB::VirtualServer') } - let(:sat_type) { + let(:sat_type) do F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType - } + end let(:chef_run) do ChefSpec::SoloRunner.new( @@ -21,14 +21,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -61,7 +61,7 @@ context 'and the client ssl profile is missing' do before do allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } # must allow the server profile and sat to be set @@ -79,12 +79,12 @@ before do allow(server_api) .to receive(:get_source_address_translation_type) { - { item: sat_type::SRC_TRANS_NONE.member } - } + { item: sat_type::SRC_TRANS_NONE.member } + } # must allow the client profile to be set allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:add_profile) end @@ -92,10 +92,10 @@ it 'sets the SNAT pool' do expect(server_api) .to receive(:set_source_address_translation_snat_pool) - .with({ - virtual_servers: { item: ['/Common/myvip'] }, - pools: { item: ['/Common/mysnatpool'] } - }) + .with( + virtual_servers: { item: ['/Common/myvip'] }, + pools: { item: ['/Common/mysnatpool'] } + ) chef_run end end @@ -135,7 +135,7 @@ # must allow the client profile to be set allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:add_profile) end @@ -143,10 +143,10 @@ it 'sets the SNAT pool' do expect(server_api) .to receive(:set_source_address_translation_snat_pool) - .with({ - virtual_servers: { item: ['/Common/myvip'] }, - pools: { item: ['/Common/mysnatpool'] } - }) + .with( + virtual_servers: { item: ['/Common/myvip'] }, + pools: { item: ['/Common/mysnatpool'] } + ) chef_run end end diff --git a/spec/unit/recipes/test_create_vip_snat_pool_none_spec.rb b/spec/unit/recipes/test_create_vip_snat_pool_none_spec.rb index 02b1758..aba33cc 100644 --- a/spec/unit/recipes/test_create_vip_snat_pool_none_spec.rb +++ b/spec/unit/recipes/test_create_vip_snat_pool_none_spec.rb @@ -8,9 +8,9 @@ describe 'f5_test::test_create_vip_snat_pool_none' do let(:api) { double('F5::Icontrol') } let(:server_api) { double('F5::Icontrol::LocalLB::VirtualServer') } - let(:sat_type) { + let(:sat_type) do F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType - } + end let(:chef_run) do ChefSpec::SoloRunner.new( @@ -21,14 +21,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -62,12 +62,12 @@ before do allow(server_api) .to receive(:get_source_address_translation_type) { - { item: sat_type::SRC_TRANS_AUTOMAP.member } - } + { item: sat_type::SRC_TRANS_AUTOMAP.member } + } # must allow the client profile to be set allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:add_profile) end @@ -113,7 +113,7 @@ # must allow the client profile to be set allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:add_profile) end diff --git a/spec/unit/recipes/test_create_vip_spec.rb b/spec/unit/recipes/test_create_vip_spec.rb index 33012ca..7638747 100644 --- a/spec/unit/recipes/test_create_vip_spec.rb +++ b/spec/unit/recipes/test_create_vip_spec.rb @@ -17,14 +17,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -33,7 +33,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -43,7 +43,7 @@ before do # these vips have no profiles allow(server_api).to receive(:get_profile) { - { item: { item: [] }} + { item: { item: [] } } } allow(server_api).to receive(:get_destination_v2) { @@ -53,9 +53,10 @@ # these vips have their SAT set to None allow(server_api) .to receive(:get_source_address_translation_type) { - { item: [ - F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE - ]}} + { item: [ + F5::Icontrol::LocalLB::VirtualServer::SourceAddressTranslationType::SRC_TRANS_NONE, + ] } + } end context 'and the vip does not exist' do diff --git a/spec/unit/recipes/test_create_vip_ssl_profiles_spec.rb b/spec/unit/recipes/test_create_vip_ssl_profiles_spec.rb index 2101c2d..2200d28 100644 --- a/spec/unit/recipes/test_create_vip_ssl_profiles_spec.rb +++ b/spec/unit/recipes/test_create_vip_ssl_profiles_spec.rb @@ -7,12 +7,12 @@ describe 'f5_test::test_create_vip_ssl_profiles' do let(:api) { double('F5::Icontrol') } let(:server_api) { double('F5::Icontrol::LocalLB::VirtualServer') } - let(:profile_type) { + let(:profile_type) do F5::Icontrol::LocalLB::ProfileType - } - let(:profile_context_type) { + end + let(:profile_context_type) do F5::Icontrol::LocalLB::ProfileContextType - } + end let(:chef_run) do ChefSpec::SoloRunner.new( @@ -23,14 +23,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -39,7 +39,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) allow(server_api).to receive(:get_destination_v2) { { item: { address: '86.75.30.9', port: '80' } } } @@ -71,13 +71,13 @@ end it 'adds the client ssl profile' do - expect(server_api).to receive(:add_profile).with({ - virtual_servers: { item: ['/Common/myvip'] }, - profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: '/Common/client.cert' - }]}] - }}) + expect(server_api).to receive(:add_profile).with( + virtual_servers: { item: ['/Common/myvip'] }, + profiles: { item: [ { item: [ { + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: '/Common/client.cert', + }] }], + }) chef_run end end @@ -86,11 +86,11 @@ before do allow(server_api).to receive(:get_profile) { { item: { item: [{ - profile_type: profile_type::PROFILE_TYPE_CLIENT_SSL.member, - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: '/Common/client.cert' - }] - }} + profile_type: profile_type::PROFILE_TYPE_CLIENT_SSL.member, + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: '/Common/client.cert', + }], + } } } # must allow the server profile to be set @@ -98,13 +98,13 @@ end it 'does not add the client ssl profile' do - expect(server_api).to_not receive(:add_profile).with({ - virtual_servers: anything, - profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: anything - }]}] - }}) + expect(server_api).to_not receive(:add_profile).with( + virtual_servers: anything, + profiles: { item: [ { item: [ { + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: anything, + }] }], + }) chef_run end end @@ -120,13 +120,13 @@ end it 'adds the server ssl profile' do - expect(server_api).to receive(:add_profile).with({ + expect(server_api).to receive(:add_profile).with( virtual_servers: { item: ['/Common/myvip'] }, profiles: { item: [ { item: [ { profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: '/Common/server.cert' - }]}] - }}) + profile_name: '/Common/server.cert', + }] }], + }) chef_run end end @@ -135,23 +135,23 @@ before do allow(server_api).to receive(:get_profile) { { item: { item: [{ - profile_type: profile_type::PROFILE_TYPE_SERVER_SSL.member, - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: '/Common/server.cert' - }] - }} + profile_type: profile_type::PROFILE_TYPE_SERVER_SSL.member, + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: '/Common/server.cert', + }], + } } } end it 'does not add the server ssl profile' do - expect(server_api).to_not receive(:add_profile).with({ + expect(server_api).to_not receive(:add_profile).with( virtual_servers: anything, profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: anything - }] - }] - }}) + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: anything, + }], + }], + }) chef_run end end @@ -181,13 +181,13 @@ end it 'adds the client ssl profile' do - expect(server_api).to receive(:add_profile).with({ - virtual_servers: { item: ['/Common/myvip'] }, - profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: '/Common/client.cert' - }]}] - }}) + expect(server_api).to receive(:add_profile).with( + virtual_servers: { item: ['/Common/myvip'] }, + profiles: { item: [ { item: [ { + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: '/Common/client.cert', + }] }], + }) chef_run end end @@ -196,11 +196,11 @@ before do allow(server_api).to receive(:get_profile) { { item: { item: [{ - profile_type: profile_type::PROFILE_TYPE_CLIENT_SSL.member, - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: '/Common/client.cert' - }] - }} + profile_type: profile_type::PROFILE_TYPE_CLIENT_SSL.member, + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: '/Common/client.cert', + }], + } } } # must allow the server profile to be set @@ -208,13 +208,13 @@ end it 'does not add the client ssl profile' do - expect(server_api).to_not receive(:add_profile).with({ - virtual_servers: anything, - profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: anything - }]}] - }}) + expect(server_api).to_not receive(:add_profile).with( + virtual_servers: anything, + profiles: { item: [ { item: [ { + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, + profile_name: anything, + }] }], + }) chef_run end end @@ -230,13 +230,13 @@ end it 'adds the server ssl profile' do - expect(server_api).to receive(:add_profile).with({ + expect(server_api).to receive(:add_profile).with( virtual_servers: { item: ['/Common/myvip'] }, profiles: { item: [ { item: [ { profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: '/Common/server.cert' - }]}] - }}) + profile_name: '/Common/server.cert', + }] }], + }) chef_run end end @@ -245,23 +245,23 @@ before do allow(server_api).to receive(:get_profile) { { item: { item: [{ - profile_type: profile_type::PROFILE_TYPE_SERVER_SSL.member, - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: '/Common/server.cert' - }] - }} + profile_type: profile_type::PROFILE_TYPE_SERVER_SSL.member, + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: '/Common/server.cert', + }], + } } } end it 'does not add the server ssl profile' do - expect(server_api).to_not receive(:add_profile).with({ + expect(server_api).to_not receive(:add_profile).with( virtual_servers: anything, profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: anything - }] - }] - }}) + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: anything, + }], + }], + }) chef_run end end @@ -276,27 +276,27 @@ it 'adds a client profile' do allow(server_api).to receive(:add_profile) - expect(server_api).to receive(:add_profile).with({ + expect(server_api).to receive(:add_profile).with( virtual_servers: { item: ['/Common/myvip'] }, profiles: { item: [ { item: [ { profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: '/Common/client.cert' - }]}] - }}) + profile_name: '/Common/client.cert', + }] }], + }) chef_run end it 'adds a server profile' do allow(server_api).to receive(:add_profile) - expect(server_api).to receive(:add_profile).with({ + expect(server_api).to receive(:add_profile).with( virtual_servers: anything, profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: anything - }] - }] - }}) + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: anything, + }], + }], + }) chef_run end end @@ -306,8 +306,8 @@ allow(server_api).to receive(:get_profile) { { item: { item: - {:profile_type=>"PROFILE_TYPE_TCP", :profile_context=>"PROFILE_CONTEXT_TYPE_ALL", :profile_name=>"/Common/tcp"} - } + { profile_type: 'PROFILE_TYPE_TCP', profile_context: 'PROFILE_CONTEXT_TYPE_ALL', profile_name: '/Common/tcp' }, + }, } } end @@ -315,27 +315,27 @@ it 'adds a client profile' do allow(server_api).to receive(:add_profile) - expect(server_api).to receive(:add_profile).with({ + expect(server_api).to receive(:add_profile).with( virtual_servers: { item: ['/Common/myvip'] }, profiles: { item: [ { item: [ { profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_CLIENT.member, - profile_name: '/Common/client.cert' - }]}] - }}) + profile_name: '/Common/client.cert', + }] }], + }) chef_run end it 'adds a server profile' do allow(server_api).to receive(:add_profile) - expect(server_api).to receive(:add_profile).with({ + expect(server_api).to receive(:add_profile).with( virtual_servers: anything, profiles: { item: [ { item: [ { - profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, - profile_name: anything - }] - }] - }}) + profile_context: profile_context_type::PROFILE_CONTEXT_TYPE_SERVER.member, + profile_name: anything, + }], + }], + }) chef_run end end diff --git a/spec/unit/recipes/test_create_vip_staged_firewall_policy_named_spec.rb b/spec/unit/recipes/test_create_vip_staged_firewall_policy_named_spec.rb index cd60fd1..73cc219 100644 --- a/spec/unit/recipes/test_create_vip_staged_firewall_policy_named_spec.rb +++ b/spec/unit/recipes/test_create_vip_staged_firewall_policy_named_spec.rb @@ -18,14 +18,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) # these vips have no profiles allow(server_api).to receive(:get_profile) { { item: { item: [] } } @@ -74,13 +74,13 @@ end it 'adds the staged firewall policy to the vip' do - expect(server_api).to receive(:get_staged_firewall_policy).with({ + expect(server_api).to receive(:get_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_staged_firewall_policy).with({ - virtual_servers: { item: ['/Common/myvip'] }, - policies: { item: [ '/Common/myfwpolicy-staged' ] } - }) + ) + expect(server_api).to receive(:set_staged_firewall_policy).with( + virtual_servers: { item: ['/Common/myvip'] }, + policies: { item: [ '/Common/myfwpolicy-staged' ] } + ) chef_run end end @@ -96,12 +96,12 @@ end it 'fails to converge' do - expect(server_api).to receive(:get_staged_firewall_policy).with({ + expect(server_api).to receive(:get_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect { + ) + expect do chef_run - }.to raise_error /Firewall policy myfwpolicy-staged does not exist/ + end.to raise_error /Firewall policy myfwpolicy-staged does not exist/ end end end @@ -133,13 +133,13 @@ end it 'adds the staged firewall policy to the vip' do - expect(server_api).to receive(:get_staged_firewall_policy).with({ + expect(server_api).to receive(:get_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_staged_firewall_policy).with({ - virtual_servers: { item: ['/Common/myvip'] }, - policies: { item: [ '/Common/myfwpolicy-staged' ] } - }) + ) + expect(server_api).to receive(:set_staged_firewall_policy).with( + virtual_servers: { item: ['/Common/myvip'] }, + policies: { item: [ '/Common/myfwpolicy-staged' ] } + ) chef_run end end @@ -155,14 +155,13 @@ end it 'fails to converge' do - expect(server_api).to receive(:get_staged_firewall_policy).with({ + expect(server_api).to receive(:get_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect { + ) + expect do chef_run - }.to raise_error /Firewall policy myfwpolicy-staged does not exist/ + end.to raise_error /Firewall policy myfwpolicy-staged does not exist/ end end end - end diff --git a/spec/unit/recipes/test_create_vip_staged_firewall_policy_none_spec.rb b/spec/unit/recipes/test_create_vip_staged_firewall_policy_none_spec.rb index cfc5591..348771c 100644 --- a/spec/unit/recipes/test_create_vip_staged_firewall_policy_none_spec.rb +++ b/spec/unit/recipes/test_create_vip_staged_firewall_policy_none_spec.rb @@ -18,14 +18,14 @@ node.normal[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', - password: 'testing' + password: 'testing', } end.converge(described_recipe) end before do allow(F5::Icontrol::API).to receive(:new) { api } - + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api) .to receive_message_chain('LocalLB.VirtualServer') { server_api } @@ -37,7 +37,7 @@ stub_data_bag_item('f5', 'default') .and_return(host: '1.2.3.4', username: 'api', password: 'testing') - allow(server_api).to receive(:get_rule).and_return({item: {}}) + allow(server_api).to receive(:get_rule).and_return(item: {}) # these vips have no profiles allow(server_api).to receive(:get_profile) { { item: { item: [] } } @@ -62,7 +62,6 @@ allow(server_api).to receive(:set_default_pool_name) end - context 'and the staged firewall policy is set to empty' do before do allow(fw_policy_api).to receive(:get_list) { @@ -75,14 +74,14 @@ end it 'unsets the staged firewall policy' do - expect(server_api).to receive(:get_staged_firewall_policy).with({ + expect(server_api).to receive(:get_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_staged_firewall_policy).with({ + ) + expect(server_api).to receive(:set_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] }, policies: { item: [ '' ] } - }) - chef_run + ) + chef_run end end end @@ -114,16 +113,15 @@ end it 'unsets the staged firewall policy' do - expect(server_api).to receive(:get_staged_firewall_policy).with({ + expect(server_api).to receive(:get_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] } - }) - expect(server_api).to receive(:set_staged_firewall_policy).with({ + ) + expect(server_api).to receive(:set_staged_firewall_policy).with( virtual_servers: { item: ['/Common/myvip'] }, policies: { item: [ '' ] } - }) + ) chef_run end end end - end diff --git a/spec/unit/recipes/test_manage_nodes_disabled_spec.rb b/spec/unit/recipes/test_manage_nodes_disabled_spec.rb index 7d974a6..d6ac642 100644 --- a/spec/unit/recipes/test_manage_nodes_disabled_spec.rb +++ b/spec/unit/recipes/test_manage_nodes_disabled_spec.rb @@ -8,18 +8,18 @@ describe 'f5_test::test_manage_nodes_disabled' do let(:api) { double('F5::Icontrol') } let (:node) { double('node') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) - } + end let(:enabled_status) { F5::Icontrol::LocalLB::EnabledStatus } let(:enabled_state) { F5::Icontrol::Common::EnabledState } before do allow(F5::Icontrol::API).to receive(:new) { api } + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api).to receive_message_chain('LocalLB.NodeAddressV2') { node } allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') - end context 'managing explicitly disabled nodes' do @@ -32,18 +32,18 @@ context 'when the node does not exist' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/a', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/a', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } # after the node is created, it's default status will be enabled: # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx - allow(node).to receive(:get_object_status).with({ - nodes: { item: ['/Common/fauxhai.local'] } - }).and_return({ item: { - availability_status: [], - enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, - status_description: '' - }}) + allow(node).to receive(:get_object_status).with( + nodes: { item: ['/Common/fauxhai.local'] } + ).and_return(item: { + availability_status: [], + enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, + status_description: '', + }) end it 'does add the node' do @@ -55,10 +55,10 @@ it 'does set the node enabled status to disabled' do allow(node).to receive(:create) # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__set_session_enabled_state.ashx - expect(node).to receive(:set_session_enabled_state).with({ + expect(node).to receive(:set_session_enabled_state).with( nodes: { item: [ '/Common/fauxhai.local' ] }, states: { item: [ enabled_state::STATE_DISABLED ] } - }) + ) chef_run end end @@ -66,20 +66,20 @@ context 'the node exists' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/fauxhai.local', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/fauxhai.local', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end context 'and is enabled' do before do # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx - allow(node).to receive(:get_object_status).with({ - nodes: { item: ['/Common/fauxhai.local'] } - }).and_return({ item: { - availability_status: [], - enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, - status_description: '' - }}) + allow(node).to receive(:get_object_status).with( + nodes: { item: ['/Common/fauxhai.local'] } + ).and_return(item: { + availability_status: [], + enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, + status_description: '', + }) end it 'does not add the node' do @@ -90,10 +90,10 @@ it 'does set the node enabled status to disabled' do # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__set_session_enabled_state.ashx - expect(node).to receive(:set_session_enabled_state).with({ + expect(node).to receive(:set_session_enabled_state).with( nodes: { item: [ '/Common/fauxhai.local' ] }, states: { item: [ enabled_state::STATE_DISABLED ] } - }) + ) chef_run end end @@ -101,13 +101,13 @@ context 'and is disabled' do before do # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx - allow(node).to receive(:get_object_status).with({ - nodes: { item: ['/Common/fauxhai.local'] } - }).and_return({ item: { - availability_status: [], - enabled_status: enabled_status::ENABLED_STATUS_DISABLED.member, - status_description: '' - }}) + allow(node).to receive(:get_object_status).with( + nodes: { item: ['/Common/fauxhai.local'] } + ).and_return(item: { + availability_status: [], + enabled_status: enabled_status::ENABLED_STATUS_DISABLED.member, + status_description: '', + }) end it 'does not add the node' do diff --git a/spec/unit/recipes/test_manage_nodes_enabled_spec.rb b/spec/unit/recipes/test_manage_nodes_enabled_spec.rb index b852da8..f8d4b08 100644 --- a/spec/unit/recipes/test_manage_nodes_enabled_spec.rb +++ b/spec/unit/recipes/test_manage_nodes_enabled_spec.rb @@ -8,14 +8,15 @@ describe 'f5_test::test_manage_nodes_enabled' do let(:api) { double('F5::Icontrol') } let (:node) { double('node') } - let(:chef_run) { + let(:chef_run) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) - } + end let(:enabled_status) { F5::Icontrol::LocalLB::EnabledStatus } let(:enabled_state) { F5::Icontrol::Common::EnabledState } before do allow(F5::Icontrol::API).to receive(:new) { api } + allow(api).to receive_message_chain('System.Session.set_active_folder') allow(api).to receive_message_chain('LocalLB.NodeAddressV2') { node } allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') @@ -31,18 +32,18 @@ context 'when the node does not exist' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/a', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/a', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } # after the node is created, it's default status will be enabled: # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx - allow(node).to receive(:get_object_status).with({ - nodes: { item: ['/Common/fauxhai.local'] } - }).and_return({ item: { - availability_status: [], - enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, - status_description: '' - }}) + allow(node).to receive(:get_object_status).with( + nodes: { item: ['/Common/fauxhai.local'] } + ).and_return(item: { + availability_status: [], + enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, + status_description: '', + }) end it 'does add the node' do @@ -61,20 +62,20 @@ context 'the node exists' do before do expect(node).to receive(:get_list) { - { :item => ['/Common/fauxhai.local', '/Common/two'], :"@s:type" => 'A:Array', :"@a:array_type" => 'y:string[2]' } + { item: ['/Common/fauxhai.local', '/Common/two'], "@s:type": 'A:Array', "@a:array_type": 'y:string[2]' } } end context 'and is enabled' do before do # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx - allow(node).to receive(:get_object_status).with({ - nodes: { item: ['/Common/fauxhai.local'] } - }).and_return({ item: { - availability_status: [], - enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, - status_description: '' - }}) + allow(node).to receive(:get_object_status).with( + nodes: { item: ['/Common/fauxhai.local'] } + ).and_return(item: { + availability_status: [], + enabled_status: enabled_status::ENABLED_STATUS_ENABLED.member, + status_description: '', + }) end it 'does not add the node' do @@ -92,13 +93,13 @@ context 'and is disabled' do before do # https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx - allow(node).to receive(:get_object_status).with({ - nodes: { item: ['/Common/fauxhai.local'] } - }).and_return({ item: { - availability_status: [], - enabled_status: enabled_status::ENABLED_STATUS_DISABLED.member, - status_description: '' - }}) + allow(node).to receive(:get_object_status).with( + nodes: { item: ['/Common/fauxhai.local'] } + ).and_return(item: { + availability_status: [], + enabled_status: enabled_status::ENABLED_STATUS_DISABLED.member, + status_description: '', + }) end it 'does not add the node' do @@ -108,10 +109,10 @@ end it 'does set the node enabled status to enabled' do - expect(node).to receive(:set_session_enabled_state).with({ + expect(node).to receive(:set_session_enabled_state).with( nodes: { item: [ '/Common/fauxhai.local' ] }, states: { item: [ enabled_state::STATE_ENABLED ] } - }) + ) chef_run end end diff --git a/spec/unit/recipes/test_other_lb_spec.rb b/spec/unit/recipes/test_other_lb_spec.rb index 6b0f19b..06d64ba 100644 --- a/spec/unit/recipes/test_other_lb_spec.rb +++ b/spec/unit/recipes/test_other_lb_spec.rb @@ -2,6 +2,7 @@ require 'f5/icontrol' require_relative '../../../libraries/chef_f5' require_relative '../../../libraries/credentials' +require_relative '../../../libraries/gem_helper' describe 'f5_test::test_other_lb' do let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) } @@ -14,7 +15,7 @@ it 'calls the second load balancer' do expect(F5::Icontrol::API).to receive(:new).with(nil, host: '4.4.4.4', username: 'test2', password: 'testing').and_call_original - expect(F5::Icontrol::API).to receive(:new).with('LocalLB', host: '4.4.4.4', username: 'test2', password: 'testing').and_raise(ArgumentError) + expect(F5::Icontrol::API).to receive(:new).with('System', host: '4.4.4.4', username: 'test2', password: 'testing').and_raise(ArgumentError) expect { chef_run }.to raise_error(ArgumentError) end end diff --git a/spec/unit/recipes/test_other_partition_spec.rb b/spec/unit/recipes/test_other_partition_spec.rb new file mode 100644 index 0000000..b3ff0f8 --- /dev/null +++ b/spec/unit/recipes/test_other_partition_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' +require 'f5/icontrol' +require_relative '../../../libraries/chef_f5' +require_relative '../../../libraries/credentials' +require_relative '../../../libraries/gem_helper' + +describe 'f5_test::test_other_partition' do + let(:api) { double('F5::Icontrol') } + let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04', step_into: ['f5_pool']).converge(described_recipe) } + + before do + allow(F5::Icontrol::API).to receive(:new) { api } + allow(api).to receive_message_chain('System.Session.set_active_folder').and_raise(ArgumentError) + allow_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile_libraries).and_return(true) + stub_data_bag_item('f5', 'default').and_return(host: '1.2.3.4', username: 'api', password: 'testing') + stub_data_bag_item('f5', 'lb2').and_return(host: '4.4.4.4', username: 'test2', password: 'testing') + end + + it 'calls the second load balancer' do + expect(F5::Icontrol::API).to receive(:new).with(nil, host: '4.4.4.4', username: 'test2', password: 'testing') + expect(api).to receive_message_chain('System.Session.set_active_folder').with(folder: '/DMZ') + expect { chef_run }.to raise_error(ArgumentError) + end +end diff --git a/test/fixtures/cookbooks/f5_test/recipes/test_create_irule.rb b/test/fixtures/cookbooks/f5_test/recipes/test_create_irule.rb index edb1609..a4d5faa 100644 --- a/test/fixtures/cookbooks/f5_test/recipes/test_create_irule.rb +++ b/test/fixtures/cookbooks/f5_test/recipes/test_create_irule.rb @@ -1,10 +1,10 @@ f5_irule 'test-irule' do definition <<-EOL -# For hosts that serve both http but attached to http and https vips, +# For hosts that serve both http but attached to http and https vips, # this lets them know if the request # originally came in on https when HTTP_REQUEST { HTTP::header insert HTTPS true } EOL -end \ No newline at end of file +end diff --git a/test/fixtures/cookbooks/f5_test/recipes/test_create_monitor.rb b/test/fixtures/cookbooks/f5_test/recipes/test_create_monitor.rb index 68fda8c..5b9ebe5 100644 --- a/test/fixtures/cookbooks/f5_test/recipes/test_create_monitor.rb +++ b/test/fixtures/cookbooks/f5_test/recipes/test_create_monitor.rb @@ -7,4 +7,4 @@ 'STYPE_SEND' => 'GET /health HTTP/1.1\r\nHost: dontmatter\r\nConnection: Close\r\n\r\n', 'STYPE_RECEIVE' => 'status.*UP' ) -end \ No newline at end of file +end diff --git a/test/fixtures/cookbooks/f5_test/recipes/test_create_vip_snat_pool_none.rb b/test/fixtures/cookbooks/f5_test/recipes/test_create_vip_snat_pool_none.rb index ea31c5a..c010edd 100644 --- a/test/fixtures/cookbooks/f5_test/recipes/test_create_vip_snat_pool_none.rb +++ b/test/fixtures/cookbooks/f5_test/recipes/test_create_vip_snat_pool_none.rb @@ -3,6 +3,6 @@ port '80' protocol 'PROTOCOL_TCP' pool 'reallybasic' - + snat_pool :none end diff --git a/test/fixtures/cookbooks/f5_test/recipes/test_other_partition.rb b/test/fixtures/cookbooks/f5_test/recipes/test_other_partition.rb new file mode 100644 index 0000000..279fed5 --- /dev/null +++ b/test/fixtures/cookbooks/f5_test/recipes/test_other_partition.rb @@ -0,0 +1,7 @@ +f5_pool 'reallybasic' do + ip '127.0.0.1' + host 'test_host' + port 80 + load_balancer 'lb2' + partition 'DMZ' +end