Moved migration and fixed tests from upstream

This commit is contained in:
Christopher MacGown
2011-08-22 22:17:51 -07:00
parent b91a5542c1
commit 7f1adb50cf
7 changed files with 61 additions and 20 deletions

View File

@@ -526,7 +526,7 @@ class API(base.Base):
availability_zone, user_data, metadata, availability_zone, user_data, metadata,
injected_files, admin_password, zone_blob, injected_files, admin_password, zone_blob,
reservation_id, access_ip_v4, access_ip_v6, reservation_id, access_ip_v4, access_ip_v6,
requested_networks, config_drive requested_networks, config_drive)
block_device_mapping = block_device_mapping or [] block_device_mapping = block_device_mapping or []
instances = [] instances = []

View File

@@ -0,0 +1,38 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2011 Piston Cloud Computing, Inc.
#
# 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 sqlalchemy import Column, Integer, MetaData, String, Table
from nova import utils
meta = MetaData()
instances = Table("instances", meta,
Column("id", Integer(), primary_key=True, nullable=False))
# matches the size of an image_ref
config_drive_column = Column("config_drive", String(255), nullable=True)
def upgrade(migrate_engine):
meta.bind = migrate_engine
instances.create_column(config_drive_column)
def downgrade(migrate_engine):
meta.bind = migrate_engine
instances.drop_column(config_drive_column)

View File

