~ubuntu-branches/ubuntu/saucy/heat/saucy-updates

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/tests/test_instance_network.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2013-08-08 15:23:59 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130808152359-9jgqjp23kssvc3x9
Tags: 2013.2~b2.a186.g2b4b248-0ubuntu1
[ Chuck Short ]
* debian/patches/rename-quantumclient.patch: Dropped no longer needed. 
* debian/control: Add python-oslo.sphinx

[ James Page ]
* New upstream snapshot.
* d/watch: Updated to track releases on launchpad.
* d/control: Drop BD in pep8, no longer required.
* d/control,rules: Drop use of openstack-pkg-tools, revert use of xz
  compression for debs.
* d/control,*.config,*.templates,po: Drop use of debconf/dbconfig-common
  to configure heat.
* d/*.upstart: Add upstart configurations for Ubuntu.
* d/p/default-kombu.patch: Switch default messaging from qpid to
  kombu.
* d/p/default-sqlite.patch: Use sqlite as default database option.
* d/control: Add python-ceilometerclient to BD's.
* d/rules: Fail package build for unit test failures.
* d/*.install: Directly install configuration files to /etc/heat.
* d/control: Update VCS locations to ubuntu-server-dev branches.
* d/heat-common.{install,manpages}: Include new binaries and associated
  manpages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
 
#    not use this file except in compliance with the License. You may obtain
5
 
#    a copy of the License at
6
 
#
7
 
#         http://www.apache.org/licenses/LICENSE-2.0
8
 
#
9
 
#    Unless required by applicable law or agreed to in writing, software
10
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 
#    License for the specific language governing permissions and limitations
13
 
#    under the License.
14
 
 
15
 
 
16
 
from heat.engine import environment
17
 
from heat.tests.v1_1 import fakes
18
 
from heat.engine.resources import instance as instances
19
 
from heat.engine.resources import network_interface as network_interfaces
20
 
from heat.common import template_format
21
 
from heat.engine import parser
22
 
from heat.engine import scheduler
23
 
from heat.openstack.common import uuidutils
24
 
from heat.tests.common import HeatTestCase
25
 
from heat.tests import utils
26
 
from heat.tests.utils import setup_dummy_db
27
 
 
28
 
 
29
 
wp_template = '''
30
 
{
31
 
  "AWSTemplateFormatVersion" : "2010-09-09",
32
 
  "Description" : "WordPress",
33
 
  "Parameters" : {
34
 
    "KeyName" : {
35
 
      "Description" : "KeyName",
36
 
      "Type" : "String",
37
 
      "Default" : "test"
38
 
    },
39
 
    "InstanceType": {
40
 
      "Type": "String",
41
 
      "Description": "EC2 instance type",
42
 
      "Default": "m1.small",
43
 
      "AllowedValues": [ "m1.small", "m1.large" ]
44
 
    },
45
 
    "SubnetId": {
46
 
      "Type" : "String",
47
 
      "Description" : "SubnetId of an existing subnet in your VPC"
48
 
    },
49
 
  },
50
 
  "Resources" : {
51
 
    "WebServer": {
52
 
      "Type": "AWS::EC2::Instance",
53
 
      "Properties": {
54
 
        "ImageId"        : "F17-x86_64-gold",
55
 
        "InstanceType"   : { "Ref" : "InstanceType" },
56
 
        "SubnetId"       : { "Ref" : "SubnetId" },
57
 
        "KeyName"        : { "Ref" : "KeyName" },
58
 
        "UserData"       : "wordpress"
59
 
      }
60
 
    }
61
 
  }
62
 
}
63
 
'''
64
 
 
65
 
 
66
 
wp_template_with_nic = '''
67
 
{
68
 
  "AWSTemplateFormatVersion" : "2010-09-09",
69
 
  "Description" : "WordPress",
70
 
  "Parameters" : {
71
 
    "KeyName" : {
72
 
      "Description" : "KeyName",
73
 
      "Type" : "String",
74
 
      "Default" : "test"
75
 
    },
76
 
    "InstanceType": {
77
 
      "Type": "String",
78
 
      "Description": "EC2 instance type",
79
 
      "Default": "m1.small",
80
 
      "AllowedValues": [ "m1.small", "m1.large" ]
81
 
    },
82
 
    "SubnetId": {
83
 
      "Type" : "String",
84
 
      "Description" : "SubnetId of an existing subnet in your VPC"
85
 
    },
86
 
  },
87
 
  "Resources" : {
88
 
 
89
 
    "nic1": {
90
 
        "Type": "AWS::EC2::NetworkInterface",
91
 
        "Properties": {
92
 
            "SubnetId": { "Ref": "SubnetId" }
93
 
        }
94
 
    },
95
 
 
96
 
    "WebServer": {
97
 
      "Type": "AWS::EC2::Instance",
98
 
      "Properties": {
99
 
        "ImageId"        : "F17-x86_64-gold",
100
 
        "InstanceType"   : { "Ref" : "InstanceType" },
101
 
        "NetworkInterfaces": [ { "NetworkInterfaceId" : {"Ref": "nic1"},
102
 
                                 "DeviceIndex" : "0"  } ],
103
 
        "KeyName"        : { "Ref" : "KeyName" },
104
 
        "UserData"       : "wordpress"
105
 
      }
106
 
    }
107
 
  }
108
 
}
109
 
'''
110
 
 
111
 
 
112
 
class FakeQuantum(object):
113
 
 
114
 
    def show_subnet(self, subnet, **_params):
115
 
        return {
116
 
            'subnet': {
117
 
                'name': 'name',
118
 
                'network_id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
119
 
                'tenant_id': 'c1210485b2424d48804aad5d39c61b8f',
120
 
                'allocation_pools': [{'start': '10.10.0.2',
121
 
                                      'end': '10.10.0.254'}],
122
 
                'gateway_ip': '10.10.0.1',
123
 
                'ip_version': 4,
124
 
                'cidr': '10.10.0.0/24',
125
 
                'id': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861',
126
 
                'enable_dhcp': False,
127
 
            }}
128
 
 
129
 
    def create_port(self, body=None):
130
 
        return {
131
 
            'port': {
132
 
                'admin_state_up': True,
133
 
                'device_id': '',
134
 
                'device_owner': '',
135
 
                'fixed_ips': [{
136
 
                    'ip_address': '10.0.3.3',
137
 
                    'subnet_id': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}],
138
 
                'id': '64d913c1-bcb1-42d2-8f0a-9593dbcaf251',
139
 
                'mac_address': 'fa:16:3e:25:32:5d',
140
 
                'name': '',
141
 
                'network_id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
142
 
                'status': 'ACTIVE',
143
 
                'tenant_id': 'c1210485b2424d48804aad5d39c61b8f'
144
 
            }}
145
 
 
146
 
 
147
 
class instancesTest(HeatTestCase):
148
 
    def setUp(self):
149
 
        super(instancesTest, self).setUp()
150
 
        self.fc = fakes.FakeClient()
151
 
        setup_dummy_db()
152
 
 
153
 
    def _create_test_instance(self, return_server, name):
154
 
        stack_name = '%s_stack' % name
155
 
        t = template_format.parse(wp_template)
156
 
        template = parser.Template(t)
157
 
        kwargs = {'KeyName': 'test',
158
 
                  'InstanceType': 'm1.large',
159
 
                  'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
160
 
        stack = parser.Stack(None, stack_name, template,
161
 
                             environment.Environment(kwargs),
162
 
                             stack_id=uuidutils.generate_uuid())
163
 
 
164
 
        t['Resources']['WebServer']['Properties']['ImageId'] = 'CentOS 5.2'
165
 
        instance = instances.Instance('%s_name' % name,
166
 
                                      t['Resources']['WebServer'], stack)
167
 
 
168
 
        self.m.StubOutWithMock(instance, 'nova')
169
 
        instance.nova().MultipleTimes().AndReturn(self.fc)
170
 
 
171
 
        self.m.StubOutWithMock(instance, 'quantum')
172
 
        instance.quantum().MultipleTimes().AndReturn(FakeQuantum())
173
 
 
174
 
        instance.t = instance.stack.resolve_runtime_data(instance.t)
175
 
 
176
 
        # need to resolve the template functions
177
 
        server_userdata = instance._build_userdata(
178
 
            instance.t['Properties']['UserData'])
179
 
 
180
 
        self.m.StubOutWithMock(self.fc.servers, 'create')
181
 
        self.fc.servers.create(
182
 
            image=1, flavor=3, key_name='test',
183
 
            name=utils.PhysName(stack_name, instance.name),
184
 
            security_groups=None,
185
 
            userdata=server_userdata, scheduler_hints=None, meta=None,
186
 
            nics=[{'port-id': '64d913c1-bcb1-42d2-8f0a-9593dbcaf251'}],
187
 
            availability_zone=None).AndReturn(
188
 
                return_server)
189
 
        self.m.ReplayAll()
190
 
 
191
 
        scheduler.TaskRunner(instance.create)()
192
 
        return instance
193
 
 
194
 
    def _create_test_instance_with_nic(self, return_server, name):
195
 
        stack_name = '%s_stack' % name
196
 
        t = template_format.parse(wp_template_with_nic)
197
 
        template = parser.Template(t)
198
 
        kwargs = {'KeyName': 'test',
199
 
                  'InstanceType': 'm1.large',
200
 
                  'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861'}
201
 
        stack = parser.Stack(None, stack_name, template,
202
 
                             environment.Environment(kwargs),
203
 
                             stack_id=uuidutils.generate_uuid())
204
 
 
205
 
        t['Resources']['WebServer']['Properties']['ImageId'] = 'CentOS 5.2'
206
 
 
207
 
        nic = network_interfaces.NetworkInterface('%s_nic' % name,
208
 
                                                  t['Resources']['nic1'],
209
 
                                                  stack)
210
 
 
211
 
        instance = instances.Instance('%s_name' % name,
212
 
                                      t['Resources']['WebServer'], stack)
213
 
 
214
 
        self.m.StubOutWithMock(nic, 'quantum')
215
 
        nic.quantum().MultipleTimes().AndReturn(FakeQuantum())
216
 
 
217
 
        self.m.StubOutWithMock(instance, 'nova')
218
 
        instance.nova().MultipleTimes().AndReturn(self.fc)
219
 
 
220
 
        nic.t = nic.stack.resolve_runtime_data(nic.t)
221
 
        instance.t = instance.stack.resolve_runtime_data(instance.t)
222
 
 
223
 
        # need to resolve the template functions
224
 
        server_userdata = instance._build_userdata(
225
 
            instance.t['Properties']['UserData'])
226
 
        self.m.StubOutWithMock(self.fc.servers, 'create')
227
 
        self.fc.servers.create(
228
 
            image=1, flavor=3, key_name='test',
229
 
            name=utils.PhysName(stack_name, instance.name),
230
 
            security_groups=None,
231
 
            userdata=server_userdata, scheduler_hints=None, meta=None,
232
 
            nics=[{'port-id': '64d913c1-bcb1-42d2-8f0a-9593dbcaf251'}],
233
 
            availability_zone=None).AndReturn(
234
 
                return_server)
235
 
        self.m.ReplayAll()
236
 
 
237
 
        # create network interface
238
 
        scheduler.TaskRunner(nic.create)()
239
 
        stack.resources["nic1"] = nic
240
 
 
241
 
        scheduler.TaskRunner(instance.create)()
242
 
        return instance
243
 
 
244
 
    def test_instance_create(self):
245
 
        return_server = self.fc.servers.list()[1]
246
 
        instance = self._create_test_instance(return_server,
247
 
                                              'test_instance_create')
248
 
        # this makes sure the auto increment worked on instance creation
249
 
        self.assertTrue(instance.id > 0)
250
 
 
251
 
        expected_ip = return_server.networks['public'][0]
252
 
        self.assertEqual(instance.FnGetAtt('PublicIp'), expected_ip)
253
 
        self.assertEqual(instance.FnGetAtt('PrivateIp'), expected_ip)
254
 
        self.assertEqual(instance.FnGetAtt('PrivateDnsName'), expected_ip)
255
 
        self.assertEqual(instance.FnGetAtt('PrivateDnsName'), expected_ip)
256
 
 
257
 
        self.m.VerifyAll()
258
 
 
259
 
    def test_instance_create_with_nic(self):
260
 
        return_server = self.fc.servers.list()[1]
261
 
        instance = self._create_test_instance_with_nic(
262
 
            return_server, 'test_instance_create_with_network_interface')
263
 
 
264
 
        # this makes sure the auto increment worked on instance creation
265
 
        self.assertTrue(instance.id > 0)
266
 
 
267
 
        expected_ip = return_server.networks['public'][0]
268
 
        self.assertEqual(instance.FnGetAtt('PublicIp'), expected_ip)
269
 
        self.assertEqual(instance.FnGetAtt('PrivateIp'), expected_ip)
270
 
        self.assertEqual(instance.FnGetAtt('PrivateDnsName'), expected_ip)
271
 
        self.assertEqual(instance.FnGetAtt('PrivateDnsName'), expected_ip)
272
 
 
273
 
        self.m.VerifyAll()