Browse Source

Merge intree freezer-api tempest plugin into freezer tempest plugin

* It merges the freezer-api tempest plugin into freezer tempest
  plugin by moving freezer and freezer-api tempest tests in
  freezer_tempest_plugin/tests/freezer and
  freezer_tempest_plugin/tests/freezer_api.

* clients.py is moved under main root folder.

Change-Id: I66cc2507b0bbd9dda9d6279f9b8d74c546d1b0a6
Chandan Kumar 1 year ago
parent
commit
84b0c74205
23 changed files with 1296 additions and 7 deletions
  1. 24
    0
      freezer_tempest_plugin/clients.py
  2. 29
    0
      freezer_tempest_plugin/config.py
  3. 10
    1
      freezer_tempest_plugin/plugin.py
  4. 184
    0
      freezer_tempest_plugin/services/freezer_api_client.py
  5. 0
    0
      freezer_tempest_plugin/tests/freezer/__init__.py
  6. 0
    0
      freezer_tempest_plugin/tests/freezer/api/__init__.py
  7. 0
    0
      freezer_tempest_plugin/tests/freezer/api/base.py
  8. 1
    1
      freezer_tempest_plugin/tests/freezer/api/test_backup_compress.py
  9. 1
    1
      freezer_tempest_plugin/tests/freezer/api/test_fs_backup.py
  10. 1
    1
      freezer_tempest_plugin/tests/freezer/api/test_metadata_checksum.py
  11. 1
    1
      freezer_tempest_plugin/tests/freezer/api/test_swift_backup.py
  12. 1
    1
      freezer_tempest_plugin/tests/freezer/api/test_tests_running.py
  13. 0
    0
      freezer_tempest_plugin/tests/freezer/scenario/__init__.py
  14. 1
    1
      freezer_tempest_plugin/tests/freezer/scenario/test_backups.py
  15. 0
    0
      freezer_tempest_plugin/tests/freezer_api/__init__.py
  16. 0
    0
      freezer_tempest_plugin/tests/freezer_api/api/__init__.py
  17. 33
    0
      freezer_tempest_plugin/tests/freezer_api/api/base.py
  18. 219
    0
      freezer_tempest_plugin/tests/freezer_api/api/test_api_actions.py
  19. 300
    0
      freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py
  20. 96
    0
      freezer_tempest_plugin/tests/freezer_api/api/test_api_clients.py
  21. 154
    0
      freezer_tempest_plugin/tests/freezer_api/api/test_api_jobs.py
  22. 131
    0
      freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py
  23. 110
    0
      freezer_tempest_plugin/tests/freezer_api/api/test_api_version.py

+ 24
- 0
freezer_tempest_plugin/clients.py View File

@@ -0,0 +1,24 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from tempest import clients
16
+
17
+from freezer_tempest_plugin.services import freezer_api_client
18
+
19
+
20
+class Manager(clients.Manager):
21
+    def __init__(self, credentials=None):
22
+        super(Manager, self).__init__(credentials)
23
+        self.freezer_api_client = freezer_api_client.FreezerApiClient(
24
+            self.auth_provider)

+ 29
- 0
freezer_tempest_plugin/config.py View File

@@ -19,3 +19,32 @@ service_option = cfg.BoolOpt('freezer',
19 19
                              default=True,
20 20
                              help="Whether or not freezer is expected to be "
21 21
                                   "available")
22
+
23
+ServiceAvailableGroup = [
24
+    cfg.BoolOpt("freezer-api",
25
+                default=True,
26
+                help="Whether or not Freezer API is expected to be available"),
27
+]
28
+
29
+service_available_group = cfg.OptGroup(name="service_available",
30
+                                       title="Available OpenStack Services")
31
+
32
+freezer_api_group = cfg.OptGroup(name="backup",
33
+                                 title="Freezer API Service Options")
34
+
35
+FreezerApiGroup = [
36
+    cfg.StrOpt("region",
37
+               default="",
38
+               help="The freezer api region name to use. If empty, the value "
39
+                    "of identity.region is used instead. If no such region "
40
+                    "is found in the service catalog, the first found one is "
41
+                    "used."),
42
+    cfg.StrOpt("catalog_type",
43
+               default="backup",
44
+               help="Catalog type of the freezer-api service."),
45
+    cfg.StrOpt('endpoint_type',
46
+               default='publicURL',
47
+               choices=['public', 'admin', 'internal',
48
+                        'publicURL', 'adminURL', 'internalURL'],
49
+               help="The endpoint type to use for the freezer-api service.")
50
+]

+ 10
- 1
freezer_tempest_plugin/plugin.py View File

@@ -15,6 +15,7 @@
15 15
 
16 16
 import os
17 17
 
18
+from tempest import config as tempest_config
18 19
 from tempest.test_discover import plugins
19 20
 
20 21
 from freezer_tempest_plugin import config as freezer_config
@@ -29,8 +30,16 @@ class FreezerTempestPlugin(plugins.TempestPlugin):
29 30
         return full_test_dir, base_path
30 31
 
31 32
     def register_opts(self, conf):
33
+        tempest_config.register_opt_group(
34
+            conf, freezer_config.service_available_group,
35
+            freezer_config.ServiceAvailableGroup)
36
+        tempest_config.register_opt_group(
37
+            conf, freezer_config.freezer_api_group,
38
+            freezer_config.FreezerApiGroup)
32 39
         conf.register_opt(freezer_config.service_option,
33 40
                           group='service_available')
34 41
 
35 42
     def get_opt_lists(self):
36
-        return [('service_available', [freezer_config.service_option])]
43
+        return [('service_available', [freezer_config.service_option]),
44
+                (freezer_config.freezer_api_group.name,
45
+                 freezer_config.FreezerApiGroup)]

+ 184
- 0
freezer_tempest_plugin/services/freezer_api_client.py View File

