Skip to content

Commit

Permalink
Adding connected physical servers to physical switches page
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasgabriel committed Aug 3, 2018
1 parent f6c97ab commit 4c8cfde
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/physical_switch_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def show_list
def textual_group_list
[
%i(properties management_networks relationships),
%i(power_management firmware_details),
%i(power_management firmware_details connected_components),
]
end
helper_method(:textual_group_list)

def self.display_methods
%w(physical_switches physical_network_ports)
%w(physical_switches physical_network_ports physical_servers)
end

def display_physical_network_ports
Expand Down
20 changes: 18 additions & 2 deletions app/helpers/physical_switch_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ def textual_group_firmware_details
TextualTable.new(_("Firmwares"), firmware_details, [_("Name"), _("Version")])
end

def textual_group_connected_components
TextualGroup.new(
_("Connected Components"),
%i(connected_physical_servers)
)
end

def textual_ports
ports_count = @record.physical_network_ports.count
ports = {:label => _("Ports"), :value => ports_count, :icon => "ff ff-network-port"}
ports = {:label => _("Ports"), :value => ports_count, :icon => PhysicalNetworkPortDecorator.fonticon}
if ports_count.positive?
ports[:link] = "/physical_switch/show/#{@record.id}?display=physical_network_ports"
ports[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'physical_network_ports')
end
ports
end
Expand All @@ -43,6 +50,15 @@ def textual_ext_management_system
textual_link(ExtManagementSystem.find(@record.ems_id))
end

def textual_connected_physical_servers
physical_servers_count = @record.physical_servers.count
physical_servers = {:label => _("Physical Servers"), :value => physical_servers_count, :icon => PhysicalServerDecorator.fonticon}
if physical_servers_count.positive?
physical_servers[:link] = url_for_only_path(:action => 'show', :id => @record, :display => 'physical_servers')
end
physical_servers
end

def textual_name
{:label => _("Name"), :value => @record.name }
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/physical_switch/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#main_div
- if %w(physical_switches physical_network_ports).include?(@display)
- if %w(physical_switches physical_network_ports physical_servers).include?(@display)
= render :partial => "layouts/gtl", :locals => {:action_url => "show/#{@record.id}"}
- else
- case @showtype
Expand Down
147 changes: 147 additions & 0 deletions spec/helpers/physical_switch_helper/textual_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
describe PhysicalSwitchHelper::TextualSummary do
include ApplicationHelper

let(:ems) do
FactoryGirl.create(:physical_infra,
:name => 'LXCA',
:hostname => 'my.physicalinfra.com',
:port => '443',
:ipaddress => '1.2.3.4')
end

let(:asset_detail) do
FactoryGirl.create(:asset_detail,
:product_name => 'Switch Product Name',
:serial_number => 'Switch serial number',
:part_number => 'Switch part number',
:field_replaceable_unit => 'FRU',
:description => 'Switch description',
:manufacturer => 'Switch manufacturer')
end

let(:network) do
FactoryGirl.build(:network, :ipaddress => '192.168.1.1')
end

let(:hardware) do
FactoryGirl.build(:hardware, :networks => [network])
end

let(:switch_physical_network_port) do
FactoryGirl.create(:physical_network_port,
:uid_ems => '1',
:connected_port_uid => '2')
end

let(:physical_switch) do
FactoryGirl.create(:physical_switch,
:name => 'Switch name',
:uid_ems => 'NVH20GH0T4HN268902G6Y2N-G28Y8YWG',
:switch_uuid => 'NVH20GH0T4HN268902G6Y2N-G28Y8YWG',
:power_state => 'On',
:health_state => 'Valid',
:ems_id => ems.id,
:asset_detail => asset_detail,
:hardware => hardware,
:physical_network_ports => [switch_physical_network_port])
end

let(:server_physical_network_port) do
physical_server = FactoryGirl.build(:physical_server)

server_computer_system = FactoryGirl.build(:computer_system, :managed_entity => physical_server)

server_guest_device = FactoryGirl.build(:guest_device, :computer_system => server_computer_system)

server_physical_network_port = FactoryGirl.create(:physical_network_port,
:uid_ems => '2',
:connected_port_uid => '1',
:guest_device => server_guest_device,
)
end

before do
server_physical_network_port
@record = physical_switch
end

#
# Textual Groups
# Properties, Management Network, Relationships, Power Management, Connected Components
#
describe '.textual_group_properties' do
subject { textual_group_properties }

it 'has the right title' do
expect(subject.title).to eq('Properties')
end

it 'shows main properties' do
expect(subject.items).to include(
:name,
:product_name,
:manufacturer,
:serial_number,
:part_number,
:ports,
:health_state,
:uid_ems,
:description
)
end
end

describe '.textual_group_management_networks' do
subject { textual_group_management_networks }

it 'has the right title' do
expect(subject.title).to eq('Management Networks')
end

it 'shows 1 management ipaddress' do
expect(subject.rows).to be_kind_of(Array)
expect(subject.rows[0].size).to eq(3)
expect(subject.rows[0][0]).to eq('192.168.1.1')
end
end

describe '.textual_group_relationships' do
subject { textual_group_relationships }

it 'has the right title' do
expect(subject.title).to eq('Relationships')
end

it 'shows main relationships' do
expect(subject.items).to include(:ext_management_system)
end
end

describe '.textual_group_power_management' do
subject { textual_group_power_management }

it 'has the right title' do
expect(subject.title).to eq('Power Management')
end

it 'shows power state' do
expect(subject.items).to include(:power_state)
end
end

describe '.textual_group_connected_components' do
subject { textual_group_connected_components }

it 'has the right title' do
expect(subject.title).to eq('Connected Components')
end

it 'shows connected components' do
expect(subject.items).to include(:connected_physical_servers)
end

it 'shows connected components' do
expect(subject.items).to include(:connected_physical_servers)
end
end
end

0 comments on commit 4c8cfde

Please sign in to comment.