remerge trunk
This commit is contained in:
@@ -53,7 +53,7 @@ flags.DEFINE_string('dnsmasq_interface', 'br0', 'Default Dnsmasq interface')
|
||||
LOG = logging.getLogger('nova.dhcpbridge')
|
||||
|
||||
|
||||
def add_lease(mac, ip_address, _hostname, _interface):
|
||||
def add_lease(mac, ip_address, _interface):
|
||||
"""Set the IP that was assigned by the DHCP server."""
|
||||
if FLAGS.fake_rabbit:
|
||||
LOG.debug(_("leasing ip"))
|
||||
@@ -67,13 +67,13 @@ def add_lease(mac, ip_address, _hostname, _interface):
|
||||
"args": {"address": ip_address}})
|
||||
|
||||
|
||||
def old_lease(mac, ip_address, hostname, interface):
|
||||
def old_lease(mac, ip_address, interface):
|
||||
"""Update just as add lease."""
|
||||
LOG.debug(_("Adopted old lease or got a change of mac/hostname"))
|
||||
add_lease(mac, ip_address, hostname, interface)
|
||||
LOG.debug(_("Adopted old lease or got a change of mac"))
|
||||
add_lease(mac, ip_address, interface)
|
||||
|
||||
|
||||
def del_lease(mac, ip_address, _hostname, _interface):
|
||||
def del_lease(mac, ip_address, _interface):
|
||||
"""Called when a lease expires."""
|
||||
if FLAGS.fake_rabbit:
|
||||
LOG.debug(_("releasing ip"))
|
||||
@@ -115,11 +115,10 @@ def main():
|
||||
if action in ['add', 'del', 'old']:
|
||||
mac = argv[2]
|
||||
ip = argv[3]
|
||||
hostname = argv[4]
|
||||
msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s and"
|
||||
" hostname %(hostname)s on interface %(interface)s") % locals()
|
||||
msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s"
|
||||
" on interface %(interface)s") % locals()
|
||||
LOG.debug(msg)
|
||||
globals()[action + '_lease'](mac, ip, hostname, interface)
|
||||
globals()[action + '_lease'](mac, ip, interface)
|
||||
else:
|
||||
print init_leases(interface)
|
||||
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Download images from Canonical Image Store
|
||||
"""
|
||||
|
||||
import gettext
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib2
|
||||
|
||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
||||
os.pardir,
|
||||
os.pardir))
|
||||
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
gettext.install('nova', unicode=1)
|
||||
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import utils
|
||||
from nova.objectstore import image
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
API_URL = 'https://imagestore.canonical.com/api/dashboard'
|
||||
|
||||
|
||||
def get_images():
|
||||
"""Get a list of the images from the imagestore URL."""
|
||||
images = json.load(urllib2.urlopen(API_URL))['images']
|
||||
images = [img for img in images if img['title'].find('amd64') > -1]
|
||||
return images
|
||||
|
||||
|
||||
def download(img):
|
||||
"""Download an image to the local filesystem."""
|
||||
# FIXME(ja): add checksum/signature checks
|
||||
tempdir = tempfile.mkdtemp(prefix='cis-')
|
||||
|
||||
kernel_id = None
|
||||
ramdisk_id = None
|
||||
|
||||
for f in img['files']:
|
||||
if f['kind'] == 'kernel':
|
||||
dest = os.path.join(tempdir, 'kernel')
|
||||
subprocess.call(['curl', '--fail', f['url'], '-o', dest])
|
||||
kernel_id = image.Image.add(dest,
|
||||
description='kernel/' + img['title'], kernel=True)
|
||||
|
||||
for f in img['files']:
|
||||
if f['kind'] == 'ramdisk':
|
||||
dest = os.path.join(tempdir, 'ramdisk')
|
||||
subprocess.call(['curl', '--fail', f['url'], '-o', dest])
|
||||
ramdisk_id = image.Image.add(dest,
|
||||
description='ramdisk/' + img['title'], ramdisk=True)
|
||||
|
||||
for f in img['files']:
|
||||
if f['kind'] == 'image':
|
||||
dest = os.path.join(tempdir, 'image')
|
||||
subprocess.call(['curl', '--fail', f['url'], '-o', dest])
|
||||
ramdisk_id = image.Image.add(dest,
|
||||
description=img['title'], kernel=kernel_id, ramdisk=ramdisk_id)
|
||||
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
utils.default_flagfile()
|
||||
argv = FLAGS(sys.argv)
|
||||
logging.setup()
|
||||
images = get_images()
|
||||
|
||||
if len(argv) == 2:
|
||||
for img in images:
|
||||
if argv[1] == 'all' or argv[1] == img['title']:
|
||||
download(img)
|
||||
else:
|
||||
print 'usage: %s (title|all)'
|
||||
print 'available images:'
|
||||
for img in images:
|
||||
print img['title']
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -346,6 +346,12 @@ DEFINE_string('logdir', None, 'output to a per-service log file in named '
|
||||
'directory')
|
||||
DEFINE_integer('logfile_mode', 0644, 'Default file mode of the logs.')
|
||||
DEFINE_string('sqlite_db', 'nova.sqlite', 'file name for sqlite')
|
||||
DEFINE_integer('sql_pool_timeout', 30,
|
||||
'seconds to wait for connection from pool before erroring')
|
||||
DEFINE_integer('sql_min_pool_size', 10,
|
||||
'minimum number of SQL connections to pool')
|
||||
DEFINE_integer('sql_max_pool_size', 10,
|
||||
'maximum number of SQL connections to pool')
|
||||
DEFINE_string('sql_connection',
|
||||
'sqlite:///$state_path/$sqlite_db',
|
||||
'connection string for sql database')
|
||||
@@ -393,3 +399,6 @@ DEFINE_bool('start_guests_on_host_boot', False,
|
||||
'Whether to restart guests when the host reboots')
|
||||
DEFINE_bool('resume_guests_state_on_host_boot', False,
|
||||
'Whether to start guests, that was running before the host reboot')
|
||||
|
||||
DEFINE_string('root_helper', 'sudo',
|
||||
'Command prefix to use for running commands as root')
|
||||
|
||||
@@ -96,7 +96,8 @@ class LeastCostScheduler(zone_aware_scheduler.ZoneAwareScheduler):
|
||||
cost_fn_str=cost_fn_str)
|
||||
|
||||
try:
|
||||
weight = getattr(FLAGS, "%s_weight" % cost_fn.__name__)
|
||||
flag_name = "%s_weight" % cost_fn.__name__
|
||||
weight = getattr(FLAGS, flag_name)
|
||||
except AttributeError:
|
||||
raise exception.SchedulerWeightFlagNotFound(
|
||||
flag_name=flag_name)
|
||||
|
||||
@@ -266,8 +266,8 @@ class ZoneAwareScheduler(driver.Scheduler):
|
||||
"""
|
||||
|
||||
if topic != "compute":
|
||||
raise NotImplemented(_("Zone Aware Scheduler only understands "
|
||||
"Compute nodes (for now)"))
|
||||
raise NotImplementedError(_("Zone Aware Scheduler only understands"
|
||||
" Compute nodes (for now)"))
|
||||
|
||||
num_instances = request_spec.get('num_instances', 1)
|
||||
instance_type = request_spec['instance_type']
|
||||
|
||||
@@ -198,7 +198,7 @@ class ZoneManager(object):
|
||||
def update_service_capabilities(self, service_name, host, capabilities):
|
||||
"""Update the per-service capabilities based on this notification."""
|
||||
logging.debug(_("Received %(service_name)s service update from "
|
||||
"%(host)s: %(capabilities)s") % locals())
|
||||
"%(host)s.") % locals())
|
||||
service_caps = self.service_states.get(host, {})
|
||||
capabilities["timestamp"] = utils.utcnow() # Reported time
|
||||
service_caps[service_name] = capabilities
|
||||
|
||||
@@ -62,7 +62,12 @@ class project_generator(object):
|
||||
|
||||
|
||||
class user_and_project_generator(object):
|
||||
def __init__(self, manager, user_state={}, project_state={}):
|
||||
def __init__(self, manager, user_state=None, project_state=None):
|
||||
if not user_state:
|
||||
user_state = {}
|
||||
if not project_state:
|
||||
project_state = {}
|
||||
|
||||
self.manager = manager
|
||||
if 'name' not in user_state:
|
||||
user_state['name'] = 'test1'
|
||||
|
||||
@@ -76,9 +76,9 @@ class ComputeTestCase(test.TestCase):
|
||||
|
||||
def _create_instance(self, params=None):
|
||||
"""Create a test instance"""
|
||||
|
||||
if params is None:
|
||||
if not params:
|
||||
params = {}
|
||||
|
||||
inst = {}
|
||||
inst['image_ref'] = 1
|
||||
inst['reservation_id'] = 'r-fakeres'
|
||||
@@ -91,8 +91,11 @@ class ComputeTestCase(test.TestCase):
|
||||
inst.update(params)
|
||||
return db.instance_create(self.context, inst)['id']
|
||||
|
||||
def _create_instance_type(self, params={}):
|
||||
def _create_instance_type(self, params=None):
|
||||
"""Create a test instance"""
|
||||
if not params:
|
||||
params = {}
|
||||
|
||||
context = self.context.elevated()
|
||||
inst = {}
|
||||
inst['name'] = 'm1.small'
|
||||
|
||||
@@ -921,18 +921,18 @@ class IptablesFirewallTestCase(test.TestCase):
|
||||
# self.fw.add_instance(instance_ref)
|
||||
def fake_iptables_execute(*cmd, **kwargs):
|
||||
process_input = kwargs.get('process_input', None)
|
||||
if cmd == ('sudo', 'ip6tables-save', '-t', 'filter'):
|
||||
if cmd == ('ip6tables-save', '-t', 'filter'):
|
||||
return '\n'.join(self.in6_filter_rules), None
|
||||
if cmd == ('sudo', 'iptables-save', '-t', 'filter'):
|
||||
if cmd == ('iptables-save', '-t', 'filter'):
|
||||
return '\n'.join(self.in_filter_rules), None
|
||||
if cmd == ('sudo', 'iptables-save', '-t', 'nat'):
|
||||
if cmd == ('iptables-save', '-t', 'nat'):
|
||||
return '\n'.join(self.in_nat_rules), None
|
||||
if cmd == ('sudo', 'iptables-restore'):
|
||||
if cmd == ('iptables-restore',):
|
||||
lines = process_input.split('\n')
|
||||
if '*filter' in lines:
|
||||
self.out_rules = lines
|
||||
return '', ''
|
||||
if cmd == ('sudo', 'ip6tables-restore'):
|
||||
if cmd == ('ip6tables-restore',):
|
||||
lines = process_input.split('\n')
|
||||
if '*filter' in lines:
|
||||
self.out6_rules = lines
|
||||
@@ -1194,8 +1194,11 @@ class NWFilterTestCase(test.TestCase):
|
||||
'project_id': 'fake',
|
||||
'instance_type_id': 1})
|
||||
|
||||
def _create_instance_type(self, params={}):
|
||||
def _create_instance_type(self, params=None):
|
||||
"""Create a test instance"""
|
||||
if not params:
|
||||
params = {}
|
||||
|
||||
context = self.context.elevated()
|
||||
inst = {}
|
||||
inst['name'] = 'm1.small'
|
||||
|
||||
@@ -414,8 +414,9 @@ class ISCSITestCase(DriverTestCase):
|
||||
self.mox.StubOutWithMock(self.volume.driver, '_execute')
|
||||
for i in volume_id_list:
|
||||
tid = db.volume_get_iscsi_target_num(self.context, i)
|
||||
self.volume.driver._execute("sudo", "ietadm", "--op", "show",
|
||||
"--tid=%(tid)d" % locals())
|
||||
self.volume.driver._execute("ietadm", "--op", "show",
|
||||
"--tid=%(tid)d" % locals(),
|
||||
run_as_root=True)
|
||||
|
||||
self.stream.truncate(0)
|
||||
self.mox.ReplayAll()
|
||||
@@ -433,8 +434,9 @@ class ISCSITestCase(DriverTestCase):
|
||||
# the first vblade process isn't running
|
||||
tid = db.volume_get_iscsi_target_num(self.context, volume_id_list[0])
|
||||
self.mox.StubOutWithMock(self.volume.driver, '_execute')
|
||||
self.volume.driver._execute("sudo", "ietadm", "--op", "show",
|
||||
"--tid=%(tid)d" % locals()).AndRaise(
|
||||
self.volume.driver._execute("ietadm", "--op", "show",
|
||||
"--tid=%(tid)d" % locals(),
|
||||
run_as_root=True).AndRaise(
|
||||
exception.ProcessExecutionError())
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@@ -548,8 +548,8 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
return '', ''
|
||||
|
||||
fake_utils.fake_execute_set_repliers([
|
||||
# Capture the sudo tee .../etc/network/interfaces command
|
||||
(r'(sudo\s+)?tee.*interfaces', _tee_handler),
|
||||
# Capture the tee .../etc/network/interfaces command
|
||||
(r'tee.*interfaces', _tee_handler),
|
||||
])
|
||||
self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE,
|
||||
glance_stubs.FakeGlance.IMAGE_KERNEL,
|
||||
@@ -592,9 +592,9 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
return '', ''
|
||||
|
||||
fake_utils.fake_execute_set_repliers([
|
||||
(r'(sudo\s+)?mount', _mount_handler),
|
||||
(r'(sudo\s+)?umount', _umount_handler),
|
||||
(r'(sudo\s+)?tee.*interfaces', _tee_handler)])
|
||||
(r'mount', _mount_handler),
|
||||
(r'umount', _umount_handler),
|
||||
(r'tee.*interfaces', _tee_handler)])
|
||||
self._test_spawn(1, 2, 3, check_injection=True)
|
||||
|
||||
# tee must not run in this case, where an injection-capable
|
||||
@@ -654,6 +654,24 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
# Ensure that it will not unrescue a non-rescued instance.
|
||||
self.assertRaises(Exception, conn.unrescue, instance, None)
|
||||
|
||||
def test_revert_migration(self):
|
||||
instance = self._create_instance()
|
||||
|
||||
class VMOpsMock():
|
||||
|
||||
def __init__(self):
|
||||
self.revert_migration_called = False
|
||||
|
||||
def revert_migration(self, instance):
|
||||
self.revert_migration_called = True
|
||||
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
|
||||
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn._vmops = VMOpsMock()
|
||||
conn.revert_migration(instance)
|
||||
self.assertTrue(conn._vmops.revert_migration_called)
|
||||
|
||||
def _create_instance(self, instance_id=1, spawn=True):
|
||||
"""Creates and spawns a test instance."""
|
||||
stubs.stubout_loopingcall_start(self.stubs)
|
||||
|
||||
Reference in New Issue
Block a user