diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 51276244e..a0fe600ca 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -4802,6 +4802,7 @@ class OpenStackCloud(_normalize.Normalizer): parameters = image_kwargs.pop('parameters', {}) image_kwargs.update(parameters) + self.create_container(container) self.create_object( container, name, filename, md5=md5, sha256=sha256, @@ -7523,9 +7524,6 @@ class OpenStackCloud(_normalize.Normalizer): for (k, v) in metadata.items(): headers['x-object-meta-' + k] = v - # On some clouds this is not necessary. On others it is. I'm confused. - self.create_container(container) - endpoint = '{container}/{name}'.format(container=container, name=name) if data is not None: diff --git a/openstack/tests/unit/cloud/test_object.py b/openstack/tests/unit/cloud/test_object.py index d87f32724..762dd7412 100644 --- a/openstack/tests/unit/cloud/test_object.py +++ b/openstack/tests/unit/cloud/test_object.py @@ -454,33 +454,6 @@ class TestObjectUploads(BaseTestObject): def test_create_object(self): self.register_uris([ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='GET', uri='https://object-store.example.com/info', json=dict( @@ -512,33 +485,6 @@ class TestObjectUploads(BaseTestObject): def test_create_directory_marker_object(self): self.register_uris([ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='PUT', uri='{endpoint}/{container}/{object}'.format( endpoint=self.endpoint, @@ -561,35 +507,6 @@ class TestObjectUploads(BaseTestObject): min_file_size = 1 uris_to_mock = [ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container, ), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='GET', uri='https://object-store.example.com/info', json=dict( @@ -632,8 +549,8 @@ class TestObjectUploads(BaseTestObject): container=self.container, name=self.object, filename=self.object_file.name, use_slo=False) - # After call 6, order become indeterminate because of thread pool - self.assert_calls(stop_after=6) + # After call 3, order become indeterminate because of thread pool + self.assert_calls(stop_after=3) for key, value in self.calls[-1]['headers'].items(): self.assertEqual( @@ -646,35 +563,6 @@ class TestObjectUploads(BaseTestObject): min_file_size = 1 uris_to_mock = [ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container, ), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='GET', uri='https://object-store.example.com/info', json=dict( swift={'max_file_size': max_file_size}, @@ -719,8 +607,8 @@ class TestObjectUploads(BaseTestObject): container=self.container, name=self.object, filename=self.object_file.name, use_slo=True) - # After call 6, order become indeterminate because of thread pool - self.assert_calls(stop_after=6) + # After call 3, order become indeterminate because of thread pool + self.assert_calls(stop_after=3) for key, value in self.calls[-1]['headers'].items(): self.assertEqual( @@ -765,35 +653,6 @@ class TestObjectUploads(BaseTestObject): min_file_size = 1 self.register_uris([ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container, ), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='GET', uri='https://object-store.example.com/info', json=dict( swift={'max_file_size': max_file_size}, @@ -840,8 +699,8 @@ class TestObjectUploads(BaseTestObject): container=self.container, name=self.object, filename=self.object_file.name, use_slo=True) - # After call 6, order become indeterminate because of thread pool - self.assert_calls(stop_after=6) + # After call 3, order become indeterminate because of thread pool + self.assert_calls(stop_after=3) def test_object_segment_retries(self): @@ -849,35 +708,6 @@ class TestObjectUploads(BaseTestObject): min_file_size = 1 self.register_uris([ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container, ), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='GET', uri='https://object-store.example.com/info', json=dict( swift={'max_file_size': max_file_size}, @@ -940,8 +770,8 @@ class TestObjectUploads(BaseTestObject): container=self.container, name=self.object, filename=self.object_file.name, use_slo=True) - # After call 6, order become indeterminate because of thread pool - self.assert_calls(stop_after=6) + # After call 3, order become indeterminate because of thread pool + self.assert_calls(stop_after=3) for key, value in self.calls[-1]['headers'].items(): self.assertEqual( @@ -983,33 +813,6 @@ class TestObjectUploads(BaseTestObject): def test_create_object_skip_checksum(self): self.register_uris([ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='GET', uri='https://object-store.example.com/info', json=dict( @@ -1038,33 +841,6 @@ class TestObjectUploads(BaseTestObject): def test_create_object_data(self): self.register_uris([ - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404), - dict(method='PUT', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }), - dict(method='HEAD', - uri='{endpoint}/{container}'.format( - endpoint=self.endpoint, container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), dict(method='PUT', uri='{endpoint}/{container}/{object}'.format( endpoint=self.endpoint, diff --git a/releasenotes/notes/remove-auto-container-527f1807605b42c0.yaml b/releasenotes/notes/remove-auto-container-527f1807605b42c0.yaml new file mode 100644 index 000000000..ef36ff6a3 --- /dev/null +++ b/releasenotes/notes/remove-auto-container-527f1807605b42c0.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + ``openstack.connection.Connection.create_object`` no longer creates + a container if one doesn't exist. It is the user's responsibility to + create a container before using it.