summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
Diffstat (limited to 'nova')
-rw-r--r--nova/api/ec2/apirequest.py2
-rw-r--r--nova/api/ec2/cloud.py4
-rw-r--r--nova/api/openstack/common.py12
-rw-r--r--nova/api/openstack/servers.py26
-rw-r--r--nova/auth/dbdriver.py2
-rw-r--r--nova/auth/manager.py8
-rw-r--r--nova/compute/api.py2
-rw-r--r--nova/compute/instance_types.py4
-rw-r--r--nova/compute/monitor.py4
-rw-r--r--nova/db/sqlalchemy/api.py2
-rw-r--r--nova/image/fake.py3
-rw-r--r--nova/image/local.py2
-rw-r--r--nova/image/s3.py2
-rw-r--r--nova/log.py2
-rw-r--r--nova/network/xenapi_net.py2
-rw-r--r--nova/tests/api/openstack/test_image_metadata.py6
-rw-r--r--nova/tests/api/openstack/test_server_metadata.py3
-rw-r--r--nova/tests/api/openstack/test_servers.py68
-rw-r--r--nova/tests/api/openstack/test_versions.py6
-rw-r--r--nova/tests/test_scheduler.py4
-rw-r--r--nova/utils.py2
-rw-r--r--nova/virt/libvirt_conn.py16
-rw-r--r--nova/virt/vmwareapi/vim.py1
23 files changed, 134 insertions, 49 deletions
diff --git a/nova/api/ec2/apirequest.py b/nova/api/ec2/apirequest.py
index d7ad08d2f..6672e60bb 100644
--- a/nova/api/ec2/apirequest.py
+++ b/nova/api/ec2/apirequest.py
@@ -196,7 +196,7 @@ class APIRequest(object):
elif isinstance(data, datetime.datetime):
data_el.appendChild(
xml.createTextNode(_database_to_isoformat(data)))
- elif data != None:
+ elif data is not None:
data_el.appendChild(xml.createTextNode(str(data)))
return data_el
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 10b1d0ac5..bd4c9dcd4 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -442,7 +442,7 @@ class CloudController(object):
group_name)
criteria = self._revoke_rule_args_to_dict(context, **kwargs)
- if criteria == None:
+ if criteria is None:
raise exception.ApiError(_("Not enough parameters to build a "
"valid rule."))
@@ -664,7 +664,7 @@ class CloudController(object):
'volumeId': ec2utils.id_to_ec2_id(volume_id, 'vol-%08x')}
def _convert_to_set(self, lst, label):
- if lst == None or lst == []:
+ if lst is None or lst == []:
return None
if not isinstance(lst, list):
lst = [lst]
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 234f921ab..0b6dc944a 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -25,7 +25,7 @@ from nova import log as logging
from nova import wsgi
-LOG = logging.getLogger('common')
+LOG = logging.getLogger('nova.api.openstack.common')
FLAGS = flags.FLAGS
@@ -116,8 +116,14 @@ def get_image_id_from_image_hash(image_service, context, image_hash):
items = image_service.index(context)
for image in items:
image_id = image['id']
- if abs(hash(image_id)) == int(image_hash):
- return image_id
+ try:
+ if abs(hash(image_id)) == int(image_hash):
+ return image_id
+ except ValueError:
+ msg = _("Requested image_id has wrong format: %s,"
+ "should have numerical format") % image_id
+ LOG.error(msg)
+ raise Exception(msg)
raise exception.NotFound(image_hash)
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 43e0c7963..f221229f0 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -118,6 +118,8 @@ class Controller(common.OpenstackController):
context = req.environ['nova.context']
+ password = self._get_server_admin_password(env['server'])
+
key_name = None
key_data = None
key_pairs = auth_manager.AuthManager.get_key_pairs(context)
@@ -127,8 +129,13 @@ class Controller(common.OpenstackController):
key_data = key_pair['public_key']
requested_image_id = self._image_id_from_req_data(env)
- image_id = common.get_image_id_from_image_hash(self._image_service,
- context, requested_image_id)
+ try:
+ image_id = common.get_image_id_from_image_hash(self._image_service,
+ context, requested_image_id)
+ except:
+ msg = _("Can not find requested image")
+ return faults.Fault(exc.HTTPBadRequest(msg))
+
kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image(
req, image_id)
@@ -180,7 +187,6 @@ class Controller(common.OpenstackController):
builder = self._get_view_builder(req)
server = builder.build(inst, is_detail=True)
- password = utils.generate_password(16)
server['server']['adminPass'] = password
self.compute_api.set_admin_password(context, server['server']['id'],
password)
@@ -242,6 +248,10 @@ class Controller(common.OpenstackController):
# if the original error is okay, just reraise it
raise error
+ def _get_server_admin_password(self, server):
+ """ Determine the admin password for a server on creation """
+ return utils.generate_password(16)
+
@scheduler_api.redirect_handler
def update(self, req, id):
""" Updates the server name or password """
@@ -648,6 +658,16 @@ class ControllerV11(Controller):
def _limit_items(self, items, req):
return common.limited_by_marker(items, req)
+ def _get_server_admin_password(self, server):
+ """ Determine the admin password for a server on creation """
+ password = server.get('adminPass')
+ if password is None:
+ return utils.generate_password(16)
+ if not isinstance(password, basestring) or password == '':
+ msg = _("Invalid adminPass")
+ raise exc.HTTPBadRequest(msg)
+ return password
+
def get_default_xmlns(self, req):
return common.XML_NS_V11
diff --git a/nova/auth/dbdriver.py b/nova/auth/dbdriver.py
index d1e3f2ed5..b2c580d83 100644
--- a/nova/auth/dbdriver.py
+++ b/nova/auth/dbdriver.py
@@ -115,7 +115,7 @@ class DbDriver(object):
# on to create the project. This way we won't have to destroy
# the project again because a user turns out to be invalid.
members = set([manager])
- if member_uids != None:
+ if member_uids is not None:
for member_uid in member_uids:
member = db.user_get(context.get_admin_context(), member_uid)
if not member:
diff --git a/nova/auth/manager.py b/nova/auth/manager.py
index 486845399..8479c95a4 100644
--- a/nova/auth/manager.py
+++ b/nova/auth/manager.py
@@ -268,7 +268,7 @@ class AuthManager(object):
LOG.debug(_('Looking up user: %r'), access_key)
user = self.get_user_from_access_key(access_key)
LOG.debug('user: %r', user)
- if user == None:
+ if user is None:
LOG.audit(_("Failed authorization for access key %s"), access_key)
raise exception.NotFound(_('No user found for access key %s')
% access_key)
@@ -280,7 +280,7 @@ class AuthManager(object):
project_id = user.name
project = self.get_project(project_id)
- if project == None:
+ if project is None:
pjid = project_id
uname = user.name
LOG.audit(_("failed authorization: no project named %(pjid)s"
@@ -646,9 +646,9 @@ class AuthManager(object):
@rtype: User
@return: The new user.
"""
- if access == None:
+ if access is None:
access = str(uuid.uuid4())
- if secret == None:
+ if secret is None:
secret = str(uuid.uuid4())
with self.driver() as drv:
user_dict = drv.create_user(name, access, secret, admin)
diff --git a/nova/compute/api.py b/nova/compute/api.py
index e6146231c..48f8b7b0e 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -239,7 +239,7 @@ class API(base.Base):
# Set sane defaults if not specified
updates = dict(hostname=self.hostname_factory(instance_id))
if (not hasattr(instance, 'display_name') or
- instance.display_name == None):
+ instance.display_name is None):
updates['display_name'] = "Server %s" % instance_id
instance = self.update(context, instance_id, **updates)
diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py
index f893f8478..98b4425c8 100644
--- a/nova/compute/instance_types.py
+++ b/nova/compute/instance_types.py
@@ -61,7 +61,7 @@ def create(name, memory, vcpus, local_gb, flavorid, swap=0,
def destroy(name):
"""Marks instance types as deleted."""
- if name == None:
+ if name is None:
raise exception.InvalidInputException(_("No instance type specified"))
else:
try:
@@ -73,7 +73,7 @@ def destroy(name):
def purge(name):
"""Removes instance types from database."""
- if name == None:
+ if name is None:
raise exception.InvalidInputException(_("No instance type specified"))
else:
try:
diff --git a/nova/compute/monitor.py b/nova/compute/monitor.py
index 04e08a235..3bb54a382 100644
--- a/nova/compute/monitor.py
+++ b/nova/compute/monitor.py
@@ -260,7 +260,7 @@ class Instance(object):
try:
data = self.fetch_cpu_stats()
- if data != None:
+ if data is not None:
LOG.debug('CPU: %s', data)
update_rrd(self, 'cpu', data)
@@ -313,7 +313,7 @@ class Instance(object):
LOG.debug('CPU: %d', self.cputime)
# Skip calculation on first pass. Need delta to get a meaningful value.
- if cputime_last_updated == None:
+ if cputime_last_updated is None:
return None
# Calculate the number of seconds between samples.
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 6b2caf46c..5277dc998 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1849,7 +1849,7 @@ def security_group_get_by_instance(context, instance_id):
def security_group_exists(context, project_id, group_name):
try:
group = security_group_get_by_name(context, project_id, group_name)
- return group != None
+ return group is not None
except exception.NotFound:
return False
diff --git a/nova/image/fake.py b/nova/image/fake.py
index d1c62757f..e02b4127e 100644
--- a/nova/image/fake.py
+++ b/nova/image/fake.py
@@ -47,8 +47,7 @@ class FakeImageService(service.BaseImageService):
'container_format': 'ami',
'disk_format': 'raw',
'properties': {'kernel_id': FLAGS.null_kernel,
- 'ramdisk_id': FLAGS.null_kernel}
- }
+ 'ramdisk_id': FLAGS.null_kernel}}
self.create(None, image)
super(FakeImageService, self).__init__()
diff --git a/nova/image/local.py b/nova/image/local.py
index d4fd62156..fa5e93346 100644
--- a/nova/image/local.py
+++ b/nova/image/local.py
@@ -101,7 +101,7 @@ class LocalImageService(service.BaseImageService):
if name == cantidate.get('name'):
image = cantidate
break
- if image == None:
+ if image is None:
raise exception.NotFound
return image
diff --git a/nova/image/s3.py b/nova/image/s3.py
index b1034d151..2a02d4674 100644
--- a/nova/image/s3.py
+++ b/nova/image/s3.py
@@ -48,7 +48,7 @@ flags.DEFINE_string('image_decryption_dir', '/tmp',
class S3ImageService(service.BaseImageService):
"""Wraps an existing image service to support s3 based register"""
def __init__(self, service=None, *args, **kwargs):
- if service == None:
+ if service is None:
service = utils.import_object(FLAGS.image_service)
self.service = service
self.service.__init__(*args, **kwargs)
diff --git a/nova/log.py b/nova/log.py
index d194ab8f0..ea94be194 100644
--- a/nova/log.py
+++ b/nova/log.py
@@ -106,7 +106,7 @@ logging.addLevelName(AUDIT, 'AUDIT')
def _dictify_context(context):
- if context == None:
+ if context is None:
return None
if not isinstance(context, dict) \
and getattr(context, 'to_dict', None):
diff --git a/nova/network/xenapi_net.py b/nova/network/xenapi_net.py
index 9a99602d9..8c22a7d4b 100644
--- a/nova/network/xenapi_net.py
+++ b/nova/network/xenapi_net.py
@@ -47,7 +47,7 @@ def ensure_vlan_bridge(vlan_num, bridge, net_attrs=None):
network_ref = network_utils.NetworkHelper.find_network_with_name_label(
session,
bridge)
- if network_ref == None:
+ if network_ref is None:
# If bridge does not exists
# 1 - create network
description = "network for nova bridge %s" % bridge
diff --git a/nova/tests/api/openstack/test_image_metadata.py b/nova/tests/api/openstack/test_image_metadata.py
index 543c59629..56be0f1cc 100644
--- a/nova/tests/api/openstack/test_image_metadata.py
+++ b/nova/tests/api/openstack/test_image_metadata.py
@@ -46,8 +46,7 @@ class ImageMetaDataTest(unittest.TestCase):
'deleted_at': None,
'properties': {
'key1': 'value1',
- 'key2': 'value2'
- },
+ 'key2': 'value2'},
'size': 5882349},
{'status': 'active',
'name': 'image2',
@@ -62,8 +61,7 @@ class ImageMetaDataTest(unittest.TestCase):
'deleted_at': None,
'properties': {
'key1': 'value1',
- 'key2': 'value2'
- },
+ 'key2': 'value2'},
'size': 5882349},
{'status': 'active',
'name': 'image3',
diff --git a/nova/tests/api/openstack/test_server_metadata.py b/nova/tests/api/openstack/test_server_metadata.py
index c8d456472..680ff3e2c 100644
--- a/nova/tests/api/openstack/test_server_metadata.py
+++ b/nova/tests/api/openstack/test_server_metadata.py
@@ -48,8 +48,7 @@ def stub_server_metadata():
"key2": "value2",
"key3": "value3",
"key4": "value4",
- "key5": "value5"
- }
+ "key5": "value5"}
return metadata
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 34513734b..556046e9d 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -79,10 +79,10 @@ def stub_instance(id, user_id=1, private_address=None, public_addresses=None,
inst_type = instance_types.get_instance_type_by_flavor_id(1)
- if public_addresses == None:
+ if public_addresses is None:
public_addresses = list()
- if host != None:
+ if host is not None:
host = str(host)
instance = {
@@ -613,6 +613,70 @@ class ServersTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
+ def test_create_instance_with_admin_pass_v10(self):
+ self._setup_for_create_instance()
+
+ body = {
+ 'server': {
+ 'name': 'test-server-create',
+ 'imageId': 3,
+ 'flavorId': 1,
+ 'adminPass': 'testpass',
+ },
+ }
+
+ req = webob.Request.blank('/v1.0/servers')
+ req.method = 'POST'
+ req.body = json.dumps(body)
+ req.headers['content-type'] = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ res = json.loads(res.body)
+ self.assertNotEqual(res['server']['adminPass'],
+ body['server']['adminPass'])
+
+ def test_create_instance_with_admin_pass_v11(self):
+ self._setup_for_create_instance()
+
+ imageRef = 'http://localhost/v1.1/images/2'
+ flavorRef = 'http://localhost/v1.1/flavors/3'
+ body = {
+ 'server': {
+ 'name': 'server_test',
+ 'imageRef': imageRef,
+ 'flavorRef': flavorRef,
+ 'adminPass': 'testpass',
+ },
+ }
+
+ req = webob.Request.blank('/v1.1/servers')
+ req.method = 'POST'
+ req.body = json.dumps(body)
+ req.headers['content-type'] = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ server = json.loads(res.body)['server']
+ self.assertEqual(server['adminPass'], body['server']['adminPass'])
+
+ def test_create_instance_with_empty_admin_pass_v11(self):
+ self._setup_for_create_instance()
+
+ imageRef = 'http://localhost/v1.1/images/2'
+ flavorRef = 'http://localhost/v1.1/flavors/3'
+ body = {
+ 'server': {
+ 'name': 'server_test',
+ 'imageRef': imageRef,
+ 'flavorRef': flavorRef,
+ 'adminPass': '',
+ },
+ }
+
+ req = webob.Request.blank('/v1.1/servers')
+ req.method = 'POST'
+ req.body = json.dumps(body)
+ req.headers['content-type'] = "application/json"
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 400)
+
def test_update_no_body(self):
req = webob.Request.blank('/v1.0/servers/1')
req.method = 'PUT'
diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/test_versions.py
index 2640a4ddb..fd8d50904 100644
--- a/nova/tests/api/openstack/test_versions.py
+++ b/nova/tests/api/openstack/test_versions.py
@@ -47,8 +47,7 @@ class VersionsTest(test.TestCase):
{
"rel": "self",
"href": "http://localhost/v1.1",
- }
- ],
+ }],
},
{
"id": "v1.0",
@@ -57,8 +56,7 @@ class VersionsTest(test.TestCase):
{
"rel": "self",
"href": "http://localhost/v1.0",
- }
- ],
+ }],
},
]
self.assertEqual(versions, expected)
diff --git a/nova/tests/test_scheduler.py b/nova/tests/test_scheduler.py
index ae56a1a16..51d987288 100644
--- a/nova/tests/test_scheduler.py
+++ b/nova/tests/test_scheduler.py
@@ -737,7 +737,7 @@ class SimpleDriverTestCase(test.TestCase):
ret = self.scheduler.driver._live_migration_src_check(self.context,
i_ref)
- self.assertTrue(ret == None)
+ self.assertTrue(ret is None)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -805,7 +805,7 @@ class SimpleDriverTestCase(test.TestCase):
ret = self.scheduler.driver._live_migration_dest_check(self.context,
i_ref,
'somewhere')
- self.assertTrue(ret == None)
+ self.assertTrue(ret is None)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
diff --git a/nova/utils.py b/nova/utils.py
index 3f6f9fc8a..76cba1a08 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -157,7 +157,7 @@ def execute(*cmd, **kwargs):
stderr=subprocess.PIPE,
env=env)
result = None
- if process_input != None:
+ if process_input is not None:
result = obj.communicate(process_input)
else:
result = obj.communicate()
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 5da091920..d212be3c9 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -438,9 +438,9 @@ class LibvirtConnection(driver.ComputeDriver):
if child.prop('dev') == device:
return str(node)
finally:
- if ctx != None:
+ if ctx is not None:
ctx.xpathFreeContext()
- if doc != None:
+ if doc is not None:
doc.freeDoc()
@exception.wrap_exception
@@ -1120,14 +1120,14 @@ class LibvirtConnection(driver.ComputeDriver):
if child.name == 'target':
devdst = child.prop('dev')
- if devdst == None:
+ if devdst is None:
continue
disks.append(devdst)
finally:
- if ctx != None:
+ if ctx is not None:
ctx.xpathFreeContext()
- if doc != None:
+ if doc is not None:
doc.freeDoc()
return disks
@@ -1162,14 +1162,14 @@ class LibvirtConnection(driver.ComputeDriver):
if child.name == 'target':
devdst = child.prop('dev')
- if devdst == None:
+ if devdst is None:
continue
interfaces.append(devdst)
finally:
- if ctx != None:
+ if ctx is not None:
ctx.xpathFreeContext()
- if doc != None:
+ if doc is not None:
doc.freeDoc()
return interfaces
diff --git a/nova/virt/vmwareapi/vim.py b/nova/virt/vmwareapi/vim.py
index 159e16a80..0cbdba363 100644
--- a/nova/virt/vmwareapi/vim.py
+++ b/nova/virt/vmwareapi/vim.py
@@ -43,6 +43,7 @@ flags.DEFINE_string('vmwareapi_wsdl_loc',
if suds:
+
class VIMMessagePlugin(suds.plugin.MessagePlugin):
def addAttributeForValue(self, node):