summaryrefslogtreecommitdiff
path: root/heat/tests/openstack/neutron/test_neutron_l2_gateway_connection.py
blob: 6fecffd1ba577bdb2f1a84454a9d143ef74f9f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright 2018 Ericsson
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from unittest import mock

from neutronclient.v2_0 import client as neutronclient

from heat.common import template_format
from heat.engine.clients.os import neutron
from heat.engine import scheduler
from heat.tests import common
from heat.tests import utils


class NeutronL2GatewayConnectionTest(common.HeatTestCase):
    test_template = '''
    heat_template_version: queens
    description: Template to test L2GatewayConnection Neutron resource
    resources:
      l2gw_conn:
        type: OS::Neutron::L2GatewayConnection
        properties:
          network_id: j29n3678-c012-p008-3975-93584a65a18a
          segmentation_id: 501
          l2_gateway_id: d3590f37-b072-4358-9719-71964d84a31c
    '''

    mock_create_req = {
        "l2_gateway_connection": {
            "network_id": "j29n3678-c012-p008-3975-93584a65a18a",
            "segmentation_id": "501",
            "l2_gateway_id": "d3590f37-b072-4358-9719-71964d84a31c"
        }}
    mock_create_reply = {
        "l2_gateway_connection": {
            "id": "e491171c-3458-4d85-b3a3-68a7c4a1cacd",
            "tenant_id": "7ea656c7c9b8447494f33b0bc741d9e6",
            "network_id": "j29n3678-c012-p008-3975-93584a65a18a",
            "segmentation_id": "501",
            "l2_gateway_id": "d3590f37-b072-4358-9719-71964d84a31c"
        }}

    def setUp(self):
        super(NeutronL2GatewayConnectionTest, self).setUp()
        self.mockclient = mock.MagicMock()
        self.patchobject(neutronclient, 'Client', return_value=self.mockclient)

        self.patchobject(neutron.NeutronClientPlugin, 'has_extension',
                         return_value=True)

    def _create_l2_gateway_connection(self):
        # stack create
        self.mockclient.create_l2_gateway_connection.return_value = (
            self.mock_create_reply)
        self.mockclient.show_l2_gateway_connection.return_value = (
            self.mock_create_reply)
        orig_template = template_format.parse(self.test_template)
        self.stack = utils.parse_stack(orig_template)
        scheduler.TaskRunner(self.stack.create)()
        self.l2gwconn_resource = self.stack['l2gw_conn']

    def test_l2_gateway_connection_create(self):
        self._create_l2_gateway_connection()
        self.assertIsNone(self.l2gwconn_resource.validate())
        self.assertEqual((self.l2gwconn_resource.CREATE,
                         self.l2gwconn_resource.COMPLETE),
                         self.l2gwconn_resource.state)
        self.assertEqual('e491171c-3458-4d85-b3a3-68a7c4a1cacd',
                         self.l2gwconn_resource.FnGetRefId())
        self.mockclient.create_l2_gateway_connection.assert_called_once_with(
            self.mock_create_req)

    def test_l2_gateway_connection_delete(self):
        self._create_l2_gateway_connection()
        self.stack.delete()
        self.mockclient.delete_l2_gateway_connection.assert_called_with(
            'e491171c-3458-4d85-b3a3-68a7c4a1cacd')