Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / livetest / astakos.py @ c6ebe715

History | View | Annotate | Download (5.2 kB)

1 6d192774 Stavros Sachtouris
# Copyright 2012-2013 GRNET S.A. All rights reserved.
2 6d192774 Stavros Sachtouris
#
3 6d192774 Stavros Sachtouris
# Redistribution and use in source and binary forms, with or
4 6d192774 Stavros Sachtouris
# without modification, are permitted provided that the following
5 6d192774 Stavros Sachtouris
# conditions are met:
6 6d192774 Stavros Sachtouris
#
7 6d192774 Stavros Sachtouris
#   1. Redistributions of source code must retain the above
8 6d192774 Stavros Sachtouris
#      copyright notice, this list of conditions and the following
9 6d192774 Stavros Sachtouris
#      disclaimer.
10 6d192774 Stavros Sachtouris
#
11 6d192774 Stavros Sachtouris
#   2. Redistributions in binary form must reproduce the above
12 6d192774 Stavros Sachtouris
#      copyright notice, this list of conditions and the following
13 6d192774 Stavros Sachtouris
#      disclaimer in the documentation and/or other materials
14 6d192774 Stavros Sachtouris
#      provided with the distribution.
15 6d192774 Stavros Sachtouris
#
16 6d192774 Stavros Sachtouris
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6d192774 Stavros Sachtouris
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6d192774 Stavros Sachtouris
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6d192774 Stavros Sachtouris
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6d192774 Stavros Sachtouris
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6d192774 Stavros Sachtouris
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6d192774 Stavros Sachtouris
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6d192774 Stavros Sachtouris
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6d192774 Stavros Sachtouris
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6d192774 Stavros Sachtouris
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6d192774 Stavros Sachtouris
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6d192774 Stavros Sachtouris
# POSSIBILITY OF SUCH DAMAGE.
28 6d192774 Stavros Sachtouris
#
29 6d192774 Stavros Sachtouris
# The views and conclusions contained in the software and
30 6d192774 Stavros Sachtouris
# documentation are those of the authors and should not be
31 6d192774 Stavros Sachtouris
# interpreted as representing official policies, either expressed
32 6d192774 Stavros Sachtouris
# or implied, of GRNET S.A.
33 6d192774 Stavros Sachtouris
34 ca65fc0b Stavros Sachtouris
from itertools import product
35 ca65fc0b Stavros Sachtouris
36 ca65fc0b Stavros Sachtouris
from kamaki.clients import livetest, ClientError
37 420598d0 Stavros Sachtouris
from kamaki.clients.astakos import AstakosClient
38 6d192774 Stavros Sachtouris
39 6d192774 Stavros Sachtouris
40 f5f2dc53 Stavros Sachtouris
class Astakos(livetest.Generic):
41 6d192774 Stavros Sachtouris
    def setUp(self):
42 2feb9477 Stavros Sachtouris
        self.cloud = 'cloud.%s' % self['testcloud']
43 420598d0 Stavros Sachtouris
        self.client = AstakosClient(
44 2feb9477 Stavros Sachtouris
            self[self.cloud, 'url'], self[self.cloud, 'token'])
45 114e19da Stavros Sachtouris
        with open(self['astakos', 'details']) as f:
46 114e19da Stavros Sachtouris
            self._astakos_details = eval(f.read())
47 6d192774 Stavros Sachtouris
48 6d192774 Stavros Sachtouris
    def test_authenticate(self):
49 409371de Stavros Sachtouris
        self._test_0010_authenticate()
50 5207c784 Stavros Sachtouris
51 409371de Stavros Sachtouris
    def _test_0010_authenticate(self):
52 6d192774 Stavros Sachtouris
        r = self.client.authenticate()
53 114e19da Stavros Sachtouris
        self.assert_dicts_are_equal(r, self._astakos_details)
54 5207c784 Stavros Sachtouris
55 ca65fc0b Stavros Sachtouris
    def test_get_services(self):
56 ca65fc0b Stavros Sachtouris
        self._test_0020_get_services()
57 ca65fc0b Stavros Sachtouris
58 ca65fc0b Stavros Sachtouris
    def _test_0020_get_services(self):
59 2feb9477 Stavros Sachtouris
        for args in (tuple(), (self[self.cloud, 'token'],)):
60 ca65fc0b Stavros Sachtouris
            r = self.client.get_services(*args)
61 ca65fc0b Stavros Sachtouris
            services = self._astakos_details['access']['serviceCatalog']
62 ca65fc0b Stavros Sachtouris
            self.assertEqual(len(services), len(r))
63 ca65fc0b Stavros Sachtouris
            for i, service in enumerate(services):
64 ca65fc0b Stavros Sachtouris
                self.assert_dicts_are_equal(r[i], service)
65 ca65fc0b Stavros Sachtouris
        self.assertRaises(ClientError, self.client.get_services, 'wrong_token')
66 ca65fc0b Stavros Sachtouris
67 ca65fc0b Stavros Sachtouris
    def test_get_service_details(self):
68 ca65fc0b Stavros Sachtouris
        self._test_0020_get_service_details()
