belzebuth 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fdfe65feb3e1f1e0a250de4382d6107932c01bd
4
+ data.tar.gz: 2db9f0e00ba697f17a9ed49804c217be042fa52b
5
+ SHA512:
6
+ metadata.gz: 2dfc173e1ec836c6a486626017142640e55be7748b7355f2fb0a966651e14b4776f466b53fe3759d7c5bc5be99284030186ddafbc9c6961b81980328e4c59b79
7
+ data.tar.gz: 43725a442aa9ddc0deda347899e4d6dfc22971b134d375801a1c7257d4e104cfa2504a99995b4e3dfa27d878e1ef118fb6fa258ee656faa56203bfd9e9a8a6e3
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ before_install: gem install bundler -v 1.14.5
@@ -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 phpellerin@gmail.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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in belzebuth.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2017 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,41 @@
1
+ # Belzebuth
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/belzebuth`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'belzebuth'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install belzebuth
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ph/belzebuth. 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.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,9 @@
1
+ create a process class
2
+ allow to add wait condition
3
+ - custom wait url response condition
4
+ - custom wait on stdout
5
+ - allow to create a custom
6
+
7
+ - add package fetcher
8
+ - add a way to provide consistent run / isolated
9
+ - make sure we add debugger
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'belzebuth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "belzebuth"
8
+ spec.version = Belzebuth::VERSION
9
+ spec.authors = ["Pier-Hugues Pellerin"]
10
+ spec.email = ["phpellerin@gmail.com"]
11
+
12
+ spec.summary = %q{Small wrapper for testing external process}
13
+ spec.description = %q{Small wrapper for testing external process and synchronize suite}
14
+ spec.homepage = "http://github.com/ph/belzebuth"
15
+ spec.licenses = ['apache-2.0']
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "childprocess"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry"
30
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "belzebuth"
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__)
@@ -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,9 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/version"
3
+ require "belzebuth/wait_condition"
4
+ require "belzebuth/response"
5
+ require "belzebuth/process"
6
+
7
+ module Belzebuth
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition"
3
+ require "belzebuth/response"
4
+ require "shellwords"
5
+ require "childprocess"
6
+ require "tempfile"
7
+ require "bundler"
8
+
9
+ # @background_process = []
10
+
11
+ # stop_background_process
12
+
13
+ # elasticsearch(
14
+ # :install_xpack => true
15
+ # :config => {
16
+ # # ....
17
+ # }
18
+ # )
19
+
20
+ # response = logstash("-f ....")
21
+ # response = logstash_plugin("...")
22
+
23
+ # expect(response).to be_successful
24
+ # auto stop service at the end
25
+
26
+ module Belzebuth
27
+ class ExecutionTimeout < StandardError; end
28
+
29
+ def self.run(command, options = {})
30
+ Process.new(command, options).run
31
+ end
32
+
33
+ class Process
34
+ DEFAULT_OPTIONS = {
35
+ :directory => Dir.pwd,
36
+ :environment => {},
37
+ :timeout => -1
38
+ }
39
+
40
+ def initialize(command, options = {})
41
+ @command = command
42
+ @options = DEFAULT_OPTIONS.merge(options)
43
+ @wait_condition = Belzebuth::WaitCondition(@options.fetch(:wait_condition, WaitCondition::Blocking.new))
44
+ end
45
+
46
+ def run
47
+ Bundler.with_clean_env do
48
+ child_process = Response.new(ChildProcess.new(*Shellwords.split(@command)))
49
+ child_process.cwd = @options[:directory]
50
+ child_process.io.stdout = create_tempfile("stdout")
51
+ child_process.io.stderr = create_tempfile("stderr")
52
+
53
+ started_at = Time.now
54
+
55
+ child_process.start
56
+ @wait_condition.start(child_process)
57
+
58
+ while !@wait_condition.call(child_process)
59
+ sleep(@wait_condition.sleep_time_between_condition(child_process))
60
+
61
+ if can_timeout? && Time.now - started_at > @options[:timeout]
62
+ child_process.stop
63
+ raise ExecutionTimeout, "`#{@command}` took too much time to execute (timeout: #{@options[:timeout]}) #{child_process}"
64
+ end
65
+ end
66
+
67
+ @wait_condition.complete(child_process)
68
+ child_process
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ def can_timeout?
75
+ @options[:timeout] != -1
76
+ end
77
+
78
+ def create_tempfile(name)
79
+ io = Tempfile.new("#{name}")
80
+ io.sync = true
81
+ io
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require "delegate"
3
+
4
+ module Belzebuth
5
+ class Response < SimpleDelegator
6
+ DEBUG_IO_LINE = 10
7
+
8
+ def stdout_lines
9
+ io_readlines(io.stdout)
10
+ end
11
+
12
+ def stderr_lines
13
+ io_readlines(io.stderr)
14
+ end
15
+
16
+ def successful?
17
+ exit_code == 0 || exit_code.nil?
18
+ end
19
+
20
+ def to_s
21
+ "Reponse: \nstdout:\n#{debug_io(stdout_lines)}\nstderr\n#{debug_io(stderr_lines)}"
22
+ end
23
+ alias_method :inspect, :to_s
24
+
25
+ private
26
+ def debug_io(io, last_items = DEBUG_IO_LINE)
27
+ return "" if io.empty?
28
+ io.last(last_items).join("\n")
29
+ end
30
+
31
+ def io_readlines(new_io)
32
+ new_io.rewind
33
+ new_io.readlines
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Belzebuth
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition/base"
3
+ require "belzebuth/wait_condition/api"
4
+ require "belzebuth/wait_condition/regular_expression"
5
+ require "belzebuth/wait_condition/closure"
6
+ require "belzebuth/wait_condition/blocking"
7
+ require "belzebuth/wait_condition/timed"
8
+ require "uri"
9
+
10
+ module Belzebuth
11
+ def self.WaitCondition(wait_condition)
12
+ case wait_condition
13
+ when WaitCondition::Base
14
+ wait_condition
15
+ when Numeric
16
+ WaitCondition::Timed.new(wait_condition)
17
+ when Proc
18
+ WaitCondition::Closure.new(wait_condition)
19
+ when Regexp
20
+ WaitCondition::RegularExpression.new(wait_condition)
21
+ when String
22
+ begin
23
+ uri = URI(wait_condition)
24
+ if uri.scheme == "http" || uri.scheme == "https"
25
+ WaitCondition::Api.new(uri)
26
+ else
27
+ WaitCondition::RegularExpression.new(/^#{wait_condition}$/)
28
+ end
29
+ rescue => e
30
+ WaitCondition::RegularExpression.new(/^#{wait_condition}/)
31
+ end
32
+ else
33
+ raise "Unknown WaitCondition for: #{wait_condition}"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition/base"
3
+ require "uri"
4
+ require "net/http"
5
+
6
+ module Belzebuth module WaitCondition
7
+ class Api < Base
8
+ MAX_SLEEP_TIME = 10
9
+
10
+ def initialize(uri, max_sleep_time = MAX_SLEEP_TIME)
11
+ @uri = URI(uri)
12
+ @sleep_time = 1
13
+ @max_sleep_time = max_sleep_time
14
+ end
15
+
16
+ def call(process)
17
+ Net::HTTP.get(@uri)
18
+ true
19
+ rescue => e
20
+ @sleep_time = [@sleep_time +1, @max_sleep_time].min
21
+ false
22
+ end
23
+
24
+ def sleep_time_between_condition
25
+ @sleep_time
26
+ end
27
+ end
28
+ end end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ module Belzebuth module WaitCondition
3
+ class Base
4
+ def start(process)
5
+ end
6
+
7
+ def complete(process)
8
+ end
9
+
10
+ def call(process)
11
+ raise NotImplemented, "#{self.class}#call is not implemented"
12
+ end
13
+
14
+ def sleep_time_between_condition(process)
15
+ 0.5
16
+ end
17
+ end
18
+ end end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition/base"
3
+
4
+ module Belzebuth module WaitCondition
5
+ class Blocking < Base
6
+ def call(process)
7
+ process.exited?
8
+ end
9
+ end
10
+ end end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition/base"
3
+
4
+ module Belzebuth module WaitCondition
5
+ class Closure < Base
6
+ def initialize(callback)
7
+ @callback = callback
8
+ end
9
+
10
+ def call(process)
11
+ @callback.call(process)
12
+ end
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition/base"
3
+
4
+ module Belzebuth module WaitCondition
5
+ class RegularExpression < Base
6
+ def initialize(expression)
7
+ @expression = expression
8
+ end
9
+
10
+ def call(process)
11
+ process.stdout_lines.any? { |line| @expression.match(line) }
12
+ end
13
+ end
14
+ end end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require "belzebuth/wait_condition/base"
3
+
4
+ module Belzebuth module WaitCondition
5
+ class Timed < Base
6
+ def initialize(time)
7
+ @time = time
8
+ end
9
+
10
+ def start(process)
11
+ @started_at = Time.now
12
+ end
13
+
14
+ def call(process)
15
+ Time.now - @started_at > @time
16
+ end
17
+
18
+ def sleep_time_between_condition(process)
19
+ 0
20
+ end
21
+ end
22
+ end end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: belzebuth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pier-Hugues Pellerin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ name: childprocess
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.14'
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ name: rspec
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: pry
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Small wrapper for testing external process and synchronize suite
84
+ email:
85
+ - phpellerin@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - TODO.md
99
+ - belzebuth.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/belzebuth.rb
103
+ - lib/belzebuth/process.rb
104
+ - lib/belzebuth/response.rb
105
+ - lib/belzebuth/version.rb
106
+ - lib/belzebuth/wait_condition.rb
107
+ - lib/belzebuth/wait_condition/api.rb
108
+ - lib/belzebuth/wait_condition/base.rb
109
+ - lib/belzebuth/wait_condition/blocking.rb
110
+ - lib/belzebuth/wait_condition/closure.rb
111
+ - lib/belzebuth/wait_condition/regular_expression.rb
112
+ - lib/belzebuth/wait_condition/timed.rb
113
+ homepage: http://github.com/ph/belzebuth
114
+ licenses:
115
+ - apache-2.0
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.4.8
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Small wrapper for testing external process
137
+ test_files: []