def test_net_disconnect_from_nat(self):
     # use external
     fake_client, fake_ctx = self.generate_client_and_context_network()
     fake_ctx._target.node.properties = {
         'use_external_resource': True
     }
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         public_nat.net_disconnect_from_nat(ctx=fake_ctx)
     # no external
     fake_client, fake_ctx = self.generate_client_and_context_network()
     fake_ctx._target.node.properties = {
         'nat': {
             'edge_gateway': 'gateway'
         },
         'rules': [{
             'type': 'DNAT'
         }]
     }
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         public_nat.net_disconnect_from_nat(ctx=fake_ctx)
     fake_client._vdc_gateway.del_nat_rule.assert_called_with(
         'DNAT', '192.168.1.1', 'any', '127.1.1.100 - 127.1.1.200',
         'any', 'any'
     )
 def test_public_network_connected_to_nat(self):
     self.ctx.target.node.properties['rules'] = \
         self.test_config['public_nat']['rules_net']
     self.ctx.source.node.properties['resource_id'] = \
         self.test_config['public_nat']['network_name']
     rules_count = self.get_rules_count()
     public_nat.net_connect_to_nat()
     self.assertEqual(rules_count + 1, self.get_rules_count())
     public_nat.net_disconnect_from_nat()
     self.assertEqual(rules_count, self.get_rules_count())
 def test_public_network_connected_to_nat(self):
     self.ctx.target.node.properties['rules'] = \
         self.test_config['public_nat']['rules_net']
     self.ctx.source.node.properties['resource_id'] = \
         self.test_config['public_nat']['network_name']
     rules_count = self.get_rules_count()
     public_nat.net_connect_to_nat()
     self.assertEqual(rules_count + 1, self.get_rules_count())
     public_nat.net_disconnect_from_nat()
     self.assertEqual(rules_count, self.get_rules_count())
 def test_net_disconnect_from_nat(self):
     # use external
     fake_client, fake_ctx = self.generate_client_and_context_network()
     fake_ctx._target.node.properties = {'use_external_resource': True}
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         public_nat.net_disconnect_from_nat(ctx=fake_ctx)
     # no external
     fake_client, fake_ctx = self.generate_client_and_context_network()
     fake_ctx._target.node.properties = {
         'nat': {
             'edge_gateway': 'gateway'
         },
         'rules': [{
             'type': 'DNAT'
         }]
     }
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         public_nat.net_disconnect_from_nat(ctx=fake_ctx)
     fake_client._vdc_gateway.del_nat_rule.assert_called_with(
         'DNAT', '192.168.1.1', 'any', '127.1.1.100 - 127.1.1.200', 'any',
         'any')