@@ -0,0 +1,184 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import urllib
16
+
17
+from oslo_serialization import jsonutils as json
18
+from tempest import config
19
+from tempest.lib.common import rest_client
20
+
21
+CONF = config.CONF
22
+
23
+
24
+class FreezerApiClient(rest_client.RestClient):
25
+    def __init__(self, auth_provider):
26
+        super(FreezerApiClient, self).__init__(
27
+            auth_provider,
28
+            CONF.backup.catalog_type,
29
+            CONF.backup.region or CONF.identity.region,
30
+            endpoint_type=CONF.backup.endpoint_type
31
+        )
32
+
33
+    def get_version(self):
34
+
35
+        resp, response_body = self.get('/')
36
+        return resp, response_body
37
+
38
+    def get_version_v1(self):
39
+
40
+        resp, response_body = self.get('/v1')
41
+        return resp, response_body
42
+
43
+    def get_version_v2(self):
44
+
45
+        resp, response_body = self.get('/v2')
46
+        return resp, response_body
47
+
48
+    def get_backups(self, backup_id=None, **params):
49
+
50
+        if backup_id is None:
51
+            uri = '/v1/backups'
52
+            if params:
53
+                uri += '?%s' % urllib.urlencode(params)
54
+        else:
55
+            uri = '/v1/backups/' + backup_id
56
+
57
+        resp, response_body = self.get(uri)
58
+        return resp, json.loads(response_body)
59
+
60
+    def post_backups(self, metadata, backup_id=None):
61
+        uri = '/v1/backups'
62
+        if backup_id is not None:
63
+            uri += '/' + backup_id
64
+
65
+        request_body = json.dumps(metadata)
66
+        resp, response_body = self.post(uri, request_body)
67
+
68
+        return resp, json.loads(response_body)
69
+
70
+    def delete_backups(self, backup_id):
71
+
72
+        uri = '/v1/backups/' + backup_id
73
+        resp, response_body = self.delete(uri)
74
+        return resp, response_body
75
+
76
+    def get_clients(self, client_id=None, **params):
77
+
78
+        if client_id is None:
79
+            uri = '/v1/clients'
80
+            if params:
81
+                uri += '?%s' % urllib.urlencode(params)
82
+        else:
83
+            uri = 'v1/clients/' + client_id
84
+
85
+        resp, response_body = self.get(uri)
86
+        return resp, response_body
87
+
88
+    def post_clients(self, client):
89
+
90
+        request_body = json.dumps(client)
91
+        resp, response_body = self.post('/v1/clients', request_body)
92
+        return resp, json.loads(response_body)
93
+
94
+    def delete_clients(self, client_id):
95
+
96
+        uri = '/v1/clients/' + client_id
97
+        resp, response_body = self.delete(uri)
98
+        return resp, response_body
99
+
100
+    def get_jobs(self, job_id=None, **params):
101
+
102
+        if job_id is None:
103
+            uri = '/v1/jobs'
104
+            if params:
105
+                uri += '?%s' % urllib.urlencode(params)
106
+        else:
107
+            uri = '/v1/jobs/' + job_id
108
+
109
+        resp, response_body = self.get(uri)
110
+        return resp, response_body
111
+
112
+    def post_jobs(self, job):
113
+
114
+        request_body = json.dumps(job)
115
+        resp, response_body = self.post('/v1/jobs', request_body)
116
+        return resp, json.loads(response_body)
117
+
118
+    def delete_jobs(self, job_id):
119
+
120
+        uri = '/v1/jobs/' + job_id
121
+        resp, response_body = self.delete(uri)
122
+        return resp, response_body
123
+
124
+    def get_actions(self, action_id=None, **params):
125
+
126
+        if action_id is None:
127
+            uri = '/v1/actions'
128
+            if params:
129
+                uri += '?%s' % urllib.urlencode(params)
130
+        else:
131
+            uri = '/v1/actions/' + action_id
132
+
133
+        resp, response_body = self.get(uri)
134
+        return resp, response_body
135
+
136
+    def post_actions(self, action, action_id=None):
137
+
138
+        request_body = json.dumps(action)
139
+
140
+        if action_id is None:
141
+            uri = '/v1/actions'
142
+        else:
143
+            uri = '/v1/actions/' + action_id
144
+
145
+        resp, response_body = self.post(uri, request_body)
146
+        return resp, json.loads(response_body)
147
+
148
+    def patch_actions(self, action, action_id):
149
+
150
+        request_body = json.dumps(action)
151
+
152
+        uri = '/v1/actions/' + action_id
153
+        resp, response_body = self.patch(uri, request_body)
154
+        return resp, json.loads(response_body)
155
+
156
+    def delete_actions(self, id):
157
+
158
+        uri = '/v1/actions/' + id
159
+        resp, response_body = self.delete(uri)
160
+        return resp, response_body
161
+
162
+    def get_sessions(self, session_id=None, **params):
163
+
164
+        if session_id is None:
165
+            uri = '/v1/sessions'
166
+            if params:
167
+                uri += '?%s' % urllib.urlencode(params)
168
+        else:
169
+            uri = 'v1/sessions/' + session_id
170
+
171
+        resp, response_body = self.get(uri)
172
+        return resp, response_body
173
+
174
+    def post_sessions(self, session):
175
+
176
+        request_body = json.dumps(session)
177
+        resp, response_body = self.post('/v1/sessions', request_body)
178
+        return resp, json.loads(response_body)
179
+
180
+    def delete_sessions(self, session_id):
181
+
182
+        uri = '/v1/sessions/' + session_id
183
+        resp, response_body = self.delete(uri)
184
+        return resp, response_body

freezer_tempest_plugin/tests/api/__init__.py → freezer_tempest_plugin/tests/freezer/__init__.py View File


freezer_tempest_plugin/tests/scenario/__init__.py → freezer_tempest_plugin/tests/freezer/api/__init__.py View File


freezer_tempest_plugin/tests/api/base.py → freezer_tempest_plugin/tests/freezer/api/base.py View File


freezer_tempest_plugin/tests/api/test_backup_compress.py → freezer_tempest_plugin/tests/freezer/api/test_backup_compress.py View File

@@ -19,7 +19,7 @@ import subprocess
19 19
 from tempest.lib import decorators
20 20
 
21 21
 from freezer_tempest_plugin import common
22
-from freezer_tempest_plugin.tests.api import base
22
+from freezer_tempest_plugin.tests.freezer.api import base
23 23
 
24 24
 
25 25
 class TestFreezerCompressGzip(base.BaseFreezerTest):

freezer_tempest_plugin/tests/api/test_fs_backup.py → freezer_tempest_plugin/tests/freezer/api/test_fs_backup.py View File

@@ -18,7 +18,7 @@ import shutil
18 18
 from oslo_utils import uuidutils
19 19
 from tempest.lib import decorators
20 20
 
21
-from freezer_tempest_plugin.tests.api import base
21
+from freezer_tempest_plugin.tests.freezer.api import base
22 22
 
23 23
 
24 24
 class TestFreezerFSBackup(base.BaseFreezerTest):

freezer_tempest_plugin/tests/api/test_metadata_checksum.py → freezer_tempest_plugin/tests/freezer/api/test_metadata_checksum.py View File

@@ -16,7 +16,7 @@ import subprocess
16 16
 from tempest.lib import decorators
17 17
 
18 18
 from freezer_tempest_plugin import common
19
-from freezer_tempest_plugin.tests.api import base
19
+from freezer_tempest_plugin.tests.freezer.api import base
20 20
 
21 21
 
22 22
 class TestFreezerMetadataChecksum(base.BaseFreezerTest):

freezer_tempest_plugin/tests/api/test_swift_backup.py → freezer_tempest_plugin/tests/freezer/api/test_swift_backup.py View File

@@ -18,7 +18,7 @@ import shutil
18 18
 from oslo_utils import uuidutils
19 19
 from tempest.lib import decorators
