Best Python code snippet using tempest_python
test_neutron_subnetpool.py
Source:test_neutron_subnetpool.py
...30 return_value=True)31 self.find_resource = self.patchobject(neutronV20,32 'find_resourceid_by_name_or_id',33 return_value='new_test')34 def create_subnetpool(self, status='COMPLETE', tags=None):35 self.t = template_format.parse(inline_templates.SPOOL_TEMPLATE)36 if tags:37 self.t['resources']['sub_pool']['properties']['tags'] = tags38 self.stack = utils.parse_stack(self.t)39 resource_defns = self.stack.t.resource_definitions(self.stack)40 rsrc = subnetpool.SubnetPool('sub_pool', resource_defns['sub_pool'],41 self.stack)42 if status == 'FAILED':43 self.patchobject(neutronclient.Client, 'create_subnetpool',44 side_effect=qe.NeutronClientException(45 status_code=500))46 error = self.assertRaises(exception.ResourceFailure,47 scheduler.TaskRunner(rsrc.create))48 self.assertEqual(49 'NeutronClientException: resources.sub_pool: '50 'An unknown exception occurred.',51 six.text_type(error))52 else:53 self.patchobject(neutronclient.Client, 'create_subnetpool',54 return_value={'subnetpool': {55 'id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'56 }})57 scheduler.TaskRunner(rsrc.create)()58 self.assertEqual((rsrc.CREATE, status), rsrc.state)59 if tags:60 self.set_tag_mock.assert_called_once_with('subnetpools',61 rsrc.resource_id,62 {'tags': tags})63 return rsrc64 def test_validate_prefixlen_min_gt_max(self):65 self.t = template_format.parse(inline_templates.SPOOL_TEMPLATE)66 props = self.t['resources']['sub_pool']['properties']67 props['min_prefixlen'] = 2868 props['max_prefixlen'] = 2469 self.stack = utils.parse_stack(self.t)70 rsrc = self.stack['sub_pool']71 errMessage = ('Illegal prefix bounds: max_prefixlen=24, '72 'min_prefixlen=28.')73 error = self.assertRaises(exception.StackValidationFailed,74 rsrc.validate)75 self.assertEqual(errMessage, six.text_type(error))76 def test_validate_prefixlen_default_gt_max(self):77 self.t = template_format.parse(inline_templates.SPOOL_TEMPLATE)78 props = self.t['resources']['sub_pool']['properties']79 props['default_prefixlen'] = 2880 props['max_prefixlen'] = 2481 self.stack = utils.parse_stack(self.t)82 rsrc = self.stack['sub_pool']83 errMessage = ('Illegal prefix bounds: max_prefixlen=24, '84 'default_prefixlen=28.')85 error = self.assertRaises(exception.StackValidationFailed,86 rsrc.validate)87 self.assertEqual(errMessage, six.text_type(error))88 def test_validate_prefixlen_min_gt_default(self):89 self.t = template_format.parse(inline_templates.SPOOL_TEMPLATE)90 props = self.t['resources']['sub_pool']['properties']91 props['min_prefixlen'] = 2892 props['default_prefixlen'] = 2493 self.stack = utils.parse_stack(self.t)94 rsrc = self.stack['sub_pool']95 errMessage = ('Illegal prefix bounds: min_prefixlen=28, '96 'default_prefixlen=24.')97 error = self.assertRaises(exception.StackValidationFailed,98 rsrc.validate)99 self.assertEqual(errMessage, six.text_type(error))100 def test_validate_minimal(self):101 self.t = template_format.parse(inline_templates.SPOOL_MINIMAL_TEMPLATE)102 self.stack = utils.parse_stack(self.t)103 rsrc = self.stack['sub_pool']104 self.assertIsNone(rsrc.validate())105 def test_create_subnetpool(self):106 rsrc = self.create_subnetpool()107 ref_id = rsrc.FnGetRefId()108 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)109 def test_create_subnetpool_with_tags(self):110 tags = ['for_test']111 self.set_tag_mock = self.patchobject(neutronclient.Client,112 'replace_tag')113 rsrc = self.create_subnetpool(tags=tags)114 ref_id = rsrc.FnGetRefId()115 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)116 def test_create_subnetpool_failed(self):117 self.create_subnetpool('FAILED')118 def test_delete_subnetpool(self):119 self.patchobject(neutronclient.Client, 'delete_subnetpool')120 rsrc = self.create_subnetpool()121 ref_id = rsrc.FnGetRefId()122 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)123 self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())124 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)125 def test_delete_subnetpool_not_found(self):126 self.patchobject(neutronclient.Client, 'delete_subnetpool',127 side_effect=qe.NotFound(status_code=404))128 rsrc = self.create_subnetpool()129 ref_id = rsrc.FnGetRefId()130 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)131 self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())132 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)133 def test_delete_subnetpool_resource_id_none(self):134 delete_pool = self.patchobject(neutronclient.Client,135 'delete_subnetpool')136 rsrc = self.create_subnetpool()137 rsrc.resource_id = None138 self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())139 delete_pool.assert_not_called()140 def test_update_subnetpool(self):141 update_subnetpool = self.patchobject(neutronclient.Client,142 'update_subnetpool')143 self.set_tag_mock = self.patchobject(neutronclient.Client,144 'replace_tag')145 old_tags = ['old_tag']146 rsrc = self.create_subnetpool(tags=old_tags)147 self.patchobject(rsrc, 'physical_resource_name',148 return_value='the_new_sp')149 ref_id = rsrc.FnGetRefId()150 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)151 new_tags = ['new_tag']152 props = {153 'name': 'the_new_sp',154 'prefixes': [155 '10.1.0.0/16',156 '10.2.0.0/16'],157 'address_scope': 'new_test',158 'default_quota': '16',159 'default_prefixlen': '24',160 'min_prefixlen': '24',161 'max_prefixlen': '28',162 'is_default': False,163 'tags': new_tags164 }165 update_dict = props.copy()166 update_dict['name'] = 'the_new_sp'167 update_dict['address_scope_id'] = update_dict.pop('address_scope')168 update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),169 props)170 # with name171 self.assertIsNone(rsrc.handle_update(update_snippet, {}, props))172 self.set_tag_mock.assert_called_with('subnetpools',173 rsrc.resource_id,174 {'tags': new_tags})175 # without name176 props['name'] = None177 self.assertIsNone(rsrc.handle_update(update_snippet, {}, props))178 self.assertEqual(2, update_subnetpool.call_count)179 update_dict.pop('tags')180 update_subnetpool.assert_called_with(181 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',182 {'subnetpool': update_dict})183 def test_update_subnetpool_no_prop_diff(self):184 update_subnetpool = self.patchobject(neutronclient.Client,185 'update_subnetpool')186 rsrc = self.create_subnetpool()187 ref_id = rsrc.FnGetRefId()188 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)189 update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),190 rsrc.t._properties)191 self.assertIsNone(rsrc.handle_update(update_snippet, {}, {}))192 update_subnetpool.assert_not_called()193 def test_update_subnetpool_validate_prefixes(self):194 update_subnetpool = self.patchobject(neutronclient.Client,195 'update_subnetpool')196 rsrc = self.create_subnetpool()197 ref_id = rsrc.FnGetRefId()198 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)199 prefix_old = rsrc.properties['prefixes']200 props = {201 'name': 'the_new_sp',202 'prefixes': ['10.5.0.0/16']203 }204 prefix_new = props['prefixes']205 update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),206 props)207 errMessage = ('Property prefixes updated value %(value1)s '208 'should be superset of existing value %(value2)s.'209 % dict(value1=sorted(prefix_new),210 value2=sorted(prefix_old)))211 error = self.assertRaises(exception.StackValidationFailed,212 rsrc.handle_update,213 update_snippet, {}, props)214 self.assertEqual(errMessage, six.text_type(error))215 update_subnetpool.assert_not_called()216 props = {217 'name': 'the_new_sp',218 'prefixes': ['10.0.0.0/8',219 '10.6.0.0/16'],220 }221 update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),222 props)223 self.assertIsNone(rsrc.handle_update(update_snippet, {}, props))224 update_subnetpool.assert_called_once_with(225 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',226 {'subnetpool': props})227 def test_update_subnetpool_update_address_scope(self):228 update_subnetpool = self.patchobject(neutronclient.Client,229 'update_subnetpool')230 rsrc = self.create_subnetpool()231 ref_id = rsrc.FnGetRefId()232 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)233 props = {234 'name': 'the_new_sp',235 'address_scope': 'new_test',236 'prefixes': ['10.0.0.0/8',237 '10.6.0.0/16'],238 }239 update_dict = {240 'name': 'the_new_sp',241 'address_scope_id': 'new_test',242 'prefixes': ['10.0.0.0/8',243 '10.6.0.0/16'],244 }245 update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),246 props)247 self.assertIsNone(rsrc.handle_update(update_snippet, {}, props))248 self.assertEqual(3, self.find_resource.call_count)249 update_subnetpool.assert_called_once_with(250 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',251 {'subnetpool': update_dict})252 def test_update_subnetpool_remove_address_scope(self):253 update_subnetpool = self.patchobject(neutronclient.Client,254 'update_subnetpool')255 rsrc = self.create_subnetpool()256 ref_id = rsrc.FnGetRefId()257 self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766', ref_id)258 props = {259 'name': 'the_new_sp',260 'prefixes': ['10.0.0.0/8',261 '10.6.0.0/16'],262 }263 props_diff = {'address_scope': None}264 update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),265 props)266 self.assertIsNone(rsrc.handle_update(update_snippet, {}, props_diff))267 self.assertEqual(2, self.find_resource.call_count)268 update_subnetpool.assert_called_once_with(269 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',...
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!!