@@ -1776,8 +1776,8 @@ class ServersTest(test.TestCase):
self.config_drive = True self.config_drive = True
self._setup_for_create_instance() self._setup_for_create_instance()
image_href = 'http://localhost/v1.1/images/2' image_href = 'http://localhost/v1.1/123/images/2'
flavor_ref = 'http://localhost/v1.1/flavors/3' flavor_ref = 'http://localhost/v1.1/123/flavors/3'
body = { body = {
'server': { 'server': {
'name': 'config_drive_test', 'name': 'config_drive_test',
@@ -1792,12 +1792,13 @@ class ServersTest(test.TestCase):
}, },
} }
req = webob.Request.blank('/v1.1/servers') req = webob.Request.blank('/v1.1/123/servers')
req.method = 'POST' req.method = 'POST'
req.body = json.dumps(body) req.body = json.dumps(body)
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app()) res = req.get_response(fakes.wsgi_app())
print res
self.assertEqual(res.status_int, 202) self.assertEqual(res.status_int, 202)
server = json.loads(res.body)['server'] server = json.loads(res.body)['server']
self.assertEqual(1, server['id']) self.assertEqual(1, server['id'])
@@ -1807,8 +1808,8 @@ class ServersTest(test.TestCase):
self.config_drive = 2 self.config_drive = 2
self._setup_for_create_instance() self._setup_for_create_instance()
image_href = 'http://localhost/v1.1/images/2' image_href = 'http://localhost/v1.1/123/images/2'
flavor_ref = 'http://localhost/v1.1/flavors/3' flavor_ref = 'http://localhost/v1.1/123/flavors/3'
body = { body = {
'server': { 'server': {
'name': 'config_drive_test', 'name': 'config_drive_test',
@@ -1823,7 +1824,7 @@ class ServersTest(test.TestCase):
}, },
} }
req = webob.Request.blank('/v1.1/servers') req = webob.Request.blank('/v1.1/123/servers')
req.method = 'POST' req.method = 'POST'
req.body = json.dumps(body) req.body = json.dumps(body)
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"
@@ -1840,8 +1841,8 @@ class ServersTest(test.TestCase):
self.config_drive = "asdf" self.config_drive = "asdf"
self._setup_for_create_instance() self._setup_for_create_instance()
image_href = 'http://localhost/v1.1/images/2' image_href = 'http://localhost/v1.1/123/images/2'
flavor_ref = 'http://localhost/v1.1/flavors/3' flavor_ref = 'http://localhost/v1.1/123/flavors/3'
body = { body = {
'server': { 'server': {
'name': 'config_drive_test', 'name': 'config_drive_test',
@@ -1856,7 +1857,7 @@ class ServersTest(test.TestCase):
}, },
} }
req = webob.Request.blank('/v1.1/servers') req = webob.Request.blank('/v1.1/123/servers')
req.method = 'POST' req.method = 'POST'
req.body = json.dumps(body) req.body = json.dumps(body)
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"
@@ -1867,8 +1868,8 @@ class ServersTest(test.TestCase):
def test_create_instance_without_config_drive_v1_1(self): def test_create_instance_without_config_drive_v1_1(self):
self._setup_for_create_instance() self._setup_for_create_instance()
image_href = 'http://localhost/v1.1/images/2' image_href = 'http://localhost/v1.1/123/images/2'
flavor_ref = 'http://localhost/v1.1/flavors/3' flavor_ref = 'http://localhost/v1.1/123/flavors/3'
body = { body = {
'server': { 'server': {
'name': 'config_drive_test', 'name': 'config_drive_test',
@@ -1883,7 +1884,7 @@ class ServersTest(test.TestCase):
}, },
} }
req = webob.Request.blank('/v1.1/servers') req = webob.Request.blank('/v1.1/123/servers')
req.method = 'POST' req.method = 'POST'
req.body = json.dumps(body) req.body = json.dumps(body)
req.headers["content-type"] = "application/json" req.headers["content-type"] = "application/json"
@@ -3588,6 +3589,7 @@ class ServersViewBuilderV11Test(test.TestCase):
"id": 1, "id": 1,
"uuid": self.instance['uuid'], "uuid": self.instance['uuid'],
"name": "test_server", "name": "test_server",
"config_drive": None,
"links": [ "links": [
{ {
"rel": "self", "rel": "self",
@@ -3747,6 +3749,7 @@ class ServersViewBuilderV11Test(test.TestCase):
}, },
"addresses": {}, "addresses": {},
"metadata": {}, "metadata": {},
"config_drive": None,
"accessIPv4": "1.2.3.4", "accessIPv4": "1.2.3.4",
"accessIPv6": "", "accessIPv6": "",
"links": [ "links": [
@@ -3801,6 +3804,7 @@ class ServersViewBuilderV11Test(test.TestCase):
}, },
"addresses": {}, "addresses": {},
"metadata": {}, "metadata": {},
"config_drive": None,
"accessIPv4": "", "accessIPv4": "",
"accessIPv6": "fead::1234", "accessIPv6": "fead::1234",
"links": [ "links": [

View File

@@ -163,7 +163,7 @@ class ComputeTestCase(test.TestCase):
def test_create_instance_associates_config_drive(self): def test_create_instance_associates_config_drive(self):
"""Make sure create associates a config drive.""" """Make sure create associates a config drive."""
instance_id = self._create_instance(params={'config_drive': True,}) instance_id = self._create_instance(params={'config_drive': True, })
try: try:
self.compute.run_instance(self.context, instance_id) self.compute.run_instance(self.context, instance_id)

View File

@@ -228,7 +228,7 @@ def _inject_metadata_into_fs(metadata, fs, execute=None):
metadata_path = os.path.join(fs, "meta.js") metadata_path = os.path.join(fs, "meta.js")
metadata = dict([(m.key, m.value) for m in metadata]) metadata = dict([(m.key, m.value) for m in metadata])
utils.execute('sudo', 'tee', metadata_path, utils.execute('sudo', 'tee', metadata_path,
process_input=json.dumps(metadata)) process_input=json.dumps(metadata))

View File

@@ -131,8 +131,8 @@ flags.DEFINE_string('libvirt_vif_type', 'bridge',
flags.DEFINE_string('libvirt_vif_driver', flags.DEFINE_string('libvirt_vif_driver',
'nova.virt.libvirt.vif.LibvirtBridgeDriver', 'nova.virt.libvirt.vif.LibvirtBridgeDriver',
'The libvirt VIF driver to configure the VIFs.') 'The libvirt VIF driver to configure the VIFs.')
flags.DEFINE_string('default_local_format', flags.DEFINE_string('default_local_format',
None, None,
'The default format a local_volume will be formatted with ' 'The default format a local_volume will be formatted with '
'on creation.') 'on creation.')
@@ -970,7 +970,7 @@ class LibvirtConnection(driver.ComputeDriver):
for injection in ('metadata', 'key', 'net'): for injection in ('metadata', 'key', 'net'):
if locals()[injection]: if locals()[injection]:
LOG.info(_('instance %(inst_name)s: injecting ' LOG.info(_('instance %(inst_name)s: injecting '
'%(injection)s into image %(img_id)s' '%(injection)s into image %(img_id)s'
% locals())) % locals()))
try: try:
disk.inject_data(injection_path, key, net, metadata, disk.inject_data(injection_path, key, net, metadata,
@@ -1106,7 +1106,6 @@ class LibvirtConnection(driver.ComputeDriver):
block_device_info)): block_device_info)):
xml_info['swap_device'] = self.default_swap_device xml_info['swap_device'] = self.default_swap_device
config_drive = False config_drive = False
if instance.get('config_drive') or instance.get('config_drive_id'): if instance.get('config_drive') or instance.get('config_drive_id'):
xml_info['config_drive'] = xml_info['basepath'] + "/disk.config" xml_info['config_drive'] = xml_info['basepath'] + "/disk.config"

View File

@@ -741,7 +741,7 @@ class VMHelper(HelperBase):
# if at all, so determine whether it's required first, and then do # if at all, so determine whether it's required first, and then do
# everything # everything
mount_required = False mount_required = False
key, net, metadata = _prepare_injectables(instance, network_info) key, net, metadata = _prepare_injectables(instance, network_info)
mount_required = key or net or metadata mount_required = key or net or metadata
if not mount_required: if not mount_required:
return return