20 20
 
21
-from freezer_tempest_plugin.tests.api import base
21
+from freezer_tempest_plugin.tests.freezer.api import base
22 22
 
23 23
 
24 24
 class TestFreezerSwiftBackup(base.BaseFreezerTest):

freezer_tempest_plugin/tests/api/test_tests_running.py → freezer_tempest_plugin/tests/freezer/api/test_tests_running.py View File

@@ -14,7 +14,7 @@
14 14
 
15 15
 from tempest.lib import decorators
16 16
 
17
-from freezer_tempest_plugin.tests.api import base
17
+from freezer_tempest_plugin.tests.freezer.api import base
18 18
 
19 19
 
20 20
 class TestFreezerTestsRunning(base.BaseFreezerTest):

+ 0
- 0
freezer_tempest_plugin/tests/freezer/scenario/__init__.py View File


freezer_tempest_plugin/tests/scenario/test_backups.py → freezer_tempest_plugin/tests/freezer/scenario/test_backups.py View File

@@ -22,7 +22,7 @@ import time
22 22
 from tempest.lib.cli import base as cli_base
23 23
 from tempest.lib.cli import output_parser
24 24
 
25
-from freezer_tempest_plugin.tests.api import base
25
+from freezer_tempest_plugin.tests.freezer.api import base
26 26
 
27 27
 JOB_TABLE_RESULT_COLUMN = 3
28 28
 

+ 0
- 0
freezer_tempest_plugin/tests/freezer_api/__init__.py View File


+ 0
- 0
freezer_tempest_plugin/tests/freezer_api/api/__init__.py View File


+ 33
- 0
freezer_tempest_plugin/tests/freezer_api/api/base.py View File

@@ -0,0 +1,33 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from tempest import config
16
+from tempest import test
17
+
18
+from freezer_tempest_plugin import clients
19
+
20
+CONF = config.CONF
21
+
22
+
23
+class BaseFreezerApiTest(test.BaseTestCase):
24
+    """Base test case class for all Freezer API tests."""
25
+
26
+    credentials = ['primary']
27
+
28
+    client_manager = clients.Manager
29
+
30
+    @classmethod
31
+    def setup_clients(cls):
32
+        super(BaseFreezerApiTest, cls).setup_clients()
33
+        cls.freezer_api_client = cls.os_primary.freezer_api_client

+ 219
- 0
freezer_tempest_plugin/tests/freezer_api/api/test_api_actions.py View File

@@ -0,0 +1,219 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import json
16
+
17
+from tempest.lib import decorators
18
+from tempest.lib import exceptions
19
+
20
+from freezer_tempest_plugin.tests.freezer_api.api import base
21
+
22
+
23
+class TestFreezerApiActions(base.BaseFreezerApiTest):
24
+    @classmethod
25
+    def resource_setup(cls):
26
+        super(TestFreezerApiActions, cls).resource_setup()
27
+
28
+    @classmethod
29
+    def resource_cleanup(cls):
30
+        super(TestFreezerApiActions, cls).resource_cleanup()
31
+
32
+    @decorators.attr(type="gate")
33
+    def test_api_actions(self):
34
+        resp, response_body = self.freezer_api_client.get_actions()
35
+        self.assertEqual(200, resp.status)
36
+
37
+        resp_body_json = json.loads(response_body)
38
+        self.assertIn('actions', resp_body_json)
39
+        actions = resp_body_json['actions']
40
+        self.assertEqual(actions, [])
41
+
42
+    @decorators.attr(type="gate")
43
+    def test_api_actions_get_limit(self):
44
+        # limits > 0 should return successfully
45
+        for valid_limit in [2, 1]:
46
+            resp, body = self.freezer_api_client.get_actions(limit=valid_limit)
47
+            self.assertEqual(200, resp.status)
48
+
49
+        # limits <= 0 should raise a bad request error
50
+        for bad_limit in [0, -1, -2]:
51
+            self.assertRaises(exceptions.BadRequest,
52
+                              self.freezer_api_client.get_actions,
53
+                              limit=bad_limit)
54
+
55
+    @decorators.attr(type="gate")
56
+    def test_api_actions_get_offset(self):
57
+        # offsets >= 0 should return 200
58
+        for valid_offset in [1, 0]:
59
+            resp, body = self.freezer_api_client.get_actions(
60
+                offset=valid_offset)
61
+            self.assertEqual(200, resp.status)
62
+
63
+        # offsets < 0 should return 400
64
+        for bad_offset in [-1, -2]:
65
+            self.assertRaises(exceptions.BadRequest,
66
+                              self.freezer_api_client.get_actions,
67
+                              offset=bad_offset)
68
+
69
+    @decorators.attr(type="gate")
70
+    def test_api_actions_post(self):
71
+
72
+        action = {
73
+            'freezer_action':
74
+                {
75
+                    'actions': 'backup',
76
+                    'mode': 'fs',
77
+                    'src_file': '/dev/null',
78
+                    'backup_name': 'test freezer api actions',
79
+                    'container': 'test_freezer_api_actions_container',
80
+                    'max_backup_level': 1,
81
+                    'always_backup_level': 0,
82
+                    'no_incremental': True,
83
+                    'encrypt_pass_file': '/dev/null',
84
+                    'log_file': '/dev/null',
85
+                    'hostname': False,
86
+                    'max_cpu_priority': False
87
+                }
88
+        }
89
+
90
+        # Create the action with POST
91
+        resp, response_body = self.freezer_api_client.post_actions(action)
92
+        self.assertEqual(201, resp.status)
93
+
94
+        self.assertIn('action_id', response_body)
95
+        action_id = response_body['action_id']
96
+
97
+        # Check that the action has the correct values
98
+        resp, response_body = self.freezer_api_client.get_actions(action_id)
99
+        self.assertEqual(200, resp.status)
100
+
101
+        resp_body_json = json.loads(response_body)
102
+        freezer_action_json = resp_body_json['freezer_action']
103
+
104
+        self.assertIn('backup_name', freezer_action_json)
105
+        backup_name = freezer_action_json['backup_name']
106
+        self.assertEqual('test freezer api actions', backup_name)
107
+
108
+        self.assertIn('container', freezer_action_json)
109
+        container = freezer_action_json['container']
110
+        self.assertEqual('test_freezer_api_actions_container', container)
111
+
112
+        self.assertIn('no_incremental', freezer_action_json)
113
+        no_incremental = freezer_action_json['no_incremental']
114
+        self.assertEqual(True, no_incremental)
115
+
116
+        self.assertIn('max_backup_level', freezer_action_json)
117
+        max_backup_level = freezer_action_json['max_backup_level']
118
+        self.assertEqual(1, max_backup_level)
119
+
120
+        self.assertIn('hostname', freezer_action_json)
121
+        hostname = freezer_action_json['hostname']
122
+        self.assertEqual(False, hostname)
123
+
124
+        self.assertIn('_version', response_body)
125
+        _version = resp_body_json['_version']
126
+        self.assertEqual(1, _version)
127
+
128
+        self.assertIn('actions', freezer_action_json)
129
+        actions = freezer_action_json['actions']
130
+        self.assertEqual('backup', actions)
131
+
132
+        self.assertIn('src_file', freezer_action_json)
133
+        src_file = freezer_action_json['src_file']
134
+        self.assertEqual('/dev/null', src_file)
135
+
136
+        self.assertIn('always_backup_level', freezer_action_json)
137
+        always_backup_level = freezer_action_json['always_backup_level']
138
+        self.assertEqual(0, always_backup_level)
139
+
140
+        self.assertIn('mode', freezer_action_json)
141
+        mode = freezer_action_json['mode']
142
+        self.assertEqual('fs', mode)
143
+
144
+        self.assertIn('encrypt_pass_file', freezer_action_json)
145
+        encrypt_pass_file = freezer_action_json['encrypt_pass_file']
146
+        self.assertEqual('/dev/null', encrypt_pass_file)
147
+
148
+        self.assertIn('max_cpu_priority', freezer_action_json)
149
+        max_cpu_priority = freezer_action_json['max_cpu_priority']
150
+        self.assertEqual(False, max_cpu_priority)
151
+
152
+        self.assertIn('user_id', response_body)
153
+
154
+        self.assertIn('log_file', freezer_action_json)
155
+        log_file = freezer_action_json['log_file']
156
+        self.assertEqual('/dev/null', log_file)
157
+
158
+        self.assertIn('action_id', response_body)
159
+        action_id_in_resp_body = resp_body_json['action_id']
160
+        self.assertEqual(action_id, action_id_in_resp_body)
161
+
162
+        # Update the action backup_name with POST
163
+        action['freezer_action']['backup_name'] = \
164
+            'test freezer api actions update with post'
165
+
166
+        resp, response_body = self.freezer_api_client.post_actions(
167
+            action, action_id)
168
+        self.assertEqual(201, resp.status)
169
+
170
+        self.assertIn('version', response_body)
171
+        version = response_body['version']
172
+        self.assertEqual(2, version)
173
+
174
+        self.assertIn('action_id', response_body)
175
+        action_id_in_resp_body = response_body['action_id']
176
+        self.assertEqual(action_id, action_id_in_resp_body)
177
+
178
+        resp, response_body = self.freezer_api_client.get_actions(action_id)
179
+        self.assertEqual(200, resp.status)
180
+
181
+        resp_body_json = json.loads(response_body)
182
+        freezer_action_json = resp_body_json['freezer_action']
183
+
184
+        self.assertIn('backup_name', freezer_action_json)
185
+        backup_name = freezer_action_json['backup_name']
186
+        self.assertEqual('test freezer api actions update with post',
187
+                         backup_name)
188
+
189
+        # Update the action backup_name with PATCH
190
+        action['freezer_action']['backup_name'] = \
191
+            'test freezer api actions update with patch'
192
+
193
+        resp, response_body = self.freezer_api_client.patch_actions(
194
+            action, action_id)
195
+        self.assertEqual(200, resp.status)
196
+
197
+        self.assertIn('version', response_body)
198
+        version = response_body['version']
199
+        self.assertEqual(3, version)
200
+
201
+        self.assertIn('action_id', response_body)
202
+        action_id_in_resp_body = response_body['action_id']
203
+        self.assertEqual(action_id, action_id_in_resp_body)
204
+
205
+        resp, response_body = self.freezer_api_client.get_actions(action_id)
206
+        self.assertEqual(200, resp.status)
207
+
208
+        resp_body_json = json.loads(response_body)
209
+        freezer_action_json = resp_body_json['freezer_action']
210
+
211
+        self.assertIn('backup_name', freezer_action_json)
212
+        backup_name = freezer_action_json['backup_name']
213
+        self.assertEqual('test freezer api actions update with patch',
214
+                         backup_name)
215
+
216
+        # Delete the action
217
+        resp, response_body = self.freezer_api_client.delete_actions(
218
+            action_id)
219
+        self.assertEqual(204, resp.status)

+ 300
- 0
freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py View File

@@ -0,0 +1,300 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import json
16
+
17
+import tempest
18
+from tempest.lib import decorators
19
+
20
+from freezer_tempest_plugin.tests.freezer_api.api import base
21
+
22
+
23
+class TestFreezerApiBackups(base.BaseFreezerApiTest):
24
+    credentials = ['primary', 'alt']
25
+
26
+    @decorators.attr(type="gate")
27
+    def test_api_backups_list(self):
28
+        for i in range(1, 4):
29
+            self._create_temporary_backup(
30
+                self._build_metadata("test_freezer_backups_" + str(i)))
31
+
32
+        resp, response_body = self.freezer_api_client.get_backups()
33
+        self.assertEqual(200, resp.status)
34
+
35
+        self.assertIn('backups', response_body)
36
+        backups = response_body['backups']
37
+
38
+        self.assertEqual(3, len(backups))
39
+
40
+        backup_names = [b['backup_metadata']['backup_name'] for b in backups]
41
+        for i in range(1, 4):
42
+            self.assertIn("test_freezer_backups_" + str(i), backup_names)
43
+
44
+    @decorators.attr(type="gate")
45
+    def test_api_backups_list_other_users_backups(self):
46
+        # Test if it is not possible to list backups
47
+        # from a different user
48
+        self._create_temporary_backup(
49
+            self._build_metadata("test_freezer_backups"))
50
+
51
+        # Switching to alt_user here
52
+        resp, response_body = self.os_alt.freezer_api_client.get_backups()
53
+
54
+        self.assertEqual(200, resp.status)
55
+        self.assertEmpty(response_body['backups'])
56
+
57
+    @decorators.attr(type="gate")
58
+    def test_api_backups_list_empty(self):
59
+        resp, response_body = self.freezer_api_client.get_backups()
60
+        self.assertEqual(200, resp.status)
61
+
62
+        self.assertEmpty(response_body['backups'])
63
+
64
+    @decorators.attr(type="gate")
65
+    def test_api_backups_list_limit(self):
66
+        for i in range(1, 9):
67
+            self._create_temporary_backup(
68
+                self._build_metadata("test_freezer_backups_" + str(i)))
69
+
70
+        resp, response_body = self.freezer_api_client.get_backups(limit=5)
71
+        self.assertEqual(200, resp.status)
72
+
73
+        self.assertIn('backups', response_body)
74
+        backups = response_body['backups']
75
+        self.assertEqual(5, len(backups))
76
+
77
+        # limits <= 0 should return an error (bad request)
78
+        for bad_limit in [0, -1, -2]:
79
+            self.assertRaises(tempest.lib.exceptions.BadRequest,
80
+                              self.freezer_api_client.get_actions,
81
+                              limit=bad_limit)
82
+
83
+    @decorators.attr(type="gate")
84
+    def test_api_backups_list_offset(self):
85
+        for i in range(1, 9):
86
+            self._create_temporary_backup(
87
+                self._build_metadata("test_freezer_backups_" + str(i)))
88
+
89
+        # valid offsets should return the correct number of entries
90
+        resp, response_body = self.freezer_api_client.get_backups(offset=0)
91
+        self.assertEqual(200, resp.status)
92
+        self.assertEqual(8, len(response_body['backups']))
93
+
94
+        resp, response_body = self.freezer_api_client.get_backups(offset=5)
95
+        self.assertEqual(200, resp.status)
96
+        self.assertEqual(3, len(response_body['backups']))
97
+
98
+        resp, response_body = self.freezer_api_client.get_backups(offset=8)
99
+        self.assertEqual(200, resp.status)
100
+        self.assertEqual(0, len(response_body['backups']))
101
+
102
+        # an offset greater than the number of entries should successfully
103
+        # return no entries
104
+        resp, response_body = self.freezer_api_client.get_backups(offset=10)
105
+        self.assertEqual(200, resp.status)
106
+        self.assertEqual(0, len(response_body['backups']))
107
+
108
+        # negative offsets should raise an error
109
+        self.assertRaises(tempest.lib.exceptions.BadRequest,
110
+                          self.freezer_api_client.get_backups, offset=-1)
111
+
112
+        self.assertRaises(tempest.lib.exceptions.BadRequest,
113
+                          self.freezer_api_client.get_backups, offset=-2)
114
+
115
+    @decorators.attr(type="gate")
116
+    def test_api_backups_list_limit_offset(self):
117
+        """ Test pagination by grabbing the backups in two steps and
118
+        comparing to the list of all backups.
119
+        """
120
+        for i in range(1, 9):
121
+            self._create_temporary_backup(
122
+                self._build_metadata("test_freezer_backups_" + str(i)))
123
+
124
+        resp, response_body = self.freezer_api_client.get_backups(limit=5)
125
+        self.assertEqual(200, resp.status)
126
+
127
+        self.assertIn('backups', response_body)
128
+        first_5_backups = response_body['backups']
129
+        self.assertEqual(5, len(first_5_backups))
130
+
131
+        resp, response_body = self.freezer_api_client.get_backups(limit=3,
132
+                                                                  offset=5)
133
+        second_3_backups = response_body['backups']
134
+        self.assertEqual(3, len(second_3_backups))
135
+
136
+        resp, response_body = self.freezer_api_client.get_backups()
137
+        all_backups = response_body['backups']
138
+
139
+        self.assertEqual(len(all_backups),
140
+                         len(first_5_backups + second_3_backups))
141
+        self.assertEqual(all_backups, first_5_backups + second_3_backups)
142
+
143
+    @decorators.attr(type="gate")
144
+    def test_api_backups_post(self):
145
+        metadata = self._build_metadata("test_freezer_backups")
146
+        backup_id = self._create_temporary_backup(metadata)
147
+
148
+        resp, response_body = self._workaround_get_backup(backup_id)
149
+
150
+        expected = self._build_expected_data(backup_id, metadata)
151
+
152
+        # backup_id is generated automatically, we can't know it
153
+        del(response_body['backup_id'])
154
+
155
+        self.assertEqual(200, resp.status)
156
+        self.assertEqual(expected, response_body)
157
+
158
+    @decorators.attr(type="gate")
159
+    def test_api_backups_post_without_content_type(self):
160
+        """ Test the backup endpoint without content-type=application/json.
161
+
162
+        It's expected to work regardless of whether content-type is set or not.
163
+        """
164
+        metadata = self._build_metadata("test_freezer_backups")
165
+
166
+        uri = '/v1/backups'
167
+        request_body = json.dumps(metadata)
168
+
169
+        # Passing in an empty dict for headers to avoid automatically
170
+        # generating headers
171
+        resp, response_body = self.freezer_api_client.post(uri, request_body,
172
+                                                           headers={})
173
+
174
+        self.assertEqual(resp.status, 201)
175
+
176
+    @decorators.attr(type="gate")
177
+    def test_api_backups_post_incomplete(self):
178
+        metadata = self._build_metadata("test_freezer_backups")
179
+        del (metadata['container'])
180
+
181
+        self.assertRaises(tempest.lib.exceptions.BadRequest,
182
+                          self.freezer_api_client.post_backups, metadata)
183
+
184
+    @decorators.attr(type="gate")
185
+    def test_api_backups_post_minimal(self):
186
+        metadata = {
187
+            "curr_backup_level": 0,
188
+            "container": "test_freezer_api_backups_container",
189
+            "hostname": "localhost",
190
+            "backup_name": "test_freezer_backups",
191
+            "time_stamp": 1459349846,
192
+        }
193
+
194
+        backup_id = self._create_temporary_backup(metadata)
195
+        resp, response_body = self._workaround_get_backup(backup_id)
196
+
197
+        expected = self._build_expected_data(backup_id, metadata)
198
+
199
+        # backup_id is generated automatically, we can't know it
200
+        del(response_body['backup_id'])
201
+
202
+        self.assertEqual(200, resp.status)
203
+        self.assertEqual(expected, response_body)
204
+
205
+    @decorators.attr(type="gate")
206
+    def test_api_backups_delete(self):
207
+        metadata = self._build_metadata("test_freezer_backups")
208
+        backup_id = self._create_temporary_backup(metadata)
209
+
210
+        self.freezer_api_client.delete_backups(backup_id)
211
+
212
+        resp, response_body = self.freezer_api_client.get_backups()
213
+        self.assertEqual(0, len(response_body['backups']))
214
+
215
+    @decorators.attr(type="gate")
216
+    def test_api_backups_delete_other_users_backups(self):
217
+        metadata = self._build_metadata("test_freezer_backups")
218
+        backup_id = self._create_temporary_backup(metadata)
219
+
220
+        # Switching user
221
+        resp, response_body = self.os_alt.freezer_api_client.delete_backups(
222
+            backup_id)
223
+        self.assertEqual('204', resp['status'])
224
+        self.assertEmpty(response_body)
225
+
226
+        # Switching back to original user
227
+        resp, response_body = self.freezer_api_client.get_backups()
228
+        self.assertEqual(1, len(response_body['backups']))
229
+
230
+    def _build_expected_data(self, backup_id, metadata):
231
+        return {
232
+            'user_name': self.os_primary.credentials.username,
233
+            'user_id': self.os_primary.credentials.user_id,
234
+            'backup_metadata': metadata
235
+        }
236
+
237
+    def _build_metadata(self, backup_name):
238
+        return {
239
+            "action": "backup",
240
+            "always_level": "",
241
+            "backup_media": "fs",
242
+            "client_id": "freezer",
243
+            "client_version": "1.2.18",
244
+            "container_segments": "",
245
+            "curr_backup_level": 0,
246
+            "dry_run": "",
247
+            "log_file": "",
248
+            "job_id": "76cf6739ca2e4dc58b2215632c2a0b49",
249
+            "os_auth_version": "",
250
+            "path_to_backup": "/dev/null",
251
+            "proxy": "",
252
+            "ssh_host": "",
253
+            "ssh_key": "",
254
+            "ssh_port": 22,
255
+            "ssh_username": "",
256
+            "storage": "swift",
257
+            "container": "test_freezer_api_backups_container",
258
+            "hostname": "localhost",
259
+            "backup_name": backup_name,
260
+            "time_stamp": 1459349846,
261
+            "level": 1,
262
+            "max_level": 14,
263
+            "mode": "fs",
264
+            "fs_real_path": "/dev/null",
265
+            "vol_snap_path": "",
266
+            "total_broken_links": 1,
267
+            "total_fs_files": 100,
268
+            "total_directories": 100,
269
+            "backup_size_uncompressed": 10000,
270
+            "backup_size_compressed": 1000,
271
+            "compression": "gzip",
272
+            "encrypted": False,
273
+            "client_os": "linux2",
274
+            "broken_links": [],
275
+            "excluded_files": [],
276
+            "cli": "freezer",
277
+            "version": "1.0"
278
+        }
279
+
280
+    def _create_temporary_backup(self, metadata):
281
+        resp, response_body = self.freezer_api_client.post_backups(metadata)
282
+
283
+        self.assertEqual('201', resp['status'])
284
+
285
+        self.assertIn('backup_id', response_body)
286
+        backup_id = response_body['backup_id']
287
+
288
+        self.addCleanup(self.freezer_api_client.delete_backups, backup_id)
289
+
290
+        return backup_id
291
+
292
+    def _workaround_get_backup(self, backup_id):
293
+        # TODO(JonasPf): Use the following line, once this bug is fixed:
294
+        # https://bugs.launchpad.net/freezer/+bug/1564649
295
+        # resp, response_body = self.freezer_api_client.get_backups(backup_id)
296
+        resp, response_body = self.freezer_api_client.get_backups()
297
+
298
+        result = next((b for b in response_body['backups'] if
299
+                       b['backup_id'] == backup_id))
300
+        return resp, result

