phut 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +14 -1
  4. data/.travis.yml +2 -6
  5. data/Gemfile +30 -2
  6. data/Gemfile.lock +156 -0
  7. data/README.md +7 -2
  8. data/Rakefile +4 -3
  9. data/bin/phut +35 -83
  10. data/bin/vhost +28 -26
  11. data/features/{dsl.feature → dsl/error.feature} +8 -6
  12. data/features/{dsl_link.feature → dsl/link.feature} +11 -14
  13. data/features/dsl/netns.feature +115 -0
  14. data/features/dsl/vhost.feature +37 -0
  15. data/features/{dsl_vswitch.feature → dsl/vswitch.feature} +12 -12
  16. data/features/phut_run.feature +15 -0
  17. data/features/shell/vswitch#destroy.feature +10 -0
  18. data/features/shell/vswitch#ports.feature +36 -0
  19. data/features/shell/vswitch.all.feature +26 -0
  20. data/features/shell/vswitch.create.feature +30 -0
  21. data/features/shell/vswitch.destroy.feature +19 -0
  22. data/features/shell/vswitch.destroy_all.feature +18 -0
  23. data/features/step_definitions/link_steps.rb +5 -0
  24. data/features/step_definitions/netns_steps.rb +31 -0
  25. data/features/step_definitions/phut_steps.rb +5 -34
  26. data/features/step_definitions/vhost_steps.rb +5 -0
  27. data/features/step_definitions/vswitch_steps.rb +17 -0
  28. data/features/support/env.rb +3 -3
  29. data/features/support/hooks.rb +23 -15
  30. data/lib/phut.rb +3 -0
  31. data/lib/phut/finder.rb +19 -0
  32. data/lib/phut/link.rb +84 -0
  33. data/lib/phut/netns.rb +111 -22
  34. data/lib/phut/open_vswitch.rb +98 -96
  35. data/lib/phut/parser.rb +39 -8
  36. data/lib/phut/raw_socket.rb +4 -0
  37. data/lib/phut/route.rb +34 -0
  38. data/lib/phut/setting.rb +21 -4
  39. data/lib/phut/shell_runner.rb +13 -2
  40. data/lib/phut/syntax.rb +31 -14
  41. data/lib/phut/syntax/directive.rb +9 -1
  42. data/lib/phut/syntax/netns_directive.rb +13 -2
  43. data/lib/phut/syntax/vhost_directive.rb +2 -0
  44. data/lib/phut/syntax/vswitch_directive.rb +3 -1
  45. data/lib/phut/version.rb +3 -1
  46. data/lib/phut/veth.rb +68 -0
  47. data/lib/phut/vhost.rb +99 -58
  48. data/lib/phut/vhost_daemon.rb +53 -11
  49. data/lib/phut/vsctl.rb +125 -0
  50. data/lib/phut/vswitch.rb +10 -0
  51. data/phut.gemspec +9 -31
  52. data/tasks/cucumber.rake +5 -1
  53. data/tasks/flay.rake +2 -0
  54. data/tasks/flog.rake +3 -1
  55. data/tasks/gem.rake +2 -0
  56. data/tasks/minitest.rake +7 -0
  57. data/tasks/reek.rake +2 -0
  58. data/tasks/rubocop.rake +2 -0
  59. data/tasks/yard.rake +2 -0
  60. data/test/phut/link_test.rb +85 -0
  61. data/test/phut/netns_test.rb +58 -0
  62. data/test/phut/open_vswitch_test.rb +125 -0
  63. data/test/phut/veth_test.rb +48 -0
  64. data/test/phut/vhost_test.rb +56 -0
  65. metadata +41 -287
  66. data/.rspec +0 -3
  67. data/Guardfile +0 -29
  68. data/features/dsl_vhost.feature +0 -37
  69. data/features/phut_kill.feature +0 -27
  70. data/features/shell.feature +0 -39
  71. data/lib/phut/configuration.rb +0 -92
  72. data/lib/phut/null_logger.rb +0 -14
  73. data/lib/phut/virtual_link.rb +0 -109
  74. data/spec/phut/parser_spec.rb +0 -66
  75. data/spec/phut_spec.rb +0 -45
  76. data/spec/spec_helper.rb +0 -14
  77. data/tasks/LICENSE +0 -675
  78. data/tasks/relish.rake +0 -8
  79. data/tasks/rspec.rake +0 -8
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/array/access'
4
+ require 'minitest/autorun'
5
+ require 'phut/link'
6
+ require 'phut/veth'
7
+
8
+ module Phut
9
+ class VethTest < Minitest::Test
10
+ def test_veth_all
11
+ assert Veth.all.empty?
12
+
13
+ Link.create :switch1, :switch2
14
+ assert_equal 2, Veth.all.size
15
+ assert_equal 'switch1', Veth.all.sort.first.name
16
+ assert_equal 'switch2', Veth.all.sort.second.name
17
+ end
18
+
19
+ def test_name
20
+ assert_equal 'switch1', Veth.new(name: 'switch1', link_id: 0).name
21
+ assert_equal '192.168.0.1', Veth.new(name: '192.168.0.1', link_id: 0).name
22
+ end
23
+
24
+ def test_device
25
+ assert_equal 'L0_switch1', Veth.new(name: 'switch1', link_id: 0).device
26
+ assert_equal 'L0_c0a80001', Veth.new(name: '192.168.0.1', link_id: 0).device
27
+ end
28
+
29
+ private
30
+
31
+ def setup
32
+ log_dir = File.expand_path('../../log', __dir__)
33
+ Phut.logger = ::Logger.new("#{log_dir}/test.log")
34
+ destroy_all
35
+ end
36
+
37
+ def teardown
38
+ destroy_all
39
+ end
40
+
41
+ def destroy_all
42
+ `ifconfig -a`.split("\n").each do |each|
43
+ next unless /^(#{Veth::PREFIX}\S+)/ =~ each
44
+ system "sudo ip link delete #{Regexp.last_match(1)} 2>/dev/null"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faker'
4
+ require 'phut/vhost'
5
+
6
+ module Phut
7
+ class VhostTest < Minitest::Test
8
+ def test_vhost_all
9
+ assert Vhost.all.empty?
10
+ end
11
+
12
+ def test_vhost_create
13
+ link = Link.create('host', 'switch')
14
+ vhost = Vhost.create(name: 'myhost',
15
+ ip_address: Faker::Internet.ip_v4_address,
16
+ mac_address: Faker::Internet.mac_address,
17
+ device: link.device('host'))
18
+
19
+ assert_equal 1, Vhost.all.size
20
+ assert_equal 'myhost', vhost.name
21
+ assert_equal link.device('host'), vhost.device
22
+ end
23
+
24
+ def test_kill
25
+ link = Link.create('host', 'switch')
26
+ vhost = Vhost.create(name: 'myhost',
27
+ ip_address: Faker::Internet.ip_v4_address,
28
+ mac_address: Faker::Internet.mac_address,
29
+ device: link.device('host'))
30
+ vhost.kill
31
+
32
+ assert Vhost.all.empty?
33
+ end
34
+
35
+ private
36
+
37
+ def setup
38
+ Phut.log_dir = test_dir('log')
39
+ Phut.pid_dir = test_dir('tmp/pids')
40
+ Phut.socket_dir = test_dir('tmp/sockets')
41
+
42
+ Vhost.all.each(&:kill)
43
+ end
44
+
45
+ def teardown
46
+ Vhost.all.each(&:kill)
47
+ Link.destroy_all
48
+ end
49
+
50
+ def test_dir(path)
51
+ dir = File.expand_path(path, File.expand_path('../..', __dir__))
52
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
53
+ dir
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhito Takamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,48 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 4.2.5
19
+ version: 5.1.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '4.2'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 4.2.5
26
+ version: 5.1.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: gli
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: 2.13.4
33
+ version: 2.16.0
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: 2.13.4
40
+ version: 2.16.0
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: pio
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 0.30.0
47
+ version: 0.30.2
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: 0.30.0
54
+ version: 0.30.2
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: pry
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,258 +66,6 @@ dependencies:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
68
  version: 0.10.3
75
- - !ruby/object:Gem::Dependency
76
- name: relish
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- - !ruby/object:Gem::Dependency
90
- name: yard
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: 0.8.7.6
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 0.8.7.6
103
- - !ruby/object:Gem::Dependency
104
- name: guard
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: 2.13.0
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: 2.13.0
117
- - !ruby/object:Gem::Dependency
118
- name: guard-bundler
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - "~>"
122
- - !ruby/object:Gem::Version
123
- version: 2.1.0
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - "~>"
129
- - !ruby/object:Gem::Version
130
- version: 2.1.0
131
- - !ruby/object:Gem::Dependency
132
- name: guard-cucumber
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: 2.0.0
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: 2.0.0
145
- - !ruby/object:Gem::Dependency
146
- name: guard-rspec
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: 4.6.4
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: 4.6.4
159
- - !ruby/object:Gem::Dependency
160
- name: guard-rubocop
161
- requirement: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - "~>"
164
- - !ruby/object:Gem::Version
165
- version: 1.2.0
166
- type: :development
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- requirements:
170
- - - "~>"
171
- - !ruby/object:Gem::Version
172
- version: 1.2.0
173
- - !ruby/object:Gem::Dependency
174
- name: aruba
175
- requirement: !ruby/object:Gem::Requirement
176
- requirements:
177
- - - "~>"
178
- - !ruby/object:Gem::Version
179
- version: 0.11.2
180
- type: :development
181
- prerelease: false
182
- version_requirements: !ruby/object:Gem::Requirement
183
- requirements:
184
- - - "~>"
185
- - !ruby/object:Gem::Version
186
- version: 0.11.2
187
- - !ruby/object:Gem::Dependency
188
- name: codeclimate-test-reporter
189
- requirement: !ruby/object:Gem::Requirement
190
- requirements:
191
- - - ">="
192
- - !ruby/object:Gem::Version
193
- version: '0'
194
- type: :development
195
- prerelease: false
196
- version_requirements: !ruby/object:Gem::Requirement
197
- requirements:
198
- - - ">="
199
- - !ruby/object:Gem::Version
200
- version: '0'
201
- - !ruby/object:Gem::Dependency
202
- name: coveralls
203
- requirement: !ruby/object:Gem::Requirement
204
- requirements:
205
- - - "~>"
206
- - !ruby/object:Gem::Version
207
- version: 0.8.10
208
- type: :development
209
- prerelease: false
210
- version_requirements: !ruby/object:Gem::Requirement
211
- requirements:
212
- - - "~>"
213
- - !ruby/object:Gem::Version
214
- version: 0.8.10
215
- - !ruby/object:Gem::Dependency
216
- name: cucumber
217
- requirement: !ruby/object:Gem::Requirement
218
- requirements:
219
- - - "~>"
220
- - !ruby/object:Gem::Version
221
- version: 2.1.0
222
- type: :development
223
- prerelease: false
224
- version_requirements: !ruby/object:Gem::Requirement
225
- requirements:
226
- - - "~>"
227
- - !ruby/object:Gem::Version
228
- version: 2.1.0
229
- - !ruby/object:Gem::Dependency
230
- name: flay
231
- requirement: !ruby/object:Gem::Requirement
232
- requirements:
233
- - - "~>"
234
- - !ruby/object:Gem::Version
235
- version: 2.6.1
236
- type: :development
237
- prerelease: false
238
- version_requirements: !ruby/object:Gem::Requirement
239
- requirements:
240
- - - "~>"
241
- - !ruby/object:Gem::Version
242
- version: 2.6.1
243
- - !ruby/object:Gem::Dependency
244
- name: flog
245
- requirement: !ruby/object:Gem::Requirement
246
- requirements:
247
- - - "~>"
248
- - !ruby/object:Gem::Version
249
- version: 4.3.2
250
- type: :development
251
- prerelease: false
252
- version_requirements: !ruby/object:Gem::Requirement
253
- requirements:
254
- - - "~>"
255
- - !ruby/object:Gem::Version
256
- version: 4.3.2
257
- - !ruby/object:Gem::Dependency
258
- name: rake
259
- requirement: !ruby/object:Gem::Requirement
260
- requirements:
261
- - - ">="
262
- - !ruby/object:Gem::Version
263
- version: '0'
264
- type: :development
265
- prerelease: false
266
- version_requirements: !ruby/object:Gem::Requirement
267
- requirements:
268
- - - ">="
269
- - !ruby/object:Gem::Version
270
- version: '0'
271
- - !ruby/object:Gem::Dependency
272
- name: reek
273
- requirement: !ruby/object:Gem::Requirement
274
- requirements:
275
- - - "~>"
276
- - !ruby/object:Gem::Version
277
- version: 3.7.1
278
- type: :development
279
- prerelease: false
280
- version_requirements: !ruby/object:Gem::Requirement
281
- requirements:
282
- - - "~>"
283
- - !ruby/object:Gem::Version
284
- version: 3.7.1
285
- - !ruby/object:Gem::Dependency
286
- name: rspec
287
- requirement: !ruby/object:Gem::Requirement
288
- requirements:
289
- - - "~>"
290
- - !ruby/object:Gem::Version
291
- version: 3.4.0
292
- type: :development
293
- prerelease: false
294
- version_requirements: !ruby/object:Gem::Requirement
295
- requirements:
296
- - - "~>"
297
- - !ruby/object:Gem::Version
298
- version: 3.4.0
299
- - !ruby/object:Gem::Dependency
300
- name: rspec-given
301
- requirement: !ruby/object:Gem::Requirement
302
- requirements:
303
- - - "~>"
304
- - !ruby/object:Gem::Version
305
- version: 3.7.1
306
- type: :development
307
- prerelease: false
308
- version_requirements: !ruby/object:Gem::Requirement
309
- requirements:
310
- - - "~>"
311
- - !ruby/object:Gem::Version
312
- version: 3.7.1
313
- - !ruby/object:Gem::Dependency
314
- name: rubocop
315
- requirement: !ruby/object:Gem::Requirement
316
- requirements:
317
- - - "~>"
318
- - !ruby/object:Gem::Version
319
- version: 0.35.1
320
- type: :development
321
- prerelease: false
322
- version_requirements: !ruby/object:Gem::Requirement
323
- requirements:
324
- - - "~>"
325
- - !ruby/object:Gem::Version
326
- version: 0.35.1
327
69
  description: A simple network emulator with capabilities similar to mininet.
328
70
  email:
329
71
  - yasuhito@gmail.com
@@ -336,35 +78,45 @@ extra_rdoc_files:
336
78
  files:
337
79
  - ".gitignore"
338
80
  - ".hound.yml"
339
- - ".rspec"
340
81
  - ".rubocop.yml"
341
82
  - ".travis.yml"
342
83
  - CHANGELOG.md
343
84
  - CONTRIBUTING.md
344
85
  - Gemfile
345
- - Guardfile
86
+ - Gemfile.lock
346
87
  - LICENSE
347
88
  - README.md
348
89
  - Rakefile
349
90
  - bin/phut
350
91
  - bin/vhost
351
- - features/dsl.feature
352
- - features/dsl_link.feature
353
- - features/dsl_vhost.feature
354
- - features/dsl_vswitch.feature
92
+ - features/dsl/error.feature
93
+ - features/dsl/link.feature
94
+ - features/dsl/netns.feature
95
+ - features/dsl/vhost.feature
96
+ - features/dsl/vswitch.feature
355
97
  - features/phut.feature
356
- - features/phut_kill.feature
357
- - features/shell.feature
98
+ - features/phut_run.feature
99
+ - features/shell/vswitch#destroy.feature
100
+ - features/shell/vswitch#ports.feature
101
+ - features/shell/vswitch.all.feature
102
+ - features/shell/vswitch.create.feature
103
+ - features/shell/vswitch.destroy.feature
104
+ - features/shell/vswitch.destroy_all.feature
105
+ - features/step_definitions/link_steps.rb
106
+ - features/step_definitions/netns_steps.rb
358
107
  - features/step_definitions/phut_steps.rb
108
+ - features/step_definitions/vhost_steps.rb
109
+ - features/step_definitions/vswitch_steps.rb
359
110
  - features/support/env.rb
360
111
  - features/support/hooks.rb
361
112
  - lib/phut.rb
362
- - lib/phut/configuration.rb
113
+ - lib/phut/finder.rb
114
+ - lib/phut/link.rb
363
115
  - lib/phut/netns.rb
364
- - lib/phut/null_logger.rb
365
116
  - lib/phut/open_vswitch.rb
366
117
  - lib/phut/parser.rb
367
118
  - lib/phut/raw_socket.rb
119
+ - lib/phut/route.rb
368
120
  - lib/phut/setting.rb
369
121
  - lib/phut/shell_runner.rb
370
122
  - lib/phut/syntax.rb
@@ -373,28 +125,31 @@ files:
373
125
  - lib/phut/syntax/vhost_directive.rb
374
126
  - lib/phut/syntax/vswitch_directive.rb
375
127
  - lib/phut/version.rb
128
+ - lib/phut/veth.rb
376
129
  - lib/phut/vhost.rb
377
130
  - lib/phut/vhost_daemon.rb
378
- - lib/phut/virtual_link.rb
131
+ - lib/phut/vsctl.rb
132
+ - lib/phut/vswitch.rb
379
133
  - phut.gemspec
380
- - spec/phut/parser_spec.rb
381
- - spec/phut_spec.rb
382
- - spec/spec_helper.rb
383
134
  - tasks/.gitignore
384
- - tasks/LICENSE
385
135
  - tasks/README.md
386
136
  - tasks/cucumber.rake
387
137
  - tasks/flay.rake
388
138
  - tasks/flog.rake
389
139
  - tasks/gem.rake
140
+ - tasks/minitest.rake
390
141
  - tasks/reek.rake
391
- - tasks/relish.rake
392
- - tasks/rspec.rake
393
142
  - tasks/rubocop.rake
394
143
  - tasks/yard.rake
144
+ - test/phut/link_test.rb
145
+ - test/phut/netns_test.rb
146
+ - test/phut/open_vswitch_test.rb
147
+ - test/phut/veth_test.rb
148
+ - test/phut/vhost_test.rb
395
149
  homepage: http://github.com/trema/phut
396
150
  licenses:
397
- - GPL3
151
+ - GPLv2
152
+ - MIT
398
153
  metadata: {}
399
154
  post_install_message:
400
155
  rdoc_options: []
@@ -404,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
404
159
  requirements:
405
160
  - - ">="
406
161
  - !ruby/object:Gem::Version
407
- version: 2.0.0
162
+ version: 2.3.0
408
163
  required_rubygems_version: !ruby/object:Gem::Requirement
409
164
  requirements:
410
165
  - - ">="
@@ -412,9 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
412
167
  version: '0'
413
168
  requirements: []
414
169
  rubyforge_project:
415
- rubygems_version: 2.5.1
170
+ rubygems_version: 2.6.11
416
171
  signing_key:
417
172
  specification_version: 4
418
173
  summary: Virtual network in seconds.
419
174
  test_files: []
420
- has_rdoc: