diff options
author | Robert Speicher <robert@gitlab.com> | 2016-08-25 17:44:08 +0000 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2016-08-26 11:32:07 -0500 |
commit | ef5758469698d82c181c6480d160aa5e2475728a (patch) | |
tree | 39f514f22b0777aab7152fb4873eb9e0bc46ab54 /spec | |
parent | 52b07013e7aec539b864299744090e331408a550 (diff) | |
download | gitlab-ce-ef5758469698d82c181c6480d160aa5e2475728a.tar.gz |
Merge branch '21378-error-500-after-8-11-update-on-system-infos-page' into 'master'
Handle unavailable system info
## What does this MR do?
Handle the case where we can't get system info without blowing up. As this is the first tab in the monitoring section, it's difficult to get to the other tabs if this page throws a 500. Also be more specific about the info we want, so we don't fail on something we don't care about (like `/proc/net/dev`).
## Why was this MR needed?
grsecurity can prevent users from reading `/proc`, which is what Vmstat uses to find CPU and memory info.
## What are the relevant issue numbers?
Closes #21378.
See merge request !5989
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/admin/admin_system_info_spec.rb | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/spec/features/admin/admin_system_info_spec.rb b/spec/features/admin/admin_system_info_spec.rb index f4e5c26b519..1df972843e2 100644 --- a/spec/features/admin/admin_system_info_spec.rb +++ b/spec/features/admin/admin_system_info_spec.rb @@ -6,12 +6,49 @@ describe 'Admin System Info' do end describe 'GET /admin/system_info' do - it 'shows system info page' do - visit admin_system_info_path + let(:cpu) { double(:cpu, length: 2) } + let(:memory) { double(:memory, active_bytes: 4294967296, total_bytes: 17179869184) } - expect(page).to have_content 'CPU' - expect(page).to have_content 'Memory' - expect(page).to have_content 'Disks' + context 'when all info is available' do + before do + allow(Vmstat).to receive(:cpu).and_return(cpu) + allow(Vmstat).to receive(:memory).and_return(memory) + visit admin_system_info_path + end + + it 'shows system info page' do + expect(page).to have_content 'CPU 2 cores' + expect(page).to have_content 'Memory 4 GB / 16 GB' + expect(page).to have_content 'Disks' + end + end + + context 'when CPU info is not available' do + before do + allow(Vmstat).to receive(:cpu).and_raise(Errno::ENOENT) + allow(Vmstat).to receive(:memory).and_return(memory) + visit admin_system_info_path + end + + it 'shows system info page with no CPU info' do + expect(page).to have_content 'CPU Unable to collect CPU info' + expect(page).to have_content 'Memory 4 GB / 16 GB' + expect(page).to have_content 'Disks' + end + end + + context 'when memory info is not available' do + before do + allow(Vmstat).to receive(:cpu).and_return(cpu) + allow(Vmstat).to receive(:memory).and_raise(Errno::ENOENT) + visit admin_system_info_path + end + + it 'shows system info page with no CPU info' do + expect(page).to have_content 'CPU 2 cores' + expect(page).to have_content 'Memory Unable to collect memory info' + expect(page).to have_content 'Disks' + end end end end |