"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/unit/cli/test_manage_shard_ranges.py" between
swift-2.19.1.tar.gz and swift-2.21.0.tar.gz

About: OpenStack swift is software for creating redundant, scalable object storage using clusters of commodity servers to store terabytes or even petabytes of accessible data (now supporting storage policies).
The "Stein" series (latest release).

test_manage_shard_ranges.py  (swift-2.19.1):test_manage_shard_ranges.py  (swift-2.21.0)
skipping to change at line 13 skipping to change at line 13
# of the License at # of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import unicode_literals
import json import json
import os import os
import unittest import unittest
import mock import mock
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from six.moves import cStringIO as StringIO from six.moves import cStringIO as StringIO
from swift.cli.manage_shard_ranges import main from swift.cli.manage_shard_ranges import main
skipping to change at line 186 skipping to change at line 184
with mock_timestamp_now(epoch) as now: with mock_timestamp_now(epoch) as now:
broker.enable_sharding(epoch) broker.enable_sharding(epoch)
self.assertTrue(broker.set_sharding_state()) self.assertTrue(broker.set_sharding_state())
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err): with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err):
with mock_timestamp_now(now): with mock_timestamp_now(now):
main([broker.db_file, 'info']) main([broker.db_file, 'info'])
expected = ['Sharding enabled = True', expected = ['Sharding enabled = True',
'Own shard range: {', 'Own shard range: {',
' "bytes_used": 0, ', ' "bytes_used": 0,',
' "deleted": 0, ', ' "deleted": 0,',
' "epoch": "%s", ' % epoch.internal, ' "epoch": "%s",' % epoch.internal,
' "lower": "", ', ' "lower": "",',
' "meta_timestamp": "%s", ' % now.internal, ' "meta_timestamp": "%s",' % now.internal,
' "name": "a/c", ', ' "name": "a/c",',
' "object_count": 0, ', ' "object_count": 0,',
' "state": "sharding", ', ' "state": "sharding",',
' "state_timestamp": "%s", ' % now.internal, ' "state_timestamp": "%s",' % now.internal,
' "timestamp": "%s", ' % now.internal, ' "timestamp": "%s",' % now.internal,
' "upper": ""', ' "upper": ""',
'}', '}',
'db_state = sharding', 'db_state = sharding',
'Retiring db id: %s' % retiring_db_id, 'Retiring db id: %s' % retiring_db_id,
'Cleaving context: {', 'Cleaving context: {',
' "cleave_to_row": null, ', ' "cleave_to_row": null,',
' "cleaving_done": false, ', ' "cleaving_done": false,',
' "cursor": "", ', ' "cursor": "",',
' "last_cleave_to_row": null, ', ' "last_cleave_to_row": null,',
' "max_row": -1, ', ' "max_row": -1,',
' "misplaced_done": false, ', ' "misplaced_done": false,',
' "ranges_done": 0, ', ' "ranges_done": 0,',
' "ranges_todo": 0, ', ' "ranges_todo": 0,',
' "ref": "%s"' % retiring_db_id, ' "ref": "%s"' % retiring_db_id,
'}', '}',
'Metadata:', 'Metadata:',
' X-Container-Sysmeta-Sharding = True'] ' X-Container-Sysmeta-Sharding = True']
self.assertEqual(expected, out.getvalue().splitlines()) # The json.dumps() in py2 produces trailing space, not in py3.
result = [x.rstrip() for x in out.getvalue().splitlines()]
self.assertEqual(expected, result)
self.assertEqual(['Loaded db broker for a/c.'], self.assertEqual(['Loaded db broker for a/c.'],
err.getvalue().splitlines()) err.getvalue().splitlines())
self.assertTrue(broker.set_sharded_state()) self.assertTrue(broker.set_sharded_state())
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err): with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err):
with mock_timestamp_now(now): with mock_timestamp_now(now):
main([broker.db_file, 'info']) main([broker.db_file, 'info'])
expected = ['Sharding enabled = True', expected = ['Sharding enabled = True',
'Own shard range: {', 'Own shard range: {',
' "bytes_used": 0, ', ' "bytes_used": 0,',
' "deleted": 0, ', ' "deleted": 0,',
' "epoch": "%s", ' % epoch.internal, ' "epoch": "%s",' % epoch.internal,
' "lower": "", ', ' "lower": "",',
' "meta_timestamp": "%s", ' % now.internal, ' "meta_timestamp": "%s",' % now.internal,
' "name": "a/c", ', ' "name": "a/c",',
' "object_count": 0, ', ' "object_count": 0,',
' "state": "sharding", ', ' "state": "sharding",',
' "state_timestamp": "%s", ' % now.internal, ' "state_timestamp": "%s",' % now.internal,
' "timestamp": "%s", ' % now.internal, ' "timestamp": "%s",' % now.internal,
' "upper": ""', ' "upper": ""',
'}', '}',
'db_state = sharded', 'db_state = sharded',
'Metadata:', 'Metadata:',
' X-Container-Sysmeta-Sharding = True'] ' X-Container-Sysmeta-Sharding = True']
self.assertEqual(expected, out.getvalue().splitlines()) self.assertEqual(expected,
[x.rstrip() for x in out.getvalue().splitlines()])
self.assertEqual(['Loaded db broker for a/c.'], self.assertEqual(['Loaded db broker for a/c.'],
err.getvalue().splitlines()) err.getvalue().splitlines())
def test_replace(self): def test_replace(self):
broker = self._make_broker() broker = self._make_broker()
broker.update_metadata({'X-Container-Sysmeta-Sharding': broker.update_metadata({'X-Container-Sysmeta-Sharding':
(True, Timestamp.now().internal)}) (True, Timestamp.now().internal)})
input_file = os.path.join(self.testdir, 'shards') input_file = os.path.join(self.testdir, 'shards')
with open(input_file, 'wb') as fd: with open(input_file, 'w') as fd:
json.dump(self.shard_data, fd) json.dump(self.shard_data, fd)
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err): with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err):
main([broker.db_file, 'replace', input_file]) main([broker.db_file, 'replace', input_file])
expected = [ expected = [
'No shard ranges found to delete.', 'No shard ranges found to delete.',
'Injected 10 shard ranges.', 'Injected 10 shard ranges.',
'Run container-replicator to replicate them to other nodes.', 'Run container-replicator to replicate them to other nodes.',
'Use the enable sub-command to enable sharding.'] 'Use the enable sub-command to enable sharding.']
 End of changes. 7 change blocks. 
33 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)