-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
162 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ruby: | ||
enabled: true | ||
config_file: .rubocop.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Style/StringLiterals: | ||
EnforcedStyle: single_quotes | ||
|
||
Style/DotPosition: | ||
EnforcedStyle: trailing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## Contributing | ||
In the spirit of [free software][free-sw], **everyone** is encouraged to help | ||
improve this project. | ||
|
||
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html | ||
|
||
Here are some ways *you* can contribute: | ||
|
||
* by using alpha, beta, and prerelease versions | ||
* by reporting bugs | ||
* by suggesting new features | ||
* by writing or editing documentation | ||
* by writing specifications | ||
* by writing code (**no patch is too small**: fix typos, add comments, clean up | ||
inconsistent whitespace) | ||
* by refactoring code | ||
* by fixing [issues][] | ||
* by reviewing patches | ||
|
||
[issues]: https://github.com/trema/switch_monitor/issues | ||
|
||
## Submitting an Issue | ||
We use the [GitHub issue tracker][issues] to track bugs and features. Before | ||
submitting a bug report or feature request, check to make sure it hasn't | ||
already been submitted. When submitting a bug report, please include a [Gist][] | ||
that includes a stack trace and any details that may be necessary to reproduce | ||
the bug, including your gem version, Ruby version, and operating system. | ||
Ideally, a bug report should include a pull request with failing specs. | ||
|
||
[gist]: https://gist.github.com/ | ||
|
||
## Submitting a Pull Request | ||
1. [Fork the repository.][fork] | ||
2. [Create a topic branch.][branch] | ||
3. Add specs for your unimplemented feature or bug fix. | ||
4. Run `bundle exec rake spec`. If your specs pass, return to step 3. | ||
5. Implement your feature or bug fix. | ||
6. Run `bundle exec rake default`. If your specs fail, return to step 5. | ||
7. Run `open coverage/index.html`. If your changes are not completely covered | ||
by your tests, return to step 3. | ||
8. Add, commit, and push your changes. | ||
9. [Submit a pull request.][pr] | ||
|
||
[fork]: http://help.github.com/fork-a-repo/ | ||
[branch]: http://learn.github.com/p/branching.html | ||
[pr]: http://help.github.com/send-pull-requests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Before do | ||
Before('@sudo') do | ||
fail 'sudo authentication failed' unless system 'sudo -v' | ||
@aruba_timeout_seconds = 10 | ||
end | ||
|
||
After do | ||
After('@sudo') do | ||
run 'trema killall' | ||
sleep 10 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
Feature: Switch Monitor example | ||
Background: | ||
Given a file named ".trema/config" with: | ||
""" | ||
LOG_DIR: . | ||
PID_DIR: . | ||
SOCKET_DIR: . | ||
""" | ||
|
||
Scenario: Run | ||
Given a file named "trema.conf" with: | ||
""" | ||
vswitch { datapath_id 0x1 } | ||
vswitch { datapath_id 0x2 } | ||
vswitch { datapath_id 0x3 } | ||
""" | ||
When I successfully run `trema run ../../lib/switch_monitor.rb -c trema.conf -d` | ||
And I run `sleep 5` | ||
|
||
@sudo | ||
Scenario: Run | ||
When I run `trema run ../../lib/switch_monitor.rb -c trema.conf -p . -l . -s .` interactively | ||
Then I wait for stdout to contain "SwitchMonitor started" | ||
And I wait for stdout to contain "0x1 is up" | ||
And I wait for stdout to contain "0x2 is up" | ||
And I wait for stdout to contain "0x3 is up" | ||
When I run `trema kill 0x2` | ||
And I wait for stdout to contain "0x2 is down (all = 0x1, 0x3)" | ||
When I run `trema up 0x2` | ||
And I wait for stdout to contain "0x2 is up (all = 0x1, 0x2, 0x3)" | ||
|
||
@sudo | ||
Scenario: Run as a daemon | ||
When I successfully run `trema run ../../lib/switch_monitor.rb -c trema.conf -d -p . -l . -s .` | ||
And I run `sleep 10` | ||
Then a file named "SwitchMonitor.log" should exist | ||
And the file "SwitchMonitor.log" should contain "Switch 0x1 is UP" | ||
And the file "SwitchMonitor.log" should contain "Switch 0x2 is UP" | ||
And the file "SwitchMonitor.log" should contain "Switch 0x3 is UP" | ||
And the file "SwitchMonitor.log" should contain "0x1 is up" | ||
And the file "SwitchMonitor.log" should contain "0x2 is up" | ||
And the file "SwitchMonitor.log" should contain "0x3 is up" | ||
And the file "SwitchMonitor.log" should contain "all = 0x1, 0x2, 0x3" | ||
When I successfully run `trema kill 0x2` | ||
Then the file "SwitchMonitor.log" should contain "Switch 0x2 is DOWN" | ||
Then a file named "open_vswitch.0x2.pid" should not exist | ||
Then the file "SwitchMonitor.log" should contain "0x2 is down (all = 0x1, 0x3)" | ||
And a file named "open_vswitch.0x2.pid" should not exist | ||
When I successfully run `trema up 0x2` | ||
Then a file named "open_vswitch.0x2.pid" should exist | ||
And the file "SwitchMonitor.log" should contain "0x2 is up (all = 0x1, 0x2, 0x3)" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
# Switch liveness monitor. | ||
class SwitchMonitor < Trema::Controller | ||
timer_event :show_switches, interval: 10.sec | ||
|
||
def start(_argv) | ||
def start(_args) | ||
@switches = [] | ||
logger.info 'SwitchMonitor started.' | ||
end | ||
|
||
def switch_ready(datapath_id) | ||
@switches << datapath_id.to_hex | ||
logger.info "Switch #{ datapath_id.to_hex } is UP" | ||
@switches << datapath_id | ||
logger.info "#{datapath_id.to_hex} is up (all = #{switches_in_string})" | ||
end | ||
|
||
def switch_disconnected(datapath_id) | ||
@switches -= [datapath_id.to_hex] | ||
logger.info "Switch #{ datapath_id.to_hex } is DOWN" | ||
@switches -= [datapath_id] | ||
logger.info "#{datapath_id.to_hex} is down (all = #{switches_in_string})" | ||
end | ||
|
||
def show_switches | ||
logger.info 'All switches = ' + @switches.sort.join(', ') | ||
private | ||
|
||
def switches_in_string | ||
@switches.sort.map(&:to_hex).join(', ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters