Skip to content

Commit 7882db5

Browse files
authored
[testbed]: support python3 and ubuntu 20.04 (#1771)
Need to move kvm testbed infrastructure to ubuntu 20.04 to support kvm save/restore, which is important to repro testbed issues. Signed-off-by: Guohan Lu <gulv@microsoft.com>
1 parent df043e4 commit 7882db5

7 files changed

Lines changed: 55 additions & 26 deletions

File tree

ansible/roles/vm_set/library/ceos_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def cmd(cmdline):
207207

208208
with open(cmd_debug_fname, 'a') as fp:
209209
pprint("OUTPUT: %s" % stdout, fp)
210-
return stdout
210+
return stdout.decode('utf-8')
211211

212212
@staticmethod
213213
def get_ovs_br_ports(bridge):

ansible/roles/vm_set/library/kvm_port.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ def main():
2929

3030
try:
3131
output = subprocess.check_output(
32-
"virsh domiflist %s" % vmname,
33-
env={"LIBVIRT_DEFAULT_URI": "qemu:///system"},
34-
shell=True)
32+
"virsh domiflist %s" % vmname,
33+
env={"LIBVIRT_DEFAULT_URI": "qemu:///system"},
34+
shell=True).decode('utf-8')
3535
except subprocess.CalledProcessError:
3636
module.fail_json(msg="failed to iflist dom %s" % vmname)
3737

3838
mgmt_port = None
3939
fp_ports = []
4040

4141
for l in output.split('\n'):
42-
fds = re.split('\s+', l)
42+
fds = re.split('\s+', l.lstrip())
4343
if len(fds) != 5:
4444
continue
4545
if fds[1] == "ethernet":

ansible/roles/vm_set/library/sonic_kickstart.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, port, debug):
4242
self.d = debug
4343
self.d.debug('Starting')
4444
self.tn = Telnet('127.0.0.1', port)
45-
self.tn.write('\r\n')
45+
self.tn.write(b"\r\n")
4646

4747
return
4848

@@ -62,9 +62,9 @@ def cleanup(self):
6262
def pair(self, action, wait_for, timeout=60):
6363
self.d.debug('output: %s' % action)
6464
self.d.debug('match: %s' % ",".join(wait_for))
65-
self.tn.write("%s\n" % action)
65+
self.tn.write(b"%s\n" % action.encode('ascii'))
6666
if wait_for is not None:
67-
index, match, text = self.tn.expect(wait_for, timeout)
67+
index, match, text = self.tn.expect([ x.encode('ascii') for x in wait_for ], timeout)
6868
self.d.debug('Result of matching: %d %s %s' % (index, str(match), text))
6969
if index == -1:
7070
raise EMatchNotFound
@@ -154,7 +154,7 @@ def main():
154154
result = {'kickstart_code': -1, 'changed': False, 'msg': 'EOF during the chat'}
155155
except EMatchNotFound:
156156
result = {'kickstart_code': -1, 'changed': False, 'msg': "Match for output isn't found"}
157-
except Exception, e:
157+
except Exception as e:
158158
module.fail_json(msg=str(e))
159159

160160
module.exit_json(**result)

ansible/roles/vm_set/library/vm_topology.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ def init(self, vm_set_name, topo, vm_base, dut_fp_ports, ptf_exists=True):
128128
self.vm_base_index = self.vm_names.index(vm_base)
129129
else:
130130
raise Exception('VM_base "%s" should be presented in current vm_names: %s' % (vm_base, str(self.vm_names)))
131-
for k, v in topo['VMs'].iteritems():
131+
for k, v in topo['VMs'].items():
132132
if self.vm_base_index + v['vm_offset'] < len(self.vm_names):
133133
self.VMs[k] = v
134134

135-
for hostname, attrs in self.VMs.iteritems():
135+
for hostname, attrs in self.VMs.items():
136136
vmname = self.vm_names[self.vm_base_index + attrs['vm_offset']]
137137
if len(attrs['vlans']) > len(self.get_bridges(vmname)):
138138
raise Exception("Wrong vlans parameter for hostname %s, vm %s. Too many vlans. Maximum is %d" % (hostname, vmname, len(self.get_bridges(vmname))))
139-
139+
140140
if 'host_interfaces' in topo:
141141
self.host_interfaces = topo['host_interfaces']
142142
else:
@@ -180,14 +180,14 @@ def update(self):
180180

181181
def extract_vm_vlans(self):
182182
vlans = []
183-
for attr in self.VMs.itervalues():
183+
for attr in self.VMs.values():
184184
vlans.extend(attr['vlans'])
185185

186186
return vlans
187187

188188
def create_bridges(self):
189189
for vm in self.vm_names:
190-
for fp_num in xrange(self.max_fp_num):
190+
for fp_num in range(self.max_fp_num):
191191
fp_br_name = OVS_FP_BRIDGE_TEMPLATE % (vm, fp_num)
192192
self.create_ovs_bridge(fp_br_name, self.fp_mtu)
193193

@@ -358,7 +358,7 @@ def unbind_mgmt_port(self, mgmt_port):
358358
return
359359