+ 96
- 0
freezer_tempest_plugin/tests/freezer_api/api/test_api_clients.py View File

@@ -0,0 +1,96 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import json
16
+import time
17
+
18
+from tempest.lib import decorators
19
+from tempest.lib import exceptions
20
+
21
+from freezer_tempest_plugin.tests.freezer_api.api import base
22
+
23
+
24
+class TestFreezerApiClients(base.BaseFreezerApiTest):
25
+    @classmethod
26
+    def resource_setup(cls):
27
+        super(TestFreezerApiClients, cls).resource_setup()
28
+
29
+    @classmethod
30
+    def resource_cleanup(cls):
31
+        super(TestFreezerApiClients, cls).resource_cleanup()
32
+
33
+    @decorators.attr(type="gate")
34
+    def test_api_clients(self):
35
+
36
+        resp, response_body = self.freezer_api_client.get_clients()
37
+        self.assertEqual(200, resp.status)
38
+
39
+        response_body_json = json.loads(response_body)
40
+        self.assertIn('clients', response_body_json)
41
+        clients = response_body_json['clients']
42
+        self.assertEmpty(clients)
43
+
44
+    @decorators.attr(type="gate")
45
+    def test_api_clients_get_limit(self):
46
+        # limits > 0 should return successfully
47
+        for valid_limit in [2, 1]:
48
+            resp, body = self.freezer_api_client.get_clients(limit=valid_limit)
49
+            self.assertEqual(200, resp.status)
50
+
51
+        # limits <= 0 should raise a bad request error
52
+        for bad_limit in [0, -1, -2]:
53
+            self.assertRaises(exceptions.BadRequest,
54
+                              self.freezer_api_client.get_clients,
55
+                              limit=bad_limit)
56
+
57
+    @decorators.attr(type="gate")
58
+    def test_api_clients_get_offset(self):
59
+        # offsets >= 0 should return 200
60
+        for valid_offset in [1, 0]:
61
+            resp, body = self.freezer_api_client.get_clients(
62
+                offset=valid_offset)
63
+            self.assertEqual(200, resp.status)
64
+
65
+        # offsets < 0 should return 400
66
+        for bad_offset in [-1, -2]:
67
+            self.assertRaises(exceptions.BadRequest,
68
+                              self.freezer_api_client.get_clients,
69
+                              offset=bad_offset)
70
+
71
+    @decorators.attr(type="gate")
72
+    def test_api_clients_post(self):
73
+        client = {'client_id': 'test-client-id',
74
+                  'hostname': 'test-host-name',
75
+                  'description': 'a test client',
76
+                  'uuid': 'test-client-uuid'}
77
+
78
+        # Create the client with POST
79
+        resp, response_body = self.freezer_api_client.post_clients(client)
80
+        self.assertEqual(201, resp.status)
81
+
82
+        self.assertIn('client_id', response_body)
83
+        client_id = response_body['client_id']
84
+
85
+        # Check that the client has the correct values
86
+
87
+        # Give the DB some time to catch up
88
+        time.sleep(5)
89
+
90
+        resp, response_body = self.freezer_api_client.get_clients(client_id)
91
+        self.assertEqual(200, resp.status)
92
+
93
+        # Delete the client
94
+        resp, response_body = self.freezer_api_client.delete_clients(
95
+            client_id)
96
+        self.assertEqual(204, resp.status)

