@@ -315,6 +315,118 @@ def test_run_instance(self):
315315 self .assert_ok (response )
316316 assert 'RunInstancesResponse' in response .data
317317
318+ def test_run_instance_gp2 (self ):
319+ data = self .get_example_data ()
320+ data ['Action' ] = 'RunInstances'
321+ data ['ImageId' ] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
322+ data ['MinCount' ] = '0'
323+ data ['MaxCount' ] = '0'
324+ data ['SecurityGroupId.1' ] = 'example-security-group-id'
325+ data ['SecurityGroup.1' ] = 'example-security-group-name'
326+ data ['KeyName' ] = 'example-ssh-key-name'
327+ data ['UserData' ] = 'example-user-data'
328+ data ['BlockDeviceMapping.1.Ebs.VolumeType' ] = 'gp2'
329+ data ['BlockDeviceMapping.1.Ebs.VolumeSize' ] = '20'
330+ data ['Signature' ] = generate_signature (data , 'POST' , 'localhost' , '/' )
331+
332+ get = mock .Mock ()
333+ get .return_value .text = read_file (
334+ 'tests/data/valid_run_instance.json'
335+ )
336+ get .return_value .status_code = 200
337+
338+ get_disk_offering = mock .Mock ()
339+ get_disk_offering .return_value = json .loads (read_file (
340+ 'tests/data/disk_offering_search.json'
341+ ))
342+
343+ get_service_offering = mock .Mock ()
344+ get_service_offering .return_value = json .loads (read_file (
345+ 'tests/data/service_offering_search.json'
346+ ))
347+
348+ get_zone = mock .Mock ()
349+ get_zone .return_value = json .loads (read_file (
350+ 'tests/data/zones_search.json'
351+ ))
352+
353+ with mock .patch ('requests.get' , get ):
354+ with mock .patch (
355+ 'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering' ,
356+ get_disk_offering
357+ ):
358+ with mock .patch (
359+ 'ec2stack.providers.cloudstack.service_offerings.get_service_offering' ,
360+ get_service_offering
361+ ):
362+ with mock .patch (
363+ 'ec2stack.providers.cloudstack.zones.get_zone' ,
364+ get_zone
365+ ):
366+ response = self .post (
367+ '/' ,
368+ data = data
369+ )
370+
371+ self .assert_ok (response )
372+ assert 'RunInstancesResponse' in response .data
373+
374+ def test_run_instance_gp2_no_volume_size (self ):
375+ data = self .get_example_data ()
376+ data ['Action' ] = 'RunInstances'
377+ data ['ImageId' ] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
378+ data ['MinCount' ] = '0'
379+ data ['MaxCount' ] = '0'
380+ data ['SecurityGroupId.1' ] = 'example-security-group-id'
381+ data ['SecurityGroup.1' ] = 'example-security-group-name'
382+ data ['KeyName' ] = 'example-ssh-key-name'
383+ data ['UserData' ] = 'example-user-data'
384+ data ['BlockDeviceMapping.1.Ebs.VolumeType' ] = 'gp2'
385+ data ['Signature' ] = generate_signature (data , 'POST' , 'localhost' , '/' )
386+
387+ get = mock .Mock ()
388+ get .return_value .text = read_file (
389+ 'tests/data/valid_run_instance.json'
390+ )
391+ get .return_value .status_code = 200
392+
393+ get_disk_offering = mock .Mock ()
394+ get_disk_offering .return_value = json .loads (read_file (
395+ 'tests/data/disk_offering_search.json'
396+ ))
397+
398+ get_service_offering = mock .Mock ()
399+ get_service_offering .return_value = json .loads (read_file (
400+ 'tests/data/service_offering_search.json'
401+ ))
402+
403+ get_zone = mock .Mock ()
404+ get_zone .return_value = json .loads (read_file (
405+ 'tests/data/zones_search.json'
406+ ))
407+
408+ with mock .patch ('requests.get' , get ):
409+ with mock .patch (
410+ 'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering' ,
411+ get_disk_offering
412+ ):
413+ with mock .patch (
414+ 'ec2stack.providers.cloudstack.service_offerings.get_service_offering' ,
415+ get_service_offering
416+ ):
417+ with mock .patch (
418+ 'ec2stack.providers.cloudstack.zones.get_zone' ,
419+ get_zone
420+ ):
421+ response = self .post (
422+ '/' ,
423+ data = data
424+ )
425+
426+ self .assert_bad_request (response )
427+ assert 'VolumeSize not found in BlockDeviceMapping' in response .data
428+
429+
318430 def test_run_instance_with_zone_and_type_ (self ):
319431 data = self .get_example_data ()
320432 data ['Action' ] = 'RunInstances'
0 commit comments