77import copy
88
99import mock
10- from pprint import pprint as pp
1110
1211import SoftLayer
1312from SoftLayer import fixtures
@@ -118,7 +117,7 @@ def test_reload(self):
118117 def test_get_create_options (self ):
119118 options = self .hardware .get_create_options ()
120119
121- extras = {'key' : '1_IPV6_ADDRESS' , 'name' : '1 IPv6 Address' }
120+ extras = {'key' : '1_IPV6_ADDRESS' , 'name' : '1 IPv6 Address' }
122121 locations = {'key' : 'wdc01' , 'name' : 'Washington 1' }
123122 operating_systems = {
124123 'key' : 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT' ,
@@ -141,7 +140,6 @@ def test_get_create_options(self):
141140 self .assertEqual (options ['port_speeds' ][0 ]['name' ], port_speeds ['name' ])
142141 self .assertEqual (options ['sizes' ][0 ], sizes )
143142
144-
145143 def test_get_create_options_package_missing (self ):
146144 packages = self .set_mock ('SoftLayer_Product_Package' , 'getAllObjects' )
147145 packages .return_value = []
@@ -174,7 +172,7 @@ def test_generate_create_dict(self):
174172 'post_uri' : 'http://example.com/script.php' ,
175173 'ssh_keys' : [10 ],
176174 }
177-
175+
178176 package = 'BARE_METAL_SERVER'
179177 location = 'wdc01'
180178 item_keynames = [
@@ -194,7 +192,7 @@ def test_generate_create_dict(self):
194192 'hostname' : 'unicorn' ,
195193 }],
196194 'provisionScripts' : ['http://example.com/script.php' ],
197- 'sshKeys' : [{'sshKeyIds' : [10 ]}]
195+ 'sshKeys' : [{'sshKeyIds' : [10 ]}]
198196 }
199197
200198 data = self .hardware ._generate_create_dict (** args )
@@ -204,7 +202,25 @@ def test_generate_create_dict(self):
204202 for keyname in item_keynames :
205203 self .assertIn (keyname , data ['item_keynames' ])
206204 self .assertEqual (extras , data ['extras' ])
205+ self .assertEqual (preset_keyname , data ['preset_keyname' ])
206+ self .assertEqual (hourly , data ['hourly' ])
207207
208+ def test_generate_create_dict_network_key (self ):
209+ args = {
210+ 'size' : 'S1270_8GB_2X1TBSATA_NORAID' ,
211+ 'hostname' : 'test1' ,
212+ 'domain' : 'test.com' ,
213+ 'location' : 'wdc01' ,
214+ 'os' : 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT' ,
215+ 'network' : 'NETWORKING' ,
216+ 'hourly' : True ,
217+ 'extras' : ['1_IPV6_ADDRESS' ],
218+ 'post_uri' : 'http://example.com/script.php' ,
219+ 'ssh_keys' : [10 ],
220+ }
221+
222+ data = self .hardware ._generate_create_dict (** args )
223+ self .assertIn ('NETWORKING' , data ['item_keynames' ])
208224
209225 @mock .patch ('SoftLayer.managers.ordering.OrderingManager.verify_order' )
210226 @mock .patch ('SoftLayer.managers.hardware.HardwareManager._generate_create_dict' )
@@ -613,17 +629,99 @@ def test_get_hard_drive_empty(self):
613629
614630class HardwareHelperTests (testing .TestCase ):
615631
632+ def set_up (self ):
633+ self .items = [
634+ {
635+ "itemCategory" : {"categoryCode" : "port_speed" },
636+ "capacity" : 100 ,
637+ "attributes" : [
638+ {'attributeTypeKeyName' : 'NON_LACP' },
639+ {'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }
640+ ],
641+ "keyName" : "ITEM_1" ,
642+ "prices" : [{"id" : 1 , "locationGroupId" : 100 }]
643+ },
644+ {
645+ "itemCategory" : {"categoryCode" : "port_speed" },
646+ "capacity" : 200 ,
647+ "attributes" : [
648+ {'attributeTypeKeyName' : 'YES_LACP' },
649+ {'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }
650+ ],
651+ "keyName" : "ITEM_2" ,
652+ "prices" : [{"id" : 1 , "locationGroupId" : 151 }]
653+ },
654+ {
655+ "itemCategory" : {"categoryCode" : "port_speed" },
656+ "capacity" : 200 ,
657+ "attributes" : [
658+ {'attributeTypeKeyName' : 'YES_LACP' },
659+ {'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }
660+ ],
661+ "keyName" : "ITEM_3" ,
662+ "prices" : [{"id" : 1 , "locationGroupId" : 51 }]
663+ },
664+ {
665+ "itemCategory" : {"categoryCode" : "bandwidth" },
666+ "capacity" : 0.0 ,
667+ "attributes" : [],
668+ "keyName" : "HOURLY_BANDWIDTH_1" ,
669+ "prices" : [{"id" : 1 , "locationGroupId" : 51 , "hourlyRecurringFee" : 1.0 , "recurringFee" : 1.0 }]
670+ },
671+ {
672+ "itemCategory" : {"categoryCode" : "bandwidth" },
673+ "capacity" : 10.0 ,
674+ "attributes" : [],
675+ "keyName" : "MONTHLY_BANDWIDTH_1" ,
676+ "prices" : [{"id" : 1 , "locationGroupId" : 151 , "recurringFee" : 1.0 }]
677+ },
678+ {
679+ "itemCategory" : {"categoryCode" : "bandwidth" },
680+ "capacity" : 10.0 ,
681+ "attributes" : [],
682+ "keyName" : "MONTHLY_BANDWIDTH_2" ,
683+ "prices" : [{"id" : 1 , "locationGroupId" : 51 , "recurringFee" : 1.0 }]
684+ },
685+ ]
686+ self .location = {'location' : {'location' : {'priceGroups' : [{'id' : 50 }, {'id' : 51 }]}}}
687+
688+ def test_bandwidth_key (self ):
689+ result = managers .hardware ._get_bandwidth_key (self .items , True , False , self .location )
690+ self .assertEqual ('HOURLY_BANDWIDTH_1' , result )
691+ result = managers .hardware ._get_bandwidth_key (self .items , False , True , self .location )
692+ self .assertEqual ('HOURLY_BANDWIDTH_1' , result )
693+ result = managers .hardware ._get_bandwidth_key (self .items , False , False , self .location )
694+ self .assertEqual ('MONTHLY_BANDWIDTH_2' , result )
695+ ex = self .assertRaises (SoftLayer .SoftLayerError ,
696+ managers .hardware ._get_bandwidth_key , [], True , False , self .location )
697+ self .assertEqual ("Could not find valid price for bandwidth option" , str (ex ))
698+
699+ def test_port_speed_key (self ):
700+ result = managers .hardware ._get_port_speed_key (self .items , 200 , True , self .location )
701+ self .assertEqual ("ITEM_3" , result )
702+
703+ def test_port_speed_key_exception (self ):
704+ items = []
705+ location = {}
706+ ex = self .assertRaises (SoftLayer .SoftLayerError ,
707+ managers .hardware ._get_port_speed_key , items , 999 , False , location )
708+ self .assertEqual ("Could not find valid price for port speed: '999'" , str (ex ))
709+
616710 def test_matches_location (self ):
617711 price = {'id' : 1 , 'locationGroupId' : 51 , 'recurringFee' : 99 }
618- location = {
619- 'location' : {
620- 'location' : {
621- 'priceGroups' : [
622- {'id' : 50 },
623- {'id' : 51 }
624- ]
625- }
626- }
627- }
628- result = managers .hardware ._matches_location (price , location )
629- self .assertTrue (result )
712+
713+ self .assertTrue (managers .hardware ._matches_location (price , self .location ))
714+ price ['locationGroupId' ] = 99999
715+ self .assertFalse (managers .hardware ._matches_location (price , self .location ))
716+
717+ def test_is_bonded (self ):
718+ item_non_lacp = {'attributes' : [{'attributeTypeKeyName' : 'NON_LACP' }]}
719+ item_lacp = {'attributes' : [{'attributeTypeKeyName' : 'YES_LACP' }]}
720+ self .assertFalse (managers .hardware ._is_bonded (item_non_lacp ))
721+ self .assertTrue (managers .hardware ._is_bonded (item_lacp ))
722+
723+ def test_is_private (self ):
724+ item_private = {'attributes' : [{'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }]}
725+ item_public = {'attributes' : [{'attributeTypeKeyName' : 'NOT_PRIVATE_NETWORK_ONLY' }]}
726+ self .assertTrue (managers .hardware ._is_private_port_speed_item (item_private ))
727+ self .assertFalse (managers .hardware ._is_private_port_speed_item (item_public ))
0 commit comments