kitchen-habitat 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 214fe452fd77fdc55785e5f8d14b0187f1b940bf
4
- data.tar.gz: c3e5686edd119d4c16b44393992362dfe86e759f
3
+ metadata.gz: 1ef68d3e9be79866921be55aeadcff446de300bc
4
+ data.tar.gz: 99fcd6c0e79d77d273e029289b53109ac206e0fd
5
5
  SHA512:
6
- metadata.gz: 323f8e9d9b496645e4bee1e533fcbd91ba866164f2f62b72b21bbddd5249e503fa5384176cd0b00961fedb3fbc4bffeebc59b748f6fc08953515eb573589a306
7
- data.tar.gz: c664eb0a7b82c7303e0ba62b1d7ffc1501e40ad49d0e52ecb72c91a49bc21b9042e856292fc00004bba025d4d73c10743570df316470aa5d6f977e4d5eacd2d4
6
+ metadata.gz: 8e398a2ac127fb4871f49560392320c45b69f664a8f6081dcc992df3014cf33b88d343dc8dc12d72a6b705c1da8a9c69ab29dd7b8f7b9884e2181068bb2f612d
7
+ data.tar.gz: 7da3596810126194576dcc2dbe2a52a7ffdd1250a6e1101f6067f2cd98fde925f1c3da7b54215cf1e07989499a9e1b7ed27ba8b95cee8dd69ee8cd2c7074862e
data/README.md CHANGED
@@ -19,9 +19,23 @@ You'll need the test-kitchen & kitchen-habitat gems installed in your system, al
19
19
 
20
20
  ### Supervisor Settings
21
21
 
22
- * `hab_sup`
22
+ * `hab_sup_origin`
23
23
  * Package identification for the supervisor to use.
