Agent get configuration from database

This commit is contained in:
Ofer Ben-Yacov 2017-01-24 14:07:32 +02:00
parent 65ea68466f
commit 8807e8d3e5
7 changed files with 50 additions and 10 deletions

View File

@ -19,6 +19,7 @@ import oslo_messaging as messaging
from neutron import context as ctx
from neutron import manager
from neutron_lib import exceptions
from wan_qos.agent import tc_driver
from wan_qos.common import api
@ -59,6 +60,18 @@ class TcAgentManager(manager.Manager):
'max_rate': self.conf.WANTC.wan_max_rate
}
self.agent.set_root_queue(tc_dict)
agent_conf = self.plugin_rpc.get_configuration_from_db(
ctx.get_admin_context())
class_tree = agent_conf['class_tree']
if class_tree['id'] == 'root':
self.init_child_classes(class_tree['child_list'])
return
raise exceptions.InvalidInput(error_message='Did not get root class')
def init_child_classes(self, child_list):
for child in child_list:
self.create_wtc_class(None, child)
self.init_child_classes(child['child_list'])
def after_start(self):
LOG.info("WAN QoS agent started")
@ -88,6 +101,5 @@ class TcAgentManager(manager.Manager):
class_dict['port_side'] = 'wan_port'
self._create_wtc_class(class_dict)
def _create_wtc_class(self, class_dict):
self.agent.create_traffic_class(class_dict)

View File

@ -38,6 +38,7 @@ def upgrade():
nullable=False),
sa.Column('project_id', sa.String(length=36)),
sa.Column('class_ext_id', sa.Integer()),
sa.Column('parent_class_ext_id', sa.Integer()),
sa.Column('min', sa.String(length=15)),
sa.Column('max', sa.String(length=15)),
sa.PrimaryKeyConstraint('id')

View File

@ -41,6 +41,7 @@ class WanTcClass(model_base.BASEV2,
sa.ForeignKey('wan_tc_class.id',
ondelete='CASCADE'),
nullable=True)
parent_class_ext_id = sa.Column(sa.Integer)
min = sa.Column(sa.String(15))
max = sa.Column(sa.String(15))

View File

@ -113,16 +113,16 @@ class WanTcDb(object):
class_ext_id=self.get_last_class_ext_id(context)
)
parent_class_ext_id = 1
if 'parent' in wtc_class:
if wtc_class['parent'] != '':
parent = wtc_class['parent']
parent_class = self.get_class_by_id(context, parent)
if not parent_class:
raise exceptions.BadRequest(msg='invalid parent id')
wtc_class_db.parent = parent
parent_class_ext_id = parent_class['class_ext_id']
wtc_class_db.parent_class_ext_id = parent_class['class_ext_id']
else:
wtc_class_db.parent = 'root'
wtc_class_db.parent_class_ext_id = 1
with context.session.begin(subtransactions=True):
@ -133,7 +133,7 @@ class WanTcDb(object):
context.session.add(wtc_class_db)
class_dict = self._class_to_dict(wtc_class_db)
class_dict['parent_class_ext_id'] = parent_class_ext_id
class_dict['parent_class_ext_id'] = wtc_class_db.parent_class_ext_id
return class_dict
def delete_wtc_class(self, context, id):
@ -165,7 +165,8 @@ class WanTcDb(object):
'min': wtc_class.min,
'max': wtc_class.max,
'class_ext_id': wtc_class.class_ext_id,
'parent': wtc_class.parent
'parent': wtc_class.parent,
'parent_class_ext_id': wtc_class.parent_class_ext_id
}
return class_dict

View File

@ -49,6 +49,13 @@ class PluginRpcCallback(object):
def device_heartbeat(self, context, host):
self.plugin.db.device_heartbeat(context, host)
def get_configuration_from_db(self, context, host):
conf = {
'class_tree': self.plugin.db.get_class_tree()
}
return conf
class WanQosPlugin(wanqos.WanQosPluginBase,
wantcdevice.WanTcDevicePluginBase,

View File

@ -5,7 +5,7 @@ from neutron.tests.unit import testlib_api
from oslo_config import cfg
from wan_qos.db import wan_qos_db
from wan_qos.services import plugin
class TestTcDb(testlib_api.SqlTestCase):
def setUp(self):
@ -49,3 +49,22 @@ class TestTcDb(testlib_api.SqlTestCase):
wtc_class['max'] = max
return self.db.create_wan_tc_class(self.context, wtc_class)
class TestPlugin(testlib_api.SqlTestCase):
def setUp(self):
super(TestPlugin, self).setUp()
self.plugin = plugin.WanQosPlugin()
def test_create_class(self):
wtc_class = {
'wan_tc_class': {
'direction': 'both',
'min': '1mbit'
}
}
wan_tc = self.plugin.create_wan_tc_class(ctx.get_admin_context(), wtc_class)
assert wan_tc is not None
print (wan_tc)

View File

@ -23,7 +23,7 @@ from wan_qos.agent import tc_manager
from wan_qos.services import plugin
WANTC_group = cfg.OptGroup(name='WANTC',
title='WAN QoS options')
title='WAN QoS options')
opts = [
cfg.StrOpt('lan_port_name',
@ -145,7 +145,6 @@ class TestApiMessages(base.BaseTestCase):
super(TestApiMessages, self).setUp()
cfg.CONF.register_group(WANTC_group)
cfg.CONF.register_opts(opts, group='WANTC')
self.plugin = plugin.WANTCPlugin()
self.plugin = plugin.WanQosPlugin()