'Test create image from volume with protected properties.'

@mock.patch.object(volume_api.API, 'get_volume_image_metadata')
@mock.patch.object(glance.GlanceImageService, 'create')
@mock.patch.object(volume_rpcapi.VolumeAPI, 'copy_volume_to_image')
def test_copy_volume_to_image_version_3_1(self, mock_copy_volume_to_image, mock_create, mock_get_volume_image_metadata):

    (volume, expected) = self._create_volume_with_type()
    mock_get_volume_image_metadata.return_value = {'volume_id': volume.id, 'key': 'x_billing_code_license', 'value': '246254365'}
    mock_create.side_effect = self.fake_image_service_create_3_1
    mock_copy_volume_to_image.side_effect = self.fake_rpc_copy_volume_to_image
    self.override_config('glance_api_version', 2)
    req = fakes.HTTPRequest.blank(('/v3/%s/volumes/%s/action' % (fake.PROJECT_ID, volume.id)), use_admin_context=self.context.is_admin)
    req.environ['cinder.context'].is_admin = True
    req.headers = {'OpenStack-API-Version': 'volume    3.1'}
    req.api_version_request = api_version.APIVersionRequest('3.1')
    body = self._get_os_volume_upload_image()
    body['os-volume_upload_image']['visibility'] = 'public'
    body['os-volume_upload_image']['protected'] = True
    res_dict = self.controller._volume_upload_image(req, volume.id, body)
    expected['os-volume_upload_image'].update(visibility='public', protected=True)
    self.assertDictEqual(expected, res_dict)
