From e5ceb3a99c373481e58a47210f14780a672f8b22 Mon Sep 17 00:00:00 2001 From: Dave Kasberg Date: Thu, 2 Mar 2017 08:08:49 -0800 Subject: [PATCH] Fix for cnos.py utility file for Python3.5 (#21750) * fix in cnos.py utility file * fix compile errors in cnos.py, update module short description in cnos_vlan.py, move vlan roles under integration/roles * corrections in readme * Change module directory name to Lenovo * change import cnos statement --- lib/ansible/module_utils/cnos.py | 9 ++++++--- lib/ansible/modules/network/{cnos => lenovo}/__init__.py | 0 .../modules/network/{cnos => lenovo}/cnos_vlan.py | 4 ++-- test/integration/roles/cnos_vlan/README.md | 2 +- test/integration/roles/cnos_vlan/tasks/main.yml | 8 ++++++++ 5 files changed, 17 insertions(+), 6 deletions(-) rename lib/ansible/modules/network/{cnos => lenovo}/__init__.py (100%) rename lib/ansible/modules/network/{cnos => lenovo}/cnos_vlan.py (98%) diff --git a/lib/ansible/module_utils/cnos.py b/lib/ansible/module_utils/cnos.py index 0338fabe7a..c469e2c2bc 100644 --- a/lib/ansible/module_utils/cnos.py +++ b/lib/ansible/module_utils/cnos.py @@ -3118,7 +3118,7 @@ def enterEnableModeForDevice(enablePassword, timeout, obj): flag = False retVal = "" count = 5 - while (flag is False): + while not flag: # If wait time is execeeded. if(count == 0): flag = True @@ -3168,7 +3168,7 @@ def waitForDeviceResponse(command, prompt, timeout, obj): obj.send(command) flag = False retVal = "" - while (flag is False): + while not flag: time.sleep(1) try: buffByte = obj.recv(9999) @@ -3179,7 +3179,10 @@ def waitForDeviceResponse(command, prompt, timeout, obj): if(gotit != -1): flag = True except: - retVal = retVal + "\n Error-101" + if prompt != "(yes/no)?": + retVal = retVal + "\n Error-101" + else: + retVal = retVal flag = True return retVal # EOM diff --git a/lib/ansible/modules/network/cnos/__init__.py b/lib/ansible/modules/network/lenovo/__init__.py similarity index 100% rename from lib/ansible/modules/network/cnos/__init__.py rename to lib/ansible/modules/network/lenovo/__init__.py diff --git a/lib/ansible/modules/network/cnos/cnos_vlan.py b/lib/ansible/modules/network/lenovo/cnos_vlan.py similarity index 98% rename from lib/ansible/modules/network/cnos/cnos_vlan.py rename to lib/ansible/modules/network/lenovo/cnos_vlan.py index c7b513cfaa..9bdcf33ae0 100644 --- a/lib/ansible/modules/network/cnos/cnos_vlan.py +++ b/lib/ansible/modules/network/lenovo/cnos_vlan.py @@ -30,7 +30,7 @@ ANSIBLE_METADATA = {'status': ['preview'], DOCUMENTATION = ''' --- module: cnos_vlan -short_description: Performs VLAN switch configuration and state management. +short_description: Manage VLAN resources and attributes on devices running Lenovo CNOS description: - This module allows you to work with VLAN related configurations. The operators used are overloaded to ensure control over switch VLAN @@ -196,7 +196,7 @@ import time import re try: - import cnos + from ansible.module_utils import cnos HAS_LIB = True except: HAS_LIB = False diff --git a/test/integration/roles/cnos_vlan/README.md b/test/integration/roles/cnos_vlan/README.md index 35e89792ca..7deb238783 100644 --- a/test/integration/roles/cnos_vlan/README.md +++ b/test/integration/roles/cnos_vlan/README.md @@ -67,7 +67,7 @@ Variable | Description Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up. -Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The hosts file for the role is located in the main directory of the multiple layer vLAG configuration solution. +Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory. ``` [cnos_vlan_sample] diff --git a/test/integration/roles/cnos_vlan/tasks/main.yml b/test/integration/roles/cnos_vlan/tasks/main.yml index 0d19e68555..6409f8196c 100644 --- a/test/integration/roles/cnos_vlan/tasks/main.yml +++ b/test/integration/roles/cnos_vlan/tasks/main.yml @@ -3,27 +3,35 @@ - name: Test Vlan - Create a vlan, name it cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' with_items: "{{cnos_vlan_data1}}" + - name: Test Vlan - Create a vlan, Flood configuration cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' with_items: "{{cnos_vlan_data2}}" + - name: Test Vlan - Create a vlan, State configuration cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' with_items: "{{cnos_vlan_data3}}" + - name: Test Vlan - VLAN Access map1 cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' with_items: "{{cnos_vlan_data4}}" + - name: Test Vlan - VLAN Accep Map2 cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}' with_items: "{{cnos_vlan_data5}}" + - name: Test Vlan - ip igmp snooping query interval cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}' with_items: "{{cnos_vlan_data6}}" + - name: Test Vlan - ip igmp snooping last member query interval cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}' with_items: "{{cnos_vlan_data7}}" + - name: Test Vlan - ip igmp snooping mrouter interface port-aggregation cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}' vlanArg5='{{item.vlanArg5}}' with_items: "{{cnos_vlan_data8}}" + - name: Idempotent Command cnos_command: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} clicommand='{{item.clicommand}}' outputfile=./results/cnos_command_{{ inventory_hostname }}_output.txt with_items: "{{cnos_vlan_data9}}"