Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / pithos_tests.py @ 79a5c431

History | View | Annotate | Download (5.3 kB)

1
# Copyright 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

    
34
"""
35
This is the burnin class that tests the Pithos functionality
36

37
"""
38

    
39
import random
40
import tempfile
41

    
42
from synnefo_tools.burnin import common
43

    
44

    
45
# Too many public methods. pylint: disable-msg=R0904
46
class PithosTestSuite(common.BurninTests):
47
    """Test Pithos functionality"""
48
    containers = None
49
    created_container = None
50

    
51
    def test_001_list_containers(self):
52
        """Test container list actually returns containers"""
53
        self._set_pithos_account(self._get_uuid())
54
        containers = self._get_list_of_containers()
55
        self._setattr("containers", containers)
56
        self.assertGreater(len(self.containers), 0)
57

    
58
    def test_002_unique_containers(self):
59
        """Test if containers have unique names"""
60
        names = [n['name'] for n in self.containers]
61
        names = sorted(names)
62
        self.assertEqual(sorted(list(set(names))), names)
63

    
64
    def test_003_create_container(self):
65
        """Test creating a new container"""
66
        names = [n['name'] for n in self.containers]
67
        while True:
68
            rand_num = random.randint(1000, 9999)
69
            rand_name = "%s%s" % (self.run_id, rand_num)
70
            self.info("Trying container name %s", rand_name)
71
            if rand_name not in names:
72
                break
73
            self.info("Container name %s already exists", rand_name)
74
        # Create container
75
        self._create_pithos_container(rand_name)
76
        # Verify that container is created
77
        containers = self._get_list_of_containers()
78
        self.info("Verify that container %s is created", rand_name)
79
        names = [n['name'] for n in containers]
80
        self.assertIn(rand_name, names)
81
        # Keep the name of the container so we can remove it
82
        # at cleanup phase, if something goes wrong.
83
        self._setattr("created_container", rand_name)
84

    
85
    def test_004_upload_file(self):
86
        """Test uploading a txt file to Pithos"""
87
        # Create a tmp file
88
        with tempfile.TemporaryFile() as fout:
89
            fout.write("This is a temp file")
90
            fout.seek(0, 0)
91
            # Upload the file,
92
            # The container is the one choosen during the `create_container'
93
            self.clients.pithos.upload_object("test.txt", fout)
94

    
95
    def test_005_download_file(self):
96
        """Test downloading the file from Pithos"""
97
        # Create a tmp directory to save the file
98
        with tempfile.TemporaryFile() as fout:
99
            self.clients.pithos.download_object("test.txt", fout)
100
            # Now read the file
101
            fout.seek(0, 0)
102
            contents = fout.read()
103
            # Compare results
104
            self.info("Comparing contents with the uploaded file")
105
            self.assertEqual(contents, "This is a temp file")
106

    
107
    def test_006_remove(self):
108
        """Test removing files and containers from Pithos"""
109
        self.info("Removing the file %s from container %s",
110
                  "test.txt", self.created_container)
111
        # The container is the one choosen during the `create_container'
112
        self.clients.pithos.del_object("test.txt")
113

    
114
        self.info("Removing the container %s", self.created_container)
115
        self.clients.pithos.purge_container()
116

    
117
        # List containers
118
        containers = self._get_list_of_containers()
119
        self.info("Check that the container %s has been deleted",
120
                  self.created_container)
121
        names = [n['name'] for n in containers]
122
        self.assertNotIn(self.created_container, names)
123
        # We successfully deleted our container, no need to do it
124
        # in our clean up phase
125
        self._setattr("created_container", None)
126

    
127
    @classmethod
128
    def tearDownClass(cls):  # noqa
129
        """Clean up"""
130
        if cls.created_container is not None:
131
            cls.clients.pithos.del_container(delimiter='/')
132
            cls.clients.pithos.purge_container()