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 ...@@ -25,9 +25,12 @@ module Clusters
state :updating, value: 4 state :updating, value: 4
state :updated, value: 5 state :updated, value: 5
state :update_errored, value: 6 state :update_errored, value: 6
state :uninstalling, value: 7
state :uninstall_errored, value: 8
state :uninstalled, value: 9
event :make_scheduled do event :make_scheduled do
transition [:installable, :errored, :installed, :updated, :update_errored] => :scheduled transition [:installable, :errored, :installed, :updated, :update_errored, :uninstall_errored] => :scheduled
end end
event :make_installing do event :make_installing do
...@@ -40,8 +43,9 @@ module Clusters ...@@ -40,8 +43,9 @@ module Clusters
end end
event :make_errored do event :make_errored do
transition any - [:updating] => :errored transition any - [:updating, :uninstalling] => :errored
transition [:updating] => :update_errored transition [:updating] => :update_errored
transition [:uninstalling] => :uninstall_errored
end end
event :make_updating do event :make_updating do
...@@ -52,6 +56,14 @@ module Clusters ...@@ -52,6 +56,14 @@ module Clusters
transition any => :update_errored transition any => :update_errored
end end
event :make_uninstalling do
transition [:scheduled] => :uninstalling
end
event :make_uninstalled do
transition [:uninstalling] => :uninstalled
end
before_transition any => [:scheduled] do |app_status, _| before_transition any => [:scheduled] do |app_status, _|
app_status.status_reason = nil app_status.status_reason = nil
end end
...@@ -65,7 +77,7 @@ module Clusters ...@@ -65,7 +77,7 @@ module Clusters
app_status.status_reason = nil app_status.status_reason = nil
end 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 status_reason = transition.args.first
app_status.status_reason = status_reason if status_reason app_status.status_reason = status_reason if status_reason
end end
......
...@@ -6,6 +6,11 @@ FactoryBot.define do ...@@ -6,6 +6,11 @@ FactoryBot.define do
status(-2) status(-2)
end end
trait :errored do
status(-1)
status_reason 'something went wrong'
end
trait :installable do trait :installable do
status 0 status 0
end end
...@@ -30,16 +35,24 @@ FactoryBot.define do ...@@ -30,16 +35,24 @@ FactoryBot.define do
status 5 status 5
end end
trait :errored do trait :update_errored do
status(-1) status(6)
status_reason 'something went wrong' status_reason 'something went wrong'
end end
trait :update_errored do trait :uninstalling do
status(6) status 7
end
trait :uninstall_errored do
status(8)
status_reason 'something went wrong' status_reason 'something went wrong'
end end
trait :uninstalled do
status 9
end
trait :timeouted do trait :timeouted do
installing installing
updated_at { ClusterWaitForAppInstallationWorker::TIMEOUT.ago } updated_at { ClusterWaitForAppInstallationWorker::TIMEOUT.ago }
......
...@@ -114,6 +114,17 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -114,6 +114,17 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject.status_reason).to eq(reason) expect(subject.status_reason).to eq(reason)
end end
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 end
describe '#make_scheduled' do describe '#make_scheduled' do
...@@ -125,6 +136,16 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -125,6 +136,16 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject).to be_scheduled expect(subject).to be_scheduled
end 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 describe 'when was errored' do
subject { create(application_name, :errored) } subject { create(application_name, :errored) }
...@@ -148,6 +169,38 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -148,6 +169,38 @@ shared_examples 'cluster application status specs' do |application_name|
expect(subject.status_reason).to be_nil expect(subject.status_reason).to be_nil
end end
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
end end
...@@ -155,16 +208,19 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -155,16 +208,19 @@ shared_examples 'cluster application status specs' do |application_name|
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:trait, :available) do where(:trait, :available) do
:not_installable | false :not_installable | false
:installable | false :installable | false
:scheduled | false :scheduled | false
:installing | false :installing | false
:installed | true :installed | true
:updating | false :updating | false
:updated | true :updated | true
:errored | false :errored | false
:update_errored | false :update_errored | false
:timeouted | false :uninstalling | false
:uninstall_errored | false
:uninstalled | false
:timeouted | false
end end
with_them do with_them do
......
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