serverspec-extra-types 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +6 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +191 -0
  10. data/Rakefile +7 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/serverspec_extra_types.rb +3 -0
  14. data/lib/serverspec_extra_types/helpers/properties.rb +11 -0
  15. data/lib/serverspec_extra_types/matchers.rb +34 -0
  16. data/lib/serverspec_extra_types/matchers/be_a_manager_node.rb +15 -0
  17. data/lib/serverspec_extra_types/matchers/be_a_worker_node.rb +14 -0
  18. data/lib/serverspec_extra_types/matchers/be_active.rb +11 -0
  19. data/lib/serverspec_extra_types/matchers/configure_queue.rb +8 -0
  20. data/lib/serverspec_extra_types/matchers/have_count.rb +11 -0
  21. data/lib/serverspec_extra_types/matchers/have_domain_name.rb +10 -0
  22. data/lib/serverspec_extra_types/matchers/have_engine_version.rb +11 -0
  23. data/lib/serverspec_extra_types/matchers/have_environment_variable.rb +21 -0
  24. data/lib/serverspec_extra_types/matchers/have_ha_mode.rb +5 -0
  25. data/lib/serverspec_extra_types/matchers/have_ha_nodes.rb +8 -0
  26. data/lib/serverspec_extra_types/matchers/have_ha_sync_mode.rb +5 -0
  27. data/lib/serverspec_extra_types/matchers/have_host.rb +8 -0
  28. data/lib/serverspec_extra_types/matchers/have_hostname.rb +6 -0
  29. data/lib/serverspec_extra_types/matchers/have_image.rb +8 -0
  30. data/lib/serverspec_extra_types/matchers/have_image_sha.rb +5 -0
  31. data/lib/serverspec_extra_types/matchers/have_label.rb +20 -0
  32. data/lib/serverspec_extra_types/matchers/have_mount.rb +11 -0
  33. data/lib/serverspec_extra_types/matchers/have_network.rb +8 -0
  34. data/lib/serverspec_extra_types/matchers/have_placement_constraint.rb +8 -0
  35. data/lib/serverspec_extra_types/matchers/have_replica_count.rb +8 -0
  36. data/lib/serverspec_extra_types/matchers/have_restart_limit.rb +8 -0
  37. data/lib/serverspec_extra_types/matchers/have_restart_policy.rb +8 -0
  38. data/lib/serverspec_extra_types/matchers/have_user.rb +10 -0
  39. data/lib/serverspec_extra_types/matchers/have_vhost.rb +5 -0
  40. data/lib/serverspec_extra_types/matchers/include_regex.rb +5 -0
  41. data/lib/serverspec_extra_types/matchers/map_port.rb +25 -0
  42. data/lib/serverspec_extra_types/matchers/mirror_all.rb +5 -0
  43. data/lib/serverspec_extra_types/matchers/publish_all_ports.rb +3 -0
  44. data/lib/serverspec_extra_types/matchers/read_from_queue.rb +8 -0
  45. data/lib/serverspec_extra_types/matchers/write_to_queue.rb +8 -0
  46. data/lib/serverspec_extra_types/types.rb +18 -0
  47. data/lib/serverspec_extra_types/types/api_base.rb +36 -0
  48. data/lib/serverspec_extra_types/types/consul_base.rb +40 -0
  49. data/lib/serverspec_extra_types/types/consul_node.rb +20 -0
  50. data/lib/serverspec_extra_types/types/consul_node_list.rb +32 -0
  51. data/lib/serverspec_extra_types/types/consul_service.rb +24 -0
  52. data/lib/serverspec_extra_types/types/consul_service_list.rb +32 -0
  53. data/lib/serverspec_extra_types/types/docker_container.rb +124 -0
  54. data/lib/serverspec_extra_types/types/docker_node.rb +41 -0
  55. data/lib/serverspec_extra_types/types/docker_service.rb +121 -0
  56. data/lib/serverspec_extra_types/types/rabbitmq_base.rb +38 -0
  57. data/lib/serverspec_extra_types/types/rabbitmq_node_list.rb +18 -0
  58. data/lib/serverspec_extra_types/types/rabbitmq_user_permission.rb +39 -0
  59. data/lib/serverspec_extra_types/types/rabbitmq_vhost_list.rb +22 -0
  60. data/lib/serverspec_extra_types/types/rabbitmq_vhost_policy.rb +57 -0
  61. data/lib/serverspec_extra_types/version.rb +3 -0
  62. data/properties.yml +23 -0
  63. data/serverspec-extra-types.gemspec +36 -0
  64. metadata +232 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1c4ce9a546e2c4e66f97a22a3898e5aa5d02fa614f6c4ae1baa7ea00fa72ac41
