Best Python code snippet using tempest_python
test_quotas.py
Source:test_quotas.py  
...62                         'key_pairs': 200, 'injected_file_path_bytes': 512,63                         'instances': 20, 'security_group_rules': 20,64                         'cores': 2, 'security_groups': 20}65        # Update limits for all quota resources66        resp, quota_set = self.adm_client.update_quota_set(67            self.demo_tenant_id,68            force=True,69            **new_quota_set)70        default_quota_set.pop('id')71        self.addCleanup(self.adm_client.update_quota_set,72                        self.demo_tenant_id, **default_quota_set)73        self.assertEqual(200, resp.status)74        self.assertEqual(new_quota_set, quota_set)75    # TODO(afazekas): merge these test cases76    @attr(type='gate')77    def test_get_updated_quotas(self):78        # Verify that GET shows the updated quota set79        tenant_name = data_utils.rand_name('cpu_quota_tenant_')80        tenant_desc = tenant_name + '-desc'81        identity_client = self.os_adm.identity_client82        _, tenant = identity_client.create_tenant(name=tenant_name,83                                                  description=tenant_desc)84        tenant_id = tenant['id']85        self.addCleanup(identity_client.delete_tenant,86                        tenant_id)87        self.adm_client.update_quota_set(tenant_id,88                                         ram='5120')89        resp, quota_set = self.adm_client.get_quota_set(tenant_id)90        self.assertEqual(200, resp.status)91        self.assertEqual(quota_set['ram'], 5120)92    # TODO(afazekas): Add dedicated tenant to the skiped quota tests93    # it can be moved into the setUpClass as well94    @attr(type='gate')95    def test_create_server_when_cpu_quota_is_full(self):96        # Disallow server creation when tenant's vcpu quota is full97        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)98        default_vcpu_quota = quota_set['cores']99        vcpu_quota = 0  # Set the quota to zero to conserve resources100        resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,101                                                           force=True,102                                                           cores=vcpu_quota)103        self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,104                        cores=default_vcpu_quota)105        self.assertRaises(exceptions.OverLimit, self.create_test_server)106    @attr(type='gate')107    def test_create_server_when_memory_quota_is_full(self):108        # Disallow server creation when tenant's memory quota is full109        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)110        default_mem_quota = quota_set['ram']111        mem_quota = 0  # Set the quota to zero to conserve resources112        self.adm_client.update_quota_set(self.demo_tenant_id,113                                         force=True,114                                         ram=mem_quota)115        self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,116                        ram=default_mem_quota)117        self.assertRaises(exceptions.OverLimit, self.create_test_server)118    @attr(type='gate')119    def test_update_quota_normal_user(self):120        self.assertRaises(exceptions.Unauthorized,121                          self.client.update_quota_set,122                          self.demo_tenant_id,123                          ram=0)124    @attr(type=['negative', 'gate'])125    def test_create_server_when_instances_quota_is_full(self):126        # Once instances quota limit is reached, disallow server creation127        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)128        default_instances_quota = quota_set['instances']129        instances_quota = 0  # Set quota to zero to disallow server creation130        self.adm_client.update_quota_set(self.demo_tenant_id,131                                         force=True,132                                         instances=instances_quota)133        self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,134                        instances=default_instances_quota)135        self.assertRaises(exceptions.OverLimit, self.create_test_server)136    @skip_because(bug="1186354",137                  condition=config.TempestConfig().service_available.neutron)138    @attr(type=['negative', 'gate'])139    def test_security_groups_exceed_limit(self):140        # Negative test: Creation Security Groups over limit should FAIL141        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)142        default_sg_quota = quota_set['security_groups']143        sg_quota = 0  # Set the quota to zero to conserve resources144        resp, quota_set =\145            self.adm_client.update_quota_set(self.demo_tenant_id,146                                             force=True,147                                             security_groups=sg_quota)148        self.addCleanup(self.adm_client.update_quota_set,149                        self.demo_tenant_id,150                        security_groups=default_sg_quota)151        # Check we cannot create anymore152        self.assertRaises(exceptions.OverLimit,153                          self.sg_client.create_security_group,154                          "sg-overlimit", "sg-desc")155    @skip_because(bug="1186354",156                  condition=config.TempestConfig().service_available.neutron)157    @attr(type=['negative', 'gate'])158    def test_security_groups_rules_exceed_limit(self):159        # Negative test: Creation of Security Group Rules should FAIL160        # when we reach limit maxSecurityGroupRules161        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)162        default_sg_rules_quota = quota_set['security_group_rules']163        sg_rules_quota = 0  # Set the quota to zero to conserve resources164        resp, quota_set =\165            self.adm_client.update_quota_set(166                self.demo_tenant_id,167                force=True,168                security_group_rules=sg_rules_quota)169        self.addCleanup(self.adm_client.update_quota_set,170                        self.demo_tenant_id,171                        security_group_rules=default_sg_rules_quota)172        s_name = data_utils.rand_name('securitygroup-')173        s_description = data_utils.rand_name('description-')174        resp, securitygroup =\175            self.sg_client.create_security_group(s_name, s_description)176        self.addCleanup(self.sg_client.delete_security_group,177                        securitygroup['id'])178        secgroup_id = securitygroup['id']179        ip_protocol = 'tcp'...quota_sets.py
Source:quota_sets.py  
1# Copyright 2014 NEC Corporation.  All rights reserved.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 copy15from nova.api.validation import parameter_types16from nova import db17common_quota = {18    'type': ['integer', 'string'],19    'pattern': '^-?[0-9]+$',20    # -1 is a flag value for unlimited21    'minimum': -1,22    'maximum': db.MAX_INT23}24quota_resources = {25    'instances': common_quota,26    'cores': common_quota,27    'ram': common_quota,28    'floating_ips': common_quota,29    'fixed_ips': common_quota,30    'metadata_items': common_quota,31    'key_pairs': common_quota,32    'security_groups': common_quota,33    'security_group_rules': common_quota,34    'injected_files': common_quota,35    'injected_file_content_bytes': common_quota,36    'injected_file_path_bytes': common_quota,37    'server_groups': common_quota,38    'server_group_members': common_quota,39    'networks': common_quota40}41update_quota_set = copy.deepcopy(quota_resources)42update_quota_set.update({'force': parameter_types.boolean})43update_quota_set_v236 = copy.deepcopy(update_quota_set)44del update_quota_set_v236['fixed_ips']45del update_quota_set_v236['floating_ips']46del update_quota_set_v236['security_groups']47del update_quota_set_v236['security_group_rules']48del update_quota_set_v236['networks']49update = {50    'type': 'object',51    'properties': {52        'type': 'object',53        'quota_set': {54            'properties': update_quota_set,55            'additionalProperties': False,56        },57    },58    'required': ['quota_set'],59    'additionalProperties': False,60}61update_v236 = copy.deepcopy(update)...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!!