24
- * Defaults to `core/hab-sup`
24
+ * Defaults to `core`, or, if `hab_sup_artifact_name` is supplied, the `hab_sup_origin` will be parsed from the filename of the hart file.
25
+ * `hab_sup_name`
26
+ * Name of the supervisor package
27
+ * Defaults to `hab-sup`, or, if `hab_sup_artifact_name` is supplied, the `hab_sup_name` will be parsed from the filename of the hart file.
28
+ * `hab_sup_version`
29
+ * Version number of `hab-sup` to run
30
+ * Defaults to `nil`, or, if `hab_sup_artifact_name` is supplied, the `hab_sup_version` will be parsed from the filename of the hart file.
31
+ * `hab_sup_timestamp`
32
+ * Timestamp of the `hab-sup` package to run
33
+ * Defaults to `nil`, or, if `hab_sup_artifact_name` is supplied, the `hab_sup_timestamp` will be parsed from the filename of the hart file.
34
+ * `hab_sup_artifact_name`
35
+ * Artifact package name for a custom supervisor to run
36
+ * Used to upload and test a local supervisor.
37
+ * Package should be located in the `results_directory`
38
+ * Defaults to `nil
25
39
  * `hab_sup_listen_http`
26
40
  * Port for the supervisor's sidecar to listen on.
27
41
  * Defaults to `nil`
@@ -34,11 +48,15 @@ You'll need the test-kitchen & kitchen-habitat gems installed in your system, al
34
48
  * `artifact_name`
35
49
  * Artifact package filename to install and run.
36
50
  * Used to upload and test a local artifact.
51
+ * Package should be located in the `results_directory`
37
52
  * Example - `core-jq-static-1.5-20170127185151-x86_64-linux.hart`
38
53
  * Defaults to `nil`
54
+ * `results_directory`
55
+ * Directory (relative to the location of the .kitchen.yml) containing package artifacts (harts) to copy to the remote system
56
+ * Defaults to checking the local directory for a `results` directory, then its parent (`..\results`) and grandparent (`..\..\results`), which should accomodate most studio layouts.
39
57
  * `package_origin`
40
58
  * Origin for the package to run.
41
- * Defaults to `core`, or or, if `artifact_name` is supplied, the `package_origin` will be parsed from the filename of the hart file.
59
+ * Defaults to `core`, or, if `artifact_name` is supplied, the `package_origin` will be parsed from the filename of the hart file.
42
60
  * `package_name`
43
61
  * Package name for the supervisor to run.
44
62
  * Defaults to the suite name or, if `artifact_name` is supplied, the `package_name` will be parsed from the filename of the hart file.
@@ -48,6 +66,14 @@ You'll need the test-kitchen & kitchen-habitat gems installed in your system, al
48
66
  * `package_timestamp`
49
67
  * Package timestamp of the package to be run.
50
68
  * Defaults to `nil` or if `artifact_name` is supplied, the `package_timestamp` will be parsed from the filename of the hart file.
69
+ * `config_directory`
70
+ * Directory containing a user.toml or/and a default.toml, hooks, and configuration files to be passed to the service under test.
71
+ * Default to `nil`
72
+ * `override_package_config`
73
+ * Tell the supervisor to the the configuration files and hooks from `config_directory` instead of what was packaged with the service. (Uses `--config-from` via the `hab-sup` CLI.)
74
+ * `user_toml_name`
75
+ * Name of the file to be used as the user.toml for the service under test.
76
+ * Defaults to `user.toml`
51
77
 
52
78
 
53
79
  ## Example
@@ -1,5 +1,5 @@
1
1
  module Kitchen
2
2
  module Habitat
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Steven Murawski (<steven.murawski@gmail.com>)
3
3
  #
4
- # Copyright (C) 2014 Steven Murawski
4
+ # Copyright (C) 2017 Steven Murawski
5
5
  #
6
6
  # Licensed under the MIT License.
7
7
  # See LICENSE for more details
@@ -17,25 +17,45 @@ module Kitchen
17
17
  kitchen_provisioner_api_version 2
18
18
 
19
19
  default_config :depot_url, nil
20
- default_config :hab_sup, "core/hab-sup"
20
+ default_config :hab_sup_origin, "core"
21
+ default_config :hab_sup_name, "hab-sup"
22
+ default_config :hab_sup_version, nil
23
+ default_config :hab_sup_timestamp, nil
24
+ default_config :hab_sup_artifact_name, nil
21
25
 
22
26
  # hab-sup manager options
23
27
  default_config :hab_sup_listen_http, nil
24
28
  default_config :hab_sup_listen_gossip, nil
29
+ default_config :hab_sup_peer, []
30
+ default_config :hab_sup_bind, []
25
31
 
26
32
  # hab-sup service options
27
- #default_config :
28
- default_config :artifact_name
33
+ default_config :artifact_name, nil
29
34
  default_config :package_origin, "core"
30
35
  default_config :package_name do |provisioner|
31
36
  provisioner.instance.suite.name
32
37
  end
33
- default_config :package_version
34
- default_config :package_timestamp
38
+ default_config :package_version, nil
39
+ default_config :package_timestamp, nil
35
40
 
36
- default_config :user_toml_path
41
+ # local stuffs to copy
42
+ default_config :results_directory, nil
43
+ default_config :config_directory, nil
44
+ default_config :user_toml_name, "user.toml"
45
+ default_config :override_package_config, false
46
+
47
+ # experimental
48
+ default_config :use_screen, false
37
49
 
38
50
  def finalize_config!(instance)
51
+ unless config[:hab_sup_artifact_name].nil?
52
+ ident = artifact_name_to_package_ident_regex.match(config[:hab_sup_artifact_name])
53
+ config[:hab_sup_origin] = ident["origin"]
54
+ config[:hab_sup_name] = ident["name"]
55
+ config[:hab_sup_version] = ident["version"]
56
+ config[:hab_sup_timestamp] = ident["timestamp"]
57
+ end
58
+
39
59
  unless config[:artifact_name].nil?
40
60
  ident = artifact_name_to_package_ident_regex.match(config[:artifact_name])
41
61
  config[:package_origin] = ident["origin"]
@@ -63,12 +83,13 @@ module Kitchen
63
83
  end
64
84
 
65
85
  def init_command
66
- wrap_shell_code "id -u hab > /dev/null || sudo useradd hab > /dev/null"
86
+ wrap_shell_code "id -u hab >/dev/null 2>&1 || sudo useradd hab >/dev/null 2>&1"
67
87
  end
68
88
 
69
89
  def create_sandbox
70
90
  super
71
91
  copy_results_to_sandbox
92
+ copy_user_toml_to_sandbox
72
93
  end
73
94
 
74
95
  def prepare_command
@@ -77,11 +98,29 @@ module Kitchen
77
98
  #{install_supervisor_command}
78
99
  #{binlink_supervisor_command}
79
100
  #{install_service_package}
101
+ #{remove_previous_user_toml}
102
+ #{copy_user_toml_to_service_directory}
80
103
  EOH
81
104
  end
82
105
 
83
106
  def run_command
84
107
  run = <<-RUN
108
+ #{clean_up_screen_sessions}
109
+ #{export_hab_origin}
110
+ echo "Running #{package_ident}."
111
+
112
+ #{run_package_in_background}
113
+ sleep 5
114
+ RUN
115
+
116
+ wrap_shell_code run
117
+ end
118
+
119
+ private
120
+
121
+ def clean_up_screen_sessions
122
+ return unless config[:use_screen]
123
+ <<-CLEAN
85
124
  if sudo screen -ls | grep -q #{clean_package_name}
86
125
  then
87
126
  echo "Killing previous supervisor session."
@@ -89,28 +128,70 @@ module Kitchen
89
128
  echo "Removing dead session."
90
129
  sudo screen -wipe > /dev/null
91
130
  fi
92
- #{export_hab_origin}
93
- echo "Running #{package_ident}."
94
- sudo screen -mdS \"#{clean_package_name}\" hab-sup start #{package_ident} #{supervisor_options}
95
- RUN
131
+ CLEAN
132
+ end
96
133
 
97
- wrap_shell_code run
134
+ def run_package_in_background
135
+ if config[:use_screen]
136
+ "sudo screen -mdS \"#{clean_package_name}\" hab-sup start #{package_ident} #{supervisor_options}"
137
+ else
138
+ "nohup sudo hab-sup start #{package_ident} #{supervisor_options} & echo $! > run.pid"
139
+ end
98
140
  end
99
141
 
100
- private
142
+ def resolve_results_directory
143
+ return config[:results_directory] unless config[:results_directory].nil?
144
+
145
+ results_in_current = File.join(config[:kitchen_root], "results")
146
+ results_in_parent = File.join(config[:kitchen_root], "../results")
147
+ results_in_grandparent = File.join(config[:kitchen_root], "../../results")
148
+
149
+ if Dir.exist?(results_in_current)
150
+ results_in_current
151
+ elsif Dir.exist?(results_in_parent)
152
+ results_in_parent
153
+ elsif Dir.exist?(results_in_grandparent)
154
+ results_in_grandparent
155
+ end
156
+ end
101
157
 
102
158
  def copy_results_to_sandbox
159
+ results_dir = resolve_results_directory
160
+ return if results_dir.nil?
103
161
  FileUtils.mkdir_p(File.join(sandbox_path, "results"))
104
162
  FileUtils.cp_r(
105
- File.join(config[:kitchen_root], "/results"),
163
+ results_dir,
106
164
  File.join(sandbox_path, "results"),
107
165
  preserve: true
108
166
  )
109
167
  end
110
168
 
169
+ def full_user_toml_path
170
+ File.join(File.join(config[:kitchen_root], config[:config_directory]), config[:user_toml_name])
171
+ end
172
+
173
+ def copy_user_toml_to_sandbox
174
+ return if config[:config_directory].nil?
175
+ FileUtils.mkdir_p(File.join(sandbox_path, "config"))
176
+ FileUtils.cp_r(File.join(config[:kitchen_root], config[:config_directory]), File.join(sandbox_path, "config"))
177
+ end
178
+
111
179
  def install_service_package
112
180
  return if config[:artifact_name].nil?
113
- "sudo hab pkg install #{File.join(File.join(config[:root_path], "results"), config[:artifact_name])}"
181
+ "sudo hab pkg install #{File.join(File.join(config[:root_path], 'results'), config[:artifact_name])}"
182
+ end
183
+
184
+ def copy_user_toml_to_service_directory
185
+ return unless !config[:config_directory].nil? && File.exist?(full_user_toml_path)
186
+ "cp #{File.join(File.join(config[:root_path], 'config'), 'user.toml')} /hab/svc/#{config[:package_name]}/"
187
+ end
188
+
189
+ def remove_previous_user_toml
190
+ <<-REMOVE
191
+ if [ -d "/hab/svc/#{config[:package_name]}" ]; then
192
+ sudo find /hab/svc/#{config[:package_name]} -name user.toml -delete
193
+ fi
194
+ REMOVE
114
195
  end
115
196
 
116
197
  def export_hab_origin
@@ -119,17 +200,25 @@ module Kitchen
119
200
  end
120
201
 
121
202
  def install_supervisor_command
122
- "sudo hab pkg install #{config[:hab_sup]}"
203
+ "sudo hab pkg install #{hab_sup_ident}"
123
204
  end
124
205
 
125
206
  def binlink_supervisor_command
126
- "sudo hab pkg binlink #{config[:hab_sup]} hab-sup"
207
+ "sudo hab pkg binlink #{hab_sup_ident} hab-sup"
127
208
  end
128
209
 
129
210
  def artifact_name_to_package_ident_regex
130
211
  /(?<origin>\w+)-(?<name>.*)-(?<version>(\d+)?(\.\d+)?(\.\d+)?(\.\d+)?)-(?<timestamp>\d+)-(?<target>.*)\.hart$/
131
212
  end
132
213
 
214
+ def hab_sup_ident
215
+ ident = "#{config[:hab_sup_origin]}/" \
216
+ "#{config[:hab_sup_name]}/" \
217
+ "#{config[:hab_sup_version]}/" \
218
+ "#{config[:hab_sup_timestamp]}".chomp("/").chomp("/")
219
+ @sup_ident ||= ident
220
+ end
221
+
133
222
  def package_ident
134
223
  ident = "#{config[:package_origin]}/" \
135
224
  "#{config[:package_name]}/" \
@@ -143,10 +232,13 @@ module Kitchen
143
232
  end
144
233
 
145
234
  def supervisor_options
146
- options = "#{'--listen-gossip' + config[:hab_sup_listen_gossip] unless config[:hab_sup_listen_gossip].nil?} " \
147
- "#{'--listen-http' + config[:hab_sup_listen_http] unless config[:hab_sup_listen_http].nil?} " \
148
- ""
149
- options.strip
235
+ options = "#{'--listen-gossip ' + config[:hab_sup_listen_gossip] unless config[:hab_sup_listen_gossip].nil?} " \
236
+ "#{'--listen-http ' + config[:hab_sup_listen_http] unless config[:hab_sup_listen_http].nil?} " \
237
+ "#{'--config-from ' + File.join(config[:root_path], 'config/') if config[:override_package_config]} "
238
+ options.strip!
239
+ options += config[:hab_sup_bind].map { |b| "--bind #{b}" }.join(" ") if config[:hab_sup_bind].any?
240
+ options += config[:hab_sup_peer].map { |p| "--peer #{p}" }.join(" ") if config[:hab_sup_peer].any?
241
+ options
150
242
  end
151
243
  end
152
244
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-habitat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Murawski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen