How to use wait_for_image_status method in tempest

Best Python code snippet using tempest_python

test_base.py

Source: test_base.py Github

copy

Full Screen

1# Copyright 2017 IBM Corp.2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http:/​/​www.apache.org/​licenses/​LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import mock15from oslo_utils import uuidutils16import six17from tempest.api.compute import base as compute_base18from tempest.common import waiters19from tempest import exceptions20from tempest.lib import exceptions as lib_exc21from tempest.tests import base22class TestBaseV2ComputeTest(base.TestCase):23 """Unit tests for utility functions in BaseV2ComputeTest."""24 @mock.patch.multiple(compute_base.BaseV2ComputeTest,25 compute_images_client=mock.DEFAULT,26 images=[], create=True)27 def test_create_image_from_server_no_wait(self, compute_images_client):28 """Tests create_image_from_server without the wait_until kwarg."""29 # setup mocks30 image_id = uuidutils.generate_uuid()31 fake_image = mock.Mock(response={'location': image_id})32 compute_images_client.create_image.return_value = fake_image33 # call the utility method34 image = compute_base.BaseV2ComputeTest.create_image_from_server(35 mock.sentinel.server_id, name='fake-snapshot-name')36 self.assertEqual(fake_image, image)37 # make our assertions38 compute_images_client.create_image.assert_called_once_with(39 mock.sentinel.server_id, name='fake-snapshot-name')40 self.assertEqual(1, len(compute_base.BaseV2ComputeTest.images))41 self.assertEqual(image_id, compute_base.BaseV2ComputeTest.images[0])42 @mock.patch.multiple(compute_base.BaseV2ComputeTest,43 compute_images_client=mock.DEFAULT,44 servers_client=mock.DEFAULT,45 images=[], create=True)46 @mock.patch.object(waiters, 'wait_for_image_status')47 @mock.patch.object(waiters, 'wait_for_server_status')48 def test_create_image_from_server_wait_until_active(self,49 wait_for_server_status,50 wait_for_image_status,51 servers_client,52 compute_images_client):53 """Tests create_image_from_server with wait_until='ACTIVE' kwarg."""54 # setup mocks55 image_id = uuidutils.generate_uuid()56 fake_image = mock.Mock(response={'location': image_id})57 compute_images_client.create_image.return_value = fake_image58 compute_images_client.show_image.return_value = (59 {'image': fake_image})60 # call the utility method61 image = compute_base.BaseV2ComputeTest.create_image_from_server(62 mock.sentinel.server_id, wait_until='ACTIVE')63 self.assertEqual(fake_image, image)64 # make our assertions65 wait_for_image_status.assert_called_once_with(66 compute_images_client, image_id, 'ACTIVE')67 wait_for_server_status.assert_called_once_with(68 servers_client, mock.sentinel.server_id, 'ACTIVE')69 compute_images_client.show_image.assert_called_once_with(image_id)70 @mock.patch.multiple(compute_base.BaseV2ComputeTest,71 compute_images_client=mock.DEFAULT,72 servers_client=mock.DEFAULT,73 images=[], create=True)74 @mock.patch.object(waiters, 'wait_for_image_status')75 @mock.patch.object(waiters, 'wait_for_server_status')76 def test_create_image_from_server_wait_until_active_no_server_wait(77 self, wait_for_server_status, wait_for_image_status,78 servers_client, compute_images_client):79 """Tests create_image_from_server with wait_until='ACTIVE' kwarg."""80 # setup mocks81 image_id = uuidutils.generate_uuid()82 fake_image = mock.Mock(response={'location': image_id})83 compute_images_client.create_image.return_value = fake_image84 compute_images_client.show_image.return_value = (85 {'image': fake_image})86 # call the utility method87 image = compute_base.BaseV2ComputeTest.create_image_from_server(88 mock.sentinel.server_id, wait_until='ACTIVE',89 wait_for_server=False)90 self.assertEqual(fake_image, image)91 # make our assertions92 wait_for_image_status.assert_called_once_with(93 compute_images_client, image_id, 'ACTIVE')94 self.assertEqual(0, wait_for_server_status.call_count)95 compute_images_client.show_image.assert_called_once_with(image_id)96 @mock.patch.multiple(compute_base.BaseV2ComputeTest,97 compute_images_client=mock.DEFAULT,98 servers_client=mock.DEFAULT,99 images=[], create=True)100 @mock.patch.object(waiters, 'wait_for_image_status',101 side_effect=lib_exc.NotFound)102 def _test_create_image_from_server_wait_until_active_not_found(103 self, wait_for_image_status, compute_images_client,104 servers_client, fault=None):105 # setup mocks106 image_id = uuidutils.generate_uuid()107 fake_image = mock.Mock(response={'location': image_id})108 compute_images_client.create_image.return_value = fake_image109 fake_server = {'id': mock.sentinel.server_id}110 if fault:111 fake_server['fault'] = fault112 servers_client.show_server.return_value = {'server': fake_server}113 # call the utility method114 ex = self.assertRaises(115 exceptions.SnapshotNotFoundException,116 compute_base.BaseV2ComputeTest.create_image_from_server,117 mock.sentinel.server_id, wait_until='active')118 # make our assertions119 if fault:120 self.assertIn(fault, six.text_type(ex))121 else:122 self.assertNotIn(fault, six.text_type(ex))123 wait_for_image_status.assert_called_once_with(124 compute_images_client, image_id, 'active')125 servers_client.show_server.assert_called_once_with(126 mock.sentinel.server_id)127 def test_create_image_from_server_wait_until_active_not_found_no_fault(128 self):129 # Tests create_image_from_server with wait_until='active' kwarg and130 # the a 404 is raised while waiting for the image status to change. In131 # this test the server does not have a fault associated with it.132 self._test_create_image_from_server_wait_until_active_not_found()133 def test_create_image_from_server_wait_until_active_not_found_with_fault(134 self):135 # Tests create_image_from_server with wait_until='active' kwarg and136 # the a 404 is raised while waiting for the image status to change. In137 # this test the server has a fault associated with it.138 self._test_create_image_from_server_wait_until_active_not_found(139 fault='Lost connection to hypervisor!')140 @mock.patch.multiple(compute_base.BaseV2ComputeTest,141 compute_images_client=mock.DEFAULT,142 images=[], create=True)143 @mock.patch.object(waiters, 'wait_for_image_status',144 side_effect=lib_exc.NotFound)145 def test_create_image_from_server_wait_until_saving_not_found(146 self, wait_for_image_status, compute_images_client):147 # Tests create_image_from_server with wait_until='SAVING' kwarg and148 # the a 404 is raised while waiting for the image status to change. In149 # this case we do not get the server details and just re-raise the 404.150 # setup mocks151 image_id = uuidutils.generate_uuid()152 fake_image = mock.Mock(response={'location': image_id})153 compute_images_client.create_image.return_value = fake_image154 # call the utility method155 self.assertRaises(156 lib_exc.NotFound,157 compute_base.BaseV2ComputeTest.create_image_from_server,158 mock.sentinel.server_id, wait_until='SAVING')159 # make our assertions160 wait_for_image_status.assert_called_once_with(...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Rebuild Confidence in Your Test Automation

These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.

What will come after “agile”?

I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

Do you possess the necessary characteristics to adopt an Agile testing mindset?

To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.

How To Refresh Page Using Selenium C# [Complete Tutorial]

When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.

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