Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #241 from joyent/fix/hardware-profile
Browse files Browse the repository at this point in the history
fix: Add rack_unit to hardware profile, fix typo
  • Loading branch information
sungo authored Apr 27, 2018
2 parents 16b74a8 + d90abcc commit 37906c8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Conch/json-schema/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ definitions:
- nics_num
- psu_total
- purpose
- rack_unit
- ram_total
- sas_num
- sas_size
Expand Down Expand Up @@ -410,6 +411,8 @@ definitions:
type: integer
purpose:
type: string
rack_unit:
type: integer
ram_total:
type: integer
sas_num:
Expand Down
4 changes: 4 additions & 0 deletions Conch/lib/Conch/Class/HardwareProductProfile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ with 'Conch::Class::Role::JsonV1';
=head2 purpose
=head2 rack_unit
=head2 ram_total
=head2 sas_num
Expand Down Expand Up @@ -69,6 +71,7 @@ has [
nics_num
psu_total
purpose
rack_unit
ram_total
sas_num
sas_size
Expand Down Expand Up @@ -101,6 +104,7 @@ sub as_v1_json {
nics_num => $self->nics_num,
psu_total => $self->psu_total,
purpose => $self->purpose,
rack_unit => $self->rack_unit,
ram_total => $self->ram_total,
sas_num => $self->sas_num,
sas_size => $self->sas_size,
Expand Down
4 changes: 3 additions & 1 deletion Conch/lib/Conch/Model/HardwareProduct.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ my $fields = q{
hw_profile.nics_num AS hw_profile_nics_num,
hw_profile.psu_total AS hw_profile_psu_total,
hw_profile.purpose AS hw_profile_purpose,
hw_profile.rack_unit AS hw_profile_rack_unit,
hw_profile.ram_total AS hw_profile_ram_total,
hw_profile.sas_num AS hw_profile_sas_num,
hw_profile.sas_size AS hw_profile_sas_size,
Expand Down Expand Up @@ -155,6 +156,7 @@ sub _build_hardware_product ($hw) {
nics_num => $hw->{hw_profile_nics_num},
psu_total => $hw->{hw_profile_psu_total},
purpose => $hw->{hw_profile_purpose},
rack_unit => $hw->{hw_profile_rack_unit},
ram_total => $hw->{hw_profile_ram_total},
sas_num => $hw->{hw_profile_sas_num},
sas_size => $hw->{hw_profile_sas_size},
Expand All @@ -165,7 +167,7 @@ sub _build_hardware_product ($hw) {
ssd_num => $hw->{hw_profile_ssd_num},
ssd_size => $hw->{hw_profile_ssd_size},
ssd_slots => $hw->{hw_profile_ssd_slots},
usb_numb => $hw->{hw_profile_usb_num},
usb_num => $hw->{hw_profile_usb_num},
zpool => $zpool_profile
);

Expand Down
45 changes: 24 additions & 21 deletions Conch/t/model/HardwareProduct.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use_ok("Conch::Model::HardwareProduct");
use Data::UUID;

my $pgtmp = mk_tmp_db() or die;
my $pg = Conch::Pg->new( $pgtmp->uri );
my $pg = Conch::Pg->new( $pgtmp->uri );

my $hardware_vendor_id = $pg->db->insert(
'hardware_vendor',
Expand All @@ -31,27 +31,30 @@ my $zpool_profile_id = $pg->db->insert(
{ returning => ['id'] }
)->hash->{id};

my %hw_profile_values = (
rack_unit => 1,
purpose => 'test',
bios_firmware => 'test',
cpu_num => 2,
cpu_type => 'test',
dimms_num => 3,
ram_total => 4,
nics_num => 5,
usb_num => 6
);

my $hardware_profile_id = $pg->db->insert(
'hardware_product_profile',
{
product_id => $hardware_product_id,
zpool_id => $zpool_profile_id,
rack_unit => 1,
purpose => 'test',
bios_firmware => 'test',
cpu_num => 2,
cpu_type => 'test',
dimms_num => 3,
ram_total => 4,
nics_num => 5,
usb_num => 6

product_id => $hardware_product_id,
zpool_id => $zpool_profile_id,
%hw_profile_values
},
{ returning => ['id'] }
)->hash->{id};

new_ok('Conch::Model::HardwareProduct');
my $hw_product_model = new_ok( "Conch::Model::HardwareProduct");
my $hw_product_model = new_ok("Conch::Model::HardwareProduct");

subtest 'list hardware products' => sub {
my $hw_products = $hw_product_model->list;
Expand All @@ -63,9 +66,9 @@ subtest 'list hardware products' => sub {
isa_ok( $hw_product->profile, 'Conch::Class::HardwareProductProfile' );
isa_ok( $hw_product->profile->zpool, 'Conch::Class::ZpoolProfile' );

is($hw_product->profile->id, $hardware_profile_id, "Profile IDs match");
is($hw_product->profile->bios_firmware, "test", "BIOS Firmware");
is($hw_product->profile->zpool->id, $zpool_profile_id, "Zpool profile ID");
is( $hw_product->profile->id, $hardware_profile_id, "Profile IDs match" );
is( $hw_product->profile->bios_firmware, "test", "BIOS Firmware" );
is( $hw_product->profile->zpool->id, $zpool_profile_id, "Zpool profile ID" );
};

subtest 'lookup hardware product' => sub {
Expand All @@ -74,10 +77,10 @@ subtest 'lookup hardware product' => sub {
isa_ok( $hw_product->profile, 'Conch::Class::HardwareProductProfile' );
isa_ok( $hw_product->profile->zpool, 'Conch::Class::ZpoolProfile' );

is($hw_product->profile->id, $hardware_profile_id, "Profile IDs match");
is($hw_product->profile->bios_firmware, "test", "BIOS Firmware");
is($hw_product->profile->zpool->id, $zpool_profile_id, "Zpool profile ID");
is( $hw_product->profile->id, $hardware_profile_id, "Profile IDs match" );
my %profile_values = %{ $hw_product->profile }{ keys %hw_profile_values };
is_deeply( { %profile_values }, { %hw_profile_values });
is( $hw_product->profile->zpool->id, $zpool_profile_id, "Zpool profile ID" );
};

done_testing();

0 comments on commit 37906c8

Please sign in to comment.