Merge "inspectors: stop using global conf"
This commit is contained in:
commit
a9f2588d3a
@ -35,7 +35,7 @@ class BaseComputePollster(plugin_base.PollsterBase):
|
||||
try:
|
||||
inspector = self._inspector
|
||||
except AttributeError:
|
||||
inspector = virt_inspector.get_hypervisor_inspector()
|
||||
inspector = virt_inspector.get_hypervisor_inspector(self.conf)
|
||||
BaseComputePollster._inspector = inspector
|
||||
return inspector
|
||||
|
||||
|
@ -77,8 +77,8 @@ exception_conversion_map = collections.OrderedDict([
|
||||
@decorate_all_methods(convert_exceptions, exception_conversion_map)
|
||||
class HyperVInspector(virt_inspector.Inspector):
|
||||
|
||||
def __init__(self):
|
||||
super(HyperVInspector, self).__init__()
|
||||
def __init__(self, conf):
|
||||
super(HyperVInspector, self).__init__(conf)
|
||||
self._utils = utilsfactory.get_metricsutils()
|
||||
self._host_max_cpu_clock = self._compute_host_max_cpu_clock()
|
||||
|
||||
|
@ -226,6 +226,9 @@ class NoSanityException(InspectorException):
|
||||
#
|
||||
class Inspector(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
|
||||
def check_sanity(self):
|
||||
"""Check the sanity of hypervisor inspector.
|
||||
|
||||
@ -365,13 +368,14 @@ class Inspector(object):
|
||||
raise ceilometer.NotImplementedError
|
||||
|
||||
|
||||
def get_hypervisor_inspector():
|
||||
def get_hypervisor_inspector(conf):
|
||||
try:
|
||||
namespace = 'ceilometer.compute.virt'
|
||||
mgr = driver.DriverManager(namespace,
|
||||
cfg.CONF.hypervisor_inspector,
|
||||
invoke_on_load=True)
|
||||
conf.hypervisor_inspector,
|
||||
invoke_on_load=True,
|
||||
invoke_args=(conf, ))
|
||||
return mgr.driver
|
||||
except ImportError as e:
|
||||
LOG.error(_("Unable to load the hypervisor inspector: %s") % e)
|
||||
return Inspector()
|
||||
return Inspector(conf)
|
||||
|
@ -67,7 +67,8 @@ class LibvirtInspector(virt_inspector.Inspector):
|
||||
|
||||
per_type_uris = dict(uml='uml:///system', xen='xen:///', lxc='lxc:///')
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, conf):
|
||||
super(LibvirtInspector, self).__init__(conf)
|
||||
self._connection = None
|
||||
|
||||
@property
|
||||
@ -77,8 +78,9 @@ class LibvirtInspector(virt_inspector.Inspector):
|
||||
if libvirt is None:
|
||||
libvirt = __import__('libvirt')
|
||||
|
||||
uri = (CONF.libvirt_uri or
|
||||
self.per_type_uris.get(CONF.libvirt_type, 'qemu:///system'))
|
||||
uri = (self.conf.libvirt_uri or
|
||||
self.per_type_uris.get(self.conf.libvirt_type,
|
||||
'qemu:///system'))
|
||||
LOG.debug('Connecting to libvirt: %s', uri)
|
||||
self._connection = libvirt.openReadOnly(uri)
|
||||
|
||||
|
@ -78,26 +78,26 @@ VC_DISK_WRITE_RATE_CNTR = "disk:write:average"
|
||||
VC_DISK_WRITE_REQUESTS_RATE_CNTR = "disk:numberWriteAveraged:average"
|
||||
|
||||
|
||||
def get_api_session():
|
||||
def get_api_session(conf):
|
||||
api_session = api.VMwareAPISession(
|
||||
cfg.CONF.vmware.host_ip,
|
||||
cfg.CONF.vmware.host_username,
|
||||
cfg.CONF.vmware.host_password,
|
||||
cfg.CONF.vmware.api_retry_count,
|
||||
cfg.CONF.vmware.task_poll_interval,
|
||||
wsdl_loc=cfg.CONF.vmware.wsdl_location,
|
||||
port=cfg.CONF.vmware.host_port,
|
||||
cacert=cfg.CONF.vmware.ca_file,
|
||||
insecure=cfg.CONF.vmware.insecure)
|
||||
conf.vmware.host_ip,
|
||||
conf.vmware.host_username,
|
||||
conf.vmware.host_password,
|
||||
conf.vmware.api_retry_count,
|
||||
conf.vmware.task_poll_interval,
|
||||
wsdl_loc=conf.vmware.wsdl_location,
|
||||
port=conf.vmware.host_port,
|
||||
cacert=conf.vmware.ca_file,
|
||||
insecure=conf.vmware.insecure)
|
||||
return api_session
|
||||
|
||||
|
||||
class VsphereInspector(virt_inspector.Inspector):
|
||||
|
||||
def __init__(self):
|
||||
super(VsphereInspector, self).__init__()
|
||||
def __init__(self, conf):
|
||||
super(VsphereInspector, self).__init__(conf)
|
||||
self._ops = vsphere_operations.VsphereOperations(
|
||||
get_api_session(), 1000)
|
||||
get_api_session(self.conf), 1000)
|
||||
|
||||
def inspect_cpu_util(self, instance, duration=None):
|
||||
vm_moid = self._ops.get_vm_moid(instance.id)
|
||||
|
@ -61,13 +61,13 @@ def swap_xapi_host(url, host_addr):
|
||||
return urlparse.urlunparse(replaced)
|
||||
|
||||
|
||||
def get_api_session():
|
||||
def get_api_session(conf):
|
||||
if not api:
|
||||
raise ImportError(_('XenAPI not installed'))
|
||||
|
||||
url = CONF.xenapi.connection_url
|
||||
username = CONF.xenapi.connection_username
|
||||
password = CONF.xenapi.connection_password
|
||||
url = conf.xenapi.connection_url
|
||||
username = conf.xenapi.connection_username
|
||||
password = conf.xenapi.connection_password
|
||||
if not url or password is None:
|
||||
raise XenapiException(_('Must specify connection_url, and '
|
||||
'connection_password to use'))
|
||||
@ -94,9 +94,9 @@ def get_api_session():
|
||||
|
||||
class XenapiInspector(virt_inspector.Inspector):
|
||||
|
||||
def __init__(self):
|
||||
super(XenapiInspector, self).__init__()
|
||||
self.session = get_api_session()
|
||||
def __init__(self, conf):
|
||||
super(XenapiInspector, self).__init__(conf)
|
||||
self.session = get_api_session(self.conf)
|
||||
|
||||
def _get_host_ref(self):
|
||||
"""Return the xenapi host on which nova-compute runs on."""
|
||||
|
@ -19,6 +19,7 @@ import sys
|
||||
|
||||
import mock
|
||||
from os_win import exceptions as os_win_exc
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslo_utils import units
|
||||
from oslotest import base
|
||||
|
||||
@ -32,7 +33,8 @@ class TestHyperVInspection(base.BaseTestCase):
|
||||
@mock.patch.object(hyperv_inspector.HyperVInspector,
|
||||
'_compute_host_max_cpu_clock')
|
||||
def setUp(self, mock_compute_host_cpu_clock):
|
||||
self._inspector = hyperv_inspector.HyperVInspector()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
self._inspector = hyperv_inspector.HyperVInspector(self.CONF)
|
||||
self._inspector._utils = mock.MagicMock()
|
||||
|
||||
super(TestHyperVInspection, self).setUp()
|
||||
|
@ -21,6 +21,7 @@ except ImportError:
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslo_utils import units
|
||||
from oslotest import base
|
||||
|
||||
@ -35,12 +36,13 @@ class TestLibvirtInspection(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLibvirtInspection, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
|
||||
class VMInstance(object):
|
||||
id = 'ff58e738-12f4-4c58-acde-77617b68da56'
|
||||
name = 'instance-00000001'
|
||||
self.instance = VMInstance
|
||||
self.inspector = libvirt_inspector.LibvirtInspector()
|
||||
self.inspector = libvirt_inspector.LibvirtInspector(self.CONF)
|
||||
libvirt_inspector.libvirt = mock.Mock()
|
||||
libvirt_inspector.libvirt.VIR_DOMAIN_SHUTOFF = 5
|
||||
libvirt_inspector.libvirt.libvirtError = self.fakeLibvirtError
|
||||
@ -426,7 +428,8 @@ class TestLibvirtInspectionWithError(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLibvirtInspectionWithError, self).setUp()
|
||||
self.inspector = libvirt_inspector.LibvirtInspector()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
self.inspector = libvirt_inspector.LibvirtInspector(self.CONF)
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'ceilometer.compute.virt.libvirt.inspector.'
|
||||
'LibvirtInspector.connection',
|
||||
@ -443,7 +446,8 @@ class TestLibvirtInitWithError(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLibvirtInitWithError, self).setUp()
|
||||
self.inspector = libvirt_inspector.LibvirtInspector()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
self.inspector = libvirt_inspector.LibvirtInspector(self.CONF)
|
||||
libvirt_inspector.libvirt = mock.Mock()
|
||||
|
||||
def test_init_error(self):
|
||||
|
@ -17,6 +17,7 @@ Tests for VMware vSphere inspector.
|
||||
"""
|
||||
|
||||
import mock
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslo_vmware import api
|
||||
from oslotest import base
|
||||
|
||||
@ -27,16 +28,16 @@ from ceilometer.compute.virt.vmware import inspector as vsphere_inspector
|
||||
class TestVsphereInspection(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestVsphereInspection, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
api_session = api.VMwareAPISession("test_server", "test_user",
|
||||
"test_password", 0, None,
|
||||
create_session=False, port=7443)
|
||||
vsphere_inspector.get_api_session = mock.Mock(
|
||||
return_value=api_session)
|
||||
self._inspector = vsphere_inspector.VsphereInspector()
|
||||
self._inspector = vsphere_inspector.VsphereInspector(self.CONF)
|
||||
self._inspector._ops = mock.MagicMock()
|
||||
|
||||
super(TestVsphereInspection, self).setUp()
|
||||
|
||||
def test_inspect_memory_usage(self):
|
||||
fake_instance_moid = 'fake_instance_moid'
|
||||
fake_instance_id = 'fake_instance_id'
|
||||
|
@ -15,6 +15,7 @@
|
||||
"""
|
||||
|
||||
import mock
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslotest import base
|
||||
|
||||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
@ -52,11 +53,11 @@ class TestSwapXapiHost(base.BaseTestCase):
|
||||
class TestXenapiInspection(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestXenapiInspection, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
api_session = mock.Mock()
|
||||
xenapi_inspector.get_api_session = mock.Mock(return_value=api_session)
|
||||
self.inspector = xenapi_inspector.XenapiInspector()
|
||||
|
||||
super(TestXenapiInspection, self).setUp()
|
||||
self.inspector = xenapi_inspector.XenapiInspector(self.CONF)
|
||||
|
||||
def test_inspect_cpu_util(self):
|
||||
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
|
||||
|
Loading…
x
Reference in New Issue
Block a user