'Test volume readonly flag can be updated at API level.'

def test_update_volume_readonly_flag(self):

    volume = tests_utils.create_volume(self.context, admin_metadata={'readonly': 'True'}, **self.volume_params)
    self.volume.create_volume(self.context, volume)
    volume.status = 'in-use'
    def sort_func(obj):
        return obj['name']
    volume_api = cinder.volume.api.API()
    self.assertRaises(exception.InvalidVolume, volume_api.update_readonly_flag, self.context, volume, False)
    volume.status = 'available'
    volume_api.update_readonly_flag(self.context, volume, False)
    volume.refresh()
    self.assertEqual('available', volume.status)
    admin_metadata = volume.volume_admin_metadata
    self.assertEqual(1, len(admin_metadata))
    self.assertEqual('readonly', admin_metadata[0]['key'])
    self.assertEqual('False', admin_metadata[0]['value'])
    self.volume.delete_volume(self.context, volume)