69 ca65fc0b Stavros Sachtouris
70 ca65fc0b Stavros Sachtouris
    def _test_0020_get_service_details(self):
71 ca65fc0b Stavros Sachtouris
        parsed_services = dict()
72 ca65fc0b Stavros Sachtouris
        for args in product(
73 ca65fc0b Stavros Sachtouris
                self._astakos_details['access']['serviceCatalog'],
74 2feb9477 Stavros Sachtouris
                ([tuple(), (self[self.cloud, 'token'],)])):
75 ca65fc0b Stavros Sachtouris
            service = args[0]
76 ca65fc0b Stavros Sachtouris
            if service['type'] in parsed_services:
77 ca65fc0b Stavros Sachtouris
                continue
78 ca65fc0b Stavros Sachtouris
            r = self.client.get_service_details(service['type'], *args[1])
79 ca65fc0b Stavros Sachtouris
            self.assert_dicts_are_equal(r, service)
80 ca65fc0b Stavros Sachtouris
            parsed_services[service['type']] = True
81 ca65fc0b Stavros Sachtouris
        self.assertRaises(
82 ca65fc0b Stavros Sachtouris
            ClientError, self.client.get_service_details, 'wrong_token')
83 ca65fc0b Stavros Sachtouris
84 ca65fc0b Stavros Sachtouris
    def test_get_service_endpoints(self):
85 ca65fc0b Stavros Sachtouris
        self._test_0020_get_service_endpoints()
86 ca65fc0b Stavros Sachtouris
87 ca65fc0b Stavros Sachtouris
    def _test_0020_get_service_endpoints(self):
88 ca65fc0b Stavros Sachtouris
        parsed_services = dict()
89 ca65fc0b Stavros Sachtouris
        for args in product(
90 ca65fc0b Stavros Sachtouris
                self._astakos_details['access']['serviceCatalog'],
91 2feb9477 Stavros Sachtouris
                ([], [self[self.cloud, 'token']])):
92 ca65fc0b Stavros Sachtouris
            service = args[0]
93 ca65fc0b Stavros Sachtouris
            if service['type'] in parsed_services:
94 ca65fc0b Stavros Sachtouris
                continue
95 ca65fc0b Stavros Sachtouris
            for endpoint, with_id in product(
96 ca65fc0b Stavros Sachtouris
                    service['endpoints'], (True, False)):
97 ca65fc0b Stavros Sachtouris
                vid = endpoint['versionId'] if (
98 ca65fc0b Stavros Sachtouris
                    with_id and endpoint['versionId']) else None
99 ca65fc0b Stavros Sachtouris
                end_args = [service['type'], vid] + args[1]
100 ca65fc0b Stavros Sachtouris
                r = self.client.get_service_endpoints(*end_args)
101 ca65fc0b Stavros Sachtouris
                self.assert_dicts_are_equal(r, endpoint)
102 ca65fc0b Stavros Sachtouris
            parsed_services[service['type']] = True
103 ca65fc0b Stavros Sachtouris
        self.assertRaises(
104 ca65fc0b Stavros Sachtouris
            ClientError, self.client.get_service_endpoints, 'wrong_token')
105 ca65fc0b Stavros Sachtouris
106 114e19da Stavros Sachtouris
    def test_user_info(self):
107 114e19da Stavros Sachtouris
        self._test_0020_user_info()
108 2182231b Stavros Sachtouris
109 114e19da Stavros Sachtouris
    def _test_0020_user_info(self):
110 2182231b Stavros Sachtouris
        self.assertTrue(set([
111 114e19da Stavros Sachtouris
            'roles',
112 2182231b Stavros Sachtouris
            'name',
113 114e19da Stavros Sachtouris
            'id']).issubset(self.client.user_info().keys()))
114 2182231b Stavros Sachtouris
115 5207c784 Stavros Sachtouris
    def test_get(self):
116 409371de Stavros Sachtouris
        self._test_0020_get()
117 5207c784 Stavros Sachtouris
118 409371de Stavros Sachtouris
    def _test_0020_get(self):
119 c088076b Stavros Sachtouris
        for term in ('id', 'name'):
120 2182231b Stavros Sachtouris
            self.assertEqual(
121 2feb9477 Stavros Sachtouris
                self.client.term(term, self[self.cloud, 'token']),
122 c088076b Stavros Sachtouris
                self['astakos', term] or '')
123 29040fef Stavros Sachtouris
124 114e19da Stavros Sachtouris
    def test_list_users(self):
125 29040fef Stavros Sachtouris
        self.client.authenticate()
126 114e19da Stavros Sachtouris
        self._test_0020_list_users()
127 29040fef Stavros Sachtouris
128 114e19da Stavros Sachtouris
    def _test_0020_list_users(self):
129 114e19da Stavros Sachtouris
        terms = set(['name', 'id'])
130 29040fef Stavros Sachtouris
        uuid = 0
131 114e19da Stavros Sachtouris
        for r in self.client.list_users():
132 29040fef Stavros Sachtouris
            self.assertTrue(terms.issubset(r.keys()))
133 114e19da Stavros Sachtouris
            self.assertTrue(uuid != r['id'] if uuid else True)
134 114e19da Stavros Sachtouris
            uuid = r['id']