Add Qos translator in neutron datasource drive.

Parts that require QoS extension placed in a separate driver.
So that the standard neutronv2_driver continues to work
for environments without the QoS extension.

Implements: blueprint add-qos-in-neutron-datasource-driver.

Change-Id: I3554f3c31f419b85ec27e734147fcb6eb2a81bde
This commit is contained in:
Songming Yan 2017-07-30 15:54:50 +08:00 committed by Eric Kao
parent 1e5ab8ceaf
commit 718b1a9d09
6 changed files with 398 additions and 0 deletions

0
config.py Normal file → Executable file
View File

View File

View File

@ -0,0 +1,68 @@
# 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.
from tempest.lib.services.network import base
class QosPoliciesClient(base.BaseNetworkClient):
def create_qos_policy(self, **kwargs):
"""Creates an OpenStack Networking qos_policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies'
post_data = {'policy': kwargs}
return self.create_resource(uri, post_data)
def update_security_group(self, qos_policy_id, **kwargs):
"""Updates a qos policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s' % qos_policy_id
post_data = {'policy': kwargs}
return self.update_resource(uri, post_data)
def show_qos_policy(self, qos_policy_id, **fields):
"""Shows details for a qos policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s' % qos_policy_id
return self.show_resource(uri, **fields)
def delete_qos_policy(self, qos_policy_id):
"""Deletes an OpenStack Networking qos policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s' % qos_policy_id
return self.delete_resource(uri)
def list_qos_policy(self, **filters):
"""Lists OpenStack Networking qos policies.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies'
return self.list_resources(uri, **filters)

View File

@ -0,0 +1,73 @@
# 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.
from tempest.lib.services.network import base
class QosRuleClient(base.BaseNetworkClient):
def create_qos_rule(self, qos_policy_id, qos_rule_type, **kwargs):
"""Creates an OpenStack Networking qos rule.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s/%s' % (qos_policy_id, qos_rule_type)
post_data = {qos_rule_type[:-1]: kwargs}
return self.create_resource(uri, post_data)
def update_qos_rule(self, qos_policy_id, qos_rule_type,
qos_rule_id, **kwargs):
"""Updates a qos rule policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s/%s/%s' % (qos_policy_id,
qos_rule_type, qos_rule_id)
post_data = {'bandwidth_limit_rules': kwargs}
return self.update_resource(uri, post_data)
def show_qos_rule(self, qos_policy_id, qos_rule_type,
qos_rule_id, **fields):
"""Shows details for a qos rule policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s/%s/%s' % (qos_policy_id,
qos_rule_type, qos_rule_id)
return self.show_resource(uri, **fields)
def delete_qos_rule(self, qos_policy_id, qos_rule_type, qos_rule_id):
"""Deletes an OpenStack Networking qos rule policy.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s/%s/%s' % (qos_policy_id,
qos_rule_type, qos_rule_id)
return self.delete_resource(uri)
def list_qos_rule(self, qos_policy_id, **filters):
"""Lists OpenStack Networking qos rule policies.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/network/v2/index.html#quality-of-service
"""
uri = '/qos/policies/%s' % (qos_policy_id)
return self.list_resources(uri, **filters)

View File

@ -0,0 +1,249 @@
# Copyright 2014 OpenStack Foundation
# All Rights Reserved.
#
# 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.
import time
from tempest import clients
from tempest.common import utils as tempest_utils
from tempest import config
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
from tempest.lib import exceptions
from tempest import test
from congress_tempest_tests.tests.scenario import helper
from congress_tempest_tests.tests.scenario import manager_congress
CONF = config.CONF
RULE_TYPE = "bandwidth_limit_rules"
class TestNeutronV2QosDriver(manager_congress.ScenarioPolicyBase):
DATASOURCE_NAME = 'neutronv2_qos'
@classmethod
def skip_checks(cls):
super(TestNeutronV2QosDriver, cls).skip_checks()
# TODO(qos): check whether QoS extension is enabled
if not (CONF.network.project_networks_reachable
or CONF.network.public_network_id):
msg = ('Either project_networks_reachable must be "true", or '
'public_network_id must be defined.')
cls.enabled = False
raise cls.skipException(msg)
if not CONF.service_available.neutron:
skip_msg = ("%s skipped as neutron is not available"
% cls.__name__)
raise cls.skipException(skip_msg)
if not tempest_utils.is_extension_enabled('qos', 'network'):
skip_msg = ("%s skipped as neutron QoS extension is not available"
% cls.__name__)
raise cls.skipException(skip_msg)
def setUp(self):
super(TestNeutronV2QosDriver, self).setUp()
self.qos_rules = []
self.qos_policies = []
self.os_primary = clients.Manager(
self.os_admin.auth_provider.credentials)
body = {"config": {"username": CONF.auth.admin_username,
"tenant_name": CONF.auth.admin_project_name,
"password": CONF.auth.admin_password,
"auth_url": CONF.identity.uri},
"driver": self.DATASOURCE_NAME,
"name": self.DATASOURCE_NAME}
try:
self.os_admin.congress_client.create_datasource(body)['id']
except exceptions.Conflict:
pass
self.datasource_id = manager_congress.get_datasource_id(
self.os_admin.congress_client, self.DATASOURCE_NAME)
# Get client
self.admin_qos_client = self.os_admin.qos_client
self.admin_qos_rule_client = self.os_admin.qos_rule_client
self.networks_client = self.os_primary.networks_client
self.ports_client = self.os_primary.ports_client
# Create qos and qos rule
self.qos_policy = self._create_qos_policy('test_qos_policy',
description="test",
share=True)
self.qos_rule = self._create_qos_bandwidth_limit_rule(
self.qos_policy['id'], 1000, 1000)
# Associate policy with port
body = self.networks_client.create_network(
name="test_qos_network")
self.network = body["network"]
body = self.ports_client.create_port(
network_id=self.network['id'])
self.port = body["port"]
self.ports_client.update_port(
self.port['id'], qos_policy_id=self.qos_policy['id'])
def tearDown(self):
super(TestNeutronV2QosDriver, self).tearDown()
# Clear port and net
self.ports_client.delete_port(self.port['id'])
self.networks_client.delete_network(self.network["id"])
# Clear qos policy and qos rule
self.admin_qos_rule_client.delete_qos_rule(
self.qos_policy['id'], RULE_TYPE, self.qos_rule['id'])
self.admin_qos_client.delete_qos_policy(self.qos_policy['id'])
def _create_qos_policy(self, name, description=None, share=False):
"""Wrapper utility that returns a test QoS policy."""
body = self.admin_qos_client.create_qos_policy(
name=name, description=description, shared=share)
qos_policy = body['policy']
self.qos_policies.append(qos_policy)
return qos_policy
def _create_qos_bandwidth_limit_rule(self, policy_id, max_kbps,
max_burst_kbps,
direction='egress'):
"""Wrapper utility that returns a test QoS bandwidth limit rule."""
rule_type = RULE_TYPE
body = self.admin_qos_rule_client.create_qos_rule(
policy_id, rule_type,
max_kbps=max_kbps, max_burst_kbps=max_burst_kbps,
direction=direction)
qos_rule = body['bandwidth_limit_rule']
self.qos_rules.append(qos_rule)
return qos_rule
@decorators.attr(type='smoke')
@test.services('network')
def test_neutronv2_ports_tables(self):
port_schema = (
self.os_admin.congress_client.show_datasource_table_schema(
self.datasource_id, 'ports')['columns'])
port_qos_binding_schema = (
self.os_admin.congress_client.show_datasource_table_schema(
self.datasource_id, 'qos_policy_port_bindings')['columns'])
qos_policy_schema = (
self.os_admin.congress_client.show_datasource_table_schema(
self.datasource_id, 'policies')['columns'])
qos_rule_schema = (
self.os_admin.congress_client.show_datasource_table_schema(
self.datasource_id, 'rules')['columns'])
@helper.retry_on_exception
def _check_data_for_port():
ports_from_neutron = self.ports_client.list_ports()
port_map = {}
for port in ports_from_neutron['ports']:
port_map[port['id']] = port
client = self.os_admin.congress_client
client.request_refresh(self.datasource_id)
time.sleep(1)
ports = (client.list_datasource_rows(self.datasource_id, 'ports'))
qos_policy_port_bindings = (
client.list_datasource_rows(
self.datasource_id, 'qos_policy_port_bindings'))
# Validate ports table
for row in ports['results']:
port_row = port_map[row['data'][0]]
for index in range(len(port_schema)):
if (str(row['data'][index]) !=
str(port_row[port_schema[index]['name']])):
return False
# validate qos_policy_port_bindings table
for row in qos_policy_port_bindings['results']:
port_row = port_map[row['data'][0]]
for index in range(len(port_qos_binding_schema)):
row_index = port_qos_binding_schema[index]['name']
# Translate port_id -> id
if row_index == 'port_id':
if (str(row['data'][index]) !=
str(port_row['id'])):
return False
elif row_index == 'qos_policy_id':
if (str(row['data'][index]) not in
port_row['policies']):
return False
return True
@helper.retry_on_exception
def _check_data_for_qos():
qos_from_neutron = self.admin_qos_client.list_qos_policy()
rule_from_neutron = self.admin_qos_rule_client.list_qos_rule(
self.qos_policy['id'])
policy_map = {}
rule_map = {}
for policy in qos_from_neutron['policies']:
policy_map[policy['id']] = policy
for rule in rule_from_neutron['policy']['rules']:
rule_map[self.qos_policy['id']] = rule
client = self.os_admin.congress_client
client.request_refresh(self.datasource_id)
time.sleep(1)
qos_policies = (client.list_datasource_rows(
self.datasource_id, 'policies'))
qos_rules = (client.list_datasource_rows(
self.datasource_id, 'rules'))
# Validate policies table
for row in qos_policies['results']:
policy_row = policy_map[row['data'][0]]
for index in range(len(qos_policy_schema)):
if (str(row['data'][index]) !=
str(policy_row[qos_policy_schema[index]['name']])):
return False
# Validate rules table
for row in qos_rules['results']:
rule_row = rule_map[row['data'][0]]
for index in range(len(qos_rule_schema)):
if str(row['data'][index]) != "None":
if (str(row['data'][index]) !=
str(rule_row[qos_rule_schema[index]['name']])):
return False
return True
if not test_utils.call_until_true(func=_check_data_for_port,
duration=200, sleep_for=10):
raise exceptions.TimeoutException("Data did not converge in time "
"or failure in server")
if not test_utils.call_until_true(func=_check_data_for_qos,
duration=200, sleep_for=10):
raise exceptions.TimeoutException("Data did not converge in time "
"or failure in server")
@decorators.attr(type='smoke')
def test_update_no_error(self):
if not test_utils.call_until_true(
func=lambda: self.check_datasource_no_error(
self.DATASOURCE_NAME),
duration=30, sleep_for=5):
raise exceptions.TimeoutException('Datasource could not poll '
'without error.')

8
tests/scenario/manager_congress.py Normal file → Executable file
View File

@ -22,6 +22,8 @@ from tempest import config
from tempest.lib.common.utils import data_utils
from tempest import manager as tempestmanager
from congress_tempest_tests.services.congress_network import qos_client
from congress_tempest_tests.services.congress_network import qos_rule_client
from congress_tempest_tests.services.policy import policy_client
# use local copy of tempest scenario manager during upstream refactoring
from congress_tempest_tests.tests.scenario import manager
@ -57,6 +59,12 @@ class ScenarioPolicyBase(manager.NetworkScenarioTest):
cls.os_admin.congress_client = policy_client.PolicyClient(
auth_prov, "policy", CONF.identity.region)
cls.os_admin.qos_client = qos_client.QosPoliciesClient(
auth_prov, "network", CONF.identity.region)
cls.os_admin.qos_rule_client = qos_rule_client.QosRuleClient(
auth_prov, "network", CONF.identity.region)
# Get telemtery_client
if getattr(CONF.service_available, 'ceilometer', False):
import ceilometer.tests.tempest.service.client as telemetry_client