Create a role for OvS-DPDK host configuration

A new role has been created to initialize DPDK in
openvswitch. Currently, puppet-vswitch module does this
initialization. This role has the functionality in par
with current puppet-vswitch's dpdk implementation.
The goal is to remove the invocation of puppet-vswitch
in two places in THT by replacing it with this role.

Depends-On: https://review.opendev.org/#/c/677726
Change-Id: Ib16face659108aa59878f47e793a6a4991b49636
changes/12/677712/14
Saravanan KR 4 years ago
parent 2f6cc5cdff
commit 2b54427b8b

5
.gitignore vendored

@ -21,4 +21,7 @@ nosetests.xml
*.retry
# roles
tripleo_ansible/roles.galaxy/*
tripleo_ansible/roles.galaxy/*
ansible-errors.json
pytestdebug.log

@ -0,0 +1,100 @@
=======================
Role - tripleo-ovs-dpdk
=======================
Role Documentation
==================
Welcome to the "tripleo-ovs-dpdk" role documentation. This role enables and
configures DPDK in OpenvSwitch.
Requirements
------------
* Ensure hugepages is enabled
Role Defaults
-------------
- ``tripleo_ovs_dpdk_pmd_core_list``
- **Description**: (*Mandatory*) List of PMD Cores for DPDK. Its a
comma-separated string of logical cores.
- **Default**: ``''``
- **Examples**: ``'1,13'``
- ``tripleo_ovs_dpdk_lcore_list``
- **Description**: (*Mandatory*) List of lcores for DPDK. Its a
comma-separated string of logical cores.
- **Default**: ``''``
- **Examples**: ``'0,12'``
- ``tripleo_ovs_dpdk_socket_memory``
- **Description**: (*Mandatory*) Memory in MB to be allocated on each NUMA
node for DPDK. Its a comma-separated string of memory in MB.
- **Default**: ``''``
- **Examples**:
- ``'1024'`` for a single NUMA memory allocation
- ``'1024,1024'`` for a dual NUMA memory allocation
- ``tripleo_ovs_dpdk_memory_channels``
- **Description**: (*Optional*) Number of memory channels in the memory
architecture. Its a number.
- **Default**: ``4``
- ``tripleo_ovs_dpdk_extra``
- **Description**: (*Optional*) Extra parameter to be passed on to DPDK for
initialization. Its a string.
- **Default**: ``''``
- ``tripleo_ovs_dpdk_revalidator_cores``
- **Description**: (*Optional*) Number of cores to he used for revalidator
threads. Its a string with a number, specifying the count of logical cores
to be used as revalidator threads.
- **Default**: ``''``
- **Examples**: ``'2'``
- ``tripleo_ovs_dpdk_handler_cores``
- **Description**: (*Optional*) Number of cores to be used for handler
threads. Its a string with a number, specifying the count of logical cores
to be used as handler threads.
- **Default**: ``''``
- **Examples**: ``'2'``
- ``triploe_ovs_dpdk_emc_insertion_probablity``
- **Description**: (*Optional*) EMC insertion inverse probability. Its a
string with a number of flows (out of which 1 flow will cached). Having
100, results in caching 1 in 100 flows. Having 0, disables EMC cache.
- **Default**: ``''``
- **Examples**: ``'100'``
Modules
-------
- ``openvswitch_db``
- **Description**: It is a ansible core module, which requires additional
changes which are in progress. Below are the pull requests against the
core module. Once these are merged, this module can be removed.
- https://github.com/ansible/ansible/pull/61092
- https://github.com/ansible/ansible/pull/60994
Dependencies
------------
None

@ -0,0 +1,29 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
# All variables intended for modification should place placed in this file.
# All variables within this role should have a prefix of "tripleo_ovs_dpdk"
tripleo_ovs_dpdk_debug: false
tripleo_ovs_dpdk_pmd_core_list: ""
tripleo_ovs_dpdk_lcore_list: ""
tripleo_ovs_dpdk_memory_channels: 4
tripleo_ovs_dpdk_extra: ""
tripleo_ovs_dpdk_socket_memory: ""
tripleo_ovs_dpdk_revalidator_cores: ""
tripleo_ovs_dpdk_handler_cores: ""
tripleo_ovs_dpdk_emc_insertion_probablity: ""

@ -0,0 +1,240 @@
#!/usr/bin/python
# coding: utf-8 -*-
#
# (c) 2015, Mark Hamilton <mhamilton@vmware.com>
# Portions copyright @ 2015 VMware, Inc.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
DOCUMENTATION = """
---
module: openvswitch_db
author: "Mark Hamilton (@markleehamilton) <mhamilton@vmware.com>"
version_added: 2.0
short_description: Configure open vswitch database.
requirements: [ "ovs-vsctl >= 2.3.3" ]
description:
- Set column values in record in database table.
options:
state:
required: false
description:
- Configures the state of the key. When set
to I(present), the I(key) and I(value) pair will be set
on the I(record) and when set to I(absent) the I(key)
will not be set.
default: present
choices: ['present', 'absent']
version_added: "2.4"
table:
required: true
description:
- Identifies the table in the database.
record:
required: true
description:
- Identifies the record in the table.
col:
required: true
description:
- Identifies the column in the record.
key:
required: false
description:
- Identifies the key in the record column, when the column is a map
type.
value:
required: false
description:
- Expected value for the table, record, column and key.
- Required when I(state) is I(present)
timeout:
required: false
default: 5
description:
- How long to wait for ovs-vswitchd to respond
"""
EXAMPLES = '''
# Increase the maximum idle time to 50 seconds before pruning unused kernel
# rules.
- openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: max-idle
value: 50000
# Disable in band copy
- openvswitch_db:
table: Bridge
record: br-int
col: other_config
key: disable-in-band
value: true
# Remove in band key
- openvswitch_db:
state: absent
table: Bridge
record: br-int
col: other_config
key: disable-in-band
# Mark port with tag 10
- openvswitch_db:
table: Port
record: port0
col: tag
value: 10
'''
import re
from ansible.module_utils.basic import AnsibleModule
# Regular expression for map type, must not be empty
NON_EMPTY_MAP_RE = re.compile(r'{.+}')
# Regular expression for a map column type
MAP_RE = re.compile(r'{.*}')
def map_obj_to_commands(want, have, module):
""" Define ovs-vsctl command to meet desired state """
commands = list()
if module.params['state'] == 'absent':
if 'key' in have.keys():
templatized_command = "%(ovs-vsctl)s -t %(timeout)s remove %(table)s %(record)s " \
"%(col)s %(key)s"
# Append the value only when provided
if 'value' in want.keys():
templatized_command += "=%(value)s"
commands.append(templatized_command % module.params)
elif module.params['key'] is None:
templatized_command = "%(ovs-vsctl)s -t %(timeout)s remove %(table)s %(record)s " \
"%(col)s"
commands.append(templatized_command % module.params)
else:
if want == have:
# Nothing to commit
return commands
if module.params['key'] is None:
templatized_command = "%(ovs-vsctl)s -t %(timeout)s set %(table)s %(record)s " \
"%(col)s=%(value)s"
commands.append(templatized_command % module.params)
else:
templatized_command = "%(ovs-vsctl)s -t %(timeout)s set %(table)s %(record)s " \
"%(col)s:%(key)s=%(value)s"
commands.append(templatized_command % module.params)
return commands
def map_config_to_obj(module):
templatized_command = "%(ovs-vsctl)s -t %(timeout)s list %(table)s %(record)s"
command = templatized_command % module.params
rc, out, err = module.run_command(command, check_rc=True)
if rc != 0:
module.fail_json(msg=err)
match = re.search(r'^' + module.params['col'] + r'(\s+):(\s+)(.*)$', out, re.M)
col_value = match.group(3)
# Map types require key argument
has_key = module.params['key'] is not None
is_map = MAP_RE.match(col_value)
if is_map and not has_key:
module.fail_json(
msg="missing required arguments: key for map type of column")
col_value_to_dict = {}
if NON_EMPTY_MAP_RE.match(col_value):
for kv in col_value[1:-1].split(', '):
k, v = kv.split('=', 1)
col_value_to_dict[k.strip()] = v.strip('\"')
obj = {
'table': module.params['table'],
'record': module.params['record'],
'col': module.params['col'],
}
if has_key and is_map:
if module.params['key'] in col_value_to_dict:
obj['key'] = module.params['key']
obj['value'] = col_value_to_dict[module.params['key']]
else:
obj['value'] = str(col_value.strip())
return obj
def map_params_to_obj(module):
obj = {
'table': module.params['table'],
'record': module.params['record'],
'col': module.params['col'],
}
if module.params['value'] is not None:
if module.params['value'] in ['True', 'False']:
module.params['value'] = module.params['value'].lower()
obj['value'] = module.params['value']
key = module.params['key']
if key is not None:
obj['key'] = key
return obj
def main():
""" Entry point for ansible module. """
argument_spec = {
'state': {'default': 'present', 'choices': ['present', 'absent']},
'table': {'required': True},
'record': {'required': True},
'col': {'required': True},
'key': {'required': False},
'value': {'required': False, 'type': 'str'},
'timeout': {'default': 5, 'type': 'int'},
}
required_if = [('state', 'present', ['value'])]
module = AnsibleModule(argument_spec=argument_spec,
required_if=required_if,
supports_check_mode=True)
result = {'changed': False}
# We add ovs-vsctl to module_params to later build up templatized commands
module.params["ovs-vsctl"] = module.get_bin_path("ovs-vsctl", True)
want = map_params_to_obj(module)
have = map_config_to_obj(module)
commands = map_obj_to_commands(want, have, module)
result['commands'] = commands
if commands:
if not module.check_mode:
for c in commands:
module.run_command(c, check_rc=True)
result['changed'] = True
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,44 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
galaxy_info:
author: OpenStack
description: TripleO OpenStack Role -- tripleo-ovs-dpdk
company: Red Hat
license: Apache-2.0
min_ansible_version: 2.7
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: Fedora
versions:
- 28
- name: CentOS
versions:
- 7
galaxy_tags:
- tripleo
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies: []

@ -0,0 +1,42 @@
# Molecule managed
# Copyright 2019 Red Hat, Inc.
# 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.
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install openvswitch python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y openvswitch python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
{% for pkg in item.easy_install | default([]) %}
# install pip for centos where there is no python-pip rpm in default repos
RUN easy_install {{ pkg }}
{% endfor %}
RUN echo $'\n\
mkdir -p /var/log/openvswitch/ \n\
mkdir -p /var/run/openvswitch/ \n\
/usr/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd --no-monitor --system-id=random start \n\
ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid \n\
' > /tmp/ovs_start.sh

@ -0,0 +1,51 @@
---
driver:
name: docker
log: true
platforms:
- name: centos7
hostname: centos7
image: centos:7
dockerfile: Dockerfile
pkg_extras: python-setuptools
easy_install:
- pip
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
override_command: true
command: "bash /tmp/ovs_start.sh"
- name: fedora28
hostname: fedora28
image: fedora:28
dockerfile: Dockerfile
pkg_extras: python*-setuptools
environment:
<<: *env
override_command: true
command: "bash /tmp/ovs_start.sh"
provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
lint:
enabled: false
verifier:
name: testinfra
lint:
name: flake8

@ -0,0 +1,41 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
- name: Prepare for removal
hosts: all
tasks:
- include_role:
name: "tripleo-ovs-dpdk"
tasks_from: "config.yml"
vars:
tripleo_ovs_dpdk_pmd_core_list: "1,13"
tripleo_ovs_dpdk_lcore_list: "0,12"
tripleo_ovs_dpdk_socket_memory: "1024,1024"
tripleo_ovs_dpdk_emc_insertion_probablity: 10
# By removing tripleo_ovs_dpdk_emc_insertion_probablity from the vars,
# which was set by earlier play, should remove this key from the ovs db.
- name: Converge
hosts: all
tasks:
- include_role:
name: "tripleo-ovs-dpdk"
tasks_from: "config.yml"
vars:
tripleo_ovs_dpdk_pmd_core_list: "1,13"
tripleo_ovs_dpdk_lcore_list: "0,12"
tripleo_ovs_dpdk_socket_memory: "1024,1024"

@ -0,0 +1,21 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
- name: Prepare
hosts: all
roles:
- role: test_deps

@ -0,0 +1,73 @@
# Copyright 2019 Red Hat, Inc.
# 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 configparser
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def get_config(host):
stdout = host.check_output('ovs-vsctl get open_vswitch . other_config')
content = '[default]\n' + stdout.replace('{', '').replace('}', '').replace(', ', '\n')
print(content)
cfg = configparser.RawConfigParser()
cfg.read_string(content)
print(dict(cfg['default']))
return dict(cfg['default'])
def test_positive_dpdk_extra(host):
other_config = get_config(host)
dpdk_extra = other_config['dpdk-extra'].replace('"', '')
assert dpdk_extra == " -n 4"
def test_positive_pmd(host):
other_config = get_config(host)
val = other_config['pmd-cpu-mask'].replace('"', '')
assert val == "2002"
def test_positive_lcore(host):
other_config = get_config(host)
val = other_config['dpdk-lcore-mask'].replace('"', '')
assert val == "1001"
def test_positive_socket_mem(host):
other_config = get_config(host)
val = other_config['dpdk-socket-mem'].replace('"', '')
assert val == "1024,1024"
def test_positive_validator_threads(host):
other_config = get_config(host)
assert 'n-revalidator-threads' not in other_config
def test_positive_handler_threads(host):
other_config = get_config(host)
assert 'n-handler-threads' not in other_config
def test_positive_emc_prob(host):
other_config = get_config(host)
assert 'emc-insert-inv-prob' not in other_config

@ -0,0 +1,42 @@
# Molecule managed
# Copyright 2019 Red Hat, Inc.
# 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.
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install openvswitch python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y openvswitch python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
{% for pkg in item.easy_install | default([]) %}
# install pip for centos where there is no python-pip rpm in default repos
RUN easy_install {{ pkg }}
{% endfor %}
RUN echo $'\n\
mkdir -p /var/log/openvswitch/ \n\
mkdir -p /var/run/openvswitch/ \n\
/usr/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd --no-monitor --system-id=random start \n\
ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid \n\
' > /tmp/ovs_start.sh

@ -0,0 +1,51 @@
---
driver:
name: docker
log: true
platforms:
- name: centos7
hostname: centos7
image: centos:7
dockerfile: Dockerfile
pkg_extras: python-setuptools
easy_install:
- pip
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
override_command: true
command: "bash /tmp/ovs_start.sh"
- name: fedora28
hostname: fedora28
image: fedora:28
dockerfile: Dockerfile
pkg_extras: python*-setuptools
environment:
<<: *env
override_command: true
command: "bash /tmp/ovs_start.sh"
provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
lint:
enabled: false
verifier:
name: testinfra
lint:
name: flake8

@ -0,0 +1,32 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
- name: Converge
hosts: all
tasks:
- include_role:
name: "tripleo-ovs-dpdk"
tasks_from: "config.yml"
vars:
tripleo_ovs_dpdk_pmd_core_list: "2,3,26,27,64,65,128,127"
tripleo_ovs_dpdk_lcore_list: "0,1,24,25"
tripleo_ovs_dpdk_memory_channels: 3
tripleo_ovs_dpdk_extra: "--iova-mode=va"
tripleo_ovs_dpdk_socket_memory: "1024,1024"
tripleo_ovs_dpdk_revalidator_cores: 2
tripleo_ovs_dpdk_handler_cores: 2
tripleo_ovs_dpdk_emc_insertion_probablity: 0

@ -0,0 +1,21 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
- name: Prepare
hosts: all
roles:
- role: test_deps

@ -0,0 +1,76 @@
# Copyright 2019 Red Hat, Inc.
# 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 configparser
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def get_config(host):
stdout = host.check_output('ovs-vsctl get open_vswitch . other_config')
content = '[default]\n' + stdout.replace('{', '').replace('}', '').replace(', ', '\n')
print(content)
cfg = configparser.RawConfigParser()
cfg.read_string(content)
print(dict(cfg['default']))
return dict(cfg['default'])
def test_positive_dpdk_extra(host):
other_config = get_config(host)
dpdk_extra = other_config['dpdk-extra'].replace('"', '')
assert dpdk_extra == "--iova-mode=va -n 3"
def test_positive_pmd(host):
other_config = get_config(host)
dpdk_extra = other_config['pmd-cpu-mask'].replace('"', '')
assert dpdk_extra == "18000000000000003000000000c00000c"
def test_positive_lcore(host):
other_config = get_config(host)
dpdk_extra = other_config['dpdk-lcore-mask'].replace('"', '')
assert dpdk_extra == "3000003"
def test_positive_socket_mem(host):
other_config = get_config(host)
dpdk_extra = other_config['dpdk-socket-mem'].replace('"', '')
assert dpdk_extra == "1024,1024"
def test_positive_validator_threads(host):
other_config = get_config(host)
dpdk_extra = other_config['n-revalidator-threads'].replace('"', '')
assert dpdk_extra == "2"
def test_positive_handler_threads(host):
other_config = get_config(host)
dpdk_extra = other_config['n-handler-threads'].replace('"', '')
assert dpdk_extra == "2"
def test_positive_emc_prob(host):
other_config = get_config(host)
dpdk_extra = other_config['emc-insert-inv-prob'].replace('"', '')
assert dpdk_extra == "0"

@ -0,0 +1,30 @@
#!/usr/bin/python
import binascii
from ansible.parsing.yaml.objects import AnsibleUnicode
class FilterModule(object):
def filters(self):
return {
'cpu_mask': self.cpu_mask
}
# Calculate the cpu mask for the list of CPUs
# Example - for input of 1,13 the mask would be 2002
def cpu_mask(self, cpu_list):
mask = 0
cpus = cpu_list.split(',')
cpus = [int(i) for i in cpus]
cpus.sort()
max_val = int(cpus[-1])
byte_arr = bytearray(int(max_val / 8) + 1)
for item in cpus:
pos = int(int(item) / 8)
bit = int(item) % 8
byte_arr[pos] |= 2**bit
byte_arr.reverse()
mask = binascii.hexlify(byte_arr)
return mask.decode("utf-8").lstrip("0")

@ -0,0 +1,123 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
- name: Check valid input for tripleo_ovs_dpdk_pmd_core_list
fail:
msg: "List of PMD cores cannot be empty - tripleo_ovs_dpdk_pmd_core_list"
when: not tripleo_ovs_dpdk_pmd_core_list|string or tripleo_ovs_dpdk_pmd_core_list == 'null'
- name: Check valid input for tripleo_ovs_dpdk_lcore_list
fail:
msg: "List of DPDK lcores cannot be empty - tripleo_ovs_dpdk_lcore_list"
when: not tripleo_ovs_dpdk_lcore_list|string or tripleo_ovs_dpdk_lcore_list == 'null'
- name: Check valid input for tripleo_ovs_dpdk_socket_memory
fail:
msg: "Socket Memory cannot be empty - tripleo_ovs_dpdk_socket_memory"
when: not tripleo_ovs_dpdk_socket_memory|string or tripleo_ovs_dpdk_socket_memory == 'null'
- name: Apply PMD cores config
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: pmd-cpu-mask
value: "{{ tripleo_ovs_dpdk_pmd_core_list | cpu_mask }}"
when: tripleo_ovs_dpdk_pmd_core_list|string
- name: Apply DPDK lcores config
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: dpdk-lcore-mask
value: "{{ tripleo_ovs_dpdk_lcore_list | cpu_mask }}"
when: tripleo_ovs_dpdk_lcore_list|string
- name: Add memory channels to dpdk extra
set_fact:
tripleo_ovs_dpdk_extra_internal: "{{ tripleo_ovs_dpdk_extra }} -n {{ tripleo_ovs_dpdk_memory_channels }}"
- name: Apply DPDK extra
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: dpdk-extra
value: "'{{ tripleo_ovs_dpdk_extra_internal }}'"
- name: Apply socket mem config
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: dpdk-socket-mem
value: "{{ tripleo_ovs_dpdk_socket_memory }}"
when: tripleo_ovs_dpdk_socket_memory|string
- name: Apply Revalidator threads config
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: n-revalidator-threads
value: "{{ tripleo_ovs_dpdk_revalidator_cores }}"
when: tripleo_ovs_dpdk_revalidator_cores|string
- name: Remove Revalidator threads config
openvswitch_db:
state: absent
table: open_vswitch
record: .
col: other_config
key: n-revalidator-threads
when: not tripleo_ovs_dpdk_revalidator_cores|string
- name: Set Handler threads config
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: n-handler-threads
value: "{{ tripleo_ovs_dpdk_handler_cores }}"
when: tripleo_ovs_dpdk_handler_cores|string
- name: Remove Handler threads config
openvswitch_db:
state: absent
table: open_vswitch
record: .
col: other_config
key: n-handler-threads
when: not tripleo_ovs_dpdk_handler_cores|string
- name: Set EMC Insertion Probability config
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: emc-insert-inv-prob
value: "{{ tripleo_ovs_dpdk_emc_insertion_probablity }}"
when: tripleo_ovs_dpdk_emc_insertion_probablity|string
- name: Remove EMC Insertion Probability config
openvswitch_db:
state: absent
table: open_vswitch
record: .
col: other_config
key: emc-insert-inv-prob
when: not tripleo_ovs_dpdk_emc_insertion_probablity|string

@ -0,0 +1,26 @@
---
# Copyright 2019 Red Hat, Inc.
# 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.
- include_tasks: config.yml
- name: Enable DPDK
openvswitch_db:
table: open_vswitch
record: .
col: other_config
key: dpdk-init
value: "true"
timeout: 300

@ -33,6 +33,7 @@
- tripleo-ansible-centos-7-molecule-tripleo-cellv2
- tripleo-ansible-centos-7-molecule-tripleo-clients-install
- tripleo-ansible-centos-7-molecule-tripleo-validations-package
- tripleo-ansible-centos-7-molecule-tripleo-ovs-dpdk
- tripleo-ansible-centos-7-molecule-tripleo-sshd
gate:
jobs:
@ -67,6 +68,7 @@
- tripleo-ansible-centos-7-molecule-tripleo-cellv2
- tripleo-ansible-centos-7-molecule-tripleo-clients-install
- tripleo-ansible-centos-7-molecule-tripleo-validations-package
- tripleo-ansible-centos-7-molecule-tripleo-ovs-dpdk
- tripleo-ansible-centos-7-molecule-tripleo-sshd
name: tripleo-ansible-molecule-jobs
- job:
@ -295,6 +297,13 @@
parent: tripleo-ansible-centos-7-base
vars:
tripleo_role_name: tripleo-validations-package
- job:
files:
- ^tripleo_ansible/roles/tripleo-ovs-dpdk/.*
name: tripleo-ansible-centos-7-molecule-tripleo-ovs-dpdk
parent: tripleo-ansible-centos-7-base
vars:
tripleo_role_name: tripleo-ovs-dpdk
- job:
files:
- ^tripleo_ansible/roles/tripleo-sshd/.*

Loading…
Cancel
Save