Skip to content

Commit

Permalink
Merge pull request #74 from splaplapla/support-upgrade-in-pbm-cloud
Browse files Browse the repository at this point in the history
pbm-cloudからupgradeができるようにする
  • Loading branch information
jiikko authored Feb 19, 2022
2 parents 6c582be + 43d259a commit a38cd97
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [0.1.20.2] - 2022-2-18
- 起動時にreniceするようにしました
- 起動時にusb gadgetモードを有効にするようにしました
- pbm-cloudからprocon_bypass_manをアップグレードできるようになりました

## [0.1.20.1] - 2022-02-13
- Switchからプロコンへ送信するバイパスのインターバルを設定できるようにしました(切断・フリーズ対策)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PATH
specs:
procon_bypass_man (0.1.20.2)
action_cable_client
pbmenv
pbmenv (>= 0.1.9)
sorted_set

GEM
Expand Down Expand Up @@ -36,7 +36,7 @@ GEM
parallel (1.21.0)
parser (3.0.3.2)
ast (~> 2.4.1)
pbmenv (0.1.8)
pbmenv (0.1.9)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down
1 change: 1 addition & 0 deletions lib/procon_bypass_man.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "ext/em_pure_ruby"
require "ext/module"
require "resolv-replace"
require "pbmenv"

require_relative "procon_bypass_man/version"
require_relative "procon_bypass_man/remote_pbm_action"
Expand Down
1 change: 1 addition & 0 deletions lib/procon_bypass_man/background.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
require "procon_bypass_man/background/jobs/report_load_config_job"
require "procon_bypass_man/background/jobs/report_error_job"
require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
require "procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job"
require "procon_bypass_man/background/jobs/sync_device_stats_job"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ProconBypassMan::ReportCompletedUpgradePbmJob < ProconBypassMan::ReportEventBaseJob
extend ProconBypassMan::HasExternalApiSetting

def self.perform
ProconBypassMan::ReportHttpClient.new(
path: path,
server_pool: server_pool,
).post(body: nil, event_type: :completed_upgrade_pbm)
end
end
2 changes: 2 additions & 0 deletions lib/procon_bypass_man/commands/print_boot_message_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def initialize
@table = {}
@table[:ruby_version] = RUBY_VERSION
@table[:pbm_version] = ProconBypassMan::VERSION
@table[:pbmenv_version] = Pbmenv::VERSION
@table[:pid] = $$
@table[:root_path] = ProconBypassMan.root
@table[:pid_path] = ProconBypassMan.pid_path
Expand Down Expand Up @@ -33,6 +34,7 @@ def to_s
----
RUBY_VERSION: #{@table[:ruby_version]}
ProconBypassMan::VERSION: #{@table[:pbm_version]}
Pbmenv::VERSION: #{@table[:pbmenv_version]}
pid: #{@table[:pid]}
root: #{@table[:root_path]}
pid_path: #{@table[:pid_path]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ def action_content(args: )
ProconBypassMan.logger.info "execute ChangePbmVersionAction!"
pbm_version = args["pbm_version"] or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "pbm_versionが必要です, #{args.inspect}")
Pbmenv.uninstall(pbm_version) # 途中でシャットダウンしてしまった、とか状態が途中の状態かもしれないので一旦消す
Pbmenv.install(pbm_version)
Pbmenv.install(pbm_version, enable_pbm_cloud: true)
Pbmenv.use(pbm_version)
ProconBypassMan.logger.info "#{pbm_version}へアップグレードしました"
ProconBypassMan::ReportCompletedUpgradePbmJob.perform
`reboot` # symlinkの参照先が変わるのでrebootする必要がある
end

Expand Down
2 changes: 1 addition & 1 deletion procon_bypass_man.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
spec.add_dependency "pbmenv"
spec.add_dependency "pbmenv", ">= 0.1.9" # Pbmenv.installでのenable_pbm_cloudに依存している
spec.add_dependency "action_cable_client"
spec.add_dependency "sorted_set"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "spec_helper"

describe ProconBypassMan::ReportCompletedUpgradePbmJob do
describe '.perform' do
context 'ProconBypassMan.api_serverが設定されていない時' do
before do
ProconBypassMan.configure do |config|
config.api_servers = nil
end
end

it do
expect(ProconBypassMan.config.api_servers).to eq([])
expect { described_class.perform() }.not_to raise_error
end
end

context 'ProconBypassMan.api_serversが設定しているとき' do
before do
ProconBypassMan.configure do |config|
config.api_servers = "http://localhost:3000"
end
end

it do
http_response = double(:http_response).as_null_object
expect(http_response).to receive(:code) { "200" }
expect_any_instance_of(Net::HTTP).to receive(:post) { http_response }
expect { described_class.perform }.not_to raise_error
end
end
end
end

0 comments on commit a38cd97

Please sign in to comment.