zygote 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6453638ec4693e43b0a13c53933f4f8e2f7e2273
4
- data.tar.gz: 998e036ab3605422f0d3efd18b36e722f06c5ba9
3
+ metadata.gz: eebe118f907539d05c38e4364bd52a89e6d0191a
4
+ data.tar.gz: 52be5146b4bf92e912ee2ff8fb0c43a3a3fbe0e7
5
5
  SHA512:
6
- metadata.gz: cca8f9c8f57e42fceb778d7f5e1ee79f64255c28ad92c32ea2e0a33fc657ba0e57d7ad769ae17c4fb3f68952a028285044bb2b0a964e6369d84ce36e111834bd
7
- data.tar.gz: 56d20bf591b3dd195762c9a4e3151e8e8837b924703c94a95cf879c21b584c3b7744a765e8c8afc931ed7b74bc90b5a29391002d71169fad64b2acfe1524afd2
6
+ metadata.gz: 8fca27b1b6f6fb84e97fd01f058bf651bbaa08915e895d085561a1379eefdfb79079fd8e1cb722c9b3a17763302df584e1914e08af6f5a8efd9eb81896a641c5
7
+ data.tar.gz: ef8dbc472d282de13ae75c6566a033cbd68e31858c1c67bb619ea4c228f9c5a69145d487e5ceb85d4a4a3757f2f176eebcc78548463d271a73ef9f0de378c7be
@@ -43,7 +43,7 @@ module CellQueue
43
43
  entry.save if entry
44
44
  end
45
45
 
46
- def all()
46
+ def all
47
47
  CellQueueEntry.all
48
48
  end
49
49
  end
@@ -10,7 +10,6 @@ require 'zygote/cell_queue'
10
10
  # Main HTTP class, handles routing methods
11
11
  # Uses sinatra format (all sinatra docs on routing methods apply)
12
12
  class ZygoteWeb < Genesis::Http::Handler
13
-
14
13
  # Requested by iPXE on boot, chains into /boot.
15
14
  # This enables us to customize what details we want iPXE to send us
16
15
  # The iPXE undionly.kpxe should contain an embedded script to call this URL
@@ -24,7 +23,7 @@ class ZygoteWeb < Genesis::Http::Handler
24
23
  cleaned = clean_params(params.to_h)
25
24
  # Add the request ip into the params
26
25
  ip = request.ip == '127.0.0.1' ? @env['HTTP_X_FORWARDED_FOR'] : request.ip
27
- ip = '127.0.0.1' if (ENV['TESTING'] || ip.nil? || ip.empty?)
26
+ ip = '127.0.0.1' if ENV['TESTING'] || ip.nil? || ip.empty?
28
27
  cleaned['ip'] = ip
29
28
  # Compute SKU from parameters
30
29
  sku = compute_sku(cleaned['manufacturer'], cleaned['serial'], cleaned['board-serial'])
@@ -33,7 +32,7 @@ class ZygoteWeb < Genesis::Http::Handler
33
32
  queued_data = CellQueue.shift(sku)
34
33
  cleaned.merge!(queued_data) if queued_data
35
34
  @channel << cleaned
36
- body { erb :menu, locals: { opts: ZygoteWeb::cell_config.merge('params' => cleaned || {}) } }
35
+ body { erb :menu, locals: { opts: ZygoteWeb.cell_config.merge('params' => cleaned || {}) } }
37
36
  end
38
37
 
39
38
  # Render an action for a particular cell
@@ -43,7 +42,7 @@ class ZygoteWeb < Genesis::Http::Handler
43
42
  # Add the cell to the parameters
44
43
  cell = cleaned['cell']
45
44
  # Merge the cleaned params in with any cell options
46
- cell_opts = ZygoteWeb::cell_config['index']['cells'][cell] || {}
45
+ cell_opts = ZygoteWeb.cell_config['index']['cells'][cell] || {}
47
46
  opts = cell_opts.merge('params' => cleaned || {})
48
47
  @channel << opts # for debugging
49
48
  body { erb :"#{cell}/#{cleaned['action']}".to_sym, locals: { opts: opts } }
@@ -59,7 +58,7 @@ class ZygoteWeb < Genesis::Http::Handler
59
58
  CellQueue.all.each do |queue_entry|
60
59
  response[queue_entry.name] = queue_entry.data
61
60
  end
62
- body { JSON.pretty_generate(response)}
61
+ body { JSON.pretty_generate(response) }
63
62
  end
64
63
 
65
64
  # Delete the queue for a SKU
@@ -69,7 +68,6 @@ class ZygoteWeb < Genesis::Http::Handler
69
68
  end
70
69
 
71
70
  post %r{/queue/bulk$} do
72
-
73
71
  bulk_queue = JSON.parse(request.body.read)
74
72
  bulk_queue.each do |asset, queue|
75
73
  queue = [queue] unless queue.is_a?(Array)
@@ -95,11 +93,11 @@ class ZygoteWeb < Genesis::Http::Handler
95
93
  puts args if ENV['DEBUG']
96
94
  end
97
95
 
98
- def ZygoteWeb::cell_config
96
+ def self::cell_config
99
97
  @@cell_config
100
- end
98
+ end
101
99
 
102
- def ZygoteWeb::cell_config= (value)
100
+ def self::cell_config=(value)
103
101
  @@cell_config = value
104
102
  end
105
103
  end
@@ -107,15 +105,15 @@ end
107
105
  def zygote(port: 7000, threads:1000, config_path: nil, cells: [], debug:false)
108
106
  debug ||= ENV['DEBUG']
109
107
 
110
- cell_config= YAML.load(File.read(config_path || File.join(Dir.pwd, 'config', 'cells.yml')))
111
- ZygoteWeb::cell_config = cell_config
108
+ cell_config = YAML.load(File.read(config_path || File.join(Dir.pwd, 'config', 'cells.yml')))
109
+ ZygoteWeb.cell_config = cell_config
112
110
  zygote = Genesis::Reactor.new(
113
111
  threads: threads,
114
112
  protocols: {
115
113
  Genesis::Http::Protocol => port
116
114
  },
117
115
  handlers: [ZygoteWeb],
118
- views: [File.expand_path('../../../views', __FILE__), cells ].flatten,
116
+ views: [File.expand_path('../../../views', __FILE__), cells].flatten,
119
117
  debug: debug
120
118
  )
121
119
  if debug
@@ -0,0 +1,81 @@
1
+ require 'net/http'
2
+ require 'socket'
3
+ require 'fileutils'
4
+
5
+ require 'rspec'
6
+ require 'em-synchrony'
7
+ require 'em-synchrony/em-http'
8
+
9
+ module Zygote
10
+
11
+ module TestConfig
12
+ extend self
13
+ attr_reader :config_path, :cells, :port, :fixtures
14
+ def setup(fixtures: fixtures, config_path: config_path, cells: cells, port: port)
15
+ @fixtures = fixtures || File.expand_path('../../../spec/fixtures', __FILE__)
16
+ @config_path = config_path || File.join(@fixtures, 'cells.yml')
17
+ @cells = cells || File.join(@fixtures, 'cells')
18
+ @port = port || 7000
19
+ end
20
+ end
21
+
22
+ # Run within synchrony block to prevent blocking
23
+ module ZygoteSpec
24
+ def self.append_features(mod)
25
+ mod.class_eval %[
26
+ around(:each) do |example|
27
+ EM.synchrony do
28
+ zygote(
29
+ config_path: TestConfig.config_path,
30
+ cells: TestConfig.cells
31
+ ).start
32
+ example.run
33
+ EM.stop
34
+ end
35
+ end
36
+ ]
37
+ end
38
+ end
39
+
40
+ # Use a fresh database fro seed for each run
41
+ module MemorySpec
42
+ def self.append_features(mod)
43
+ mod.class_eval %[
44
+ around(:each) do |example|
45
+ seed = File.join(TestConfig.fixtures, 'memory_seed.db')
46
+ FileUtils.cp(seed, ENV['DATABASE_PATH'])
47
+ Memory::load
48
+ example.run
49
+ end
50
+ ]
51
+ end
52
+ end
53
+
54
+ def match_fixture(name, actual)
55
+ path = File.join(TestConfig.fixtures, 'data', "#{name}.txt")
56
+ File.open(path, 'w') { |f| f.write(actual) } if ENV['FIXTURE_RECORD']
57
+ expect(actual).to eq(File.read(path))
58
+ end
59
+
60
+ # Returns EventMachine::HttpClient
61
+ def get(uri, params = {})
62
+ uriq = "#{uri}#{parameterize(params)}"
63
+ EM::Synchrony.sync(EventMachine::HttpRequest.new(File.join("http://#{Socket.gethostname}:#{TestConfig.port}/", uriq)).aget(query: params))
64
+ end
65
+
66
+ # Returns EventMachine::HttpClient
67
+ def delete(uri, params = {})
68
+ uriq = "#{uri}#{parameterize(params)}"
69
+ EM::Synchrony.sync(EventMachine::HttpRequest.new(File.join("http://#{Socket.gethostname}:#{TestConfig.port}/", uriq)).adelete(query: params))
70
+ end
71
+
72
+ # Returns EventMachine::HttpClient
73
+ def post(uri, params = {})
74
+ EM::Synchrony.sync(EventMachine::HttpRequest.new("http://#{Socket.gethostname}:#{TestConfig.port}/#{uri}").apost(body: params))
75
+ end
76
+
77
+ def parameterize(params)
78
+ q = params.to_query
79
+ q.empty? ? '' : "?#{q}"
80
+ end
81
+ end
@@ -28,7 +28,7 @@ def clean_params(params)
28
28
  end
29
29
 
30
30
  def my_ip
31
- Socket.ip_address_list.find{|x| x.ipv4? && !x.ipv4_loopback?}.ip_address
31
+ Socket.ip_address_list.find { |x| x.ipv4? && !x.ipv4_loopback? }.ip_address
32
32
  end
33
33
 
34
34
  def discover_domain
@@ -1,4 +1,4 @@
1
1
  # Namespace for our gem
2
2
  module Zygote
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zygote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.4
33
+ version: 0.0.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.4
40
+ version: 0.0.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: supermodel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.1.6
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: em-http-request
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.3
62
- type: :development
61
+ version: 1.1.2
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.3
68
+ version: 1.1.2
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry-byebug
70
+ name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 3.3.0
75
+ version: 0.10.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 3.3.0
82
+ version: 0.10.3
83
83
  - !ruby/object:Gem::Dependency
84
- name: em-http-request
84
+ name: pry-byebug
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 1.1.2
89
+ version: 3.3.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 1.1.2
96
+ version: 3.3.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +146,7 @@ files:
146
146
  - lib/zygote/cell_queue.rb
147
147
  - lib/zygote/http.rb
148
148
  - lib/zygote/memory.rb
149
+ - lib/zygote/test.rb
149
150
  - lib/zygote/util.rb
150
151
  - lib/zygote/version.rb
151
152
  - views/boot.erb