summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasanori Itoh <itoumsn@nttdata.co.jp>2011-04-05 11:40:35 +0900
committerMasanori Itoh <itoumsn@nttdata.co.jp>2011-04-05 11:40:35 +0900
commit4e8ade85ec5f8dcd7c76bb06de5cd1f90d54d2a4 (patch)
treef4b0a2eaa01246d1563e9c2972dba4991cd105ba
parent95fe2026e869e2da29196f8bf3e48ae2a2560e46 (diff)
parentc0a8904508edb0687b588d40a7bd181d0393884f (diff)
downloadnova-4e8ade85ec5f8dcd7c76bb06de5cd1f90d54d2a4.tar.gz
nova-4e8ade85ec5f8dcd7c76bb06de5cd1f90d54d2a4.tar.xz
nova-4e8ade85ec5f8dcd7c76bb06de5cd1f90d54d2a4.zip
Rebased to trunk 942.
-rw-r--r--Authors1
-rw-r--r--nova/adminclient.py473
-rw-r--r--nova/api/openstack/servers.py3
-rw-r--r--nova/api/openstack/views/images.py10
-rw-r--r--nova/api/openstack/views/servers.py22
-rw-r--r--nova/compute/api.py6
-rw-r--r--nova/tests/api/openstack/test_images.py57
-rw-r--r--nova/tests/api/openstack/test_servers.py10
-rw-r--r--nova/tests/test_cloud.py33
-rw-r--r--nova/virt/libvirt_conn.py2
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/agent83
-rw-r--r--smoketests/test_admin.py2
-rw-r--r--tools/pip-requires1
13 files changed, 195 insertions, 508 deletions
diff --git a/Authors b/Authors
index eccf38a43..48b912184 100644
--- a/Authors
+++ b/Authors
@@ -32,6 +32,7 @@ Jesse Andrews <anotherjesse@gmail.com>
Joe Heck <heckj@mac.com>
Joel Moore <joelbm24@gmail.com>
John Dewey <john@dewey.ws>
+John Tran <jtran@attinteractive.com>
Jonathan Bryce <jbryce@jbryce.com>
Jordan Rinke <jordan@openstack.org>
Josh Durgin <joshd@hq.newdream.net>
diff --git a/nova/adminclient.py b/nova/adminclient.py
deleted file mode 100644
index f570e12c2..000000000
--- a/nova/adminclient.py
+++ /dev/null
@@ -1,473 +0,0 @@
-# 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.
-"""
-Nova User API client library.
-"""
-
-import base64
-import boto
-import boto.exception
-import httplib
-import re
-import string
-
-from boto.ec2.regioninfo import RegionInfo
-
-
-DEFAULT_CLC_URL = 'http://127.0.0.1:8773'
-DEFAULT_REGION = 'nova'
-
-
-class UserInfo(object):
- """
- Information about a Nova user, as parsed through SAX.
-
- **Fields Include**
-
- * username
- * accesskey
- * secretkey
- * file (optional) containing zip of X509 cert & rc file
-
- """
-
- def __init__(self, connection=None, username=None, endpoint=None):
- self.connection = connection
- self.username = username
- self.endpoint = endpoint
-
- def __repr__(self):
- return 'UserInfo:%s' % self.username
-
- def startElement(self, name, attrs, connection):
- return None
-
- def endElement(self, name, value, connection):
- if name == 'username':
- self.username = str(value)
- elif name == 'file':
- self.file = base64.b64decode(str(value))
- elif name == 'accesskey':
- self.accesskey = str(value)
- elif name == 'secretkey':
- self.secretkey = str(value)
-
-
-class UserRole(object):
- """
- Information about a Nova user's role, as parsed through SAX.
-
- **Fields include**
-
- * role
-
- """
-
- def __init__(self, connection=None):
- self.connection = connection
- self.role = None
-
- def __repr__(self):
- return 'UserRole:%s' % self.role
-
- def startElement(self, name, attrs, connection):
- return None
-
- def endElement(self, name, value, connection):
- if name == 'role':
- self.role = value
- else:
- setattr(self, name, str(value))
-
-
-class ProjectInfo(object):
- """
- Information about a Nova project, as parsed through SAX.
-
- **Fields include**
-
- * projectname
- * description
- * projectManagerId
- * memberIds
-
- """
-
- def __init__(self, connection=None):
- self.connection = connection
- self.projectname = None
- self.description = None
- self.projectManagerId = None
- self.memberIds = []
-
- def __repr__(self):
- return 'ProjectInfo:%s' % self.projectname
-
- def startElement(self, name, attrs, connection):
- return None
-
- def endElement(self, name, value, connection):
- if name == 'projectname':
- self.projectname = value
- elif name == 'description':
- self.description = value
- elif name == 'projectManagerId':
- self.projectManagerId = value
- elif name == 'memberId':
- self.memberIds.append(value)
- else:
- setattr(self, name, str(value))
-
-
-class ProjectMember(object):
- """
- Information about a Nova project member, as parsed through SAX.
-
- **Fields include**
-
- * memberId
-
- """
-
- def __init__(self, connection=None):
- self.connection = connection
- self.memberId = None
-
- def __repr__(self):
- return 'ProjectMember:%s' % self.memberId
-
- def startElement(self, name, attrs, connection):
- return None
-
- def endElement(self, name, value, connection):
- if name == 'member':
- self.memberId = value
- else:
- setattr(self, name, str(value))
-
-
-class HostInfo(object):
- """
- Information about a Nova Host, as parsed through SAX.
-
- **Fields Include**
-
- * Hostname
- * Compute service status
- * Volume service status
- * Instance count
- * Volume count
- """
-
- def __init__(self, connection=None):
- self.connection = connection
- self.hostname = None
- self.compute = None
- self.volume = None
- self.instance_count = 0
- self.volume_count = 0
-
- def __repr__(self):
- return 'Host:%s' % self.hostname
-
- # this is needed by the sax parser, so ignore the ugly name
- def startElement(self, name, attrs, connection):
- return None
-
- # this is needed by the sax parser, so ignore the ugly name
- def endElement(self, name, value, connection):
- fixed_name = string.lower(re.sub(r'([A-Z])', r'_\1', name))
- setattr(self, fixed_name, value)
-
-
-class Vpn(object):
- """
- Information about a Vpn, as parsed through SAX
-
- **Fields Include**
-
- * instance_id
- * project_id
- * public_ip
- * public_port
- * created_at
- * internal_ip
- * state
- """
-
- def __init__(self, connection=None):
- self.connection = connection
- self.instance_id = None
- self.project_id = None
-
- def __repr__(self):
- return 'Vpn:%s:%s' % (self.project_id, self.instance_id)
-
- def startElement(self, name, attrs, connection):
- return None
-
- def endElement(self, name, value, connection):
- fixed_name = string.lower(re.sub(r'([A-Z])', r'_\1', name))
- setattr(self, fixed_name, value)
-
-
-class InstanceType(object):
- """
- Information about a Nova instance type, as parsed through SAX.
-
- **Fields include**
-
- * name
- * vcpus
- * disk_gb
- * memory_mb
- * flavor_id
-
- """
-
- def __init__(self, connection=None):
- self.connection = connection
- self.name = None
- self.vcpus = None
- self.disk_gb = None
- self.memory_mb = None
- self.flavor_id = None
-
- def __repr__(self):
- return 'InstanceType:%s' % self.name
-
- def startElement(self, name, attrs, connection):
- return None
-
- def endElement(self, name, value, connection):
- if name == "memoryMb":
- self.memory_mb = str(value)
- elif name == "flavorId":
- self.flavor_id = str(value)
- elif name == "diskGb":
- self.disk_gb = str(value)
- else:
- setattr(self, name, str(value))
-
-
-class NovaAdminClient(object):
-
- def __init__(
- self,
- clc_url=DEFAULT_CLC_URL,
- region=DEFAULT_REGION,
- access_key=None,
- secret_key=None,
- **kwargs):
- parts = self.split_clc_url(clc_url)
-
- self.clc_url = clc_url
- self.region = region
- self.access = access_key
- self.secret = secret_key
- self.apiconn = boto.connect_ec2(aws_access_key_id=access_key,
- aws_secret_access_key=secret_key,
- is_secure=parts['is_secure'],
- region=RegionInfo(None,
- region,
- parts['ip']),
- port=parts['port'],
- path='/services/Admin',
- **kwargs)
- self.apiconn.APIVersion = 'nova'
-
- def connection_for(self, username, project, clc_url=None, region=None,
- **kwargs):
- """Returns a boto ec2 connection for the given username."""
- if not clc_url:
- clc_url = self.clc_url
- if not region:
- region = self.region
- parts = self.split_clc_url(clc_url)
- user = self.get_user(username)
- access_key = '%s:%s' % (user.accesskey, project)
- return boto.connect_ec2(aws_access_key_id=access_key,
- aws_secret_access_key=user.secretkey,
- is_secure=parts['is_secure'],
- region=RegionInfo(None,
- self.region,
- parts['ip']),
- port=parts['port'],
- path='/services/Cloud',
- **kwargs)
-
- def split_clc_url(self, clc_url):
- """Splits a cloud controller endpoint url."""
- parts = httplib.urlsplit(clc_url)
- is_secure = parts.scheme == 'https'
- ip, port = parts.netloc.split(':')
- return {'ip': ip, 'port': int(port), 'is_secure': is_secure}
-
- def get_users(self):
- """Grabs the list of all users."""
- return self.apiconn.get_list('DescribeUsers', {}, [('item', UserInfo)])
-
- def get_user(self, name):
- """Grab a single user by name."""
- user = self.apiconn.get_object('DescribeUser',
- {'Name': name},
- UserInfo)
- if user.username != None:
- return user
-
- def has_user(self, username):
- """Determine if user exists."""
- return self.get_user(username) != None
-
- def create_user(self, username):
- """Creates a new user, returning the userinfo object with
- access/secret."""
- return self.apiconn.get_object('RegisterUser', {'Name': username},
- UserInfo)
-
- def delete_user(self, username):
- """Deletes a user."""
- return self.apiconn.get_object('DeregisterUser', {'Name': username},
- UserInfo)
-
- def get_roles(self, project_roles=True):
- """Returns a list of available roles."""
- return self.apiconn.get_list('DescribeRoles',
- {'ProjectRoles': project_roles},
- [('item', UserRole)])
-
- def get_user_roles(self, user, project=None):
- """Returns a list of roles for the given user.
-
- Omitting project will return any global roles that the user has.
- Specifying project will return only project specific roles.
-
- """
- params = {'User': user}
- if project:
- params['Project'] = project
- return self.apiconn.get_list('DescribeUserRoles',
- params,
- [('item', UserRole)])
-
- def add_user_role(self, user, role, project=None):
- """Add a role to a user either globally or for a specific project."""
- return self.modify_user_role(user, role, project=project,
- operation='add')
-
- def remove_user_role(self, user, role, project=None):
- """Remove a role from a user either globally or for a specific
- project."""
- return self.modify_user_role(user, role, project=project,
- operation='remove')
-
- def modify_user_role(self, user, role, project=None, operation='add',
- **kwargs):
- """Add or remove a role for a user and project."""
- params = {'User': user,
- 'Role': role,
- 'Project': project,
- 'Operation': operation}
- return self.apiconn.get_status('ModifyUserRole', params)
-
- def get_projects(self, user=None):
- """Returns a list of all projects."""
- if user:
- params = {'User': user}
- else:
- params = {}
- return self.apiconn.get_list('DescribeProjects',
- params,
- [('item', ProjectInfo)])
-
- def get_project(self, name):
- """Returns a single project with the specified name."""
- project = self.apiconn.get_object('DescribeProject',
- {'Name': name},
- ProjectInfo)
-
- if project.projectname != None:
- return project
-
- def create_project(self, projectname, manager_user, description=None,
- member_users=None):
- """Creates a new project."""
- params = {'Name': projectname,
- 'ManagerUser': manager_user,
- 'Description': description,
- 'MemberUsers': member_users}
- return self.apiconn.get_object('RegisterProject', params, ProjectInfo)
-
- def modify_project(self, projectname, manager_user=None, description=None):
- """Modifies an existing project."""
- params = {'Name': projectname,
- 'ManagerUser': manager_user,
- 'Description': description}
- return self.apiconn.get_status('ModifyProject', params)
-
- def delete_project(self, projectname):
- """Permanently deletes the specified project."""
- return self.apiconn.get_object('DeregisterProject',
- {'Name': projectname},
- ProjectInfo)
-
- def get_project_members(self, name):
- """Returns a list of members of a project."""
- return self.apiconn.get_list('DescribeProjectMembers',
- {'Name': name},
- [('item', ProjectMember)])
-
- def add_project_member(self, user, project):
- """Adds a user to a project."""
- return self.modify_project_member(user, project, operation='add')
-
- def remove_project_member(self, user, project):
- """Removes a user from a project."""
- return self.modify_project_member(user, project, operation='remove')
-
- def modify_project_member(self, user, project, operation='add'):
- """Adds or removes a user from a project."""
- params = {'User': user,
- 'Project': project,
- 'Operation': operation}
- return self.apiconn.get_status('ModifyProjectMember', params)
-
- def get_zip(self, user, project):
- """Returns the content of a zip file containing novarc and access
- credentials."""
- params = {'Name': user, 'Project': project}
- zip = self.apiconn.get_object('GenerateX509ForUser', params, UserInfo)
- return zip.file
-
- def start_vpn(self, project):
- """
- Starts the vpn for a user
- """
- return self.apiconn.get_object('StartVpn', {'Project': project}, Vpn)
-
- def get_vpns(self):
- """Return a list of vpn with project name"""
- return self.apiconn.get_list('DescribeVpns', {}, [('item', Vpn)])
-
- def get_hosts(self):
- return self.apiconn.get_list('DescribeHosts', {}, [('item', HostInfo)])
-
- def get_instance_types(self):
- """Grabs the list of all users."""
- return self.apiconn.get_list('DescribeInstanceTypes', {},
- [('item', InstanceType)])
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 4e2ebb2bd..6704a68ae 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -180,8 +180,7 @@ class Controller(wsgi.Controller):
builder = self._get_view_builder(req)
server = builder.build(inst, is_detail=True)
- password = "%s%s" % (server['server']['name'][:4],
- utils.generate_password(12))
+ password = utils.generate_password(16)
server['server']['adminPass'] = password
self.compute_api.set_admin_password(context, server['server']['id'],
password)
diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py
index 3807fa95f..16195b050 100644
--- a/nova/api/openstack/views/images.py
+++ b/nova/api/openstack/views/images.py
@@ -60,8 +60,8 @@ class ViewBuilder(object):
self._format_status(image_obj)
image = {
- "id": image_obj["id"],
- "name": image_obj["name"],
+ "id": image_obj.get("id"),
+ "name": image_obj.get("name"),
}
if "instance_id" in properties:
@@ -72,9 +72,9 @@ class ViewBuilder(object):
if detail:
image.update({
- "created": image_obj["created_at"],
- "updated": image_obj["updated_at"],
- "status": image_obj["status"],
+ "created": image_obj.get("created_at"),
+ "updated": image_obj.get("updated_at"),
+ "status": image_obj.get("status"),
})
if image["status"] == "SAVING":
diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py
index 4e7f62eb3..d24c025be 100644
--- a/nova/api/openstack/views/servers.py
+++ b/nova/api/openstack/views/servers.py
@@ -57,16 +57,16 @@ class ViewBuilder(object):
def _build_detail(self, inst):
"""Returns a detailed model of a server."""
power_mapping = {
- None: 'build',
- power_state.NOSTATE: 'build',
- power_state.RUNNING: 'active',
- power_state.BLOCKED: 'active',
- power_state.SUSPENDED: 'suspended',
- power_state.PAUSED: 'paused',
- power_state.SHUTDOWN: 'active',
- power_state.SHUTOFF: 'active',
- power_state.CRASHED: 'error',
- power_state.FAILED: 'error'}
+ None: 'BUILD',
+ power_state.NOSTATE: 'BUILD',
+ power_state.RUNNING: 'ACTIVE',
+ power_state.BLOCKED: 'ACTIVE',
+ power_state.SUSPENDED: 'SUSPENDED',
+ power_state.PAUSED: 'PAUSED',
+ power_state.SHUTDOWN: 'ACTIVE',
+ power_state.SHUTOFF: 'ACTIVE',
+ power_state.CRASHED: 'ERROR',
+ power_state.FAILED: 'ERROR'}
inst_dict = {
'id': int(inst['id']),
@@ -77,7 +77,7 @@ class ViewBuilder(object):
ctxt = nova.context.get_admin_context()
compute_api = nova.compute.API()
if compute_api.has_finished_migration(ctxt, inst['id']):
- inst_dict['status'] = 'resize-confirm'
+ inst_dict['status'] = 'RESIZE-CONFIRM'
# Return the metadata as a dictionary
metadata = {}
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 1dbd73f8f..996955fe3 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -37,10 +37,14 @@ from nova.compute import instance_types
from nova.scheduler import api as scheduler_api
from nova.db import base
-FLAGS = flags.FLAGS
+
LOG = logging.getLogger('nova.compute.api')
+FLAGS = flags.FLAGS
+flags.DECLARE('vncproxy_topic', 'nova.vnc')
+
+
def generate_default_hostname(instance_id):
"""Default function to generate a hostname given an instance reference."""
return str(instance_id)
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 57e447dce..69cc3116d 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -263,7 +263,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
{'id': 124, 'name': 'queued backup'},
{'id': 125, 'name': 'saving backup'},
{'id': 126, 'name': 'active backup'},
- {'id': 127, 'name': 'killed backup'}]
+ {'id': 127, 'name': 'killed backup'},
+ {'id': 129, 'name': None}]
self.assertDictListMatch(response_list, expected)
@@ -339,6 +340,24 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
self.assertEqual(expected_image.toxml(), actual_image.toxml())
+ def test_get_image_xml_no_name(self):
+ request = webob.Request.blank('/v1.0/images/129')
+ request.accept = "application/xml"
+ response = request.get_response(fakes.wsgi_app())
+
+ actual_image = minidom.parseString(response.body.replace(" ", ""))
+
+ expected_now = self.NOW_API_FORMAT
+ expected_image = minidom.parseString("""
+ <image id="129"
+ name="None"
+ updated="%(expected_now)s"
+ created="%(expected_now)s"
+ status="ACTIVE" />
+ """ % (locals()))
+
+ self.assertEqual(expected_image.toxml(), actual_image.toxml())
+
def test_get_image_v1_1_xml(self):
request = webob.Request.blank('/v1.1/images/123')
request.accept = "application/xml"
@@ -516,6 +535,13 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
'updated': self.NOW_API_FORMAT,
'created': self.NOW_API_FORMAT,
'status': 'FAILED',
+ },
+ {
+ 'id': 129,
+ 'name': None,
+ 'updated': self.NOW_API_FORMAT,
+ 'created': self.NOW_API_FORMAT,
+ 'status': 'ACTIVE',
}]
self.assertDictListMatch(expected, response_list)
@@ -635,7 +661,29 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
"type": "application/xml",
"href": "http://localhost/v1.1/images/127",
}],
- }]
+ },
+ {
+ 'id': 129,
+ 'name': None,
+ 'updated': self.NOW_API_FORMAT,
+ 'created': self.NOW_API_FORMAT,
+ 'status': 'ACTIVE',
+ "links": [{
+ "rel": "self",
+ "href": "http://localhost/v1.1/images/129",
+ },
+ {
+ "rel": "bookmark",
+ "type": "application/json",
+ "href": "http://localhost/v1.1/images/129",
+ },
+ {
+ "rel": "bookmark",
+ "type": "application/xml",
+ "href": "http://localhost/v1.1/images/129",
+ }],
+ },
+ ]
self.assertDictListMatch(expected, response_list)
@@ -694,4 +742,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
status='active', properties=other_backup_properties)
image_id += 1
+ # Image without a name
+ add_fixture(id=image_id, is_public=True, status='active',
+ properties={})
+ image_id += 1
+
return fixtures
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index cb5047da9..313676e72 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -377,7 +377,6 @@ class ServersTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
server = json.loads(res.body)['server']
- self.assertEqual('serv', server['adminPass'][:4])
self.assertEqual(16, len(server['adminPass']))
self.assertEqual('server_test', server['name'])
self.assertEqual(1, server['id'])
@@ -486,7 +485,6 @@ class ServersTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
server = json.loads(res.body)['server']
- self.assertEqual('serv', server['adminPass'][:4])
self.assertEqual(16, len(server['adminPass']))
self.assertEqual('server_test', server['name'])
self.assertEqual(1, server['id'])
@@ -631,6 +629,7 @@ class ServersTest(test.TestCase):
self.assertEqual(s['name'], 'server%d' % i)
self.assertEqual(s['imageId'], '10')
self.assertEqual(s['flavorId'], '1')
+ self.assertEqual(s['status'], 'BUILD')
self.assertEqual(s['metadata']['seq'], i)
def test_get_all_server_details_v1_1(self):
@@ -644,6 +643,7 @@ class ServersTest(test.TestCase):
self.assertEqual(s['name'], 'server%d' % i)
self.assertEqual(s['imageRef'], 'http://localhost/v1.1/images/10')
self.assertEqual(s['flavorRef'], 'http://localhost/v1.1/flavors/1')
+ self.assertEqual(s['status'], 'BUILD')
self.assertEqual(s['metadata']['seq'], i)
def test_get_all_server_details_with_host(self):
@@ -917,7 +917,7 @@ class ServersTest(test.TestCase):
fake_migration_get)
res = req.get_response(fakes.wsgi_app())
body = json.loads(res.body)
- self.assertEqual(body['server']['status'], 'resize-confirm')
+ self.assertEqual(body['server']['status'], 'RESIZE-CONFIRM')
def test_confirm_resize_server(self):
req = self.webreq('/1/action', 'POST', dict(confirmResize=None))
@@ -1494,7 +1494,7 @@ class TestServerInstanceCreation(test.TestCase):
self.assertEquals(response.status_int, 200)
response = json.loads(response.body)
self.assertTrue('adminPass' in response['server'])
- self.assertTrue(response['server']['adminPass'].startswith('fake'))
+ self.assertEqual(16, len(response['server']['adminPass']))
def test_create_instance_admin_pass_xml(self):
request, response, dummy = \
@@ -1503,7 +1503,7 @@ class TestServerInstanceCreation(test.TestCase):
dom = minidom.parseString(response.body)
server = dom.childNodes[0]
self.assertEquals(server.nodeName, 'server')
- self.assertTrue(server.getAttribute('adminPass').startswith('fake'))
+ self.assertEqual(16, len(server.getAttribute('adminPass')))
class TestGetKernelRamdiskFromImage(test.TestCase):
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index 00803d0ad..5cb969979 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -41,6 +41,7 @@ from nova.compute import power_state
from nova.api.ec2 import cloud
from nova.api.ec2 import ec2utils
from nova.image import local
+from nova.exception import NotFound
FLAGS = flags.FLAGS
@@ -71,7 +72,8 @@ class CloudTestCase(test.TestCase):
host = self.network.get_network_host(self.context.elevated())
def fake_show(meh, context, id):
- return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
+ return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
+ 'type': 'machine'}}
self.stubs.Set(local.LocalImageService, 'show', fake_show)
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
@@ -216,6 +218,35 @@ class CloudTestCase(test.TestCase):
db.service_destroy(self.context, comp1['id'])
db.service_destroy(self.context, comp2['id'])
+ def test_describe_images(self):
+ describe_images = self.cloud.describe_images
+
+ def fake_detail(meh, context):
+ return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
+ 'type': 'machine'}}]
+
+ def fake_show_none(meh, context, id):
+ raise NotFound
+
+ self.stubs.Set(local.LocalImageService, 'detail', fake_detail)
+ # list all
+ result1 = describe_images(self.context)
+ result1 = result1['imagesSet'][0]
+ self.assertEqual(result1['imageId'], 'ami-00000001')
+ # provided a valid image_id
+ result2 = describe_images(self.context, ['ami-00000001'])
+ self.assertEqual(1, len(result2['imagesSet']))
+ # provide more than 1 valid image_id
+ result3 = describe_images(self.context, ['ami-00000001',
+ 'ami-00000002'])
+ self.assertEqual(2, len(result3['imagesSet']))
+ # provide an non-existing image_id
+ self.stubs.UnsetAll()
+ self.stubs.Set(local.LocalImageService, 'show', fake_show_none)
+ self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show_none)
+ self.assertRaises(NotFound, describe_images,
+ self.context, ['ami-fake'])
+
def test_console_output(self):
instance_type = FLAGS.default_instance_type
max_count = 1
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index f34ea7225..babbc610d 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -842,7 +842,7 @@ class LibvirtConnection(driver.ComputeDriver):
for (network_ref, mapping) in network_info:
ifc_num += 1
- if not 'injected' in network_ref:
+ if not network_ref['injected']:
continue
have_injected_networks = True
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/agent b/plugins/xenserver/xenapi/etc/xapi.d/plugins/agent
index 94eaabe73..5496a6bd5 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/agent
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/agent
@@ -22,6 +22,8 @@
# XenAPI plugin for reading/writing information to xenstore
#
+import base64
+import commands
try:
import json
except ImportError:
@@ -66,7 +68,7 @@ def key_init(self, arg_dict):
try:
resp = _wait_for_agent(self, request_id, arg_dict)
except TimeoutError, e:
- raise PluginError("%s" % e)
+ raise PluginError(e)
return resp
@@ -87,7 +89,7 @@ def password(self, arg_dict):
try:
resp = _wait_for_agent(self, request_id, arg_dict)
except TimeoutError, e:
- raise PluginError("%s" % e)
+ raise PluginError(e)
return resp
@@ -102,6 +104,75 @@ def resetnetwork(self, arg_dict):
xenstore.write_record(self, arg_dict)
+@jsonify
+def inject_file(self, arg_dict):
+ """Expects a file path and the contents of the file to be written. Both
+ should be base64-encoded in order to eliminate errors as they are passed
+ through the stack. Writes that information to xenstore for the agent,
+ which will decode the file and intended path, and create it on the
+ instance. The original agent munged both of these into a single entry;
+ the new agent keeps them separate. We will need to test for the new agent,
+ and write the xenstore records to match the agent version. We will also
+ need to test to determine if the file injection method on the agent has
+ been disabled, and raise a NotImplemented error if that is the case.
+ """
+ b64_path = arg_dict["b64_path"]
+ b64_file = arg_dict["b64_file"]
+ request_id = arg_dict["id"]
+ if self._agent_has_method("file_inject"):
+ # New version of the agent. Agent should receive a 'value'
+ # key whose value is a dictionary containing 'b64_path' and
+ # 'b64_file'. See old version below.
+ arg_dict["value"] = json.dumps({"name": "file_inject",
+ "value": {"b64_path": b64_path, "b64_file": b64_file}})
+ elif self._agent_has_method("injectfile"):
+ # Old agent requires file path and file contents to be
+ # combined into one base64 value.
+ raw_path = base64.b64decode(b64_path)
+ raw_file = base64.b64decode(b64_file)
+ new_b64 = base64.b64encode("%s,%s") % (raw_path, raw_file)
+ arg_dict["value"] = json.dumps({"name": "injectfile",
+ "value": new_b64})
+ else:
+ # Either the methods don't exist in the agent, or they
+ # have been disabled.
+ raise NotImplementedError(_("NOT IMPLEMENTED: Agent does not"
+ " support file injection."))
+ arg_dict["path"] = "data/host/%s" % request_id
+ xenstore.write_record(self, arg_dict)
+ try:
+ resp = _wait_for_agent(self, request_id, arg_dict)
+ except TimeoutError, e:
+ raise PluginError(e)
+ return resp
+
+
+def _agent_has_method(self, method):
+ """Check that the agent has a particular method by checking its
+ features. Cache the features so we don't have to query the agent
+ every time we need to check.
+ """
+ try:
+ self._agent_methods
+ except AttributeError:
+ self._agent_methods = []
+ if not self._agent_methods:
+ # Haven't been defined
+ tmp_id = commands.getoutput("uuidgen")
+ dct = {}
+ dct["value"] = json.dumps({"name": "features", "value": ""})
+ dct["path"] = "data/host/%s" % tmp_id
+ xenstore.write_record(self, dct)
+ try:
+ resp = _wait_for_agent(self, tmp_id, dct)
+ except TimeoutError, e:
+ raise PluginError(e)
+ response = json.loads(resp)
+ # The agent returns a comma-separated list of methods.
+ self._agent_methods = response.split(",")
+ return method in self._agent_methods
+
+
def _wait_for_agent(self, request_id, arg_dict):
"""Periodically checks xenstore for a response from the agent.
The request is always written to 'data/host/{id}', and
@@ -119,9 +190,8 @@ def _wait_for_agent(self, request_id, arg_dict):
# First, delete the request record
arg_dict["path"] = "data/host/%s" % request_id
xenstore.delete_record(self, arg_dict)
- raise TimeoutError(
- "TIMEOUT: No response from agent within %s seconds." %
- AGENT_TIMEOUT)
+ raise TimeoutError(_("TIMEOUT: No response from agent within"
+ " %s seconds.") % AGENT_TIMEOUT)
ret = xenstore.read_record(self, arg_dict)
# Note: the response for None with be a string that includes
# double quotes.
@@ -136,4 +206,5 @@ if __name__ == "__main__":
XenAPIPlugin.dispatch(
{"key_init": key_init,
"password": password,
- "resetnetwork": resetnetwork})
+ "resetnetwork": resetnetwork,
+ "inject_file": inject_file})
diff --git a/smoketests/test_admin.py b/smoketests/test_admin.py
index 46e5b2233..1b7a8d673 100644
--- a/smoketests/test_admin.py
+++ b/smoketests/test_admin.py
@@ -30,7 +30,6 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
sys.path.insert(0, possible_topdir)
-from nova import adminclient
from smoketests import flags
from smoketests import base
@@ -47,6 +46,7 @@ TEST_PROJECTNAME = '%sproject' % TEST_PREFIX
class AdminSmokeTestCase(base.SmokeTestCase):
def setUp(self):
+ import nova_adminclient as adminclient
self.admin = adminclient.NovaAdminClient(
access_key=os.getenv('EC2_ACCESS_KEY'),
secret_key=os.getenv('EC2_SECRET_KEY'),
diff --git a/tools/pip-requires b/tools/pip-requires
index 4ab9644d8..6ea446493 100644
--- a/tools/pip-requires
+++ b/tools/pip-requires
@@ -30,4 +30,5 @@ sqlalchemy-migrate
netaddr
sphinx
glance
+nova-adminclient
suds==0.4