4
+ data.tar.gz: 5d7c518a35cc6c4815873cf4d3a6c113d5f94131e4fc6f74e8e27ab9b07049be
5
+ SHA512:
6
+ metadata.gz: c4d2a3f3606a724c0d1b8b50711432a59042b0de563d693172a9293aa125102d8e39de27235285ed63943ad60e8fb870772ceb70b7d187bc6e765d7c6ce1e648
7
+ data.tar.gz: 6caa5ca15e36ccb6551868b328800570068a01fc7fecb425c9dc85665d3668de032d10c65002ec8b14730a945d18c5c356c00d97948d5359f65233a390318a6b
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea/
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
13
+ .vagrant/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'serverspec-extra-types.gemspec'
4
+
5
+ Metric/LineLength:
6
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andrew.g.wardrobe@googlemail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in serverspec-extra-types.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrew Wardrobe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # ServerspecExtraTypes
2
+
3
+ serverspec-extra-types is a set of addition resource types and matchers for ServerSpec, providing types for technologies such as
4
+ docker swarm, consul, and rabbitmq.
5
+
6
+ All checks run on the target, which can be useful when executing via a bastion host
7
+
8
+
9
+ ## Requirements
10
+ * rabbitmq and consul checks requires curl to be installed on the target
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'serverspec-extra-types'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install serverspec-extra-types
27
+
28
+ ## Usage
29
+
30
+ ### docker_container
31
+ Extension of the serverspec docker container type, and provides the following matchers:
32
+
33
+ this type now supports selecting the container via a filter or by name
34
+ ##### exist
35
+ Check if a container exists by name
36
+ ```ruby
37
+ describe docker_container('focused_currie') do
38
+ it { should exist }
39
+ end
40
+
41
+ # Using a filter (useful for containers launch via docker swarm)
42
+ describe docker_container('name=focused_currie') do
43
+ it { should exist }
44
+ end
45
+ ```
46
+ Check if a container exists by filter
47
+ ```ruby
48
+ # Look for a container publishing port 80
49
+ describe docker_container('publish=80') do
50
+ it { should exist }
51
+ end
52
+ ```
53
+
54
+ ##### be_running
55
+ Check if a container is runnig (from serverspec)
56
+ ```ruby
57
+ describe docker_container('focused_curie') do
58
+ it { should be_running }
59
+ end
60
+ ```
61
+ ##### have_image
62
+ Check if container is running a spefic image
63
+ ```ruby
64
+ describe docker_container('focused_currie') do
65
+ it { should have_image('jenkins/jenkins:lts') }
66
+ end
67
+ ```
68
+ ##### have_hostname / has_host_name
69
+ Check container hostname
70
+ ```ruby
71
+ describe docker_container('focused_currie') do
72
+ it { should have_hostname('container1') }
73
+ end
74
+ ```
75
+ ##### have_domainname / have_domain_name
76
+ Check container domain name
77
+ ```ruby
78
+ describe docker_container('focused_currie') do
79
+ it { should have_domainname('leek.com') }
80
+ end
81
+ ```
82
+ ##### have_user / run_as_user
83
+ Check if container is running as the specified user
84
+ ```ruby
85
+ describe docker_container('focused_currie') do
86
+ it { should run_as_user('jenkins') }
87
+ end
88
+ ```
89
+
90
+ ##### map_port
91
+ Check if host port is mapped to container port
92
+ ```ruby
93
+ describe docker_container('focused_currie') do
94
+ it { should map_port('80','8080') }
95
+ end
96
+ ```
97
+ Check if host port is mapped to container port using a specific protocol
98
+ ```ruby
99
+ describe docker_container('focused_currie') do
100
+ it { should map_port('80','8080').using_protocol('tcp') }
101
+ end
102
+ ```
103
+ ##### have_volume
104
+ Check the for a volume (from serverspec)
105
+ ```ruby
106
+ describe docker_container('focused_currie') do
107
+ it { it { should have_volume('/tmp','/data') }}
108
+ end
109
+ ```
110
+ ##### have_mount
111
+ Check the for mounted volume
112
+ ```ruby
113
+ describe docker_container('focused_currie') do
114
+ it { should have_mount('/var/run/docker.sock', '/var/run/docker.sock') }
115
+ end
116
+ ```
117
+ ##### have_restart_policy
118
+ Check the containers restart policy
119
+ ```ruby
120
+ describe docker_container('focused_currie') do
121
+ it { should have_restart_policy('always') }
122
+ end
123
+ ```
124
+ ##### have_restart_limit
125
+ Check the containers restart limit
126
+ ```ruby
127
+ describe docker_container('focused_currie') do
128
+ it { should have_restart_limit(1) }
129
+ end
130
+ ```
131
+ ##### have_host
132
+ Check for additional /etc/hosts entries
133
+ ```ruby
134
+ describe docker_container('focused_currie') do
135
+ it { should have_host('8.8.8.8 dns') }
136
+ end
137
+ ```
138
+ ##### have_environment_variable
139
+ Check if the container has an specific environment variable
140
+ ```ruby
141
+ describe docker_container('focused_currie') do
142
+ it { should have_environment_variable('CONSUL_VERSION') }
143
+ end
144
+ # check its value
145
+ describe docker_container('focused_currie') do
146
+ it { should have_environment_variable('CONSUL_VERSION').with_value('1.2.0') }
147
+ end
148
+ ```
149
+
150
+ ##### be_privileged
151
+ Check if the container runs in privileged mode
152
+ ```ruby
153
+ describe docker_container('focused_currie') do
154
+ it { should be_privileged }
155
+ end
156
+ ```
157
+
158
+ ##### publishes_all_ports
159
+ Check if the container publishes all exposed ports
160
+ ```ruby
161
+ describe docker_container('focused_currie') do
162
+ it { should publishes_all_ports }
163
+ end
164
+ ```
165
+
166
+ ### docker_service
167
+ ##### exist
168
+ Check if a service exists by name
169
+ ```ruby
170
+ describe docker_service('my_service') do
171
+ it { should exist }
172
+ end
173
+ ```
174
+
175
+ ## Development
176
+
177
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
178
+
179
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
180
+
181
+ ## Contributing
182
+
183
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andrewwardrobe/serverspec-extra-types. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
184
+
185
+ ## License
186
+
187
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
188
+
189
+ ## Code of Conduct
190
+
191
+ Everyone interacting in the Serverspec::Extra::Types project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/serverspec-extra-types/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'serverspec_launcher/rake_tasks'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'serverspec_extra_types/extra/serverspec_extra_types'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require 'serverspec_extra_types/version'
2
+ require 'serverspec_extra_types/matchers'
3
+ require 'serverspec_extra_types/types'
@@ -0,0 +1,11 @@
1
+ require 'specinfra'
2
+
3
+ rabbitmq_user = ENV['RABBITMQ_USER'] || 'guest'
4
+ rabbitmq_password = ENV['RABBITMQ_PASSWORD'] || 'guest'
5
+ rabbitmq_url = ENV['RABBITMQ_URL'] || 'http://localhost:15672'
6
+ props = {
7
+ rabbitmq_user: rabbitmq_user,
8
+ rabbitmq_password: rabbitmq_password,
9
+ rabbitmq_url: rabbitmq_url
10
+ }
11
+ set_property props
@@ -0,0 +1,34 @@
1
+
2
+ #--- Docker Matchers
3
+ require 'serverspec_extra_types/matchers/be_active'
4
+ require 'serverspec_extra_types/matchers/be_a_manager_node'
5
+ require 'serverspec_extra_types/matchers/be_a_worker_node'
6
+ require 'serverspec_extra_types/matchers/have_domain_name'
7
+ require 'serverspec_extra_types/matchers/have_engine_version'
8
+ require 'serverspec_extra_types/matchers/have_placement_constraint'
9
+ require 'serverspec_extra_types/matchers/have_hostname'
10
+ require 'serverspec_extra_types/matchers/have_host'
11
+ require 'serverspec_extra_types/matchers/have_image'
12
+ require 'serverspec_extra_types/matchers/have_image_sha'
13
+ require 'serverspec_extra_types/matchers/have_restart_limit'
14
+ require 'serverspec_extra_types/matchers/have_restart_policy'
15
+ require 'serverspec_extra_types/matchers/have_environment_variable'
16
+ require 'serverspec_extra_types/matchers/have_user'
17
+ require 'serverspec_extra_types/matchers/have_mount'
18
+ require 'serverspec_extra_types/matchers/publish_all_ports'
19
+ require 'serverspec_extra_types/matchers/map_port'
20
+ require 'serverspec_extra_types/matchers/be_active'
21
+ require 'serverspec_extra_types/matchers/include_regex'
22
+ require 'serverspec_extra_types/matchers/have_network'
23
+ require 'serverspec_extra_types/matchers/have_replica_count'
24
+
25
+ #--- RabbitMQ Matchers
26
+ require 'serverspec_extra_types/matchers/have_ha_mode'
27
+ require 'serverspec_extra_types/matchers/have_ha_nodes'
28
+ require 'serverspec_extra_types/matchers/have_vhost'
29
+ require 'serverspec_extra_types/matchers/have_ha_sync_mode'
30
+ require 'serverspec_extra_types/matchers/mirror_all'
31
+ require 'serverspec_extra_types/matchers/read_from_queue'
32
+ require 'serverspec_extra_types/matchers/write_to_queue'
33
+ require 'serverspec_extra_types/matchers/configure_queue'
34
+ require 'serverspec_extra_types/matchers/have_count'
@@ -0,0 +1,15 @@
1
+ RSpec::Matchers.define :be_a_manager_node do
2
+ match do |actual|
3
+ actual.role == 'manager'
4
+ end
5
+ failure_message do |actual|
6
+ "expected '#{actual.role}' to be manager"
7
+ end
8
+ description do
9
+ 'be a manager node'
10
+ end
11
+ end
12
+
13
+ RSpec::Matchers.alias_matcher :be_manager, :be_a_manager_node
14
+ RSpec::Matchers.alias_matcher :be_a_manager, :be_a_manager_node
15
+ RSpec::Matchers.alias_matcher :be_manager_node, :be_a_manager_node