Skip to content

Commit

Permalink
Introduce VirtAPI to nova/virt
Browse files Browse the repository at this point in the history
This patch introduces a VirtAPI class which will house
callbacks provided by the manager to the virt drivers, allowing
things such as direct database accesses to be pulled out of
the virt drivers and delegated to another service.

As a first step, this introduces an instance_update() method
and makes all the virt drivers use it instead of direct calls
to db.instance_update.*().

Change-Id: I2e40831f5cfb20a03b304097d84d592aab035ef1
  • Loading branch information
kk7ds committed Nov 1, 2012
1 parent c49d96e commit 081b652
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 177 deletions.
17 changes: 16 additions & 1 deletion nova/compute/manager.py
Expand Up @@ -73,6 +73,7 @@
from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import utils
from nova.virt import driver
from nova.virt import virtapi
from nova import volume


Expand Down Expand Up @@ -209,6 +210,17 @@ def _get_image_meta(context, image_ref):
return image_service.show(context, image_id)


class ComputeVirtAPI(virtapi.VirtAPI):
def __init__(self, compute):
super(ComputeVirtAPI, self).__init__()
self._compute = compute

def instance_update(self, context, instance_uuid, updates):
return self._compute.db.instance_update_and_get_original(context,
instance_uuid,
updates)


class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""

Expand All @@ -225,10 +237,13 @@ def __init__(self, compute_driver=None, *args, **kwargs):
LOG.error(_("Compute driver option required, but not specified"))
sys.exit(1)

self.virtapi = ComputeVirtAPI(self)

LOG.info(_("Loading compute driver '%s'") % compute_driver)
try:
self.driver = utils.check_isinstance(
importutils.import_object_ns('nova.virt', compute_driver),
importutils.import_object_ns('nova.virt', compute_driver,
self.virtapi),
driver.ComputeDriver)
except ImportError as e:
LOG.error(_("Unable to load the virtualization driver: %s") % (e))
Expand Down
2 changes: 1 addition & 1 deletion nova/tests/baremetal/test_proxy_bare_metal.py
Expand Up @@ -257,7 +257,7 @@ def test_get_info(self):
self.mox.ReplayAll()

# Code under test
conn = driver.BareMetalDriver(True)
conn = driver.BareMetalDriver(None, True)
# TODO(mikalstill): this is not a very good fake instance
info = conn.get_info({'name': 'instance-00000001'})

Expand Down
10 changes: 5 additions & 5 deletions nova/tests/compute/test_resource_tracker.py
Expand Up @@ -42,7 +42,7 @@ def get_available_resource(self):

class FakeVirtDriver(driver.ComputeDriver):

def __init__(self):
def __init__(self, virtapi):
self.memory_mb = 5
self.local_gb = 6
self.vcpus = 1
Expand Down Expand Up @@ -148,9 +148,9 @@ def _tracker(self, unsupported=False):
host = "fakehost"

if unsupported:
driver = UnsupportedVirtDriver()
driver = UnsupportedVirtDriver(None)
else:
driver = FakeVirtDriver()
driver = FakeVirtDriver(None)

tracker = resource_tracker.ResourceTracker(host, driver)
return tracker
Expand Down Expand Up @@ -293,12 +293,12 @@ def testUpdateUseOnlyForTracked(self):
self.assertEqual(1, self.tracker.compute_node['current_workload'])

def testFreeRamResourceValue(self):
driver = FakeVirtDriver()
driver = FakeVirtDriver(None)
mem_free = driver.memory_mb - driver.memory_mb_used
self.assertEqual(mem_free, self.tracker.compute_node['free_ram_mb'])

def testFreeDiskResourceValue(self):
driver = FakeVirtDriver()
driver = FakeVirtDriver(None)
mem_free = driver.local_gb - driver.local_gb_used
self.assertEqual(mem_free, self.tracker.compute_node['free_disk_gb'])

Expand Down
2 changes: 1 addition & 1 deletion nova/tests/test_hypervapi.py
Expand Up @@ -66,7 +66,7 @@ def setUp(self):
vswitch_name='external')

self._hypervutils = hypervutils.HyperVUtils()
self._conn = driver_hyperv.HyperVDriver()
self._conn = driver_hyperv.HyperVDriver(None)

def _setup_stubs(self):
db_fakes.stub_out_db_instance_api(self.stubs)
Expand Down

0 comments on commit 081b652

Please sign in to comment.