diff --git a/openstack/cloud/_block_storage.py b/openstack/cloud/_block_storage.py index d55221fa7..1568db019 100644 --- a/openstack/cloud/_block_storage.py +++ b/openstack/cloud/_block_storage.py @@ -461,7 +461,7 @@ class BlockStorageCloudMixin: :raises: OpenStackCloudException on operation error. """ kwargs = self._get_volume_kwargs(kwargs) - payload = {'volume_id': volume_id} + payload = {'volume_id': volume_id, 'force': force} payload.update(kwargs) snapshot = self.block_storage.create_snapshot(**payload) if wait: diff --git a/openstack/tests/fakes.py b/openstack/tests/fakes.py index 3804a0599..533aed706 100644 --- a/openstack/tests/fakes.py +++ b/openstack/tests/fakes.py @@ -400,6 +400,7 @@ class FakeVolumeSnapshot: self.updated_at = None self.volume_id = '12345' self.metadata = {} + self.is_forced = False class FakeMachine: diff --git a/openstack/tests/functional/cloud/test_compute.py b/openstack/tests/functional/cloud/test_compute.py index becb67cce..0a5f1c934 100644 --- a/openstack/tests/functional/cloud/test_compute.py +++ b/openstack/tests/functional/cloud/test_compute.py @@ -115,6 +115,24 @@ class TestCompute(base.BaseFunctionalTest): self.assertTrue(vol_attachment[key]) # assert string is not empty self.assertIsNone(self.user_cloud.detach_volume(server, volume)) + def test_attach_volume_create_snapshot(self): + self.skipTest('Volume functional tests temporarily disabled') + server_name = self.getUniqueString() + self.addCleanup(self._cleanup_servers_and_volumes, server_name) + server = self.user_cloud.create_server( + name=server_name, image=self.image, flavor=self.flavor, wait=True + ) + volume = self.user_cloud.create_volume(1) + vol_attachment = self.user_cloud.attach_volume(server, volume) + for key in ('device', 'serverId', 'volumeId'): + self.assertIn(key, vol_attachment) + self.assertTrue(vol_attachment[key]) # assert string is not empty + snapshot = self.user_cloud.create_volume_snapshot( + volume_id=volume.id, force=True, wait=True + ) + self.addCleanup(self.user_cloud.delete_volume_snapshot, snapshot['id']) + self.assertIsNotNone(snapshot) + def test_create_and_delete_server_with_config_drive(self): self.addCleanup(self._cleanup_servers_and_volumes, self.server_name) server = self.user_cloud.create_server( diff --git a/openstack/tests/unit/cloud/test_create_volume_snapshot.py b/openstack/tests/unit/cloud/test_create_volume_snapshot.py index ed8421475..b1e0e2fb5 100644 --- a/openstack/tests/unit/cloud/test_create_volume_snapshot.py +++ b/openstack/tests/unit/cloud/test_create_volume_snapshot.py @@ -59,7 +59,11 @@ class TestCreateVolumeSnapshot(base.TestCase): 'volumev3', 'public', append=['snapshots'] ), json={'snapshot': build_snapshot_dict}, - validate=dict(json={'snapshot': {'volume_id': '1234'}}), + validate=dict( + json={ + 'snapshot': {'volume_id': '1234', 'force': False} + } + ), ), dict( method='GET', @@ -104,7 +108,11 @@ class TestCreateVolumeSnapshot(base.TestCase): 'volumev3', 'public', append=['snapshots'] ), json={'snapshot': build_snapshot_dict}, - validate=dict(json={'snapshot': {'volume_id': '1234'}}), + validate=dict( + json={ + 'snapshot': {'volume_id': '1234', 'force': False} + } + ), ), dict( method='GET', @@ -149,7 +157,11 @@ class TestCreateVolumeSnapshot(base.TestCase): 'volumev3', 'public', append=['snapshots'] ), json={'snapshot': build_snapshot_dict}, - validate=dict(json={'snapshot': {'volume_id': '1234'}}), + validate=dict( + json={ + 'snapshot': {'volume_id': '1234', 'force': False} + } + ), ), dict( method='GET',