Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the s3cmd versioning test method?

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the s3cmd versioning testing method". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the s3cmd versioning testing method is.

"" Some unit tests for the S3 Versioning. "" import unittestimport timefrom boto.s3.connection import S3Connectionfrom boto.exception import S3ResponseErrorfrom boto.s3.deletemarker import DeleteMarkerclass S3VersionTest (unittest.TestCase): def setUp (self): self.conn = S3Connection () self.bucket_name = 'version-%d'% int (time.time ()) self.bucket = self.conn.create_bucket (self.bucket_name) def tearDown (self): For k in self.bucket.list_versions (): self.bucket.delete_key (k.name Version_id=k.version_id) self.bucket.delete () def test_1_versions (self): # check versioning off d = self.bucket.get_versioning_status () self.assertFalse ('Versioning' in d) # enable versioning self.bucket.configure_versioning (versioning=True) d = self.bucket.get_versioning_status () self.assertEqual (' Enabled') D ['Versioning']) # create a new key in the versioned bucket k = self.bucket.new_key ("foobar") S1 =' This is v1' k.set_contents_from_string (S1) # remember the version id of this object v1 = k.version_id # now get the contents from s3o1 = k.get_contents _ as_string () # check to make sure content read from k is identical to original self.assertEqual (S1 S1) # now overwrite that same key with new data S2 = 'This is v2' k.set_contents_from_string (S2) v2 = k.version_id # now retrieve latest contents as a string and compare K2 = self.bucket.new_key ("foobar") O2 = k2.get_contents_as_string () self.assertEqual (S2) O2) # next retrieve explicit versions and compare o1 = k.get_contents_as_string (version_id=v1) O2 = k.get_contents_as_string (version_id=v2) self.assertEqual (S1, o1) self.assertEqual (S2, O2) # Now list all versions and compare to what we have rs = self.bucket.get_all_versions () self.assertEqual (v2) Rs [0] .version _ id) self.assertEqual (v1, rs [1] .version _ id) # Now do a regular list command and make sure only the new key shows up rs = self.bucket.get_all_keys () self.assertEqual (1 Len (rs)) # Now do regular delete self.bucket.delete_key ('foobar') # Now list versions and make sure old versions are there # plus the DeleteMarker which is latest. Rs = self.bucket.get_all_versions () self.assertEqual (3, len (rs)) self.assertTrue (isinstance (rs [0], DeleteMarker)) # Now delete v1 of the key self.bucket.delete_key ('foobar') Version_id=v1) # Now list versions again and make sure v1 is not there rs = self.bucket.get_all_versions () versions = [k.version_id for k in rs] self.assertTrue (v1 not in versions) self.assertTrue (v2 in versions) # Now suspend Versioning on the bucket self.bucket.configure_versioning (False) # Allow time for the change to fully propagate. Time.sleep (3) d = self.bucket.get_versioning_status () self.assertEqual ('Suspended' D ['Versioning']) def test_latest_version (self): self.bucket.configure_versioning (versioning=True) # add v1 of an object key_name = "key" kv1 = self.bucket.new_key (key_name) kv1.set_contents_from_string ("v1") # read list which should contain latest v1 listed_kv1 = Iter (self.bucket.get_all_versions ()). Next () self.assertEqual (listed_kv1.name Key_name) self.assertEqual (listed_kv1.version_id, kv1.version_id) self.assertEqual (listed_kv1.is_latest, True) # add v2 of the object kv2 = self.bucket.new_key (key_name) kv2.set_contents_from_string ("v2") # read 2 versions Confirm v2 is latest i = iter (self.bucket.get_all_versions ()) listed_kv2 = i.next () listed_kv1 = i.next () self.assertEqual (listed_kv2.version_id, kv2.version_id) self.assertEqual (listed_kv1.version_id, kv1.version_id) self.assertEqual (listed_kv2.is_latest, True) self.assertEqual (listed_kv1.is_latest False) # delete key, which creates a delete marker as latest self.bucket.delete_key (key_name) I = iter (self.bucket.get_all_versions ()) listed_kv3 = i.next listed_kv2 = i.next () listed_kv1 = i.next () self.assertNotEqual (listed_kv3.version_id, None) self.assertEqual (listed_kv2.version_id Kv2.version_id) self.assertEqual (listed_kv1.version_id, kv1.version_id) self.assertEqual (listed_kv3.is_latest, True) self.assertEqual (listed_kv2.is_latest, False) self.assertEqual (listed_kv1.is_latest, False) Thank you for your reading The above is the content of "what is the s3cmd versioning testing method". After the study of this article, I believe you have a deeper understanding of what the s3cmd versioning testing method is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report