How to use _create_network method in localstack

Best Python code snippet using localstack_python

test_share_network.py

Source:test_share_network.py Github

copy

Full Screen

...66 return_network67 )68 self.stub_NetworkConstraint_validate()69 self.stub_SubnetConstraint_validate()70 def _create_network(self, name, snippet, stack, use_neutron=True):71 if not use_neutron:72 net = ShareNetworkWithNova(name, snippet, stack)73 else:74 net = share_network.ManilaShareNetwork(name, snippet, stack)75 self.client.share_networks.create.return_value = DummyShareNetwork()76 self.client.share_networks.get.return_value = DummyShareNetwork()77 def get_security_service(id):78 return mock.Mock(id=id)79 self.client_plugin.get_security_service.side_effect = (80 get_security_service)81 scheduler.TaskRunner(net.create)()82 return net83 def test_create(self, rsrc_defn=None, stack=None):84 if rsrc_defn is None:85 rsrc_defn = self.rsrc_defn86 if stack is None:87 stack = self.stack88 net = self._create_network('share_network', rsrc_defn, stack)89 self.assertEqual((net.CREATE, net.COMPLETE), net.state)90 self.assertEqual('42', net.resource_id)91 net.client().share_networks.create.assert_called_with(92 name='1', description='2', neutron_net_id='3',93 neutron_subnet_id='4', nova_net_id=None)94 calls = [mock.call('42', '6'), mock.call('42', '7')]95 net.client().share_networks.add_security_service.assert_has_calls(96 calls, any_order=True)97 self.assertEqual('share_networks', net.entity)98 def test_create_with_nova(self):99 t = template_format.parse(stack_template)100 t['resources']['share_network']['properties']['nova_network'] = 'n'101 del t['resources']['share_network']['properties']['neutron_network']102 del t['resources']['share_network']['properties']['neutron_subnet']103 stack = utils.parse_stack(t)104 rsrc_defn = stack.t.resource_definitions(stack)['share_network']105 net = self._create_network('share_network', rsrc_defn, stack,106 use_neutron=False)107 self.assertEqual((net.CREATE, net.COMPLETE), net.state)108 self.assertEqual('42', net.resource_id)109 net.client().share_networks.create.assert_called_with(110 name='1', description='2', neutron_net_id=None,111 neutron_subnet_id=None, nova_net_id='n')112 calls = [mock.call('42', '6'), mock.call('42', '7')]113 net.client().share_networks.add_security_service.assert_has_calls(114 calls, any_order=True)115 self.assertEqual('share_networks', net.entity)116 def test_create_without_network(self):117 t = template_format.parse(stack_template)118 del t['resources']['share_network']['properties']['neutron_network']119 stack = utils.parse_stack(t)120 rsrc_defn = stack.t.resource_definitions(stack)['share_network']121 net = self._create_network('share_network', rsrc_defn, stack)122 self.assertEqual((net.CREATE, net.COMPLETE), net.state)123 self.assertEqual('42', net.resource_id)124 net.client().share_networks.create.assert_called_with(125 name='1', description='2', neutron_net_id='3',126 neutron_subnet_id='4', nova_net_id=None)127 calls = [mock.call('42', '6'), mock.call('42', '7')]128 net.client().share_networks.add_security_service.assert_has_calls(129 calls, any_order=True)130 self.assertEqual('share_networks', net.entity)131 def test_create_fail(self):132 self.client.share_networks.add_security_service.side_effect = (133 Exception())134 self.assertRaises(135 exception.ResourceFailure,136 self._create_network, 'share_network', self.rsrc_defn, self.stack)137 def test_validate_conflicting_net_subnet(self):138 t = template_format.parse(stack_template)139 t['resources']['share_network']['properties']['neutron_network'] = '5'140 stack = utils.parse_stack(t)141 rsrc_defn = stack.t.resource_definitions(stack)['share_network']142 net = self._create_network('share_network', rsrc_defn, stack)143 net.is_using_neutron = mock.Mock(return_value=True)144 msg = ('Provided neutron_subnet does not belong '145 'to provided neutron_network.')146 self.assertRaisesRegex(exception.StackValidationFailed, msg,147 net.validate)148 def test_update(self):149 net = self._create_network('share_network', self.rsrc_defn, self.stack)150 props = self.tmpl['resources']['share_network']['properties'].copy()151 props['name'] = 'a'152 props['description'] = 'b'153 props['neutron_network'] = 'c'154 props['neutron_subnet'] = 'd'155 props['security_services'] = ['7', '8']156 update_template = net.t.freeze(properties=props)157 scheduler.TaskRunner(net.update, update_template)()158 self.assertEqual((net.UPDATE, net.COMPLETE), net.state)159 exp_args = {160 'name': 'a',161 'description': 'b',162 'neutron_net_id': 'c',163 'neutron_subnet_id': 'd',164 'nova_net_id': None165 }166 net.client().share_networks.update.assert_called_with('42', **exp_args)167 net.client().share_networks.add_security_service.assert_called_with(168 '42', '8')169 net.client().share_networks.remove_security_service.assert_called_with(170 '42', '6')171 def test_update_security_services(self):172 net = self._create_network('share_network', self.rsrc_defn, self.stack)173 props = self.tmpl['resources']['share_network']['properties'].copy()174 props['security_services'] = ['7', '8']175 update_template = net.t.freeze(properties=props)176 scheduler.TaskRunner(net.update, update_template)()177 self.assertEqual((net.UPDATE, net.COMPLETE), net.state)178 called = net.client().share_networks.update.called179 self.assertFalse(called)180 net.client().share_networks.add_security_service.assert_called_with(181 '42', '8')182 net.client().share_networks.remove_security_service.assert_called_with(183 '42', '6')184 def test_update_fail(self):185 net = self._create_network('share_network', self.rsrc_defn, self.stack)186 self.client.share_networks.remove_security_service.side_effect = (187 Exception())188 props = self.tmpl['resources']['share_network']['properties'].copy()189 props['security_services'] = []190 update_template = net.t.freeze(properties=props)191 run = scheduler.TaskRunner(net.update, update_template)192 self.assertRaises(exception.ResourceFailure, run)193 def test_nova_net_neutron_net_conflict(self):194 t = template_format.parse(stack_template)195 t['resources']['share_network']['properties']['nova_network'] = 1196 stack = utils.parse_stack(t)197 rsrc_defn = stack.t.resource_definitions(stack)['share_network']198 net = self._create_network('share_network', rsrc_defn, stack)199 msg = ('Cannot define the following properties at the same time: '200 'neutron_network, nova_network.')201 self.assertRaisesRegex(exception.ResourcePropertyConflict, msg,202 net.validate)203 def test_nova_net_neutron_subnet_conflict(self):204 t = template_format.parse(stack_template)205 t['resources']['share_network']['properties']['nova_network'] = 1206 del t['resources']['share_network']['properties']['neutron_network']207 stack = utils.parse_stack(t)208 rsrc_defn = stack.t.resource_definitions(stack)['share_network']209 net = self._create_network('share_network', rsrc_defn, stack)210 msg = ('Cannot define the following properties at the same time: '211 'neutron_subnet, nova_network.')212 self.assertRaisesRegex(exception.ResourcePropertyConflict, msg,213 net.validate)214 def test_nova_net_while_using_neutron(self):215 t = template_format.parse(stack_template)216 t['resources']['share_network']['properties']['nova_network'] = 'n'217 del t['resources']['share_network']['properties']['neutron_network']218 del t['resources']['share_network']['properties']['neutron_subnet']219 stack = utils.parse_stack(t)220 rsrc_defn = stack.t.resource_definitions(stack)['share_network']221 net = self._create_network('share_network', rsrc_defn, stack)222 net.is_using_neutron = mock.Mock(return_value=True)223 msg = ('With Neutron enabled you need to pass Neutron network '224 'and Neutron subnet instead of Nova network')225 self.assertRaisesRegex(exception.StackValidationFailed, msg,226 net.validate)227 def test_neutron_net_without_neutron_subnet(self):228 t = template_format.parse(stack_template)229 del t['resources']['share_network']['properties']['neutron_subnet']230 stack = utils.parse_stack(t)231 rsrc_defn = stack.t.resource_definitions(stack)['share_network']232 net = self._create_network('share_network', rsrc_defn, stack)233 msg = ('neutron_network cannot be specified without neutron_subnet.')234 self.assertRaisesRegex(exception.ResourcePropertyDependency, msg,235 net.validate)236 def test_attributes(self):237 net = self._create_network('share_network', self.rsrc_defn,238 self.stack)239 self.assertEqual('2', net.FnGetAtt('segmentation_id'))240 self.assertEqual('3', net.FnGetAtt('cidr'))241 self.assertEqual('5', net.FnGetAtt('ip_version'))242 self.assertEqual('6', net.FnGetAtt('network_type'))243 def test_get_live_state(self):244 net = self._create_network('share_network', self.rsrc_defn,245 self.stack)246 value = mock.MagicMock()247 value.to_dict.return_value = {248 'name': 'test',249 'segmentation_id': '123',250 'created_at': '2016-02-02T18:40:24.000000',251 'neutron_subnet_id': None,252 'updated_at': None,253 'network_type': None,254 'neutron_net_id': '4321',255 'ip_version': None,256 'nova_net_id': None,257 'cidr': None,258 'project_id': '221b4f51e9bd4f659845f657a3051a46',...

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 localstack 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