def test_upload_new_lu(self, mock_create_file): """Tests create/upload of SSP LU.""" # traits are already set to use the REST API upload ssp_in = stor.SSP.bld(self.adpt, 'ssp1', []) ssp_in.entry.properties = {'links': {'SELF': [ '/rest/api/uom/SharedStoragePool/ssp_uuid']}} self.adpt.update_by_path.side_effect = _mock_update_by_path mock_create_file.return_value = self._fake_meta() size_b = 1224067890 new_lu, f_wrap = ts.upload_new_lu( self.v_uuid, ssp_in, None, 'lu1', size_b, d_size=25, sha_chksum='abc123') # Check the new LU's properties self.assertEqual(new_lu.name, 'lu1') # 1224067890 / 1GB = 1.140002059; round up to 2dp self.assertEqual(new_lu.capacity, 1.15) self.assertTrue(new_lu.is_thin) self.assertEqual(new_lu.lu_type, stor.LUType.IMAGE) # Ensure the create file was called mock_create_file.assert_called_once_with( self.adpt, 'lu1', vf.FileType.DISK_IMAGE, self.v_uuid, f_size=size_b, tdev_udid='udid_lu1', sha_chksum='abc123') # Ensure cleanup was called after the upload self.adpt.delete.assert_called_once_with( 'File', service='web', root_id='6233b070-31cc-4b57-99bd-37f80e845de9') self.assertIsNone(f_wrap)
def _get_or_upload_image_lu(self, context, image_meta): """Ensures our SSP has an LU containing the specified image. If an LU of type IMAGE corresponding to the input image metadata already exists in our SSP, return it. Otherwise, create it, prime it with the image contents from glance, and return it. :param context: nova context used to retrieve image from glance :param nova.objects.ImageMeta image_meta: The metadata of the image of the instance. :return: A pypowervm LU ElementWrapper representing the image. """ # Key off of the name to see whether we already have the image luname = self._get_image_name(image_meta) lu = self._find_lu(luname, pvm_stg.LUType.IMAGE) if lu: LOG.info(_LI('SSP: Using already-uploaded image LU %s.'), luname) return lu # We don't have it yet. Create it and upload the glance image to it. # Make the image LU only as big as the image. stream = self._get_image_upload(context, image_meta) LOG.info(_LI('SSP: Uploading new image LU %s.'), luname) lu, f_wrap = tsk_stg.upload_new_lu(self._any_vios_uuid(), self._ssp, stream, luname, image_meta.size) return lu
def _get_or_upload_image_lu(self, context, image_meta): """Ensures our SSP has an LU containing the specified image. If an LU of type IMAGE corresponding to the input image metadata already exists in our SSP, return it. Otherwise, create it, prime it with the image contents from glance, and return it. :param context: nova context used to retrieve image from glance :param nova.objects.ImageMeta image_meta: The metadata of the image of the instance. :return: A pypowervm LU ElementWrapper representing the image. """ # Key off of the name to see whether we already have the image luname = self._get_image_name(image_meta) lu = self._find_lu(luname, pvm_stg.LUType.IMAGE) if lu: LOG.info(_LI('SSP: Using already-uploaded image LU %s.'), luname) return lu # We don't have it yet. Create it and upload the glance image to it. # Make the image LU only as big as the image. stream = self._get_image_upload(context, image_meta) LOG.info(_LI('SSP: Uploading new image LU %s.'), luname) lu, f_wrap = tsk_stg.upload_new_lu( self._any_vios_uuid(), self._ssp, stream, luname, image_meta.size) return lu
def _get_or_upload_image_lu(self, context, img_meta): """Ensures our SSP has an LU containing the specified image. If an LU of type IMAGE corresponding to the input image metadata already exists in our SSP, return it. Otherwise, create it, prime it with the image contents from glance, and return it. :param context: nova context used to retrieve image from glance :param img_meta: image metadata dict: { 'id': reference used to locate the image in glance, 'size': size in bytes of the image. } :return: A pypowervm LU ElementWrapper representing the image. """ # Key off of the name to see whether we already have the image luname = self._get_image_name(img_meta) ssp = self._ssp for lu in ssp.logical_units: if lu.lu_type == pvm_stg.LUType.IMAGE and lu.name == luname: LOG.info(_LI('SSP: Using already-uploaded image LU %s.'), luname) return lu # We don't have it yet. Create it and upload the glance image to it. # Make the image LU only as big as the image. stream = self._get_image_upload(context, img_meta) LOG.info(_LI('SSP: Uploading new image LU %s.'), luname) lu, f_wrap = tsk_stg.upload_new_lu(self._any_vios_uuid(), ssp, stream, luname, img_meta['size']) return lu
def test_upload_new_lu(self, mock_create_file): """Tests create/upload of SSP LU.""" # traits are already set to use the REST API upload ssp_in = stor.SSP.bld(self.adpt, 'ssp1', []) ssp_in.entry.properties = { 'links': { 'SELF': ['/rest/api/uom/SharedStoragePool/ssp_uuid'] } } self.adpt.update_by_path.side_effect = _mock_update_by_path mock_create_file.return_value = self._fake_meta() size_b = 1224067890 new_lu, f_wrap = ts.upload_new_lu(self.v_uuid, ssp_in, None, 'lu1', size_b, d_size=25, sha_chksum='abc123') # Check the new LU's properties self.assertEqual(new_lu.name, 'lu1') # 1224067890 / 1GB = 1.140002059; round up to 2dp self.assertEqual(new_lu.capacity, 1.15) self.assertTrue(new_lu.is_thin) self.assertEqual(new_lu.lu_type, stor.LUType.IMAGE) # Ensure the create file was called mock_create_file.assert_called_once_with(self.adpt, 'lu1', vf.FileType.DISK_IMAGE, self.v_uuid, f_size=size_b, tdev_udid='udid_lu1', sha_chksum='abc123') # Ensure cleanup was called after the upload self.adpt.delete.assert_called_once_with( 'File', service='web', root_id='6233b070-31cc-4b57-99bd-37f80e845de9') self.assertIsNone(f_wrap)