Skip to content

Commit

Permalink
Turn advanced mode for dpdk interfaces by default
Browse files Browse the repository at this point in the history
This patchset will make sure, that topology module
is run with 'advanced' mode for dpdk interfaces, so
that no multiple runs required in mixed deployments.

Change-Id: I26692c7b5ddf6d8bdacf1925d25c7a5e476f06cb
  • Loading branch information
Vlad Gridin committed Oct 8, 2020
1 parent 2acbf39 commit 93f2a5d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
35 changes: 30 additions & 5 deletions nuage_topology_collector/library/bridgeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,39 @@ def __init__(self, module):

def _get_ovsdb_client(self, module):
try:
from ovsdbapp.backend.ovs_idl import command
from ovsdbapp.backend.ovs_idl import connection
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp.schema.open_vswitch import impl_idl
except ImportError as e:
self.module.log(msg=str(e))
self.module.fail_json(msg="ovsdbapp module is required")

class GetIfaceCommand(command.ReadOnlyCommand):
def __init__(self, api, iface):
super(GetIfaceCommand, self).__init__(api)
self.iface = iface

def run_idl(self, txn):
iface = idlutils.row_by_value(self.api.idl,
'Interface',
'name',
self.iface)
self.result = iface

class TcOvsdbIdl(impl_idl.OvsdbIdl):
def __init__(self, connection):
super(TcOvsdbIdl, self).__init__(connection)

def get_iface(self, iface):
return GetIfaceCommand(self, iface)

endpoint = ("tcp:%(host)s:%(port)s" % module.params)
client = None
try:
idl = connection.OvsdbIdl.from_server(endpoint, 'Open_vSwitch')
connection = connection.Connection(idl=idl, timeout=3)
client = impl_idl.OvsdbIdl(connection)
client = TcOvsdbIdl(connection)
except Exception as e:
self.module.fail_json(msg=("could not connect to openvswitch. "
"error: %s") % str(e))
Expand All @@ -103,13 +124,17 @@ def check_linux_bond(self, iface):
def get_ovs_topology(self):
ovs_topology = dict()
bridges = self.ovsdbclient.list_br().execute(check_error=True)

for br in bridges:
ifaces = self.ovsdbclient.list_ifaces(br).execute(check_error=True)
for iface in ifaces:
bond_slaves = self.check_linux_bond(iface)
for ifname in ifaces:
bond_slaves = self.check_linux_bond(ifname)
for slave in bond_slaves:
ovs_topology[slave] = br
ovs_topology[iface] = br
ovs_topology[slave] = {'bridge': br, 'dpdk': False}
iface = self.ovsdbclient.get_iface(ifname).execute(
check_error=True)
ovs_topology[ifname] = {'bridge': br,
'dpdk': iface.type == 'dpdk'}
return ovs_topology


Expand Down
12 changes: 9 additions & 3 deletions nuage_topology_collector/library/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,14 @@ def clean_lldp_config(ovsdbapi, interface, bridge, module):
pname = 'lldp.' + interface
params = {
'prefix': "sudo " if os.getlogin() != "root" else "",
'lldptool': module.get_bin_path("lldptool", True),
'ofctl': module.get_bin_path("ovs-ofctl", True),
'ovsif': pname,
'br': bridge,
}
command = ("%(prefix)s %(lldptool)s set-lldp -i %(ovsif)s "
"adminStatus=disabled" % params)
module.run_command(command, check_rc=True)
command = ("%(prefix)s %(ofctl)s del-flows %(br)s "
"dl_dst=01:80:c2:00:00:0e" % params)
module.run_command(command, check_rc=True)
Expand Down Expand Up @@ -327,7 +332,7 @@ def main():
host=dict(type='str', required=False, default='127.0.0.1'),
port=dict(type='str', required=False, default='6640'),
advanced_mode=dict(type='bool', required=False, default=False),
lldp_poll_delay=dict(type='int', required=False, default=5)
lldp_poll_delay=dict(type='int', required=False, default=30)
)

module = AnsibleModule(argument_spec=arg_spec)
Expand All @@ -347,12 +352,13 @@ def main():
if advanced_mode:
ovsdb_client = get_ovsdb_client(module)
itf = prepare_itf_for_lldp(ovsdb_client, interface, ovs_bridge, module)

time.sleep(lldp_poll_delay)
time.sleep(lldp_poll_delay)

lldpcmd = prefix + "%s -t -n -i %s" % (LLDPTOOL, itf)

lldprc, lldpout, lldperr = module.run_command(lldpcmd)
module.log("cmd: {} cmdout: {}".format(lldpcmd, lldpout))

if lldperr is None:
lldperr = ''
if lldpout is None:
Expand Down
29 changes: 20 additions & 9 deletions nuage_topology_collector/roles/topology/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
interface_list: "{{ interfaces | union(ovs_topology.keys() | list) }}"

- name: Display interface list when verbosity >= 1, skip otherwise
debug: msg="{{ interface_list }}" verbosity=1
debug:
msg: "{{ interface_list }}"
verbosity: 1

- name: Ensure lldpad
become: true
Expand All @@ -68,31 +70,38 @@
service:
name: lldpad
enabled: yes
state: started
state: restarted

- name: Configure lldpad
become: true
command: lldptool set-lldp -i {{ item }} adminStatus=rx
with_items: "{{ interface_list }}"
when:
- "'dpdk' not in item"
- not ovs_advanced_mode|default(False)
- ovs_topology[item] is not defined or not ovs_topology[item]['dpdk']

- name: Allow lldpad see packets
pause:
seconds: "{{ lldp_poll_delay | default(30) }}"

- name: Execute topology collector
vars:
brdict: "{{ ovs_topology[item] | default({}) }}"
topology:
system_name: "{{ inventory_hostname }}"
interface: "{{ item }}"
ovs_bridge: "{{ ovs_topology[item] | default(omit) }}"
ovs_bridge: "{{ brdict['bridge'] | default(omit) }}"
host: "{{ ovs_manager_ip | default(omit) }}"
port: "{{ ovs_manager_port | default(omit) }}"
advanced_mode: "{{ ovs_advanced_mode | default(False) }}"
lldp_poll_delay: "{{ lldp_poll_delay | default(5) }}"
advanced_mode: "{{ ovs_topology[item] is defined and ovs_topology[item]['dpdk'] }}"
lldp_poll_delay: "{{ lldp_poll_delay | default(30) }}"
with_items: "{{ interface_list }}"
register: interface_json
ignore_errors: yes

- name: Display topology json when verbosity >= 1, skip otherwise
debug: msg="{{ interface_json }}" verbosity=1
debug:
msg: "{{ interface_json }}"
verbosity: 1

- name: Create output file name
set_fact: json_outfile={{ temp_dir }}/{{ inventory_hostname }}.json
Expand All @@ -102,4 +111,6 @@
delegate_to: 127.0.0.1

- name: Print out the contents of the json output file when verbosity >= 1, skip otherwise
debug: msg="{{ lookup('file', '{{ json_outfile }}') }}" verbosity=1
debug:
msg: "{{ lookup('file', '{{ json_outfile }}') }}"
verbosity: 1
3 changes: 1 addition & 2 deletions nuage_topology_collector/user_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
remote_usr: heat-admin
osc_env_file: /home/stack/overcloudrc
undercloud_env_file : /home/stack/stackrc
lldp_poll_delay: 5
lldp_poll_delay: 30
# ovs_manager_ip: 127.0.0.1
# ovs_manager_port: 6640
# ovs_advanced_mode: False

0 comments on commit 93f2a5d

Please sign in to comment.