+ 154
- 0
freezer_tempest_plugin/tests/freezer_api/api/test_api_jobs.py View File

@@ -0,0 +1,154 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import json
16
+
17
+from tempest.lib import decorators
18
+from tempest.lib import exceptions
19
+
20
+from freezer_tempest_plugin.tests.freezer_api.api import base
21
+
22
+fake_job = {
23
+    "job_actions":
24
+        [
25
+            {
26
+                "freezer_action":
27
+                    {
28
+                        "action": "backup",
29
+                        "mode": "fs",
30
+                        "src_file": "/home/tylerdurden/project_mayhem",
31
+                        "backup_name": "project_mayhem_backup",
32
+                        "container": "my_backup_container",
33
+                    },
34
+                "exit_status": "success",
35
+                "max_retries": 1,
36
+                "max_retries_interval": 1,
37
+                "mandatory": True
38
+            }
39
+        ],
40
+    "job_schedule":
41
+        {
42
+            "time_created": 1234,
43
+            "time_started": 1234,
44
+            "time_ended": 0,
45
+            "status": "stop",
46
+            "schedule_date": "2015-06-02T16:20:00",
47
+            "schedule_month": "1-6, 9-12",
48
+            "schedule_day": "mon, wed, fri",
49
+            "schedule_hour": "03",
50
+            "schedule_minute": "25",
51
+        },
52
+    "job_id": "blabla",
53
+    "client_id": "01b0f00a-4ce2-11e6-beb8-9e71128cae77_myhost.mydomain.mytld",
54
+    "user_id": "blabla",
55
+    "description": "scheduled one shot"
56
+}
57
+
58
+
59
+class TestFreezerApiJobs(base.BaseFreezerApiTest):
60
+    @classmethod
61
+    def resource_setup(cls):
62
+        super(TestFreezerApiJobs, cls).resource_setup()
63
+
64
+    @classmethod
65
+    def resource_cleanup(cls):
66
+        super(TestFreezerApiJobs, cls).resource_cleanup()
67
+
68
+    @decorators.attr(type="gate")
69
+    def test_api_jobs(self):
70
+
71
+        resp, response_body = self.freezer_api_client.get_jobs()
72
+        self.assertEqual(200, resp.status)
73
+
74
+        response_body_json = json.loads(response_body)
75
+        self.assertIn('jobs', response_body_json)
76
+        jobs = response_body_json['jobs']
77
+        self.assertEmpty(jobs)
78
+
79
+    @decorators.attr(type="gate")
80
+    def test_api_jobs_get_limit(self):
81
+        # limits > 0 should return successfully
82
+        for valid_limit in [2, 1]:
83
+            resp, body = self.freezer_api_client.get_jobs(limit=valid_limit)
84
+            self.assertEqual(200, resp.status)
85
+
86
+        # limits <= 0 should raise a bad request error
87
+        for bad_limit in [0, -1, -2]:
88
+            self.assertRaises(exceptions.BadRequest,
89
+                              self.freezer_api_client.get_jobs,
90
+                              limit=bad_limit)
91
+
92
+    @decorators.attr(type="gate")
93
+    def test_api_jobs_get_offset(self):
94
+        # offsets >= 0 should return 200
95
+        for valid_offset in [1, 0]:
96
+            resp, body = self.freezer_api_client.get_jobs(offset=valid_offset)
97
+            self.assertEqual(200, resp.status)
98
+
99
+        # offsets < 0 should return 400
100
+        for bad_offset in [-1, -2]:
101
+            self.assertRaises(exceptions.BadRequest,
102
+                              self.freezer_api_client.get_jobs,
103
+                              offset=bad_offset)
104
+
105
+    @decorators.attr(type="gate")
106
+    def test_api_jobs_post(self):
107
+
108
+        # Create the job with POST
109
+        resp, response_body = self.freezer_api_client.post_jobs(fake_job)
110
+        self.assertEqual(201, resp.status)
111
+
112
+        self.assertIn('job_id', response_body)
113
+        job_id = response_body['job_id']
114
+
115
+        # Check that the job has the correct values
116
+        resp, response_body = self.freezer_api_client.get_jobs(job_id)
117
+        self.assertEqual(200, resp.status)
118
+
119
+        # Delete the job
120
+        resp, response_body = self.freezer_api_client.delete_jobs(
121
+            job_id)
122
+        self.assertEqual(204, resp.status)
123
+
124
+    @decorators.attr(type="gate")
125
+    def test_api_jobs_with_invalid_client_project_id_fail(self):
126
+        """Ensure that a job submitted with a bad client_id project id fails"""
127
+        fake_bad_job = fake_job
128
+        fake_bad_job['client_id'] = 'bad%project$id_host.domain.tld'
129
+
130
+        # Create the job with POST
131
+        self.assertRaises(exceptions.BadRequest,
132
+                          lambda: self.freezer_api_client.post_jobs(
133
+                              fake_bad_job))
134
+
135
+    @decorators.attr(type="gate")
136
+    def test_api_jobs_with_invalid_client_host_fail(self):
137
+        """Ensure that a job submitted with a bad client_id hostname fails"""
138
+        fake_bad_job = fake_job
139
+        fake_bad_job['client_id'] = ("01b0f00a-4ce2-11e6-beb8-9e71128cae77"
140
+                                     "_bad_hostname.bad/domain.b")
141
+
142
+        # Create the job with POST
143
+        self.assertRaises(exceptions.BadRequest,
144
+                          lambda: self.freezer_api_client.post_jobs(
145
+                              fake_bad_job))
146
+
147
+    def test_api_jobs_with_only_fqdn_succeeds(self):
148
+        """Ensure that a job submitted with only an FQDN succeeds"""
149
+        fqdn_only_job = fake_job
150
+        fqdn_only_job['client_id'] = 'padawan-ccp-c1-m1-mgmt'
151
+
152
+        # Attempt to post the job, should succeed
153
+        resp, response_body = self.freezer_api_client.post_jobs(fqdn_only_job)
154
+        self.assertEqual(201, resp.status)

+ 131
- 0
freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py View File

@@ -0,0 +1,131 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import json
16
+
17
+from tempest.lib import decorators
18
+from tempest.lib import exceptions
19
+
20
+from freezer_tempest_plugin.tests.freezer_api.api import base
21
+
22
+
23
+class TestFreezerApiSessions(base.BaseFreezerApiTest):
24
+    @classmethod
25
+    def resource_setup(cls):
26
+        super(TestFreezerApiSessions, cls).resource_setup()
27
+
28
+    @classmethod
29
+    def resource_cleanup(cls):
30
+        super(TestFreezerApiSessions, cls).resource_cleanup()
31
+
32
+    @decorators.attr(type="gate")
33
+    def test_api_sessions(self):
34
+
35
+        resp, response_body = self.freezer_api_client.get_sessions()
36
+        self.assertEqual(200, resp.status)
37
+
38
+        response_body_json = json.loads(response_body)
39
+        self.assertIn('sessions', response_body_json)
40
+        sessions = response_body_json['sessions']
41
+        self.assertEmpty(sessions)
42
+
43
+    @decorators.attr(type="gate")
44
+    def test_api_sessions_get_limit(self):
45
+        # limits > 0 should return successfully
46
+        for valid_limit in [2, 1]:
47
+            resp, body = self.freezer_api_client.get_sessions(
48
+                limit=valid_limit)
49
+            self.assertEqual(200, resp.status)
50
+
51
+        # limits <= 0 should raise a bad request error
52
+        for bad_limit in [0, -1, -2]:
53
+            self.assertRaises(exceptions.BadRequest,
54
+                              self.freezer_api_client.get_sessions,
55
+                              limit=bad_limit)
56
+
57
+    @decorators.attr(type="gate")
58
+    def test_api_sessions_get_offset(self):
59
+        # offsets >= 0 should return 200
60
+        for valid_offset in [1, 0]:
61
+            resp, body = self.freezer_api_client.get_sessions(
62
+                offset=valid_offset)
63
+            self.assertEqual(200, resp.status)
64
+
65
+        # offsets < 0 should return 400
66
+        for bad_offset in [-1, -2]:
67
+            self.assertRaises(exceptions.BadRequest,
68
+                              self.freezer_api_client.get_sessions,
69
+                              offset=bad_offset)
70
+
71
+    @decorators.attr(type="gate")
72
+    def test_api_sessions_post(self):
73
+
74
+        session = {
75
+            "session_id": "test-session",
76
+            "session_tag": 1,
77
+            "description": "a test session",
78
+            "hold_off": 5,
79
+            "schedule": {
80
+                "time_created": 1234,
81
+                "time_started": 1234,
82
+                "time_ended": 0,
83
+                "status": "stop",
84
+                "schedule_date": "2015-06-02T16:20:00",
85
+                "schedule_month": "1-6, 9-12",
86
+                "schedule_day": "mon, wed, fri",
87
+                "schedule_hour": "03",
88
+                "schedule_minute": "25",
89
+            },
90
+            "jobs": [
91
+                {
92
+                    'job_id_1': {
93
+                        "client_id": "client-id-1",
94
+                        "status": "stop",
95
+                        "result": "success",
96
+                        "time_started": 1234,
97
+                        "time_ended": 1234
98
+                    },
99
+                    'job_id_2': {
100
+                        "client_id": "client-id-1",
101
+                        "status": "stop",
102
+                        "result": "success",
103
+                        "time_started": 1234,
104
+                        "time_ended": 1234,
105
+                    }
106
+                }
107
+            ],
108
+            "time_start": 1234,
109
+            "time_end": 1234,
110
+            "time_started": 1234,
111
+            "time_ended": 1234,
112
+            "status": "completed",
113
+            "result": "success",
114
+            "user_id": "user-id-1"
115
+        }
116
+
117
+        # Create the session with POST
118
+        resp, response_body = self.freezer_api_client.post_sessions(session)
119
+        self.assertEqual(201, resp.status)
120
+
121
+        self.assertIn('session_id', response_body)
122
+        session_id = response_body['session_id']
123
+
124
+        # Check that the session has the correct values
125
+        resp, response_body = self.freezer_api_client.get_sessions(session_id)
126
+        self.assertEqual(200, resp.status)
127
+
128
+        # Delete the session
129
+        resp, response_body = self.freezer_api_client.delete_sessions(
130
+            session_id)
131
+        self.assertEqual(204, resp.status)

+ 110
- 0
freezer_tempest_plugin/tests/freezer_api/api/test_api_version.py View File

@@ -0,0 +1,110 @@
1
+# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+import json
16
+
17
+from tempest.lib import decorators
18
+
19
+from freezer_tempest_plugin.tests.freezer_api.api import base
20
+
21
+
22
+class TestFreezerApiVersion(base.BaseFreezerApiTest):
23
+    @classmethod
24
+    def resource_setup(cls):
25
+        super(TestFreezerApiVersion, cls).resource_setup()
26
+
27
+    @classmethod
28
+    def resource_cleanup(cls):
29
+        super(TestFreezerApiVersion, cls).resource_cleanup()
30
+
31
+    @decorators.attr(type="gate")
32
+    def test_api_version(self):
33
+        resp, response_body = self.freezer_api_client.get_version()
34
+        self.assertEqual(300, resp.status)
35
+
36
+        resp_body_json = json.loads(response_body)
37
+        self.assertIn('versions', resp_body_json)
38
+        current_version = resp_body_json['versions'][1]
39
+        self.assertEqual(len(current_version), 4)
40
+        self.assertIn('id', current_version)
41
+        self.assertEqual(current_version['id'], 'v1')
42
+        self.assertIn('links', current_version)
43
+        links = current_version['links'][0]
44
+        self.assertIn('href', links)
45
+        href = links['href']
46
+        self.assertIn('/v1/', href)
47
+        self.assertIn('rel', links)
48
+        rel = links['rel']
49
+        self.assertEqual('self', rel)
50
+        self.assertIn('status', current_version)
51
+        status = current_version['status']
52
+        self.assertEqual('CURRENT', status)
53
+        self.assertIn('updated', current_version)
54
+
55
+    @decorators.attr(type="gate")
56
+    def test_api_version_v1(self):
57
+        resp, response_body = self.freezer_api_client.get_version_v1()
58
+        self.assertEqual(200, resp.status)
59
+
60
+        response_body_jason = json.loads(response_body)
61
+        self.assertIn('resources', response_body_jason)
62
+        resource = response_body_jason['resources']
63
+        self.assertIn('rel/backups', resource)
64
+        rel_backups = resource['rel/backups']
65
+        self.assertIn('href-template', rel_backups)
66
+        href_template = rel_backups['href-template']
67
+        self.assertEqual('/v1/backups/{backup_id}', href_template)
68
+        self.assertIn('href-vars', rel_backups)
69
+        href_vars = rel_backups['href-vars']
70
+        self.assertIn('backup_id', href_vars)
71
+        backup_id = href_vars['backup_id']
72
+        self.assertEqual('param/backup_id', backup_id)
73
+        self.assertIn('hints', rel_backups)
74
+        hints = rel_backups['hints']
75
+        self.assertIn('allow', hints)
76
+        allow = hints['allow']
77
+        self.assertEqual('GET', allow[0])
78
+        self.assertIn('formats', hints)
79
+        formats = hints['formats']
80
+        self.assertIn('application/json', formats)
81
+
82
+    @decorators.attr(type="gate")
83
+    def test_api_version_v2(self):
84
+        resp, response_body = self.freezer_api_client.get_version_v2()
85
+        self.assertEqual(200, resp.status)
86
+
87
+        response_body_jason = json.loads(response_body)
88
+        self.assertIn('resources', response_body_jason)
89
+        resource = response_body_jason['resources']
90
+        self.assertIn('rel/backups', resource)
91
+        rel_backups = resource['rel/backups']
92
+        self.assertIn('href-template', rel_backups)
93
+        href_template = rel_backups['href-template']
94
+        self.assertEqual('/v2/{project_id}/backups/{backup_id}', href_template)
95
+        self.assertIn('href-vars', rel_backups)
96
+        href_vars = rel_backups['href-vars']
97
+        self.assertIn('backup_id', href_vars)
98
+        self.assertIn('project_id', href_vars)
99
+        backup_id = href_vars['backup_id']
100
+        self.assertEqual('param/backup_id', backup_id)
101
+        project_id = href_vars['project_id']
102
+        self.assertEqual('param/project_id', project_id)
103
+        self.assertIn('hints', rel_backups)
104
+        hints = rel_backups['hints']
105
+        self.assertIn('allow', hints)
106
+        allow = hints['allow']
107
+        self.assertEqual('GET', allow[0])
108
+        self.assertIn('formats', hints)
109
+        formats = hints['formats']
110
+        self.assertIn('application/json', formats)

Loading…
Cancel
Save