How to use create_group_snapshot method in tempest

Best Python code snippet using tempest_python

test_group_snapshots.py

Source:test_group_snapshots.py Github

copy

Full Screen

...48 volume_id = utils.create_volume(49 self.context,50 group_id=group.id,51 volume_type_id=fake.VOLUME_TYPE_ID)['id']52 group_snapshot = utils.create_group_snapshot(53 self.context, group_id=group.id)54 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %55 (fake.PROJECT_ID, group_snapshot.id),56 version=GROUP_MICRO_VERSION)57 res_dict = self.controller.show(req, group_snapshot.id)58 self.assertEqual(1, len(res_dict))59 self.assertEqual('this is a test group snapshot',60 res_dict['group_snapshot']['description'])61 self.assertEqual('test_group_snapshot',62 res_dict['group_snapshot']['name'])63 self.assertEqual('creating', res_dict['group_snapshot']['status'])64 group_snapshot.destroy()65 db.volume_destroy(context.get_admin_context(),66 volume_id)67 group.destroy()68 def test_show_group_snapshot_with_group_snapshot_NotFound(self):69 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %70 (fake.PROJECT_ID,71 fake.WILL_NOT_BE_FOUND_ID),72 version=GROUP_MICRO_VERSION)73 self.assertRaises(exception.GroupSnapshotNotFound,74 self.controller.show,75 req, fake.WILL_NOT_BE_FOUND_ID)76 def test_list_group_snapshots_json(self):77 group = utils.create_group(78 self.context,79 group_type_id=fake.GROUP_TYPE_ID,80 volume_type_ids=[fake.VOLUME_TYPE_ID],)81 volume_id = utils.create_volume(82 self.context,83 group_id=group.id,84 volume_type_id=fake.VOLUME_TYPE_ID)['id']85 group_snapshot1 = utils.create_group_snapshot(86 self.context, group_id=group.id)87 group_snapshot2 = utils.create_group_snapshot(88 self.context, group_id=group.id)89 group_snapshot3 = utils.create_group_snapshot(90 self.context, group_id=group.id)91 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %92 fake.PROJECT_ID,93 version=GROUP_MICRO_VERSION)94 res_dict = self.controller.index(req)95 self.assertEqual(1, len(res_dict))96 self.assertEqual(group_snapshot1.id,97 res_dict['group_snapshots'][0]['id'])98 self.assertEqual('test_group_snapshot',99 res_dict['group_snapshots'][0]['name'])100 self.assertEqual(group_snapshot2.id,101 res_dict['group_snapshots'][1]['id'])102 self.assertEqual('test_group_snapshot',103 res_dict['group_snapshots'][1]['name'])104 self.assertEqual(group_snapshot3.id,105 res_dict['group_snapshots'][2]['id'])106 self.assertEqual('test_group_snapshot',107 res_dict['group_snapshots'][2]['name'])108 group_snapshot3.destroy()109 group_snapshot2.destroy()110 group_snapshot1.destroy()111 db.volume_destroy(context.get_admin_context(),112 volume_id)113 group.destroy()114 def test_list_group_snapshots_detail_json(self):115 group = utils.create_group(116 self.context,117 group_type_id=fake.GROUP_TYPE_ID,118 volume_type_ids=[fake.VOLUME_TYPE_ID],)119 volume_id = utils.create_volume(120 self.context,121 group_id=group.id,122 volume_type_id=fake.VOLUME_TYPE_ID)['id']123 group_snapshot1 = utils.create_group_snapshot(124 self.context, group_id=group.id)125 group_snapshot2 = utils.create_group_snapshot(126 self.context, group_id=group.id)127 group_snapshot3 = utils.create_group_snapshot(128 self.context, group_id=group.id)129 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/detail' %130 fake.PROJECT_ID,131 version=GROUP_MICRO_VERSION)132 res_dict = self.controller.detail(req)133 self.assertEqual(1, len(res_dict))134 self.assertEqual(3, len(res_dict['group_snapshots']))135 self.assertEqual('this is a test group snapshot',136 res_dict['group_snapshots'][0]['description'])137 self.assertEqual('test_group_snapshot',138 res_dict['group_snapshots'][0]['name'])139 self.assertEqual(group_snapshot1.id,140 res_dict['group_snapshots'][0]['id'])141 self.assertEqual('creating',142 res_dict['group_snapshots'][0]['status'])143 self.assertEqual('this is a test group snapshot',144 res_dict['group_snapshots'][1]['description'])145 self.assertEqual('test_group_snapshot',146 res_dict['group_snapshots'][1]['name'])147 self.assertEqual(group_snapshot2.id,148 res_dict['group_snapshots'][1]['id'])149 self.assertEqual('creating',150 res_dict['group_snapshots'][1]['status'])151 self.assertEqual('this is a test group snapshot',152 res_dict['group_snapshots'][2]['description'])153 self.assertEqual('test_group_snapshot',154 res_dict['group_snapshots'][2]['name'])155 self.assertEqual(group_snapshot3.id,156 res_dict['group_snapshots'][2]['id'])157 self.assertEqual('creating',158 res_dict['group_snapshots'][2]['status'])159 group_snapshot3.destroy()160 group_snapshot2.destroy()161 group_snapshot1.destroy()162 db.volume_destroy(context.get_admin_context(),163 volume_id)164 group.destroy()165 @mock.patch(166 'cinder.api.openstack.wsgi.Controller.validate_name_and_description')167 @mock.patch('cinder.db.volume_type_get')168 @mock.patch('cinder.quota.VolumeTypeQuotaEngine.reserve')169 def test_create_group_snapshot_json(self, mock_quota, mock_vol_type,170 mock_validate):171 group = utils.create_group(172 self.context,173 group_type_id=fake.GROUP_TYPE_ID,174 volume_type_ids=[fake.VOLUME_TYPE_ID],)175 volume_id = utils.create_volume(176 self.context,177 group_id=group.id,178 volume_type_id=fake.VOLUME_TYPE_ID)['id']179 body = {"group_snapshot": {"name": "group_snapshot1",180 "description":181 "Group Snapshot 1",182 "group_id": group.id}}183 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %184 fake.PROJECT_ID,185 version=GROUP_MICRO_VERSION)186 res_dict = self.controller.create(req, body)187 self.assertEqual(1, len(res_dict))188 self.assertIn('id', res_dict['group_snapshot'])189 self.assertTrue(mock_validate.called)190 group.destroy()191 group_snapshot = objects.GroupSnapshot.get_by_id(192 context.get_admin_context(), res_dict['group_snapshot']['id'])193 db.volume_destroy(context.get_admin_context(),194 volume_id)195 group_snapshot.destroy()196 @mock.patch(197 'cinder.api.openstack.wsgi.Controller.validate_name_and_description')198 @mock.patch('cinder.db.volume_type_get')199 def test_create_group_snapshot_when_volume_in_error_status(200 self, mock_vol_type, mock_validate):201 group = utils.create_group(202 self.context,203 group_type_id=fake.GROUP_TYPE_ID,204 volume_type_ids=[fake.VOLUME_TYPE_ID],)205 volume_id = utils.create_volume(206 self.context,207 status='error',208 group_id=group.id,209 volume_type_id=fake.VOLUME_TYPE_ID)['id']210 body = {"group_snapshot": {"name": "group_snapshot1",211 "description":212 "Group Snapshot 1",213 "group_id": group.id}}214 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %215 fake.PROJECT_ID,216 version=GROUP_MICRO_VERSION)217 self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,218 req, body)219 self.assertTrue(mock_validate.called)220 group.destroy()221 db.volume_destroy(context.get_admin_context(),222 volume_id)223 def test_create_group_snapshot_with_no_body(self):224 # omit body from the request225 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %226 fake.PROJECT_ID,227 version=GROUP_MICRO_VERSION)228 self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,229 req, None)230 @mock.patch.object(group_api.API, 'create_group_snapshot',231 side_effect=exception.InvalidGroupSnapshot(232 reason='Invalid group snapshot'))233 def test_create_with_invalid_group_snapshot(self, mock_create_group_snap):234 group = utils.create_group(235 self.context,236 group_type_id=fake.GROUP_TYPE_ID,237 volume_type_ids=[fake.VOLUME_TYPE_ID],)238 volume_id = utils.create_volume(239 self.context,240 status='error',241 group_id=group.id,242 volume_type_id=fake.VOLUME_TYPE_ID)['id']243 body = {"group_snapshot": {"name": "group_snapshot1",244 "description":245 "Group Snapshot 1",246 "group_id": group.id}}247 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %248 fake.PROJECT_ID,249 version=GROUP_MICRO_VERSION)250 self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,251 req, body)252 group.destroy()253 db.volume_destroy(context.get_admin_context(),254 volume_id)255 @mock.patch.object(group_api.API, 'create_group_snapshot',256 side_effect=exception.GroupSnapshotNotFound(257 group_snapshot_id='invalid_id'))258 def test_create_with_group_snapshot_not_found(self, mock_create_grp_snap):259 group = utils.create_group(260 self.context,261 group_type_id=fake.GROUP_TYPE_ID,262 volume_type_ids=[fake.VOLUME_TYPE_ID],)263 volume_id = utils.create_volume(264 self.context,265 status='error',266 group_id=group.id,267 volume_type_id=fake.VOLUME_TYPE_ID)['id']268 body = {"group_snapshot": {"name": "group_snapshot1",269 "description":270 "Group Snapshot 1",271 "group_id": group.id}}272 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %273 fake.PROJECT_ID,274 version=GROUP_MICRO_VERSION)275 self.assertRaises(exception.GroupSnapshotNotFound,276 self.controller.create,277 req, body)278 group.destroy()279 db.volume_destroy(context.get_admin_context(),280 volume_id)281 def test_create_group_snapshot_from_empty_group(self):282 group = utils.create_group(283 self.context,284 group_type_id=fake.GROUP_TYPE_ID,285 volume_type_ids=[fake.VOLUME_TYPE_ID],)286 body = {"group_snapshot": {"name": "group_snapshot1",287 "description":288 "Group Snapshot 1",289 "group_id": group.id}}290 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots' %291 fake.PROJECT_ID,292 version=GROUP_MICRO_VERSION)293 self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,294 req, body)295 group.destroy()296 def test_delete_group_snapshot_available(self):297 group = utils.create_group(298 self.context,299 group_type_id=fake.GROUP_TYPE_ID,300 volume_type_ids=[fake.VOLUME_TYPE_ID],)301 volume_id = utils.create_volume(302 self.context,303 group_id=group.id,304 volume_type_id=fake.VOLUME_TYPE_ID)['id']305 group_snapshot = utils.create_group_snapshot(306 self.context,307 group_id=group.id,308 status='available')309 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %310 (fake.PROJECT_ID, group_snapshot.id),311 version=GROUP_MICRO_VERSION)312 res_dict = self.controller.delete(req, group_snapshot.id)313 group_snapshot = objects.GroupSnapshot.get_by_id(self.context,314 group_snapshot.id)315 self.assertEqual(202, res_dict.status_int)316 self.assertEqual('deleting', group_snapshot.status)317 group_snapshot.destroy()318 db.volume_destroy(context.get_admin_context(),319 volume_id)320 group.destroy()321 def test_delete_group_snapshot_available_used_as_source(self):322 group = utils.create_group(323 self.context,324 group_type_id=fake.GROUP_TYPE_ID,325 volume_type_ids=[fake.VOLUME_TYPE_ID],)326 volume_id = utils.create_volume(327 self.context,328 group_id=group.id,329 volume_type_id=fake.VOLUME_TYPE_ID)['id']330 group_snapshot = utils.create_group_snapshot(331 self.context,332 group_id=group.id,333 status='available')334 group2 = utils.create_group(335 self.context, status='creating',336 group_snapshot_id=group_snapshot.id,337 group_type_id=fake.GROUP_TYPE_ID,338 volume_type_ids=[fake.VOLUME_TYPE_ID],)339 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %340 (fake.PROJECT_ID, group_snapshot.id),341 version=GROUP_MICRO_VERSION)342 self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,343 req, group_snapshot.id)344 group_snapshot.destroy()345 db.volume_destroy(context.get_admin_context(),346 volume_id)347 group.destroy()348 group2.destroy()349 def test_delete_group_snapshot_with_group_snapshot_NotFound(self):350 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %351 (fake.PROJECT_ID,352 fake.WILL_NOT_BE_FOUND_ID),353 version=GROUP_MICRO_VERSION)354 self.assertRaises(exception.GroupSnapshotNotFound,355 self.controller.delete,356 req, fake.WILL_NOT_BE_FOUND_ID)357 def test_delete_group_snapshot_with_Invalid_group_snapshot(self):358 group = utils.create_group(359 self.context,360 group_type_id=fake.GROUP_TYPE_ID,361 volume_type_ids=[fake.VOLUME_TYPE_ID],)362 volume_id = utils.create_volume(363 self.context,364 group_id=group.id,365 volume_type_id=fake.VOLUME_TYPE_ID)['id']366 group_snapshot = utils.create_group_snapshot(367 self.context,368 group_id=group.id,369 status='invalid')370 req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %371 (fake.PROJECT_ID, group_snapshot.id),372 version=GROUP_MICRO_VERSION)373 self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,374 req, group_snapshot.id)375 group_snapshot.destroy()376 db.volume_destroy(context.get_admin_context(),377 volume_id)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful