commit fe81ddd764f40125393055a2e39c393149712dc7
Author: Stavros Sachtouris <saxtouri@admin.grnet.gr>
Date:   Fri Jan 17 19:35:55 2014 +0200

    Test pithos container POST/PUT

diff --git a/snf-tools/synnefo_tools/burnin/common.py b/snf-tools/synnefo_tools/burnin/common.py
index ec7d384..ce63e45 100644
--- a/snf-tools/synnefo_tools/burnin/common.py
+++ b/snf-tools/synnefo_tools/burnin/common.py
@@ -42,6 +42,9 @@ import unittest
 import datetime
 import tempfile
 import traceback
+from tempfile import NamedTemporaryFile
+from os import urandom
+from sys import stderr
 
 from kamaki.clients.cyclades import CycladesClient, CycladesNetworkClient
 from kamaki.clients.astakos import AstakosClient, parse_endpoints
@@ -305,6 +308,23 @@ class BurninTests(unittest.TestCase):
         except OSError:
             pass
 
+    def _create_large_file(self, size):
+        """Create a large file at fs"""
+        f = NamedTemporaryFile()
+        Ki = size / 8
+        c = ['|', '/', '-', '\\']
+        stderr.write('Create file %s  ' % f.name)
+        for i, bytes in enumerate([b * Ki for b in range(size / Ki)]):
+            f.seek(bytes)
+            f.write(urandom(Ki))
+            f.flush()
+            stderr.write('\b' + c[i % 4])
+            stderr.flush()
+        stderr.write('\n')
+        stderr.flush()
+        f.seek(0)
+        return f
+
     def _get_uuid_of_system_user(self):
         """Get the uuid of the system user
 
diff --git a/snf-tools/synnefo_tools/burnin/pithos_tests.py b/snf-tools/synnefo_tools/burnin/pithos_tests.py
index d5ecdae..7aa03c7 100644
--- a/snf-tools/synnefo_tools/burnin/pithos_tests.py
+++ b/snf-tools/synnefo_tools/burnin/pithos_tests.py
@@ -198,7 +198,7 @@ class PithosTestSuite(BurninTests):
         self.info('Container meta exists')
 
         self.obj_metakey = 'metakey%s' % random.randint(1000, 9999)
-        obj = 'object%s' % random.randint(1000, 9999)
+        obj = 'object_with_meta'
         pithos.create_object(obj)
         pithos.set_object_meta(obj, {self.obj_metakey: 'our value'})
         r = pithos.get_container_object_meta()
@@ -268,9 +268,139 @@ class PithosTestSuite(BurninTests):
         except ClientError:
             pass
 
-    # def test_050_stop_test(self):
-    #     """STOP TESTING ALREADY"""
-    #     self.assertTrue(False)
+    def test_030_container_put(self):
+        """Test container PUT"""
+        pithos = self.clients.pithos
+        pithos.container = 'cont%s%s' % (
+            self.run_id or 0, random.randint(1000, 9999))
+        self.temp_containers.append(pithos.container)
+
+        r = pithos.create_container()
+        self.assertTrue(isinstance(r, dict))
+
+        r = pithos.get_container_limit(pithos.container)
+        cquota = r.values()[0]
+        newquota = 2 * int(cquota)
+        self.info('Limit is OK')
+        pithos.del_container()
+
+        r = pithos.create_container(sizelimit=newquota)
+        self.assertTrue(isinstance(r, dict))
+
+        r = pithos.get_container_limit(pithos.container)
+        xquota = int(r.values()[0])
+        self.assertEqual(newquota, xquota)
+        self.info('Can set container limit')
+        pithos.del_container()
+
+        r = pithos.create_container(versioning='auto')
+        self.assertTrue(isinstance(r, dict))
+
+        r = pithos.get_container_versioning(pithos.container)
+        nvers = r.values()[0]
+        self.assertEqual('auto', nvers)
+        self.info('Versioning=auto is OK')
+        pithos.del_container()
+
+        r = pithos.container_put(versioning='none')
+        self.assertEqual(r.status_code, 201)
+
+        r = pithos.get_container_versioning(pithos.container)
+        nvers = r.values()[0]
+        self.assertEqual('none', nvers)
+        self.info('Versioning=none is OK')
+        pithos.del_container()
+
+        r = pithos.create_container(metadata={'m1': 'v1', 'm2': 'v2'})
+        self.assertTrue(isinstance(r, dict))
+
+        r = pithos.get_container_meta(pithos.container)
+        self.assertTrue('x-container-meta-m1' in r)
+        self.assertEqual(r['x-container-meta-m1'], 'v1')
+        self.assertTrue('x-container-meta-m2' in r)
+        self.assertEqual(r['x-container-meta-m2'], 'v2')
+
+        r = pithos.container_put(metadata={'m1': '', 'm2': 'v2a'})
+        self.assertEqual(r.status_code, 202)
+
+        r = pithos.get_container_meta(pithos.container)
+        self.assertTrue('x-container-meta-m1' not in r)
+        self.assertTrue('x-container-meta-m2' in r)
+        self.assertEqual(r['x-container-meta-m2'], 'v2a')
+        self.info('Container meta is OK')
+
+        pithos.del_container_meta(pithos.container)
+
+    def test_035_container_post(self):
+        """Test container POST"""
+        pithos = self.clients.pithos
+
+        r = pithos.container_post()
+        self.assertEqual(r.status_code, 202)
+        self.info('Status is OK')
+
+        pithos.set_container_meta({'m1': 'v1', 'm2': 'v2'})
+        r = pithos.get_container_meta(pithos.container)
+        self.assertTrue('x-container-meta-m1' in r)
+        self.assertEqual(r['x-container-meta-m1'], 'v1')
+        self.assertTrue('x-container-meta-m2' in r)
+        self.assertEqual(r['x-container-meta-m2'], 'v2')
+        self.info('Set metadata works')
+
+        r = pithos.del_container_meta('m1')
+        r = pithos.set_container_meta({'m2': 'v2a'})
+        r = pithos.get_container_meta(pithos.container)
+        self.assertTrue('x-container-meta-m1' not in r)
+        self.assertTrue('x-container-meta-m2' in r)
+        self.assertEqual(r['x-container-meta-m2'], 'v2a')
+        self.info('Delete metadata works')
+
+        r = pithos.get_container_limit(pithos.container)
+        cquota = r.values()[0]
+        newquota = 2 * int(cquota)
+        r = pithos.set_container_limit(newquota)
+        r = pithos.get_container_limit(pithos.container)
+        xquota = int(r.values()[0])
+        self.assertEqual(newquota, xquota)
+        self.info('Set quota works')
+
+        pithos.set_container_versioning('auto')
+        r = pithos.get_container_versioning(pithos.container)
+        nvers = r.values()[0]
+        self.assertEqual('auto', nvers)
+        pithos.set_container_versioning('none')
+        r = pithos.get_container_versioning(pithos.container)
+        nvers = r.values()[0]
+        self.assertEqual('none', nvers)
+        self.info('Set versioning works')
+
+        f = self._create_large_file(1024 * 1024 * 100)
+        self.info('Created file %s of 100 MB' % f.name)
+
+        pithos.create_directory('dir')
+        r = pithos.upload_object('/dir/sample.file', f)
+        for term in ('content-length', 'content-type', 'x-object-version'):
+            self.assertTrue(term in r)
+        r = pithos.get_object_info('/dir/sample.file')
+        self.assertTrue(int(r['content-length']) > 100000000)
+        self.info('Made remote directory /dir and object /dir/sample.file')
+
+        """What is tranfer_encoding? What should I check about it? """
+        #TODO
+
+        obj = 'object_with_meta'
+        pithos.container = self.temp_containers[-2]
+        r = pithos.object_post(
+            obj, update='False', metadata={'newmeta': 'newval'})
+
+        r = pithos.get_object_info(obj)
+        self.assertTrue('x-object-meta-newmeta' in r)
+        self.assertFalse('x-object-meta-%s' % self.obj_metakey not in r)
+        self.info('Metadata with update=False works')
+
+    def test_050_stop_test(self):
+        """STOP TESTING ALREADY"""
+        self.assertTrue(False)
 
     def test_051_list_containers(self):
         """Test container list actually returns containers"""
@@ -284,27 +414,6 @@ class PithosTestSuite(BurninTests):
         names = sorted(names)
         self.assertEqual(sorted(list(set(names))), names)
 
-    def test_053_create_container(self):
-        """Test creating a new container"""
-        names = [n['name'] for n in self.containers]
-        while True:
-            rand_num = random.randint(1000, 9999)
-            rand_name = "%s%s" % (self.run_id or 0, rand_num)
-            self.info("Trying container name %s", rand_name)
-            if rand_name not in names:
-                break
-            self.info("Container name %s already exists", rand_name)
-        # Create container
-        self._create_pithos_container(rand_name)
-        # Verify that container is created
-        containers = self._get_list_of_containers()
-        self.info("Verify that container %s is created", rand_name)
-        names = [n['name'] for n in containers]
-        self.assertIn(rand_name, names)
-        # Keep the name of the container so we can remove it
-        # at cleanup phase, if something goes wrong.
-        self.created_container = rand_name
-
     def test_054_upload_file(self):
         """Test uploading a txt file to Pithos"""
         # Create a tmp file
