Commit 43be4d54 authored by Thong Kuah's avatar Thong Kuah Committed by Stan Hu

Define state transitions for uninstalling apps

Added :uninstalled state as wasn't sure if we should be destroying the
cluster apps
parent a2543ee2
......@@ -25,9 +25,12 @@ module Clusters
state :updating, value: 4
state :updated, value: 5
state :update_errored, value: 6
state :uninstalling, value: 7
state :uninstall_errored, value: 8
state :uninstalled, value: 9
event :make_scheduled do
transition [:installable, :errored, :installed, :updated, :update_errored] => :scheduled
transition [:installable, :errored, :installed, :updated, :update_errored, :uninstall_errored] => :scheduled
end
event :make_installing do
......@@ -40,8 +43,9 @@ module Clusters
end
event :make_errored do
transition any - [:updating] => :errored
transition any - [:updating, :uninstalling] => :errored
transition [:updating] => :update_errored
transition [:uninstalling] => :uninstall_errored
end
event :make_updating do
......@@ -52,6 +56,14 @@ module Clusters
transition any => :update_errored
end
event :make_uninstalling do
transition [:scheduled] => :uninstalling
end
event :make_uninstalled do
transition [:uninstalling] => :uninstalled
end
before_transition any => [:scheduled] do |app_status, _|
app_status.status_reason = nil
end
......@@ -65,7 +77,7 @@ module Clusters
app_status.status_reason = nil
end
before_transition any => [:update_errored] do |app_status, transition|
before_transition any => [:update_errored, :uninstall_errored] do |app_status, transition|
status_reason = transition.args.first
app_status.status_reason = status_reason if status_reason
end
......
......@@ -6,6 +6,11 @@ FactoryBot.define do
status(-2)
end
trait :errored do
status(-1)
status_reason 'something went wrong'
end
trait :installable do
status 0
end
......@@ -30,16 +35,24 @@ FactoryBot.define do
status 5
end
trait :errored do
status(-1)
trait :update_errored do
status(6)
status_reason 'something went wrong'
end
trait :update_errored do
status(6)
trait :uninstalling do
status 7
end
trait :uninstall_errored do
status(8)
status_reason 'something went wrong'
end
trait :uninstalled do
status 9
end
trait :timeouted do
installing
updated_at { ClusterWaitForAppInstallationWorker::TIMEOUT.ago }
......
......@@ -114,6 +114,17 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject.status_reason).to eq(reason)
end
end
context 'application is uninstalling' do
subject { create(application_name, :uninstalling) }
it 'is uninstall_errored' do
subject.make_errored(reason)
expect(subject).to be_uninstall_errored
expect(subject.status_reason).to eq(reason)
end
end
end
describe '#make_scheduled' do
......@@ -125,6 +136,16 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_scheduled
end
describe 'when installed' do
subject { create(application_name, :installed) }
it 'is scheduled' do
subject.make_scheduled
expect(subject).to be_scheduled
end
end
describe 'when was errored' do
subject { create(application_name, :errored) }
......@@ -148,6 +169,38 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject.status_reason).to be_nil
end
end
describe 'when was uninstall_errored' do
subject { create(application_name, :uninstall_errored) }
it 'clears #status_reason' do
expect(subject.status_reason).not_to be_nil
subject.make_scheduled!
expect(subject.status_reason).to be_nil
end
end
end
describe '#make_uninstalling' do
subject { create(application_name, :scheduled) }
it 'is uninstalling' do
subject.make_uninstalling!
expect(subject).to be_uninstalling
end
end
describe '#make_uninstalled' do
subject { create(application_name, :uninstalling) }
it 'is uninstalled' do
subject.make_uninstalled!
expect(subject).to be_uninstalled
end
end
end
......@@ -164,6 +217,9 @@ shared_examples 'cluster application status specs' do |application_name|
:updated | true
:errored | false
:update_errored | false
:uninstalling | false
:uninstall_errored | false
:uninstalled | false
:timeouted | false
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment