How to use list_resources method in tempest

Best Python code snippet using tempest_python

test_create_update.py

Source:test_create_update.py Github

copy

Full Screen

...143 stack_identifier = self.stack_create(144 template=template)145 expected_resources = {'test1': 'OS::Heat::TestResource'}146 self.assertEqual(expected_resources,147 self.list_resources(stack_identifier))148 # Update with no changes, resources should be unchanged149 self.update_stack(stack_identifier, template)150 self.assertEqual(expected_resources,151 self.list_resources(stack_identifier))152 def test_stack_in_place_update(self):153 template = _change_rsrc_properties(test_template_one_resource,154 ['test1'],155 {'value': 'test_in_place'})156 stack_identifier = self.stack_create(157 template=template)158 expected_resources = {'test1': 'OS::Heat::TestResource'}159 self.assertEqual(expected_resources,160 self.list_resources(stack_identifier))161 resource = self.client.resources.list(stack_identifier)162 initial_phy_id = resource[0].physical_resource_id163 tmpl_update = _change_rsrc_properties(164 test_template_one_resource, ['test1'],165 {'value': 'test_in_place_update'})166 # Update the Value167 self.update_stack(stack_identifier, tmpl_update)168 resource = self.client.resources.list(stack_identifier)169 # By default update_in_place170 self.assertEqual(initial_phy_id,171 resource[0].physical_resource_id)172 def test_stack_update_replace(self):173 template = _change_rsrc_properties(test_template_one_resource,174 ['test1'],175 {'value': 'test_replace'})176 stack_identifier = self.stack_create(177 template=template)178 expected_resources = {'test1': 'OS::Heat::TestResource'}179 self.assertEqual(expected_resources,180 self.list_resources(stack_identifier))181 resource = self.client.resources.list(stack_identifier)182 initial_phy_id = resource[0].physical_resource_id183 # Update the value and also set update_replace prop184 tmpl_update = _change_rsrc_properties(185 test_template_one_resource, ['test1'],186 {'value': 'test_in_place_update', 'update_replace': True})187 self.update_stack(stack_identifier, tmpl_update)188 resource = self.client.resources.list(stack_identifier)189 # update Replace190 self.assertNotEqual(initial_phy_id,191 resource[0].physical_resource_id)192 def test_stack_update_add_remove(self):193 template = _change_rsrc_properties(test_template_one_resource,194 ['test1'],195 {'value': 'test_add_remove'})196 stack_identifier = self.stack_create(197 template=template)198 initial_resources = {'test1': 'OS::Heat::TestResource'}199 self.assertEqual(initial_resources,200 self.list_resources(stack_identifier))201 tmpl_update = _change_rsrc_properties(202 test_template_two_resource, ['test1', 'test2'],203 {'value': 'test_add_remove_update'})204 # Add one resource via a stack update205 self.update_stack(stack_identifier, tmpl_update)206 updated_resources = {'test1': 'OS::Heat::TestResource',207 'test2': 'OS::Heat::TestResource'}208 self.assertEqual(updated_resources,209 self.list_resources(stack_identifier))210 # Then remove it by updating with the original template211 self.update_stack(stack_identifier, template)212 self.assertEqual(initial_resources,213 self.list_resources(stack_identifier))214 def test_stack_update_rollback(self):215 template = _change_rsrc_properties(test_template_one_resource,216 ['test1'],217 {'value': 'test_update_rollback'})218 stack_identifier = self.stack_create(219 template=template)220 initial_resources = {'test1': 'OS::Heat::TestResource'}221 self.assertEqual(initial_resources,222 self.list_resources(stack_identifier))223 tmpl_update = _change_rsrc_properties(224 test_template_two_resource, ['test1', 'test2'],225 {'value': 'test_update_rollback', 'fail': True})226 # stack update, also set failure227 self.update_stack(stack_identifier, tmpl_update,228 expected_status='ROLLBACK_COMPLETE',229 disable_rollback=False)230 # since stack update failed only the original resource is present231 updated_resources = {'test1': 'OS::Heat::TestResource'}232 self.assertEqual(updated_resources,233 self.list_resources(stack_identifier))234 def test_stack_update_from_failed(self):235 # Prove it's possible to update from an UPDATE_FAILED state236 template = _change_rsrc_properties(test_template_one_resource,237 ['test1'],238 {'value': 'test_update_failed'})239 stack_identifier = self.stack_create(240 template=template)241 initial_resources = {'test1': 'OS::Heat::TestResource'}242 self.assertEqual(initial_resources,243 self.list_resources(stack_identifier))244 tmpl_update = _change_rsrc_properties(245 test_template_one_resource, ['test1'], {'fail': True})246 # Update with bad template, we should fail247 self.update_stack(stack_identifier, tmpl_update,248 expected_status='UPDATE_FAILED')249 # but then passing a good template should succeed250 self.update_stack(stack_identifier, test_template_two_resource)251 updated_resources = {'test1': 'OS::Heat::TestResource',252 'test2': 'OS::Heat::TestResource'}253 self.assertEqual(updated_resources,254 self.list_resources(stack_identifier))255 def test_stack_update_provider(self):256 template = _change_rsrc_properties(257 test_template_one_resource, ['test1'],258 {'value': 'test_provider_template'})259 files = {'provider.template': json.dumps(template)}260 env = {'resource_registry':261 {'My::TestResource': 'provider.template'}}262 stack_identifier = self.stack_create(263 template=self.provider_template,264 files=files,265 environment=env266 )267 initial_resources = {'test1': 'My::TestResource'}268 self.assertEqual(initial_resources,269 self.list_resources(stack_identifier))270 # Prove the resource is backed by a nested stack, save the ID271 nested_identifier = self.assert_resource_is_a_stack(stack_identifier,272 'test1')273 nested_id = nested_identifier.split('/')[-1]274 # Then check the expected resources are in the nested stack275 nested_resources = {'test1': 'OS::Heat::TestResource'}276 self.assertEqual(nested_resources,277 self.list_resources(nested_identifier))278 tmpl_update = _change_rsrc_properties(279 test_template_two_resource, ['test1', 'test2'],280 {'value': 'test_provider_template'})281 # Add one resource via a stack update by changing the nested stack282 files['provider.template'] = json.dumps(tmpl_update)283 self.update_stack(stack_identifier, self.provider_template,284 environment=env, files=files)285 # Parent resources should be unchanged and the nested stack286 # should have been updated in-place without replacement287 self.assertEqual(initial_resources,288 self.list_resources(stack_identifier))289 rsrc = self.client.resources.get(stack_identifier, 'test1')290 self.assertEqual(rsrc.physical_resource_id, nested_id)291 # Then check the expected resources are in the nested stack292 nested_resources = {'test1': 'OS::Heat::TestResource',293 'test2': 'OS::Heat::TestResource'}294 self.assertEqual(nested_resources,295 self.list_resources(nested_identifier))296 def test_stack_update_alias_type(self):297 env = {'resource_registry':298 {'My::TestResource': 'OS::Heat::RandomString',299 'My::TestResource2': 'OS::Heat::RandomString'}}300 stack_identifier = self.stack_create(301 template=self.provider_template,302 environment=env303 )304 p_res = self.client.resources.get(stack_identifier, 'test1')305 self.assertEqual('My::TestResource', p_res.resource_type)306 initial_resources = {'test1': 'My::TestResource'}307 self.assertEqual(initial_resources,308 self.list_resources(stack_identifier))309 res = self.client.resources.get(stack_identifier, 'test1')310 # Modify the type of the resource alias to My::TestResource2311 tmpl_update = copy.deepcopy(self.provider_template)312 tmpl_update['resources']['test1']['type'] = 'My::TestResource2'313 self.update_stack(stack_identifier, tmpl_update, environment=env)314 res_a = self.client.resources.get(stack_identifier, 'test1')315 self.assertEqual(res.physical_resource_id, res_a.physical_resource_id)316 self.assertEqual(res.attributes['value'], res_a.attributes['value'])317 def test_stack_update_alias_changes(self):318 env = {'resource_registry':319 {'My::TestResource': 'OS::Heat::RandomString'}}320 stack_identifier = self.stack_create(321 template=self.provider_template,322 environment=env323 )324 p_res = self.client.resources.get(stack_identifier, 'test1')325 self.assertEqual('My::TestResource', p_res.resource_type)326 initial_resources = {'test1': 'My::TestResource'}327 self.assertEqual(initial_resources,328 self.list_resources(stack_identifier))329 res = self.client.resources.get(stack_identifier, 'test1')330 # Modify the resource alias to point to a different type331 env = {'resource_registry':332 {'My::TestResource': 'OS::Heat::TestResource'}}333 self.update_stack(stack_identifier, template=self.provider_template,334 environment=env)335 res_a = self.client.resources.get(stack_identifier, 'test1')336 self.assertNotEqual(res.physical_resource_id,337 res_a.physical_resource_id)338 def test_stack_update_provider_type(self):339 template = _change_rsrc_properties(340 test_template_one_resource, ['test1'],341 {'value': 'test_provider_template'})342 files = {'provider.template': json.dumps(template)}343 env = {'resource_registry':344 {'My::TestResource': 'provider.template',345 'My::TestResource2': 'provider.template'}}346 stack_identifier = self.stack_create(347 template=self.provider_template,348 files=files,349 environment=env350 )351 p_res = self.client.resources.get(stack_identifier, 'test1')352 self.assertEqual('My::TestResource', p_res.resource_type)353 initial_resources = {'test1': 'My::TestResource'}354 self.assertEqual(initial_resources,355 self.list_resources(stack_identifier))356 # Prove the resource is backed by a nested stack, save the ID357 nested_identifier = self.assert_resource_is_a_stack(stack_identifier,358 'test1')359 nested_id = nested_identifier.split('/')[-1]360 # Then check the expected resources are in the nested stack361 nested_resources = {'test1': 'OS::Heat::TestResource'}362 self.assertEqual(nested_resources,363 self.list_resources(nested_identifier))364 n_res = self.client.resources.get(nested_identifier, 'test1')365 # Modify the type of the provider resource to My::TestResource2366 tmpl_update = copy.deepcopy(self.provider_template)367 tmpl_update['resources']['test1']['type'] = 'My::TestResource2'368 self.update_stack(stack_identifier, tmpl_update,369 environment=env, files=files)370 p_res = self.client.resources.get(stack_identifier, 'test1')371 self.assertEqual('My::TestResource2', p_res.resource_type)372 # Parent resources should be unchanged and the nested stack373 # should have been updated in-place without replacement374 self.assertEqual({u'test1': u'My::TestResource2'},375 self.list_resources(stack_identifier))376 rsrc = self.client.resources.get(stack_identifier, 'test1')377 self.assertEqual(rsrc.physical_resource_id, nested_id)378 # Then check the expected resources are in the nested stack379 self.assertEqual(nested_resources,380 self.list_resources(nested_identifier))381 n_res2 = self.client.resources.get(nested_identifier, 'test1')382 self.assertEqual(n_res.physical_resource_id,383 n_res2.physical_resource_id)384 def test_stack_update_provider_group(self):385 """Test two-level nested update."""386 # Create a ResourceGroup (which creates a nested stack),387 # containing provider resources (which create a nested388 # stack), thus exercising an update which traverses389 # two levels of nesting.390 template = _change_rsrc_properties(391 test_template_one_resource, ['test1'],392 {'value': 'test_provider_group_template'})393 files = {'provider.template': json.dumps(template)}394 env = {'resource_registry':395 {'My::TestResource': 'provider.template'}}396 stack_identifier = self.stack_create(397 template=self.provider_group_template,398 files=files,399 environment=env400 )401 initial_resources = {'test_group': 'OS::Heat::ResourceGroup'}402 self.assertEqual(initial_resources,403 self.list_resources(stack_identifier))404 # Prove the resource is backed by a nested stack, save the ID405 nested_identifier = self.assert_resource_is_a_stack(stack_identifier,406 'test_group')407 # Then check the expected resources are in the nested stack408 nested_resources = {'0': 'My::TestResource',409 '1': 'My::TestResource'}410 self.assertEqual(nested_resources,411 self.list_resources(nested_identifier))412 for n_rsrc in nested_resources:413 rsrc = self.client.resources.get(nested_identifier, n_rsrc)414 provider_stack = self.client.stacks.get(rsrc.physical_resource_id)415 provider_identifier = '%s/%s' % (provider_stack.stack_name,416 provider_stack.id)417 provider_resources = {u'test1': u'OS::Heat::TestResource'}418 self.assertEqual(provider_resources,419 self.list_resources(provider_identifier))420 tmpl_update = _change_rsrc_properties(421 test_template_two_resource, ['test1', 'test2'],422 {'value': 'test_provider_group_template'})423 # Add one resource via a stack update by changing the nested stack424 files['provider.template'] = json.dumps(tmpl_update)425 self.update_stack(stack_identifier, self.provider_group_template,426 environment=env, files=files)427 # Parent resources should be unchanged and the nested stack428 # should have been updated in-place without replacement429 self.assertEqual(initial_resources,430 self.list_resources(stack_identifier))431 # Resource group stack should also be unchanged (but updated)432 nested_stack = self.client.stacks.get(nested_identifier)433 self.assertEqual('UPDATE_COMPLETE', nested_stack.stack_status)434 self.assertEqual(nested_resources,435 self.list_resources(nested_identifier))436 for n_rsrc in nested_resources:437 rsrc = self.client.resources.get(nested_identifier, n_rsrc)438 provider_stack = self.client.stacks.get(rsrc.physical_resource_id)439 provider_identifier = '%s/%s' % (provider_stack.stack_name,440 provider_stack.id)441 provider_resources = {'test1': 'OS::Heat::TestResource',442 'test2': 'OS::Heat::TestResource'}443 self.assertEqual(provider_resources,444 self.list_resources(provider_identifier))445 def test_stack_update_with_replacing_userdata(self):446 """Test case for updating userdata of instance.447 Confirm that we can update userdata of instance during updating stack448 by the user of member role.449 Make sure that a resource that inherits from StackUser can be deleted450 during updating stack.451 """452 if not self.conf.minimal_image_ref:453 raise self.skipException("No minimal image configured to test")454 if not self.conf.minimal_instance_type:455 raise self.skipException("No flavor configured to test")456 parms = {'flavor': self.conf.minimal_instance_type,457 'image': self.conf.minimal_image_ref,458 'network': self.conf.fixed_network_name,459 'user_data': ''}460 stack_identifier = self.stack_create(461 template=self.update_userdata_template,462 parameters=parms463 )464 parms_updated = parms465 parms_updated['user_data'] = 'two'466 self.update_stack(467 stack_identifier,468 template=self.update_userdata_template,469 parameters=parms_updated)470 def test_stack_update_provider_group_patch(self):471 '''Test two-level nested update with PATCH'''472 template = _change_rsrc_properties(473 test_template_one_resource, ['test1'],474 {'value': 'test_provider_group_template'})475 files = {'provider.template': json.dumps(template)}476 env = {'resource_registry':477 {'My::TestResource': 'provider.template'}}478 stack_identifier = self.stack_create(479 template=self.provider_group_template,480 files=files,481 environment=env482 )483 initial_resources = {'test_group': 'OS::Heat::ResourceGroup'}484 self.assertEqual(initial_resources,485 self.list_resources(stack_identifier))486 # Prove the resource is backed by a nested stack, save the ID487 nested_identifier = self.assert_resource_is_a_stack(stack_identifier,488 'test_group')489 # Then check the expected resources are in the nested stack490 nested_resources = {'0': 'My::TestResource',491 '1': 'My::TestResource'}492 self.assertEqual(nested_resources,493 self.list_resources(nested_identifier))494 # increase the count, pass only the paramter, no env or template495 params = {'count': 3}496 self.update_stack(stack_identifier, parameters=params, existing=True)497 # Parent resources should be unchanged and the nested stack498 # should have been updated in-place without replacement499 self.assertEqual(initial_resources,500 self.list_resources(stack_identifier))501 # Resource group stack should also be unchanged (but updated)502 nested_stack = self.client.stacks.get(nested_identifier)503 self.assertEqual('UPDATE_COMPLETE', nested_stack.stack_status)504 # Add a resource, as we should have added one505 nested_resources['2'] = 'My::TestResource'506 self.assertEqual(nested_resources,507 self.list_resources(nested_identifier))508 def test_stack_update_from_failed_patch(self):509 '''Test PATCH update from a failed state.'''510 # Start with empty template511 stack_identifier = self.stack_create(512 template='heat_template_version: 2014-10-16')513 # Update with a good template, but bad parameter514 self.update_stack(stack_identifier,515 template=self.fail_param_template,516 parameters={'do_fail': True},517 expected_status='UPDATE_FAILED')518 # PATCH update, only providing the parameter519 self.update_stack(stack_identifier,520 parameters={'do_fail': False},521 existing=True)522 self.assertEqual({u'aresource': u'OS::Heat::TestResource'},523 self.list_resources(stack_identifier))524 def test_stack_update_with_new_env(self):525 """Update handles new resource types in the environment.526 If a resource type appears during an update and the update fails,527 retrying the update is able to find the type properly in the528 environment.529 """530 stack_identifier = self.stack_create(531 template=test_template_one_resource)532 # Update with a new resource and make the update fails533 template = _change_rsrc_properties(test_template_one_resource,534 ['test1'], {'fail': True})535 template['resources']['test2'] = {'type': 'My::TestResource'}536 template['resources']['test1']['depends_on'] = 'test2'537 env = {'resource_registry':538 {'My::TestResource': 'OS::Heat::TestResource'}}539 self.update_stack(stack_identifier,540 template=template,541 environment=env,542 expected_status='UPDATE_FAILED')543 # Fixing the template should fix the stack544 template = _change_rsrc_properties(template,545 ['test1'], {'fail': False})546 self.update_stack(stack_identifier,547 template=template,548 environment=env)549 self.assertEqual({'test1': 'OS::Heat::TestResource',550 'test2': 'My::TestResource'},...

Full Screen

Full Screen

interval_partitioning.py

Source:interval_partitioning.py Github

copy

Full Screen

1import sys2import heapq345# This is our priority queue implementation6class PriorityQueue:7 def __init__(self):8 self._queue = []9 self._index = 01011 def push(self, resource, finish):12 heapq.heappush(self._queue, (finish, self._index, resource)) # sort by the first element of the tuple13 self._index += 11415 def pop(self):16 if self._index == 0:17 return None18 return heapq.heappop(self._queue)[-1]192021class Resource:22 def __init__(self, number, finish):23 self.number = number24 self.finish = finish252627def find_num_resources(time):28 time.sort(key=lambda x: x[0])29 num_resources = 030 priority_queue = PriorityQueue()31 list_resources = []32 for x in time:33 # we have job here, now pop the classroom with least finishing time34 resource = priority_queue.pop()35 if resource is None:36 # allocate a new class37 num_resources += 138 new_resource = Resource(num_resources, x[1])39 list_resources.append([num_resources, x])40 priority_queue.push(new_resource, x[1])4142 else:43 # check if finish time of current classroom is44 # less than start time of this lecture45 if resource.finish <= x[0]:46 resource.finish = x[1]47 list_resources.append([resource.number, x])48 priority_queue.push(resource, x[1])49 else:50 num_resources += 151 # Since last classroom needs to be compared again, push it back52 priority_queue.push(resource, x[1])53 # Push the new classroom in list54 new_resource = Resource(num_resources, x[1])55 list_resources.append([num_resources, x])56 priority_queue.push(new_resource, x[1])57 return num_resources, list_resources585960def main():61 if len(sys.argv) != 2:62 return6364 fname = sys.argv[1] #input3.txt65 file = open(fname, 'r')66 n = int(file.readline())67 time = []68 for i in range(n):69 line = file.readline().split(' ')70 time.append([int(line[0]), int(line[1])])71 total_resources, list_resources = find_num_resources(time)72 print("Minimum number of resources: ", total_resources)73 res = []*total_resources74 for i in range(total_resources):75 res.append([])76 for x in list_resources:77 res[x[0] - 1].append(x[1])78 i = 179 for x in res:80 print("Resource ", i, " jobs: ", x)81 i += 182 file.close()838485if __name__ == '__main__': ...

Full Screen

Full Screen

list_resources_test.py

Source:list_resources_test.py Github

copy

Full Screen

1#!/usr/bin/env python2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.13""" Integration test for list_env.py14GOOGLE_APPLICATION_CREDENTIALS must be set to a Service Account for a project15that has enabled the Monitoring API.16Currently the TEST_PROJECT_ID is hard-coded to run using the project created17for this test, but it could be changed to a different project.18"""19import re20from gcp.testing.flaky import flaky21import list_resources22METRIC = 'compute.googleapis.com/instance/cpu/usage_time'23@flaky24def test_list_monitored_resources(cloud_config, capsys):25 PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)26 client = list_resources.get_client()27 list_resources.list_monitored_resource_descriptors(28 client, PROJECT_RESOURCE)29 stdout, _ = capsys.readouterr()30 regex = re.compile(31 'An application running', re.I)32 assert regex.search(stdout) is not None33@flaky34def test_list_metrics(cloud_config, capsys):35 PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)36 client = list_resources.get_client()37 list_resources.list_metric_descriptors(38 client, PROJECT_RESOURCE, METRIC)39 stdout, _ = capsys.readouterr()40 regex = re.compile(41 u'Delta CPU', re.I)42 assert regex.search(stdout) is not None43@flaky44def test_list_timeseries(cloud_config, capsys):45 PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)46 client = list_resources.get_client()47 list_resources.list_timeseries(48 client, PROJECT_RESOURCE, METRIC)49 stdout, _ = capsys.readouterr()50 regex = re.compile(u'list_timeseries response:\n', re.I)...

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