Merge w/ trunk resolving conflicts.
This commit is contained in:
1
Authors
1
Authors
@@ -62,6 +62,7 @@ Ryan Lane <rlane@wikimedia.org>
|
||||
Ryan Lucio <rlucio@internap.com>
|
||||
Salvatore Orlando <salvatore.orlando@eu.citrix.com>
|
||||
Sandy Walsh <sandy.walsh@rackspace.com>
|
||||
Sateesh Chodapuneedi <sateesh.chodapuneedi@citrix.com>
|
||||
Soren Hansen <soren.hansen@rackspace.com>
|
||||
Thierry Carrez <thierry@openstack.org>
|
||||
Todd Willey <todd@ansolabs.com>
|
||||
|
||||
@@ -34,12 +34,14 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
||||
|
||||
gettext.install('nova', unicode=1)
|
||||
|
||||
from nova import compute
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import network
|
||||
from nova import utils
|
||||
from nova import volume
|
||||
from nova import wsgi
|
||||
from nova.api import direct
|
||||
from nova.compute import api as compute_api
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
@@ -50,13 +52,42 @@ flags.DEFINE_flag(flags.HelpshortFlag())
|
||||
flags.DEFINE_flag(flags.HelpXMLFlag())
|
||||
|
||||
|
||||
# An example of an API that only exposes read-only methods.
|
||||
# In this case we're just limiting which methods are exposed.
|
||||
class ReadOnlyCompute(direct.Limited):
|
||||
"""Read-only Compute API."""
|
||||
|
||||
_allowed = ['get', 'get_all', 'get_console_output']
|
||||
|
||||
|
||||
# An example of an API that provides a backwards compatibility layer.
|
||||
# In this case we're overwriting the implementation to ensure
|
||||
# compatibility with an older version. In reality we would want the
|
||||
# "description=None" to be part of the actual API so that code
|
||||
# like this isn't even necessary, but this example shows what one can
|
||||
# do if that isn't the situation.
|
||||
class VolumeVersionOne(direct.Limited):
|
||||
_allowed = ['create', 'delete', 'update', 'get']
|
||||
|
||||
def create(self, context, size, name):
|
||||
self.proxy.create(context, size, name, description=None)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
utils.default_flagfile()
|
||||
FLAGS(sys.argv)
|
||||
logging.setup()
|
||||
|
||||
direct.register_service('compute', compute_api.API())
|
||||
direct.register_service('compute', compute.API())
|
||||
direct.register_service('volume', volume.API())
|
||||
direct.register_service('network', network.API())
|
||||
direct.register_service('reflect', direct.Reflection())
|
||||
|
||||
# Here is how we could expose the code in the examples above.
|
||||
#direct.register_service('compute-readonly',
|
||||
# ReadOnlyCompute(compute.API()))
|
||||
#direct.register_service('volume-v1', VolumeVersionOne(volume.API()))
|
||||
|
||||
router = direct.Router()
|
||||
with_json = direct.JsonParamsMiddleware(router)
|
||||
with_req = direct.PostParamsMiddleware(with_json)
|
||||
|
||||
14
bin/stack
14
bin/stack
@@ -59,11 +59,21 @@ USAGE = """usage: stack [options] <controller> <method> [arg1=value arg2=value]
|
||||
|
||||
def format_help(d):
|
||||
"""Format help text, keys are labels and values are descriptions."""
|
||||
MAX_INDENT = 30
|
||||
indent = max([len(k) for k in d])
|
||||
if indent > MAX_INDENT:
|
||||
indent = MAX_INDENT - 6
|
||||
|
||||
out = []
|
||||
for k, v in d.iteritems():
|
||||
t = textwrap.TextWrapper(initial_indent=' %s ' % k.ljust(indent),
|
||||
subsequent_indent=' ' * (indent + 6))
|
||||
if (len(k) + 6) > MAX_INDENT:
|
||||
out.extend([' %s' % k])
|
||||
initial_indent = ' ' * (indent + 6)
|
||||
else:
|
||||
initial_indent = ' %s ' % k.ljust(indent)
|
||||
subsequent_indent = ' ' * (indent + 6)
|
||||
t = textwrap.TextWrapper(initial_indent=initial_indent,
|
||||
subsequent_indent=subsequent_indent)
|
||||
out.extend(t.wrap(v))
|
||||
return out
|
||||
|
||||
|
||||
BIN
doc/source/images/vmwareapi_blockdiagram.jpg
Normal file
BIN
doc/source/images/vmwareapi_blockdiagram.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
218
doc/source/vmwareapi_readme.rst
Normal file
218
doc/source/vmwareapi_readme.rst
Normal file
@@ -0,0 +1,218 @@
|
||||
..
|
||||
Copyright (c) 2010 Citrix Systems, Inc.
|
||||
Copyright 2010 OpenStack LLC.
|
||||
|
||||
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.
|
||||
|
||||
VMware ESX/ESXi Server Support for OpenStack Compute
|
||||
====================================================
|
||||
|
||||
Introduction
|
||||
------------
|
||||
A module named 'vmwareapi' is added to 'nova.virt' to add support of VMware ESX/ESXi hypervisor to OpenStack compute (Nova). Nova may now use VMware vSphere as a compute provider.
|
||||
|
||||
The basic requirement is to support VMware vSphere 4.1 as a compute provider within Nova. As the deployment architecture, support both ESX and ESXi. VM storage is restricted to VMFS volumes on local drives. vCenter is not required by the current design, and is not currently supported. Instead, Nova Compute talks directly to ESX/ESXi.
|
||||
|
||||
The 'vmwareapi' module is integrated with Glance, so that VM images can be streamed from there for boot on ESXi using Glance server for image storage & retrieval.
|
||||
|
||||
Currently supports Nova's flat networking model (Flat Manager) & VLAN networking model.
|
||||
|
||||
.. image:: images/vmwareapi_blockdiagram.jpg
|
||||
|
||||
|
||||
System Requirements
|
||||
-------------------
|
||||
Following software components are required for building the cloud using OpenStack on top of ESX/ESXi Server(s):
|
||||
|
||||
* OpenStack
|
||||
* Glance Image service
|
||||
* VMware ESX v4.1 or VMware ESXi(licensed) v4.1
|
||||
|
||||
VMware ESX Requirements
|
||||
-----------------------
|
||||
* ESX credentials with administration/root privileges
|
||||
* Single local hard disk at the ESX host
|
||||
* An ESX Virtual Machine Port Group (For Flat Networking)
|
||||
* An ESX physical network adapter (For VLAN networking)
|
||||
* Need to enable "vSphere Web Access" in "vSphere client" UI at Configuration->Security Profile->Firewall
|
||||
|
||||
Python dependencies
|
||||
-------------------
|
||||
* suds-0.4
|
||||
|
||||
* Installation procedure on Ubuntu/Debian
|
||||
|
||||
::
|
||||
|
||||
easy_install suds==0.4
|
||||
|
||||
|
||||
Configuration flags required for nova-compute
|
||||
---------------------------------------------
|
||||
::
|
||||
|
||||
--connection_type=vmwareapi
|
||||
--vmwareapi_host_ip=<VMware ESX Host IP>
|
||||
--vmwareapi_host_username=<VMware ESX Username>
|
||||
--vmwareapi_host_password=<VMware ESX Password>
|
||||
--network_driver=nova.network.vmwareapi_net [Optional, only for VLAN Networking]
|
||||
--vlan_interface=<Physical ethernet adapter name in VMware ESX host for vlan networking E.g vmnic0> [Optional, only for VLAN Networking]
|
||||
|
||||
|
||||
Configuration flags required for nova-network
|
||||
---------------------------------------------
|
||||
::
|
||||
|
||||
--network_manager=nova.network.manager.FlatManager [or nova.network.manager.VlanManager]
|
||||
--flat_network_bridge=<ESX Virtual Machine Port Group> [Optional, only for Flat Networking]
|
||||
|
||||
|
||||
Configuration flags required for nova-console
|
||||
---------------------------------------------
|
||||
::
|
||||
|
||||
--console_manager=nova.console.vmrc_manager.ConsoleVMRCManager
|
||||
--console_driver=nova.console.vmrc.VMRCSessionConsole [Optional, only for OTP (One time Passwords) as against host credentials]
|
||||
|
||||
|
||||
Other flags
|
||||
-----------
|
||||
::
|
||||
|
||||
--image_service=nova.image.glance.GlanceImageService
|
||||
--glance_host=<Glance Host>
|
||||
--vmwareapi_wsdl_loc=<http://<WEB SERVER>/vimService.wsdl>
|
||||
|
||||
Note:- Due to a faulty wsdl being shipped with ESX vSphere 4.1 we need a working wsdl which can to be mounted on any webserver. Follow the below steps to download the SDK,
|
||||
|
||||
* Go to http://www.vmware.com/support/developer/vc-sdk/
|
||||
* Go to section VMware vSphere Web Services SDK 4.0
|
||||
* Click "Downloads"
|
||||
* Enter VMware credentials when prompted for download
|
||||
* Unzip the downloaded file vi-sdk-4.0.0-xxx.zip
|
||||
* Go to SDK->WSDL->vim25 & host the files "vimService.wsdl" and "vim.wsdl" in a WEB SERVER
|
||||
* Set the flag "--vmwareapi_wsdl_loc" with url, "http://<WEB SERVER>/vimService.wsdl"
|
||||
|
||||
|
||||
VLAN Network Manager
|
||||
--------------------
|
||||
VLAN network support is added through a custom network driver in the nova-compute node i.e "nova.network.vmwareapi_net" and it uses a Physical ethernet adapter on the VMware ESX/ESXi host for VLAN Networking (the name of the ethernet adapter is specified as vlan_interface flag in the nova-compute configuration flag) in the nova-compute node.
|
||||
|
||||
Using the physical adapter name the associated Virtual Switch will be determined. In VMware ESX there can be only one Virtual Switch associated with a Physical adapter.
|
||||
|
||||
When VM Spawn request is issued with a VLAN ID the work flow looks like,
|
||||
|
||||
1. Check that a Physical adapter with the given name exists. If no, throw an error.If yes, goto next step.
|
||||
|
||||
2. Check if a Virtual Switch is associated with the Physical ethernet adapter with vlan interface name. If no, throw an error. If yes, goto next step.
|
||||
|
||||
3. Check if a port group with the network bridge name exists. If no, create a port group in the Virtual switch with the give name and VLAN id and goto step 6. If yes, goto next step.
|
||||
|
||||
4. Check if the port group is associated with the Virtual Switch. If no, throw an error. If yes, goto next step.
|
||||
|
||||
5. Check if the port group is associated with the given VLAN Id. If no, throw an error. If yes, goto next step.
|
||||
|
||||
6. Spawn the VM using this Port Group as the Network Name for the VM.
|
||||
|
||||
|
||||
Guest console Support
|
||||
---------------------
|
||||
| VMware VMRC console is a built-in console method providing graphical control of the VM remotely.
|
||||
|
|
||||
| VMRC Console types supported:
|
||||
| # Host based credentials
|
||||
| Not secure (Sends ESX admin credentials in clear text)
|
||||
|
|
||||
| # OTP (One time passwords)
|
||||
| Secure but creates multiple session entries in DB for each OpenStack console create request.
|
||||
| Console sessions created is can be used only once.
|
||||
|
|
||||
| Install browser based VMware ESX plugins/activex on the client machine to connect
|
||||
|
|
||||
| Windows:-
|
||||
| Internet Explorer:
|
||||
| https://<VMware ESX Host>/ui/plugin/vmware-vmrc-win32-x86.exe
|
||||
|
|
||||
| Mozilla Firefox:
|
||||
| https://<VMware ESX Host>/ui/plugin/vmware-vmrc-win32-x86.xpi
|
||||
|
|
||||
| Linux:-
|
||||
| Mozilla Firefox
|
||||
| 32-Bit Linux:
|
||||
| https://<VMware ESX Host>/ui/plugin/vmware-vmrc-linux-x86.xpi
|
||||
|
|
||||
| 64-Bit Linux:
|
||||
| https://<VMware ESX Host>/ui/plugin/vmware-vmrc-linux-x64.xpi
|
||||
|
|
||||
| OpenStack Console Details:
|
||||
| console_type = vmrc+credentials | vmrc+session
|
||||
| host = <VMware ESX Host>
|
||||
| port = <VMware ESX Port>
|
||||
| password = {'vm_id': <VMware VM ID>,'username':<VMware ESX Username>, 'password':<VMware ESX Password>} //base64 + json encoded
|
||||
|
|
||||
| Instantiate the plugin/activex object
|
||||
| # In Internet Explorer
|
||||
| <object id='vmrc' classid='CLSID:B94C2238-346E-4C5E-9B36-8CC627F35574'>
|
||||
| </object>
|
||||
|
|
||||
| # Mozilla Firefox and other browsers
|
||||
| <object id='vmrc' type='application/x-vmware-vmrc;version=2.5.0.0'>
|
||||
| </object>
|
||||
|
|
||||
| Open vmrc connection
|
||||
| # Host based credentials [type=vmrc+credentials]
|
||||
| <script type="text/javascript">
|
||||
| var MODE_WINDOW = 2;
|
||||
| var vmrc = document.getElementById('vmrc');
|
||||
| vmrc.connect(<VMware ESX Host> + ':' + <VMware ESX Port>, <VMware ESX Username>, <VMware ESX Password>, '', <VMware VM ID>, MODE_WINDOW);
|
||||
| </script>
|
||||
|
|
||||
| # OTP (One time passwords) [type=vmrc+session]
|
||||
| <script type="text/javascript">
|
||||
| var MODE_WINDOW = 2;
|
||||
| var vmrc = document.getElementById('vmrc');
|
||||
| vmrc.connectWithSession(<VMware ESX Host> + ':' + <VMware ESX Port>, <VMware VM ID>, <VMware ESX Password>, MODE_WINDOW);
|
||||
| </script>
|
||||
|
||||
|
||||
Assumptions
|
||||
-----------
|
||||
1. The VMware images uploaded to the image repositories have VMware Tools installed.
|
||||
|
||||
|
||||
FAQ
|
||||
---
|
||||
|
||||
1. What type of disk images are supported?
|
||||
|
||||
* Only VMware VMDK's are currently supported and of that support is available only for thick disks, thin provisioned disks are not supported.
|
||||
|
||||
|
||||
2. How is IP address information injected into the guest?
|
||||
|
||||
* IP address information is injected through 'machine.id' vmx parameter (equivalent to XenStore in XenServer). This information can be retrived inside the guest using VMware tools.
|
||||
|
||||
|
||||
3. What is the guest tool?
|
||||
|
||||
* The guest tool is a small python script that should be run either as a service or added to system startup. This script configures networking on the guest. The guest tool is available at tools/esx/guest_tool.py
|
||||
|
||||
|
||||
4. What type of consoles are supported?
|
||||
|
||||
* VMware VMRC based consoles are supported. There are 2 options for credentials one is OTP (Secure but creates multiple session entries in DB for each OpenStack console create request.) & other is host based credentials (It may not be secure as ESX credentials are transmitted as clear text).
|
||||
|
||||
5. What does 'Vim' refer to as far as vmwareapi module is concerned?
|
||||
|
||||
* Vim refers to VMware Virtual Infrastructure Methodology. This is not to be confused with "VIM" editor.
|
||||
|
||||
@@ -298,6 +298,8 @@ DEFINE_string('ec2_dmz_host', '$my_ip', 'internal ip of api server')
|
||||
DEFINE_integer('ec2_port', 8773, 'cloud controller port')
|
||||
DEFINE_string('ec2_scheme', 'http', 'prefix for ec2')
|
||||
DEFINE_string('ec2_path', '/services/Cloud', 'suffix for ec2')
|
||||
DEFINE_string('osapi_extensions_path', '/var/lib/nova/extensions',
|
||||
'default directory for nova extensions')
|
||||
DEFINE_string('osapi_host', '$my_ip', 'ip of api server')
|
||||
DEFINE_string('osapi_scheme', 'http', 'prefix for openstack')
|
||||
DEFINE_integer('osapi_port', 8774, 'OpenStack API port')
|
||||
|
||||
57
nova/test.py
57
nova/test.py
@@ -150,3 +150,60 @@ class TestCase(unittest.TestCase):
|
||||
|
||||
_wrapped.func_name = self.originalAttach.func_name
|
||||
rpc.Consumer.attach_to_eventlet = _wrapped
|
||||
|
||||
# Useful assertions
|
||||
def assertDictMatch(self, d1, d2):
|
||||
"""Assert two dicts are equivalent.
|
||||
|
||||
This is a 'deep' match in the sense that it handles nested
|
||||
dictionaries appropriately.
|
||||
|
||||
NOTE:
|
||||
|
||||
If you don't care (or don't know) a given value, you can specify
|
||||
the string DONTCARE as the value. This will cause that dict-item
|
||||
to be skipped.
|
||||
"""
|
||||
def raise_assertion(msg):
|
||||
d1str = str(d1)
|
||||
d2str = str(d2)
|
||||
base_msg = ("Dictionaries do not match. %(msg)s d1: %(d1str)s "
|
||||
"d2: %(d2str)s" % locals())
|
||||
raise AssertionError(base_msg)
|
||||
|
||||
d1keys = set(d1.keys())
|
||||
d2keys = set(d2.keys())
|
||||
if d1keys != d2keys:
|
||||
d1only = d1keys - d2keys
|
||||
d2only = d2keys - d1keys
|
||||
raise_assertion("Keys in d1 and not d2: %(d1only)s. "
|
||||
"Keys in d2 and not d1: %(d2only)s" % locals())
|
||||
|
||||
for key in d1keys:
|
||||
d1value = d1[key]
|
||||
d2value = d2[key]
|
||||
if hasattr(d1value, 'keys') and hasattr(d2value, 'keys'):
|
||||
self.assertDictMatch(d1value, d2value)
|
||||
elif 'DONTCARE' in (d1value, d2value):
|
||||
continue
|
||||
elif d1value != d2value:
|
||||
raise_assertion("d1['%(key)s']=%(d1value)s != "
|
||||
"d2['%(key)s']=%(d2value)s" % locals())
|
||||
|
||||
def assertDictListMatch(self, L1, L2):
|
||||
"""Assert a list of dicts are equivalent"""
|
||||
def raise_assertion(msg):
|
||||
L1str = str(L1)
|
||||
L2str = str(L2)
|
||||
base_msg = ("List of dictionaries do not match: %(msg)s "
|
||||
"L1: %(L1str)s L2: %(L2str)s" % locals())
|
||||
raise AssertionError(base_msg)
|
||||
|
||||
L1count = len(L1)
|
||||
L2count = len(L2)
|
||||
if L1count != L2count:
|
||||
raise_assertion("Length mismatch: len(L1)=%(L1count)d != "
|
||||
"len(L2)=%(L2count)d" % locals())
|
||||
|
||||
for d1, d2 in zip(L1, L2):
|
||||
self.assertDictMatch(d1, d2)
|
||||
|
||||
@@ -25,12 +25,18 @@ import webob
|
||||
from nova import compute
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import network
|
||||
from nova import test
|
||||
from nova import volume
|
||||
from nova import utils
|
||||
from nova.api import direct
|
||||
from nova.tests import test_cloud
|
||||
|
||||
|
||||
class ArbitraryObject(object):
|
||||
pass
|
||||
|
||||
|
||||
class FakeService(object):
|
||||
def echo(self, context, data):
|
||||
return {'data': data}
|
||||
@@ -39,6 +45,9 @@ class FakeService(object):
|
||||
return {'user': context.user_id,
|
||||
'project': context.project_id}
|
||||
|
||||
def invalid_return(self, context):
|
||||
return ArbitraryObject()
|
||||
|
||||
|
||||
class DirectTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
@@ -84,6 +93,12 @@ class DirectTestCase(test.TestCase):
|
||||
resp_parsed = json.loads(resp.body)
|
||||
self.assertEqual(resp_parsed['data'], 'foo')
|
||||
|
||||
def test_invalid(self):
|
||||
req = webob.Request.blank('/fake/invalid_return')
|
||||
req.environ['openstack.context'] = self.context
|
||||
req.method = 'POST'
|
||||
self.assertRaises(exception.Error, req.get_response, self.router)
|
||||
|
||||
def test_proxy(self):
|
||||
proxy = direct.Proxy(self.router)
|
||||
rv = proxy.fake.echo(self.context, data='baz')
|
||||
@@ -93,12 +108,20 @@ class DirectTestCase(test.TestCase):
|
||||
class DirectCloudTestCase(test_cloud.CloudTestCase):
|
||||
def setUp(self):
|
||||
super(DirectCloudTestCase, self).setUp()
|
||||
compute_handle = compute.API(network_api=self.cloud.network_api,
|
||||
volume_api=self.cloud.volume_api)
|
||||
compute_handle = compute.API(image_service=self.cloud.image_service)
|
||||
volume_handle = volume.API()
|
||||
network_handle = network.API()
|
||||
direct.register_service('compute', compute_handle)
|
||||
direct.register_service('volume', volume_handle)
|
||||
direct.register_service('network', network_handle)
|
||||
|
||||
self.router = direct.JsonParamsMiddleware(direct.Router())
|
||||
proxy = direct.Proxy(self.router)
|
||||
self.cloud.compute_api = proxy.compute
|
||||
self.cloud.volume_api = proxy.volume
|
||||
self.cloud.network_api = proxy.network
|
||||
compute_handle.volume_api = proxy.volume
|
||||
compute_handle.network_api = proxy.network
|
||||
|
||||
def tearDown(self):
|
||||
super(DirectCloudTestCase, self).tearDown()
|
||||
|
||||
@@ -796,7 +796,8 @@ class NWFilterTestCase(test.TestCase):
|
||||
|
||||
instance_ref = db.instance_create(self.context,
|
||||
{'user_id': 'fake',
|
||||
'project_id': 'fake'})
|
||||
'project_id': 'fake',
|
||||
'mac_address': '00:A0:C9:14:C8:29'})
|
||||
inst_id = instance_ref['id']
|
||||
|
||||
ip = '10.11.12.13'
|
||||
@@ -813,7 +814,8 @@ class NWFilterTestCase(test.TestCase):
|
||||
'instance_id': instance_ref['id']})
|
||||
|
||||
def _ensure_all_called():
|
||||
instance_filter = 'nova-instance-%s' % instance_ref['name']
|
||||
instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'],
|
||||
'00A0C914C829')
|
||||
secgroup_filter = 'nova-secgroup-%s' % self.security_group['id']
|
||||
for required in [secgroup_filter, 'allow-dhcp-server',
|
||||
'no-arp-spoofing', 'no-ip-spoofing',
|
||||
|
||||
252
nova/tests/test_vmwareapi.py
Normal file
252
nova/tests/test_vmwareapi.py
Normal file
@@ -0,0 +1,252 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2011 Citrix Systems, Inc.
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Test suite for VMWareAPI.
|
||||
"""
|
||||
|
||||
import stubout
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import test
|
||||
from nova import utils
|
||||
from nova.auth import manager
|
||||
from nova.compute import power_state
|
||||
from nova.tests.glance import stubs as glance_stubs
|
||||
from nova.tests.vmwareapi import db_fakes
|
||||
from nova.tests.vmwareapi import stubs
|
||||
from nova.virt import vmwareapi_conn
|
||||
from nova.virt.vmwareapi import fake as vmwareapi_fake
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class VMWareAPIVMTestCase(test.TestCase):
|
||||
"""Unit tests for Vmware API connection calls."""
|
||||
|
||||
def setUp(self):
|
||||
super(VMWareAPIVMTestCase, self).setUp()
|
||||
self.flags(vmwareapi_host_ip='test_url',
|
||||
vmwareapi_host_username='test_username',
|
||||
vmwareapi_host_password='test_pass')
|
||||
self.manager = manager.AuthManager()
|
||||
self.user = self.manager.create_user('fake', 'fake', 'fake',
|
||||
admin=True)
|
||||
self.project = self.manager.create_project('fake', 'fake', 'fake')
|
||||
self.network = utils.import_object(FLAGS.network_manager)
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
vmwareapi_fake.reset()
|
||||
db_fakes.stub_out_db_instance_api(self.stubs)
|
||||
stubs.set_stubs(self.stubs)
|
||||
glance_stubs.stubout_glance_client(self.stubs,
|
||||
glance_stubs.FakeGlance)
|
||||
self.conn = vmwareapi_conn.get_connection(False)
|
||||
|
||||
def _create_instance_in_the_db(self):
|
||||
values = {'name': 1,
|
||||
'id': 1,
|
||||
'project_id': self.project.id,
|
||||
'user_id': self.user.id,
|
||||
'image_id': "1",
|
||||
'kernel_id': "1",
|
||||
'ramdisk_id': "1",
|
||||
'instance_type': 'm1.large',
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||
}
|
||||
self.instance = db.instance_create(values)
|
||||
|
||||
def _create_vm(self):
|
||||
"""Create and spawn the VM."""
|
||||
self._create_instance_in_the_db()
|
||||
self.type_data = db.instance_type_get_by_name(None, 'm1.large')
|
||||
self.conn.spawn(self.instance)
|
||||
self._check_vm_record()
|
||||
|
||||
def _check_vm_record(self):
|
||||
"""
|
||||
Check if the spawned VM's properties correspond to the instance in
|
||||
the db.
|
||||
"""
|
||||
instances = self.conn.list_instances()
|
||||
self.assertEquals(len(instances), 1)
|
||||
|
||||
# Get Nova record for VM
|
||||
vm_info = self.conn.get_info(1)
|
||||
|
||||
# Get record for VM
|
||||
vms = vmwareapi_fake._get_objects("VirtualMachine")
|
||||
vm = vms[0]
|
||||
|
||||
# Check that m1.large above turned into the right thing.
|
||||
mem_kib = long(self.type_data['memory_mb']) << 10
|
||||
vcpus = self.type_data['vcpus']
|
||||
self.assertEquals(vm_info['max_mem'], mem_kib)
|
||||
self.assertEquals(vm_info['mem'], mem_kib)
|
||||
self.assertEquals(vm.get("summary.config.numCpu"), vcpus)
|
||||
self.assertEquals(vm.get("summary.config.memorySizeMB"),
|
||||
self.type_data['memory_mb'])
|
||||
|
||||
# Check that the VM is running according to Nova
|
||||
self.assertEquals(vm_info['state'], power_state.RUNNING)
|
||||
|
||||
# Check that the VM is running according to vSphere API.
|
||||
self.assertEquals(vm.get("runtime.powerState"), 'poweredOn')
|
||||
|
||||
def _check_vm_info(self, info, pwr_state=power_state.RUNNING):
|
||||
"""
|
||||
Check if the get_info returned values correspond to the instance
|
||||
object in the db.
|
||||
"""
|
||||
mem_kib = long(self.type_data['memory_mb']) << 10
|
||||
self.assertEquals(info["state"], pwr_state)
|
||||
self.assertEquals(info["max_mem"], mem_kib)
|
||||
self.assertEquals(info["mem"], mem_kib)
|
||||
self.assertEquals(info["num_cpu"], self.type_data['vcpus'])
|
||||
|
||||
def test_list_instances(self):
|
||||
instances = self.conn.list_instances()
|
||||
self.assertEquals(len(instances), 0)
|
||||
|
||||
def test_list_instances_1(self):
|
||||
self._create_vm()
|
||||
instances = self.conn.list_instances()
|
||||
self.assertEquals(len(instances), 1)
|
||||
|
||||
def test_spawn(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
|
||||
def test_snapshot(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
self.conn.snapshot(self.instance, "Test-Snapshot")
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
|
||||
def test_snapshot_non_existent(self):
|
||||
self._create_instance_in_the_db()
|
||||
self.assertRaises(Exception, self.conn.snapshot, self.instance,
|
||||
"Test-Snapshot")
|
||||
|
||||
def test_reboot(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
self.conn.reboot(self.instance)
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
|
||||
def test_reboot_non_existent(self):
|
||||
self._create_instance_in_the_db()
|
||||
self.assertRaises(Exception, self.conn.reboot, self.instance)
|
||||
|
||||
def test_reboot_not_poweredon(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
self.conn.suspend(self.instance, self.dummy_callback_handler)
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.PAUSED)
|
||||
self.assertRaises(Exception, self.conn.reboot, self.instance)
|
||||
|
||||
def test_suspend(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
self.conn.suspend(self.instance, self.dummy_callback_handler)
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.PAUSED)
|
||||
|
||||
def test_suspend_non_existent(self):
|
||||
self._create_instance_in_the_db()
|
||||
self.assertRaises(Exception, self.conn.suspend, self.instance,
|
||||
self.dummy_callback_handler)
|
||||
|
||||
def test_resume(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
self.conn.suspend(self.instance, self.dummy_callback_handler)
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.PAUSED)
|
||||
self.conn.resume(self.instance, self.dummy_callback_handler)
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
|
||||
def test_resume_non_existent(self):
|
||||
self._create_instance_in_the_db()
|
||||
self.assertRaises(Exception, self.conn.resume, self.instance,
|
||||
self.dummy_callback_handler)
|
||||
|
||||
def test_resume_not_suspended(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
self.assertRaises(Exception, self.conn.resume, self.instance,
|
||||
self.dummy_callback_handler)
|
||||
|
||||
def test_get_info(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
|
||||
def test_destroy(self):
|
||||
self._create_vm()
|
||||
info = self.conn.get_info(1)
|
||||
self._check_vm_info(info, power_state.RUNNING)
|
||||
instances = self.conn.list_instances()
|
||||
self.assertEquals(len(instances), 1)
|
||||
self.conn.destroy(self.instance)
|
||||
instances = self.conn.list_instances()
|
||||
self.assertEquals(len(instances), 0)
|
||||
|
||||
def test_destroy_non_existent(self):
|
||||
self._create_instance_in_the_db()
|
||||
self.assertEquals(self.conn.destroy(self.instance), None)
|
||||
|
||||
def test_pause(self):
|
||||
pass
|
||||
|
||||
def test_unpause(self):
|
||||
pass
|
||||
|
||||
def test_diagnostics(self):
|
||||
pass
|
||||
|
||||
def test_get_console_output(self):
|
||||
pass
|
||||
|
||||
def test_get_ajax_console(self):
|
||||
pass
|
||||
|
||||
def dummy_callback_handler(self, ret):
|
||||
"""
|
||||
Dummy callback function to be passed to suspend, resume, etc., calls.
|
||||
"""
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
super(VMWareAPIVMTestCase, self).tearDown()
|
||||
vmwareapi_fake.cleanup()
|
||||
self.manager.delete_project(self.project)
|
||||
self.manager.delete_user(self.user)
|
||||
self.stubs.UnsetAll()
|
||||
@@ -186,6 +186,7 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
stubs.stubout_stream_disk(self.stubs)
|
||||
stubs.stubout_is_vdi_pv(self.stubs)
|
||||
self.stubs.Set(VMOps, 'reset_network', reset_network)
|
||||
stubs.stub_out_vm_methods(self.stubs)
|
||||
glance_stubs.stubout_glance_client(self.stubs,
|
||||
glance_stubs.FakeGlance)
|
||||
self.conn = xenapi_conn.get_connection(False)
|
||||
@@ -369,6 +370,17 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
self.assertEquals(vif_rec['qos_algorithm_params']['kbps'],
|
||||
str(4 * 1024))
|
||||
|
||||
def test_rescue(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
conn.rescue(instance, None)
|
||||
|
||||
def test_unrescue(self):
|
||||
instance = self._create_instance()
|
||||
conn = xenapi_conn.get_connection(False)
|
||||
# Ensure that it will not unrescue a non-rescued instance.
|
||||
self.assertRaises(Exception, conn.unrescue, instance, None)
|
||||
|
||||
def tearDown(self):
|
||||
super(XenAPIVMTestCase, self).tearDown()
|
||||
self.manager.delete_project(self.project)
|
||||
|
||||
21
nova/tests/vmwareapi/__init__.py
Normal file
21
nova/tests/vmwareapi/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2011 Citrix Systems, Inc.
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
:mod:`vmwareapi` -- Stubs for VMware API
|
||||
=======================================
|
||||
"""
|
||||
109
nova/tests/vmwareapi/db_fakes.py
Normal file
109
nova/tests/vmwareapi/db_fakes.py
Normal file
@@ -0,0 +1,109 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2011 Citrix Systems, Inc.
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Stubouts, mocks and fixtures for the test suite
|
||||
"""
|
||||
|
||||
import time
|
||||
|
||||
from nova import db
|
||||
from nova import utils
|
||||
|
||||
|
||||
def stub_out_db_instance_api(stubs):
|
||||
"""Stubs out the db API for creating Instances."""
|
||||
|
||||
INSTANCE_TYPES = {
|
||||
'm1.tiny': dict(memory_mb=512, vcpus=1, local_gb=0, flavorid=1),
|
||||
'm1.small': dict(memory_mb=2048, vcpus=1, local_gb=20, flavorid=2),
|
||||
'm1.medium':
|
||||
dict(memory_mb=4096, vcpus=2, local_gb=40, flavorid=3),
|
||||
'm1.large': dict(memory_mb=8192, vcpus=4, local_gb=80, flavorid=4),
|
||||
'm1.xlarge':
|
||||
dict(memory_mb=16384, vcpus=8, local_gb=160, flavorid=5)}
|
||||
|
||||
class FakeModel(object):
|
||||
"""Stubs out for model."""
|
||||
|
||||
def __init__(self, values):
|
||||
self.values = values
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self.values[name]
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key in self.values:
|
||||
return self.values[key]
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
def fake_instance_create(values):
|
||||
"""Stubs out the db.instance_create method."""
|
||||
|
||||
type_data = INSTANCE_TYPES[values['instance_type']]
|
||||
|
||||
base_options = {
|
||||
'name': values['name'],
|
||||
'id': values['id'],
|
||||
'reservation_id': utils.generate_uid('r'),
|
||||
'image_id': values['image_id'],
|
||||
'kernel_id': values['kernel_id'],
|
||||
'ramdisk_id': values['ramdisk_id'],
|
||||
'state_description': 'scheduling',
|
||||
'user_id': values['user_id'],
|
||||
'project_id': values['project_id'],
|
||||
'launch_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
|
||||
'instance_type': values['instance_type'],
|
||||
'memory_mb': type_data['memory_mb'],
|
||||
'mac_address': values['mac_address'],
|
||||
'vcpus': type_data['vcpus'],
|
||||
'local_gb': type_data['local_gb'],
|
||||
}
|
||||
return FakeModel(base_options)
|
||||
|
||||
def fake_network_get_by_instance(context, instance_id):
|
||||
"""Stubs out the db.network_get_by_instance method."""
|
||||
|
||||
fields = {
|
||||
'bridge': 'vmnet0',
|
||||
'netmask': '255.255.255.0',
|
||||
'gateway': '10.10.10.1',
|
||||
'vlan': 100}
|
||||
return FakeModel(fields)
|
||||
|
||||
def fake_instance_action_create(context, action):
|
||||
"""Stubs out the db.instance_action_create method."""
|
||||
pass
|
||||
|
||||
def fake_instance_get_fixed_address(context, instance_id):
|
||||
"""Stubs out the db.instance_get_fixed_address method."""
|
||||
return '10.10.10.10'
|
||||
|
||||
def fake_instance_type_get_all(context, inactive=0):
|
||||
return INSTANCE_TYPES
|
||||
|
||||
def fake_instance_type_get_by_name(context, name):
|
||||
return INSTANCE_TYPES[name]
|
||||
|
||||
stubs.Set(db, 'instance_create', fake_instance_create)
|
||||
stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance)
|
||||
stubs.Set(db, 'instance_action_create', fake_instance_action_create)
|
||||
stubs.Set(db, 'instance_get_fixed_address',
|
||||
fake_instance_get_fixed_address)
|
||||
stubs.Set(db, 'instance_type_get_all', fake_instance_type_get_all)
|
||||
stubs.Set(db, 'instance_type_get_by_name', fake_instance_type_get_by_name)
|
||||
46
nova/tests/vmwareapi/stubs.py
Normal file
46
nova/tests/vmwareapi/stubs.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2011 Citrix Systems, Inc.
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Stubouts for the test suite
|
||||
"""
|
||||
|
||||
from nova.virt import vmwareapi_conn
|
||||
from nova.virt.vmwareapi import fake
|
||||
from nova.virt.vmwareapi import vmware_images
|
||||
|
||||
|
||||
def fake_get_vim_object(arg):
|
||||
"""Stubs out the VMWareAPISession's get_vim_object method."""
|
||||
return fake.FakeVim()
|
||||
|
||||
|
||||
def fake_is_vim_object(arg, module):
|
||||
"""Stubs out the VMWareAPISession's is_vim_object method."""
|
||||
return isinstance(module, fake.FakeVim)
|
||||
|
||||
|
||||
def set_stubs(stubs):
|
||||
"""Set the stubs."""
|
||||
stubs.Set(vmware_images, 'fetch_image', fake.fake_fetch_image)
|
||||
stubs.Set(vmware_images, 'get_vmdk_size_and_properties',
|
||||
fake.fake_get_vmdk_size_and_properties)
|
||||
stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image)
|
||||
stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object",
|
||||
fake_get_vim_object)
|
||||
stubs.Set(vmwareapi_conn.VMWareAPISession, "_is_vim_object",
|
||||
fake_is_vim_object)
|
||||
@@ -185,6 +185,25 @@ class FakeSessionForVMTests(fake.SessionBase):
|
||||
pass
|
||||
|
||||
|
||||
def stub_out_vm_methods(stubs):
|
||||
def fake_shutdown(self, inst, vm, method="clean"):
|
||||
pass
|
||||
|
||||
def fake_acquire_bootlock(self, vm):
|
||||
pass
|
||||
|
||||
def fake_release_bootlock(self, vm):
|
||||
pass
|
||||
|
||||
def fake_spawn_rescue(self, inst):
|
||||
pass
|
||||
|
||||
stubs.Set(vmops.VMOps, "_shutdown", fake_shutdown)
|
||||
stubs.Set(vmops.VMOps, "_acquire_bootlock", fake_acquire_bootlock)
|
||||
stubs.Set(vmops.VMOps, "_release_bootlock", fake_release_bootlock)
|
||||
stubs.Set(vmops.VMOps, "spawn_rescue", fake_spawn_rescue)
|
||||
|
||||
|
||||
class FakeSessionForVolumeTests(fake.SessionBase):
|
||||
""" Stubs out a XenAPISession for Volume tests """
|
||||
def __init__(self, uri):
|
||||
|
||||
@@ -311,11 +311,15 @@ def get_my_linklocal(interface):
|
||||
|
||||
|
||||
def to_global_ipv6(prefix, mac):
|
||||
try:
|
||||
mac64 = netaddr.EUI(mac).eui64().words
|
||||
int_addr = int(''.join(['%02x' % i for i in mac64]), 16)
|
||||
mac64_addr = netaddr.IPAddress(int_addr)
|
||||
maskIP = netaddr.IPNetwork(prefix).ip
|
||||
return (mac64_addr ^ netaddr.IPAddress('::0200:0:0:0') | maskIP).format()
|
||||
return (mac64_addr ^ netaddr.IPAddress('::0200:0:0:0') | maskIP).\
|
||||
format()
|
||||
except TypeError:
|
||||
raise TypeError(_("Bad mac for to_global_ipv6: %s") % mac)
|
||||
|
||||
|
||||
def to_mac(ipv6_address):
|
||||
@@ -337,11 +341,8 @@ utcnow.override_time = None
|
||||
|
||||
|
||||
def is_older_than(before, seconds):
|
||||
"""Return True if before is older than 'seconds'"""
|
||||
if utcnow() - before > datetime.timedelta(seconds=seconds):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
"""Return True if before is older than seconds"""
|
||||
return utcnow() - before > datetime.timedelta(seconds=seconds)
|
||||
|
||||
|
||||
def utcnow_ts():
|
||||
@@ -664,6 +665,48 @@ def get_from_path(items, path):
|
||||
return get_from_path(results, remainder)
|
||||
|
||||
|
||||
def flatten_dict(dict_, flattened=None):
|
||||
"""Recursively flatten a nested dictionary"""
|
||||
flattened = flattened or {}
|
||||
for key, value in dict_.iteritems():
|
||||
if hasattr(value, 'iteritems'):
|
||||
flatten_dict(value, flattened)
|
||||
else:
|
||||
flattened[key] = value
|
||||
return flattened
|
||||
|
||||
|
||||
def partition_dict(dict_, keys):
|
||||
"""Return two dicts, one containing only `keys` the other containing
|
||||
everything but `keys`
|
||||
"""
|
||||
intersection = {}
|
||||
difference = {}
|
||||
for key, value in dict_.iteritems():
|
||||
if key in keys:
|
||||
intersection[key] = value
|
||||
else:
|
||||
difference[key] = value
|
||||
return intersection, difference
|
||||
|
||||
|
||||
def map_dict_keys(dict_, key_map):
|
||||
"""Return a dictionary in which the dictionaries keys are mapped to
|
||||
new keys.
|
||||
"""
|
||||
mapped = {}
|
||||
for key, value in dict_.iteritems():
|
||||
mapped_key = key_map[key] if key in key_map else key
|
||||
mapped[mapped_key] = value
|
||||
return mapped
|
||||
|
||||
|
||||
def subset_dict(dict_, keys):
|
||||
"""Return a dict that only contains a subset of keys"""
|
||||
subset = partition_dict(dict_, keys)[0]
|
||||
return subset
|
||||
|
||||
|
||||
def check_isinstance(obj, cls):
|
||||
"""Checks that obj is of type cls, and lets PyLint infer types"""
|
||||
if isinstance(obj, cls):
|
||||
|
||||
Reference in New Issue
Block a user