Move monitors at driver level
Following changes for cluster-drivers, move coe specific monitors at driver level. This change is needed to add the driver field properly. Change-Id: Id4658b8f7400bf3c86c8ff81756fb33d1211a0b3 Implements: blueprint bay-drivers
This commit is contained in:
parent
faccdccc7c
commit
f997a332da
@ -16,23 +16,16 @@
|
||||
import abc
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
import magnum.conf
|
||||
from magnum.objects import fields
|
||||
from magnum.drivers.common.driver import Driver
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
CONF = magnum.conf.CONF
|
||||
|
||||
COE_CLASS_PATH = {
|
||||
fields.ClusterType.SWARM: 'magnum.conductor.swarm_monitor.SwarmMonitor',
|
||||
fields.ClusterType.KUBERNETES: 'magnum.conductor.k8s_monitor.K8sMonitor',
|
||||
fields.ClusterType.MESOS: 'magnum.conductor.mesos_monitor.MesosMonitor'
|
||||
}
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class MonitorBase(object):
|
||||
@ -62,10 +55,10 @@ class MonitorBase(object):
|
||||
|
||||
|
||||
def create_monitor(context, cluster):
|
||||
if cluster.cluster_template.coe in COE_CLASS_PATH:
|
||||
coe_cls = importutils.import_class(
|
||||
COE_CLASS_PATH[cluster.cluster_template.coe])
|
||||
return coe_cls(context, cluster)
|
||||
cluster_driver = Driver.get_driver_for_cluster(context, cluster)
|
||||
monitor = cluster_driver.get_monitor(context, cluster)
|
||||
if monitor:
|
||||
return monitor
|
||||
|
||||
LOG.debug("Cannot create monitor with cluster type '%s'",
|
||||
cluster.cluster_template.coe)
|
||||
|
@ -174,3 +174,8 @@ class Driver(object):
|
||||
def delete_cluster(self, context, cluster):
|
||||
raise NotImplementedError("Subclasses must implement "
|
||||
"'delete_cluster'.")
|
||||
|
||||
def get_monitor(self, context, cluster):
|
||||
"""return the monitor with container data for this driver."""
|
||||
|
||||
return None
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from magnum.drivers.common import k8s_monitor
|
||||
from magnum.drivers.heat import driver
|
||||
from magnum.drivers.k8s_coreos_v1 import template_def
|
||||
|
||||
@ -28,3 +29,6 @@ class Driver(driver.HeatDriver):
|
||||
|
||||
def get_template_definition(self):
|
||||
return template_def.CoreOSK8sTemplateDefinition()
|
||||
|
||||
def get_monitor(self, context, cluster):
|
||||
return k8s_monitor.K8sMonitor(context, cluster)
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from magnum.drivers.common import k8s_monitor
|
||||
from magnum.drivers.heat import driver
|
||||
from magnum.drivers.k8s_fedora_atomic_v1 import template_def
|
||||
|
||||
@ -28,3 +29,6 @@ class Driver(driver.HeatDriver):
|
||||
|
||||
def get_template_definition(self):
|
||||
return template_def.AtomicK8sTemplateDefinition()
|
||||
|
||||
def get_monitor(self, context, cluster):
|
||||
return k8s_monitor.K8sMonitor(context, cluster)
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from magnum.drivers.common import k8s_monitor
|
||||
from magnum.drivers.heat import driver
|
||||
from magnum.drivers.k8s_fedora_ironic_v1 import template_def
|
||||
|
||||
@ -28,3 +29,6 @@ class Driver(driver.HeatDriver):
|
||||
|
||||
def get_template_definition(self):
|
||||
return template_def.FedoraK8sIronicTemplateDefinition()
|
||||
|
||||
def get_monitor(self, context, cluster):
|
||||
return k8s_monitor.K8sMonitor(context, cluster)
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from magnum.drivers.heat import driver
|
||||
from magnum.drivers.mesos_ubuntu_v1 import monitor
|
||||
from magnum.drivers.mesos_ubuntu_v1 import template_def
|
||||
|
||||
|
||||
@ -28,3 +29,6 @@ class Driver(driver.HeatDriver):
|
||||
|
||||
def get_template_definition(self):
|
||||
return template_def.UbuntuMesosTemplateDefinition()
|
||||
|
||||
def get_monitor(self, context, cluster):
|
||||
return monitor.MesosMonitor(context, cluster)
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from magnum.drivers.heat import driver
|
||||
from magnum.drivers.swarm_fedora_atomic_v1 import monitor
|
||||
from magnum.drivers.swarm_fedora_atomic_v1 import template_def
|
||||
|
||||
|
||||
@ -28,3 +29,6 @@ class Driver(driver.HeatDriver):
|
||||
|
||||
def get_template_definition(self):
|
||||
return template_def.AtomicSwarmTemplateDefinition()
|
||||
|
||||
def get_monitor(self, context, cluster):
|
||||
return monitor.SwarmMonitor(context, cluster)
|
||||
|
@ -16,14 +16,12 @@
|
||||
import mock
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from magnum.conductor import k8s_monitor
|
||||
from magnum.conductor import mesos_monitor
|
||||
from magnum.conductor import monitors
|
||||
from magnum.conductor import swarm_monitor
|
||||
from magnum.drivers.common import k8s_monitor
|
||||
from magnum.drivers.mesos_ubuntu_v1 import monitor as mesos_monitor
|
||||
from magnum.drivers.swarm_fedora_atomic_v1 import monitor as swarm_monitor
|
||||
from magnum import objects
|
||||
from magnum.tests import base
|
||||
from magnum.tests.unit.db import utils
|
||||
from magnum.tests.unit.objects import utils as obj_utils
|
||||
|
||||
|
||||
class MonitorsTestCase(base.TestCase):
|
||||
@ -50,31 +48,13 @@ class MonitorsTestCase(base.TestCase):
|
||||
self.k8s_monitor = k8s_monitor.K8sMonitor(self.context, self.cluster)
|
||||
self.mesos_monitor = mesos_monitor.MesosMonitor(self.context,
|
||||
self.cluster)
|
||||
p = mock.patch('magnum.conductor.swarm_monitor.SwarmMonitor.'
|
||||
'metrics_spec', new_callable=mock.PropertyMock)
|
||||
p = mock.patch('magnum.drivers.swarm_fedora_atomic_v1.monitor.'
|
||||
'SwarmMonitor.metrics_spec',
|
||||
new_callable=mock.PropertyMock)
|
||||
self.mock_metrics_spec = p.start()
|
||||
self.mock_metrics_spec.return_value = self.test_metrics_spec
|
||||
self.addCleanup(p.stop)
|
||||
|
||||
def test_create_monitor_success(self):
|
||||
self.cluster.cluster_template = obj_utils.get_test_cluster_template(
|
||||
self.context, uuid=self.cluster.cluster_template_id, coe='swarm')
|
||||
monitor = monitors.create_monitor(self.context, self.cluster)
|
||||
self.assertIsInstance(monitor, swarm_monitor.SwarmMonitor)
|
||||
|
||||
def test_create_monitor_k8s_cluster(self):
|
||||
self.cluster.cluster_template = obj_utils.get_test_cluster_template(
|
||||
self.context, uuid=self.cluster.cluster_template_id,
|
||||
coe='kubernetes')
|
||||
monitor = monitors.create_monitor(self.context, self.cluster)
|
||||
self.assertIsInstance(monitor, k8s_monitor.K8sMonitor)
|
||||
|
||||
def test_create_monitor_mesos_cluster(self):
|
||||
self.cluster.cluster_template = obj_utils.get_test_cluster_template(
|
||||
self.context, uuid=self.cluster.cluster_template_id, coe='mesos')
|
||||
monitor = monitors.create_monitor(self.context, self.cluster)
|
||||
self.assertIsInstance(monitor, mesos_monitor.MesosMonitor)
|
||||
|
||||
@mock.patch('magnum.common.docker_utils.docker_for_cluster')
|
||||
def test_swarm_monitor_pull_data_success(self, mock_docker_cluster):
|
||||
mock_docker = mock.MagicMock()
|
||||
@ -176,7 +156,7 @@ class MonitorsTestCase(base.TestCase):
|
||||
[{'Memory': 104857600.0, 'Cpu': 0.5}])
|
||||
|
||||
def test_k8s_monitor_get_metric_names(self):
|
||||
k8s_metric_spec = 'magnum.conductor.k8s_monitor.K8sMonitor.'\
|
||||
k8s_metric_spec = 'magnum.drivers.common.k8s_monitor.K8sMonitor.'\
|
||||
'metrics_spec'
|
||||
with mock.patch(k8s_metric_spec,
|
||||
new_callable=mock.PropertyMock) as mock_k8s_metric:
|
||||
@ -185,7 +165,7 @@ class MonitorsTestCase(base.TestCase):
|
||||
self.assertEqual(sorted(['metric1', 'metric2']), sorted(names))
|
||||
|
||||
def test_k8s_monitor_get_metric_unit(self):
|
||||
k8s_metric_spec = 'magnum.conductor.k8s_monitor.K8sMonitor.' \
|
||||
k8s_metric_spec = 'magnum.drivers.common.k8s_monitor.K8sMonitor.'\
|
||||
'metrics_spec'
|
||||
with mock.patch(k8s_metric_spec,
|
||||
new_callable=mock.PropertyMock) as mock_k8s_metric:
|
||||
@ -293,8 +273,8 @@ class MonitorsTestCase(base.TestCase):
|
||||
self._test_mesos_monitor_pull_data(mock_url_get, {}, 0, 0, 0, 0)
|
||||
|
||||
def test_mesos_monitor_get_metric_names(self):
|
||||
mesos_metric_spec = 'magnum.conductor.mesos_monitor.MesosMonitor.'\
|
||||
'metrics_spec'
|
||||
mesos_metric_spec = ('magnum.drivers.mesos_ubuntu_v1.monitor.'
|
||||
'MesosMonitor.metrics_spec')
|
||||
with mock.patch(mesos_metric_spec,
|
||||
new_callable=mock.PropertyMock) as mock_mesos_metric:
|
||||
mock_mesos_metric.return_value = self.test_metrics_spec
|
||||
@ -302,8 +282,8 @@ class MonitorsTestCase(base.TestCase):
|
||||
self.assertEqual(sorted(['metric1', 'metric2']), sorted(names))
|
||||
|
||||
def test_mesos_monitor_get_metric_unit(self):
|
||||
mesos_metric_spec = 'magnum.conductor.mesos_monitor.MesosMonitor.' \
|
||||
'metrics_spec'
|
||||
mesos_metric_spec = ('magnum.drivers.mesos_ubuntu_v1.monitor.'
|
||||
'MesosMonitor.metrics_spec')
|
||||
with mock.patch(mesos_metric_spec,
|
||||
new_callable=mock.PropertyMock) as mock_mesos_metric:
|
||||
mock_mesos_metric.return_value = self.test_metrics_spec
|
||||
|
Loading…
Reference in New Issue
Block a user