360360
def bind_fp_ports(self, disconnect_vm=False):
361-
for attr in self.VMs.itervalues():
361+
for attr in self.VMs.values():
362362
for vlan_num, vlan in enumerate(attr['vlans']):
363363
injected_iface = INJECTED_INTERFACES_TEMPLATE % (self.vm_set_name, vlan)
364364
br_name = OVS_FP_BRIDGE_TEMPLATE % (self.vm_names[self.vm_base_index + attr['vm_offset']], vlan_num)
@@ -368,7 +368,7 @@ def bind_fp_ports(self, disconnect_vm=False):
368368
return
369369

370370
def unbind_fp_ports(self):
371-
for attr in self.VMs.itervalues():
371+
for attr in self.VMs.values():
372372
for vlan_num, vlan in enumerate(attr['vlans']):
373373
br_name = OVS_FP_BRIDGE_TEMPLATE % (self.vm_names[self.vm_base_index + attr['vm_offset']], vlan_num)
374374
vm_iface = OVS_FP_TAP_TEMPLATE % (self.vm_names[self.vm_base_index + attr['vm_offset']], vlan_num)
@@ -385,7 +385,7 @@ def bind_vm_backplane(self):
385385

386386
self.update()
387387

388-
for attr in self.VMs.itervalues():
388+
for attr in self.VMs.values():
389389
vm_name = self.vm_names[self.vm_base_index + attr['vm_offset']]
390390
bp_port_name = OVS_BP_TAP_TEMPLATE % vm_name
391391

@@ -517,7 +517,7 @@ def cmd(cmdline):
517517

518518
with open(cmd_debug_fname, 'a') as fp:
519519
pprint("OUTPUT: %s" % stdout, fp)
520-
return stdout
520+
return stdout.decode('utf-8')
521521

522522
@staticmethod
523523
def get_ovs_br_ports(bridge):
@@ -556,7 +556,7 @@ def get_ovs_port_bindings(bridge, vlan_iface = None):
556556
if vlan_iface is None or vlan_iface in result:
557557
return result
558558
time.sleep(2*retries+1)
559-
# Flow reaches here when vlan_iface not present in result
559+
# Flow reaches here when vlan_iface not present in result
560560
raise Exception("Can't find vlan_iface_id")
561561

562562
@staticmethod
@@ -637,7 +637,7 @@ def check_topo(topo):
637637
if not isinstance(VMs, dict):
638638
raise Exception("topo['VMs'] should be a dictionary")
639639

640-
for hostname, attrs in VMs.iteritems():
640+
for hostname, attrs in VMs.items():
641641
if 'vlans' not in attrs or not isinstance(attrs['vlans'], list):
642642
raise Exception("topo['VMs']['%s'] should contain 'vlans' with a list of vlans" % hostname)
643643

ansible/roles/vm_set/tasks/docker.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
become: yes
2525
when: host_distribution_version.stdout == "18.04"
2626

27+
- name: Add docker repository for 20.04
28+
apt_repository:
29+
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
30+
state: present
31+
become: yes
32+
when: host_distribution_version.stdout == "20.04"
33+
2734
- name: Install docker-ce
2835
apt: pkg=docker-ce update_cache=yes
2936
become: yes
@@ -32,7 +39,12 @@
3239
- name: Get default pip_executable
3340
set_fact:
3441
pip_executable: pip
35-
when: pip_executable is not defined
42+
when: pip_executable is not defined and host_distribution_version.stdout != "20.04"
43+
44+
- name: Get default pip_executable
45+
set_fact:
46+
pip_executable: pip3
47+
when: pip_executable is not defined and host_distribution_version.stdout == "20.04"
3648

3749
- name: remove old python packages
3850
pip: name=docker-py state=absent executable={{ pip_executable }}

ansible/roles/vm_set/tasks/main.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,38 @@
5959
become: yes
6060
with_items:
6161
- ifupdown
62-
- python
6362
- qemu
6463
- openvswitch-switch
6564
- net-tools
6665
- bridge-utils
6766
- util-linux
6867
- iproute2
6968
- vlan
70-
- libvirt-bin
71-
- python-libvirt
72-
- python-pip
7369
- apt-transport-https
7470
- ca-certificates
7571
- curl
7672
- software-properties-common
73+
- libvirt-clients
74+
75+
- name:
76+
apt:
77+
pkg:
78+
- python
79+
- libvirt-bin
80+
- python-libvirt
81+
- python-pip
82+
become: yes
83+
when: host_distribution_version.stdout == "18.04"
84+
85+
- name:
86+
apt:
87+
pkg:
88+
- python3-libvirt
89+
- python3-pip
90+
- libvirt-daemon-system
91+
- qemu-system-x86
92+
become: yes
93+
when: host_distribution_version.stdout == "20.04"
7794

7895
- include_tasks: docker.yml
7996

ansible/roles/vm_set/templates/sonic.xml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<partition>/machine</partition>
88
</resource>
99
<os>
10-
<type arch='x86_64' machine='pc-i440fx-1.5'>hvm</type>
10+
<type arch='x86_64' machine='q35'>hvm</type>
1111
<boot dev='hd'/>
1212
</os>
1313
<features>

0 commit comments

Comments
 (0)