Best Python code snippet using tempest_python
test_pause_server.py
Source:test_pause_server.py
1# Copyright 2011 OpenStack Foundation2# Copyright 2013 IBM Corp.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15from nova.api.openstack.compute.legacy_v2.contrib import admin_actions as \16 pause_server_v217from nova.api.openstack.compute import pause_server as \18 pause_server_v2119from nova import exception20from nova import test21from nova.tests.unit.api.openstack.compute import admin_only_action_common22from nova.tests.unit.api.openstack import fakes23class PauseServerTestsV21(admin_only_action_common.CommonTests):24 pause_server = pause_server_v2125 controller_name = 'PauseServerController'26 _api_version = '2.1'27 def setUp(self):28 super(PauseServerTestsV21, self).setUp()29 self.controller = getattr(self.pause_server, self.controller_name)()30 self.compute_api = self.controller.compute_api31 def _fake_controller(*args, **kwargs):32 return self.controller33 self.stubs.Set(self.pause_server, self.controller_name,34 _fake_controller)35 self.mox.StubOutWithMock(self.compute_api, 'get')36 def test_pause_unpause(self):37 self._test_actions(['_pause', '_unpause'])38 def test_actions_raise_on_not_implemented(self):39 for action in ['_pause', '_unpause']:40 self.mox.StubOutWithMock(self.compute_api,41 action.replace('_', ''))42 self._test_not_implemented_state(action)43 # Re-mock this.44 self.mox.StubOutWithMock(self.compute_api, 'get')45 def test_pause_unpause_with_non_existed_instance(self):46 self._test_actions_with_non_existed_instance(['_pause', '_unpause'])47 def test_pause_unpause_with_non_existed_instance_in_compute_api(self):48 self._test_actions_instance_not_found_in_compute_api(['_pause',49 '_unpause'])50 def test_pause_unpause_raise_conflict_on_invalid_state(self):51 self._test_actions_raise_conflict_on_invalid_state(['_pause',52 '_unpause'])53 def test_actions_with_locked_instance(self):54 self._test_actions_with_locked_instance(['_pause', '_unpause'])55class PauseServerTestsV2(PauseServerTestsV21):56 pause_server = pause_server_v257 controller_name = 'AdminActionsController'58 _api_version = '2'59 def test_actions_raise_on_not_implemented(self):60 pass61class PauseServerPolicyEnforcementV21(test.NoDBTestCase):62 def setUp(self):63 super(PauseServerPolicyEnforcementV21, self).setUp()64 self.controller = pause_server_v21.PauseServerController()65 def test_pause_policy_failed(self):66 rule_name = "os_compute_api:os-pause-server:pause"67 self.policy.set_rules({rule_name: "project:non_fake"})68 req = fakes.HTTPRequest.blank('')69 exc = self.assertRaises(70 exception.PolicyNotAuthorized,71 self.controller._pause, req, fakes.FAKE_UUID,72 body={'pause': {}})73 self.assertEqual(74 "Policy doesn't allow %s to be performed." % rule_name,75 exc.format_message())76 def test_unpause_policy_failed(self):77 rule_name = "os_compute_api:os-pause-server:unpause"78 self.policy.set_rules({rule_name: "project:non_fake"})79 req = fakes.HTTPRequest.blank('')80 exc = self.assertRaises(81 exception.PolicyNotAuthorized,82 self.controller._unpause, req, fakes.FAKE_UUID,83 body={'unpause': {}})84 self.assertEqual(85 "Policy doesn't allow %s to be performed." % rule_name,...
main.py
Source:main.py
1from bottle import *2import bottle3n = 1004finished = []5start_time = 06finish_time = 07a = -10008b = -9009n_count = 50010n_inc = 10011n_all = 100012n_total = 013total_worker = 014pause_server = False15I = []16# Returns static file. Used for getting JavaScript files from /scripts folder17@bottle.get('/scripts/:filename#.*#')18def send_static(filename):19 return static_file(filename, root='./scripts/')20# Returns worker page21@bottle.get('/')22def worker():23 return static_file('worker.html', root='./')24# Returns server page25@bottle.get('/server')26def server():27 return static_file('server.html', root='./')28# Returns data for server: number of clients, percents29# of done work and if work finished results with working time30@get('/serverData')31def worker_get():32 _s = ''33 for i in I:34 _s += str(i) + '\n'35 if n_all == n_total:36 return {'number_of_clients': total_worker,37 'percents': 100, 'results': _s,38 'time': finish_time - start_time}39 else:40 return {'number_of_clients': total_worker,41 'percents': n_total / n_all * 100, 'results': _s,42 'time': finish_time - start_time}43# Processes data we got from worker: his id and founded integral44@post('/serverData')45def server_post():46 data = request.forms.get('data')47 global pause_server, start_time, n_total48 if data == 'pause':49 pause_server = True50 elif data == 'resume':51 pause_server = False52 elif data == 'restart':53 pause_server = False54 n_total = -155 start_time = 056# Returns data for worker: his id and text57@get('/workerData')58def worker_get():59 global total_worker60 global n_total61 if pause_server:62 return {'state': 'pause', 'a': 0, 'b': 0, 'n': 0, 'worker_number': -1}63 global start_time64 if start_time == 0:65 start_time = time.time()66 if n_total < n_all:67 total_worker += 168 return {'state': 'work', 'a': a + n_total * n_inc, 'b': b + n_total * n_inc, 'n': n_count,69 'worker_number': total_worker}70 # Message that worker needs to stop71 return {'state': 'stop', 'a': 0, 'b': 0, 'n': 0, 'worker_number': 0}72# Processes data we got from worker: his id and founded palindromes73@post('/workerData')74def worker_post():75 global total_worker76 global n_total77 global finish_time78 n_total += 179 total_worker -= 180 if n_total == n_all:81 finish_time = time.time()82 integral = request.forms.get('integral')83 I.append(integral)84 # For debugging85 print('Part #%s finished' % n_total)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!