@@ -154,6 +154,54 @@ def test_list_vs(self):
154154 'id' : 104 ,
155155 'backend_ip' : '10.45.19.35' }])
156156
157+ @mock .patch ('SoftLayer.utils.lookup' )
158+ def test_detail_vs_empty_billing (self , mock_lookup ):
159+ def mock_lookup_func (dic , key , * keys ):
160+ if key == 'billingItem' :
161+ return []
162+ if keys :
163+ return mock_lookup_func (dic .get (key , {}), keys [0 ], * keys [1 :])
164+ return dic .get (key )
165+
166+ mock_lookup .side_effect = mock_lookup_func
167+
168+ result = self .run_command (['vs' , 'detail' , '100' , '--passwords' , '--price' ])
169+
170+ self .assert_no_fail (result )
171+ self .assertEqual (json .loads (result .output ),
172+ {'active_transaction' : None ,
173+ 'cores' : 2 ,
174+ 'created' : '2013-08-01 15:23:45' ,
175+ 'datacenter' : 'TEST00' ,
176+ 'dedicated_host' : 'test-dedicated' ,
177+ 'dedicated_host_id' : 37401 ,
178+ 'hostname' : 'vs-test1' ,
179+ 'domain' : 'test.sftlyr.ws' ,
180+ 'fqdn' : 'vs-test1.test.sftlyr.ws' ,
181+ 'id' : 100 ,
182+ 'guid' : '1a2b3c-1701' ,
183+ 'memory' : 1024 ,
184+ 'modified' : {},
185+ 'os' : 'Ubuntu' ,
186+ 'os_version' : '12.04-64 Minimal for VSI' ,
187+ 'notes' : 'notes' ,
188+ 'price_rate' : 0 ,
189+ 'tags' : ['production' ],
190+ 'private_cpu' : {},
191+ 'private_ip' : '10.45.19.37' ,
192+ 'private_only' : {},
193+ 'ptr' : 'test.softlayer.com.' ,
194+ 'public_ip' : '172.16.240.2' ,
195+ 'state' : 'RUNNING' ,
196+ 'status' : 'ACTIVE' ,
197+ 'users' : [{'software' : 'Ubuntu' ,
198+ 'password' : 'pass' ,
199+ 'username' : 'user' }],
200+ 'vlans' : [{'type' : 'PUBLIC' ,
201+ 'number' : 23 ,
202+ 'id' : 1 }],
203+ 'owner' : None })
204+
157205 def test_detail_vs (self ):
158206 result = self .run_command (['vs' , 'detail' , '100' ,
159207 '--passwords' , '--price' ])
@@ -257,6 +305,7 @@ def test_create_options(self):
257305 @mock .patch ('SoftLayer.CLI.formatting.confirm' )
258306 def test_create (self , confirm_mock ):
259307 confirm_mock .return_value = True
308+
260309 result = self .run_command (['vs' , 'create' ,
261310 '--cpu=2' ,
262311 '--domain=example.com' ,
@@ -288,6 +337,52 @@ def test_create(self, confirm_mock):
288337 self .assert_called_with ('SoftLayer_Virtual_Guest' , 'createObject' ,
289338 args = args )
290339
340+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
341+ def test_create_with_wait_ready (self , confirm_mock ):
342+ mock = self .set_mock ('SoftLayer_Virtual_Guest' , 'getObject' )
343+ mock .return_value = {
344+ "provisionDate" : "2018-06-10T12:00:00-05:00" ,
345+ "id" : 100
346+ }
347+ confirm_mock .return_value = True
348+
349+ result = self .run_command (['vs' , 'create' ,
350+ '--cpu=2' ,
351+ '--domain=example.com' ,
352+ '--hostname=host' ,
353+ '--os=UBUNTU_LATEST' ,
354+ '--memory=1' ,
355+ '--network=100' ,
356+ '--billing=hourly' ,
357+ '--datacenter=dal05' ,
358+ '--wait=1' ])
359+
360+ self .assert_no_fail (result )
361+
362+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
363+ def test_create_with_wait_not_ready (self , confirm_mock ):
364+ mock = self .set_mock ('SoftLayer_Virtual_Guest' , 'getObject' )
365+ mock .return_value = {
366+ "ready" : False ,
367+ "guid" : "1a2b3c-1701" ,
368+ "id" : 100 ,
369+ "created" : "2018-06-10 12:00:00"
370+ }
371+ confirm_mock .return_value = True
372+
373+ result = self .run_command (['vs' , 'create' ,
374+ '--cpu=2' ,
375+ '--domain=example.com' ,
376+ '--hostname=host' ,
377+ '--os=UBUNTU_LATEST' ,
378+ '--memory=1' ,
379+ '--network=100' ,
380+ '--billing=hourly' ,
381+ '--datacenter=dal05' ,
382+ '--wait=10' ])
383+
384+ self .assertEqual (result .exit_code , 1 )
385+
291386 @mock .patch ('SoftLayer.CLI.formatting.confirm' )
292387 def test_create_with_integer_image_id (self , confirm_mock ):
293388 confirm_mock .return_value = True
@@ -357,6 +452,66 @@ def test_create_with_flavor(self, confirm_mock):
357452 self .assert_called_with ('SoftLayer_Virtual_Guest' , 'createObject' ,
358453 args = args )
359454
455+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
456+ def test_create_with_flavor_and_memory (self , confirm_mock ):
457+ confirm_mock .return_value = True
458+
459+ result = self .run_command (['vs' , 'create' ,
460+ '--domain=example.com' ,
461+ '--hostname=host' ,
462+ '--os=UBUNTU_LATEST' ,
463+ '--network=100' ,
464+ '--datacenter=TEST00' ,
465+ '--flavor=BL_1X2X25' ,
466+ '--memory=2048MB' ])
467+
468+ self .assertEqual (result .exit_code , 2 )
469+
470+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
471+ def test_create_with_dedicated_and_flavor (self , confirm_mock ):
472+ confirm_mock .return_value = True
473+
474+ result = self .run_command (['vs' , 'create' ,
475+ '--domain=example.com' ,
476+ '--hostname=host' ,
477+ '--os=UBUNTU_LATEST' ,
478+ '--network=100' ,
479+ '--datacenter=TEST00' ,
480+ '--dedicated' ,
481+ '--flavor=BL_1X2X25' ])
482+
483+ self .assertEqual (result .exit_code , 2 )
484+
485+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
486+ def test_create_with_hostid_and_flavor (self , confirm_mock ):
487+ confirm_mock .return_value = True
488+
489+ result = self .run_command (['vs' , 'create' ,
490+ '--domain=example.com' ,
491+ '--hostname=host' ,
492+ '--os=UBUNTU_LATEST' ,
493+ '--network=100' ,
494+ '--datacenter=dal05' ,
495+ '--host-id=100' ,
496+ '--flavor=BL_1X2X25' ])
497+
498+ self .assertEqual (result .exit_code , 2 )
499+
500+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
501+ def test_create_with_flavor_and_cpu (self , confirm_mock ):
502+ confirm_mock .return_value = True
503+
504+ result = self .run_command (['vs' , 'create' ,
505+ '--domain=example.com' ,
506+ '--hostname=host' ,
507+ '--os=UBUNTU_LATEST' ,
508+ '--network=100' ,
509+ '--datacenter=TEST00' ,
510+ '--flavor=BL_1X2X25' ,
511+ '--cpu=2' ])
512+
513+ self .assertEqual (result .exit_code , 2 )
514+
360515 @mock .patch ('SoftLayer.CLI.formatting.confirm' )
361516 def test_create_with_host_id (self , confirm_mock ):
362517 confirm_mock .return_value = True
@@ -483,6 +638,25 @@ def test_create_like_flavor(self, confirm_mock):
483638 self .assert_called_with ('SoftLayer_Virtual_Guest' , 'createObject' ,
484639 args = args )
485640
641+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
642+ def test_create_vs_test (self , confirm_mock ):
643+ confirm_mock .return_value = True
644+
645+ result = self .run_command (['vs' , 'create' , '--test' , '--hostname' , 'TEST' ,
646+ '--domain' , 'TESTING' , '--cpu' , '1' ,
647+ '--memory' , '2048MB' , '--datacenter' ,
648+ 'TEST00' , '--os' , 'UBUNTU_LATEST' ])
649+
650+ self .assertEqual (result .exit_code , - 1 )
651+
652+ def test_create_vs_bad_memory (self ):
653+ result = self .run_command (['vs' , 'create' , '--hostname' , 'TEST' ,
654+ '--domain' , 'TESTING' , '--cpu' , '1' ,
655+ '--memory' , '2034MB' , '--flavor' ,
656+ 'UBUNTU' , '--datacenter' , 'TEST00' ])
657+
658+ self .assertEqual (result .exit_code , 2 )
659+
486660 @mock .patch ('SoftLayer.CLI.formatting.confirm' )
487661 def test_dns_sync_both (self , confirm_mock ):
488662 confirm_mock .return_value = True
@@ -801,3 +975,17 @@ def test_reload_no_confirm(self, confirm_mock):
801975
802976 result = self .run_command (['vs' , 'reload' , '--postinstall' , '100' , '--key' , '100' , '--image' , '100' , '100' ])
803977 self .assertEqual (result .exit_code , 2 )
978+
979+ @mock .patch ('SoftLayer.CLI.formatting.no_going_back' )
980+ def test_cancel (self , confirm_mock ):
981+ confirm_mock .return_value = True
982+
983+ result = self .run_command (['vs' , 'cancel' , '100' ])
984+ self .assert_no_fail (result )
985+
986+ @mock .patch ('SoftLayer.CLI.formatting.no_going_back' )
987+ def test_cancel_no_confirm (self , confirm_mock ):
988+ confirm_mock .return_value = False
989+
990+ result = self .run_command (['vs' , 'cancel' , '100' ])
991+ self .assertEqual (result .exit_code , 2 )
0 commit comments