Skip to content

Commit

Permalink
[py.test/TestbedProcessing] Fixes for py.test (#1257)
Browse files Browse the repository at this point in the history
Tried to run test_bgp_speaker and faces some issues

- missed "ptf" in testbed
- missed --module-path= in pytest_cmd
- inventory_file contains absolute path not relative
- dut.host.options["inventory_manager"].get_vars failed with undefined method
  • Loading branch information
msosyak authored and lguohan committed Dec 10, 2019
1 parent df45ee3 commit 2723722
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions ansible/TestbedProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def makeSonicLabDevices(data, outfile):
error handling: checks if attribute values are None type or string "None"
"""
def makeTestbed(data, outfile):
csv_columns = "# conf-name,group-name,topo,ptf_image_name,ptf_ip,server,vm_base,dut,comment"
csv_columns = "# conf-name,group-name,topo,ptf_image_name,ptf_ip,server,vm_base,dut,ptf,comment"
topology = data
csv_file = outfile

Expand All @@ -213,6 +213,7 @@ def makeTestbed(data, outfile):
server = groupDetails.get("server")
vm_base = groupDetails.get("vm_base")
dut = groupDetails.get("dut")
ptf = groupDetails.get("ptf")
comment = groupDetails.get("comment")

# catch empty types
Expand All @@ -230,10 +231,12 @@ def makeTestbed(data, outfile):
vm_base = ""
if not dut:
dut = ""
if not ptf:
ptf = ""
if not comment:
comment = ""

row = confName + "," + groupName + "," + topo + "," + ptf_image_name + "," + ptf_ip + "," + server + "," + vm_base + "," + dut + "," + comment
row = confName + "," + groupName + "," + topo + "," + ptf_image_name + "," + ptf_ip + "," + server + "," + vm_base + "," + dut + "," + ptf + "," + comment
f.write(row + "\n")
except IOError:
print("I/O error: issue creating testbed.csv")
Expand Down Expand Up @@ -571,4 +574,4 @@ def main():

if __name__ == '__main__':
main()

6 changes: 5 additions & 1 deletion ansible/roles/test/tasks/pytest_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

- name: append inventory file
set_fact:
pytest_cmd: '{{ pytest_cmd }} --inventory=../ansible/{{ inventory_file }}'
pytest_cmd: '{{ pytest_cmd }} --inventory={{ inventory_file }}'

- name: append testbed file
set_fact:
Expand All @@ -45,6 +45,10 @@
set_fact:
pytest_cmd: '{{ pytest_cmd }} --host-pattern={{ testbed_name }}'

- name: append module path
set_fact:
pytest_cmd: '{{ pytest_cmd }} --module-path=../ansible/library'

- name: append verbosity flag
set_fact:
pytest_cmd: '{{ pytest_cmd }} -v'
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def testbed_devices(ansible_adhoc, testbed):
# when no ptf defined in testbed.csv
# try to parse it from inventory
dut = devices["dut"]
ptf_host = dut.host.options["inventory_manager"].get_vars(dut.hostname)["ptf_host"]
ptf_host = dut.host.options["inventory_manager"].get_host(dut.hostname).get_vars()["ptf_host"]
devices["ptf"] = PTFHost(ansible_adhoc, ptf_host)

# In the future, we can implement more classes for interacting with other testbed devices in the lib.devices
Expand Down

0 comments on commit 2723722

Please sign in to comment.