Skip to content
Snippets Groups Projects
Commit 6ad5373e authored by Stan Hu's avatar Stan Hu
Browse files

Gracefully handle empty roles

If a `gitlab-ctl reconfigure` fails, the JSON might be left with empty
roles. We should gracefully handle this case and not fail hard.

Changelog: changed
parent 093f08d1
No related branches found
No related tags found
2 merge requests!55Intermediate build after shift of stable series,!54GitLab 14.4
......@@ -100,7 +100,11 @@
# Parse enabled roles out of the attributes json file and return an Array of Strings
def roles(base_path)
get_node_attributes(base_path)['roles'].select { |k, v| v.key?('enable') && v['enable'] }.keys
roles = get_node_attributes(base_path)['roles']
return [] unless roles.is_a?(Hash)
roles.select { |k, v| v.key?('enable') && v['enable'] }.keys
end
def delay_for(seconds)
......
......@@ -83,6 +83,20 @@
allow(File).to receive(:read).with(fake_node_file).and_return(roled_node.to_json)
expect(described_class.roles(fake_base_path)).to eq(%w[role_one role_three])
end
it 'when no roles are defined' do
roled_node = {}
allow(File).to receive(:read).with(fake_node_file).and_return(roled_node.to_json)
expect(described_class.roles(fake_base_path)).to eq([])
end
it 'when roles is not a Hash' do
roled_node = { roles: "test" }
allow(File).to receive(:read).with(fake_node_file).and_return(roled_node.to_json)
expect(described_class.roles(fake_base_path)).to eq([])
end
end
describe '#parse_json_file' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment