@@ -701,6 +701,82 @@ def test_server_boot_with_bdm_image(self):
701701 # the attached volume had been deleted
702702 pass
703703
704+ def test_boot_from_volume (self ):
705+ # Tests creating a server using --image and --boot-from-volume where
706+ # the compute service will create a root volume of the specified size
707+ # using the provided image, attach it as the root disk for the server
708+ # and not delete the volume when the server is deleted.
709+ server_name = uuid .uuid4 ().hex
710+ server = json .loads (self .openstack (
711+ 'server create -f json ' +
712+ '--flavor ' + self .flavor_name + ' ' +
713+ '--image ' + self .image_name + ' ' +
714+ '--boot-from-volume 1 ' + # create a 1GB volume from the image
715+ self .network_arg + ' ' +
716+ '--wait ' +
717+ server_name
718+ ))
719+ self .assertIsNotNone (server ["id" ])
720+ self .assertEqual (
721+ server_name ,
722+ server ['name' ],
723+ )
724+ self .wait_for_status (server_name , 'ACTIVE' )
725+
726+ # check server volumes_attached, format is
727+ # {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
728+ cmd_output = json .loads (self .openstack (
729+ 'server show -f json ' +
730+ server_name
731+ ))
732+ volumes_attached = cmd_output ['volumes_attached' ]
733+ self .assertTrue (volumes_attached .startswith ('id=' ))
734+ attached_volume_id = volumes_attached .replace ('id=' , '' )
735+ # Don't leak the volume when the test exits.
736+ self .addCleanup (self .openstack , 'volume delete ' + attached_volume_id )
737+
738+ # Since the server is volume-backed the GET /servers/{server_id}
739+ # response will have image=''.
740+ self .assertEqual ('' , cmd_output ['image' ])
741+
742+ # check the volume that attached on server
743+ cmd_output = json .loads (self .openstack (
744+ 'volume show -f json ' +
745+ attached_volume_id
746+ ))
747+ # The volume size should be what we specified on the command line.
748+ self .assertEqual (1 , int (cmd_output ['size' ]))
749+ attachments = cmd_output ['attachments' ]
750+ self .assertEqual (
751+ 1 ,
752+ len (attachments ),
753+ )
754+ self .assertEqual (
755+ server ['id' ],
756+ attachments [0 ]['server_id' ],
757+ )
758+ self .assertEqual (
759+ "in-use" ,
760+ cmd_output ['status' ],
761+ )
762+ # TODO(mriedem): If we can parse the volume_image_metadata field from
763+ # the volume show output we could assert the image_name is what we
764+ # specified. volume_image_metadata is something like this:
765+ # {u'container_format': u'bare', u'min_ram': u'0',
766+ # u'disk_format': u'qcow2', u'image_name': u'cirros-0.4.0-x86_64-disk',
767+ # u'image_id': u'05496c83-e2df-4c2f-9e48-453b6e49160d',
768+ # u'checksum': u'443b7623e27ecf03dc9e01ee93f67afe', u'min_disk': u'0',
769+ # u'size': u'12716032'}
770+
771+ # delete server, then check the attached volume was not deleted
772+ self .openstack ('server delete --wait ' + server_name )
773+ cmd_output = json .loads (self .openstack (
774+ 'volume show -f json ' +
775+ attached_volume_id
776+ ))
777+ # check the volume is in 'available' status
778+ self .assertEqual ('available' , cmd_output ['status' ])
779+
704780 def test_server_create_with_none_network (self ):
705781 """Test server create with none network option."""
706782 server_name = uuid .uuid4 ().hex
0 commit comments