Skip to content

Commit

Permalink
CI: removed duplicated code from the...
Browse files Browse the repository at this point in the history
rate limiting related tests.

Signed-off-by: Diana Popa <[email protected]>
  • Loading branch information
dianpopa authored and acatangiu committed Oct 29, 2018
1 parent 27bf269 commit ddcaa19
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 114 deletions.
20 changes: 15 additions & 5 deletions tests/framework/microvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,14 @@ def basic_config(
)
assert self._api_session.is_good_response(response.status_code)

def ssh_network_config(self, network_config, iface_id,
allow_mmds_requests=False):
def ssh_network_config(
self,
network_config,
iface_id,
allow_mmds_requests=False,
tx_rate_limiter=None,
rx_rate_limiter=None
):
"""Create a host tap device and a guest network interface.
'network_config' is used to generate 2 IPs: one for the tap device
Expand All @@ -371,8 +377,10 @@ def ssh_network_config(self, network_config, iface_id,
:param allow_mmds_requests: specifies whether requests sent from
the guest on this interface towards the MMDS address are
intercepted and processed by the device model.
:param tx_rate_limiter: limit the tx rate
:param rx_rate_limiter: limit the rx rate
:return: an instance of the tap which needs to be kept around until
cleanup is desired.
cleanup is desired, the configured guest and host ips, respectively.
"""
# Create tap before configuring interface.
tapname = self.id[:8] + 'tap' + iface_id
Expand All @@ -391,12 +399,14 @@ def ssh_network_config(self, network_config, iface_id,
iface_id=iface_id,
host_dev_name=tapname,
guest_mac=guest_mac,
allow_mmds_requests=allow_mmds_requests
allow_mmds_requests=allow_mmds_requests,
tx_rate_limiter=tx_rate_limiter,
rx_rate_limiter=rx_rate_limiter
)
assert self._api_session.is_good_response(response.status_code)

self.ssh_config['hostname'] = guest_ip
return tap
return tap, host_ip, guest_ip

def start(self):
"""Start the microvm.
Expand Down
5 changes: 4 additions & 1 deletion tests/host_tools/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ class Tap:
def __init__(self, name, netns, ip=None):
"""Set up the name and network namespace for this tap interface.
It also creates a new tap device, and brings it up.
It also creates a new tap device, and brings it up. The tap will
stay on the host as long as the object obtained by instantiating this
class will be in scope. Once it goes out of scope, its destructor will
get called and the tap interface will get removed.
The function also moves the interface to the specified
namespace.
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/integration_tests/functional/test_cpu_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_1vcpu(test_microvm_with_ssh, network_config):
# added after we get a unique MAC and IP.
test_microvm.basic_config(vcpu_count=1)

_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')
test_microvm.start()
expected_cpu_topology = {
"CPU(s)": "1",
Expand All @@ -38,7 +38,7 @@ def test_2vcpu_ht_disabled(test_microvm_with_ssh, network_config):
# added after we get a unique MAC and IP.
test_microvm.basic_config(vcpu_count=2, ht_enabled=False)

_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')

test_microvm.start()

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_brand_string(test_microvm_with_ssh, network_config):
test_microvm.spawn()

test_microvm.basic_config(vcpu_count=1)
_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')
test_microvm.start()

ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
Expand Down
10 changes: 5 additions & 5 deletions tests/integration_tests/functional/test_drives.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_rescan(test_microvm_with_ssh, network_config):
# added after we get a unique MAC and IP.
test_microvm.basic_config()

_tap = test_microvm_with_ssh.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm_with_ssh.ssh_network_config(network_config, '1')

# Add a scratch block device.
fs = drive_tools.FilesystemFile(
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_non_partuuid_boot(test_microvm_with_ssh, network_config):
# added after we get a unique MAC and IP.
test_microvm.basic_config(vcpu_count=1)

_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')

# Add another read-only block device.
fs = drive_tools.FilesystemFile(
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_partuuid_boot(test_microvm_with_partuuid, network_config):
add_root_device=False
)

_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')

# Add the root block device specified through PARTUUID.
response = test_microvm.drive.put(
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_partuuid_update(test_microvm_with_ssh, network_config):
add_root_device=False
)

_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')

# Add the root block device specified through PARTUUID.
response = test_microvm.drive.put(
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_patch_drive(test_microvm_with_ssh, network_config):
# file system with the rw permission, and a scratch drive.
test_microvm.basic_config()

_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')

fs1 = drive_tools.FilesystemFile(
os.path.join(test_microvm.fsfiles, 'scratch')
Expand Down
6 changes: 5 additions & 1 deletion tests/integration_tests/functional/test_mmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def test_mmds(test_microvm_with_ssh, network_config):
# a root file system with the rw permission. The network interface is
# added after we get a unique MAC and IP.
test_microvm.basic_config(vcpu_count=1)
_tap = test_microvm.ssh_network_config(network_config, '1', True)
_tap = test_microvm.ssh_network_config(
network_config,
'1',
allow_mmds_requests=True
)

test_microvm.start()

Expand Down
142 changes: 45 additions & 97 deletions tests/integration_tests/functional/test_rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,68 +42,41 @@ def test_tx_rate_limiting(test_microvm_with_ssh, network_config):

iface_id = '1'
# Create tap before configuring interface.
tapname = test_microvm.id[:8] + 'tap' + iface_id
(host_ip, guest_ip) = network_config.get_next_available_ips(2)
tap1 = net_tools.Tap(tapname, test_microvm.jailer.netns, ip="{}/{}".format(
host_ip,
network_config.get_netmask_len()
))
guest_mac = net_tools.mac_from_ip(guest_ip)

response = test_microvm.network.put(
iface_id=iface_id,
host_dev_name=tap1.name,
guest_mac=guest_mac
_tap1, host_ip, guest_ip = test_microvm.ssh_network_config(
network_config,
iface_id
)
assert test_microvm.api_session.is_good_response(response.status_code)
guest_ips[0] = guest_ip
host_ips[0] = host_ip

iface_id = '2'
tapname = test_microvm.id[:8] + 'tap' + iface_id
(host_ip, guest_ip) = network_config.get_next_available_ips(2)
tap2 = net_tools.Tap(tapname, test_microvm.jailer.netns, ip="{}/{}".format(
host_ip,
network_config.get_netmask_len()
))
guest_mac = net_tools.mac_from_ip(guest_ip)

response = test_microvm.network.put(
iface_id=iface_id,
host_dev_name=tap2.name,
guest_mac=guest_mac,
tx_rate_limiter={
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'refill_time': RATE_LIMIT_REFILL_TIME
}
tx_rate_limiter_no_burst = {
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'refill_time': RATE_LIMIT_REFILL_TIME
}
}
_tap2, host_ip, guest_ip = test_microvm.ssh_network_config(
network_config,
iface_id,
tx_rate_limiter=tx_rate_limiter_no_burst
)
assert test_microvm.api_session.is_good_response(response.status_code)
guest_ips[1] = guest_ip
host_ips[1] = host_ip

iface_id = '3'
tapname = test_microvm.id[:8] + 'tap' + iface_id
(host_ip, guest_ip) = network_config.get_next_available_ips(2)
tap3 = net_tools.Tap(tapname, test_microvm.jailer.netns, ip="{}/{}".format(
host_ip,
network_config.get_netmask_len()
))
guest_mac = net_tools.mac_from_ip(guest_ip)
response = test_microvm.network.put(
iface_id=iface_id,
host_dev_name=tap3.name,
guest_mac=guest_mac,
tx_rate_limiter={
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'one_time_burst': BURST_SIZE,
'refill_time': RATE_LIMIT_REFILL_TIME
}
tx_rate_limiter_with_burst = {
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'one_time_burst': BURST_SIZE,
'refill_time': RATE_LIMIT_REFILL_TIME
}
}
_tap3, host_ip, guest_ip = test_microvm.ssh_network_config(
network_config,
iface_id,
tx_rate_limiter=tx_rate_limiter_with_burst
)
assert test_microvm.api_session.is_good_response(response.status_code)
guest_ips[2] = guest_ip
host_ips[2] = host_ip

Expand All @@ -128,66 +101,41 @@ def test_rx_rate_limiting(test_microvm_with_ssh, network_config):

iface_id = '1'
# Create tap before configuring interface.
tapname = test_microvm.id[:8] + 'tap' + iface_id
(host_ip, guest_ip) = network_config.get_next_available_ips(2)
tap1 = net_tools.Tap(tapname, test_microvm.jailer.netns, ip="{}/{}".format(
host_ip,
network_config.get_netmask_len()
))
guest_mac = net_tools.mac_from_ip(guest_ip)
response = test_microvm.network.put(
iface_id=iface_id,
host_dev_name=tap1.name,
guest_mac=guest_mac
_tap1, host_ip, guest_ip = test_microvm.ssh_network_config(
network_config,
iface_id
)
assert test_microvm.api_session.is_good_response(response.status_code)
guest_ips[0] = guest_ip
host_ips[0] = host_ip

iface_id = '2'
tapname = test_microvm.id[:8] + 'tap' + iface_id
(host_ip, guest_ip) = network_config.get_next_available_ips(2)
tap2 = net_tools.Tap(tapname, test_microvm.jailer.netns, ip="{}/{}".format(
host_ip,
network_config.get_netmask_len()
))
guest_mac = net_tools.mac_from_ip(guest_ip)
response = test_microvm.network.put(
iface_id=iface_id,
host_dev_name=tap2.name,
guest_mac=guest_mac,
rx_rate_limiter={
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'refill_time': RATE_LIMIT_REFILL_TIME
}
}
rx_rate_limiter_no_burst = {
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'refill_time': RATE_LIMIT_REFILL_TIME
}
}
_tap2, host_ip, guest_ip = test_microvm.ssh_network_config(
network_config,
iface_id,
rx_rate_limiter=rx_rate_limiter_no_burst
)
assert test_microvm.api_session.is_good_response(response.status_code)
guest_ips[1] = guest_ip
host_ips[1] = host_ip

iface_id = '3'
tapname = test_microvm.id[:8] + 'tap' + iface_id
(host_ip, guest_ip) = network_config.get_next_available_ips(2)
tap3 = net_tools.Tap(tapname, test_microvm.jailer.netns, ip="{}/{}".format(
host_ip,
network_config.get_netmask_len()
))
guest_mac = net_tools.mac_from_ip(guest_ip)
response = test_microvm.network.put(
iface_id=iface_id,
host_dev_name=tap3.name,
guest_mac=guest_mac,
rx_rate_limiter={
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'one_time_burst': BURST_SIZE,
'refill_time': RATE_LIMIT_REFILL_TIME
}
rx_rate_limiter_no_burst = {
'bandwidth': {
'size': RATE_LIMIT_BYTES,
'one_time_burst': BURST_SIZE,
'refill_time': RATE_LIMIT_REFILL_TIME
}
}
_tap3, host_ip, guest_ip = test_microvm.ssh_network_config(
network_config,
iface_id,
rx_rate_limiter=rx_rate_limiter_no_burst
)
assert test_microvm.api_session.is_good_response(response.status_code)
guest_ips[2] = guest_ip
host_ips[2] = host_ip

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/functional/test_shut_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_reboot(test_microvm_with_ssh, network_config):
# a root file system with the rw permission. The network interfaces is
# added after we get a unique MAC and IP.
test_microvm.basic_config(vcpu_count=4)
_tap = test_microvm.ssh_network_config(network_config, '1')
_tap, _, _ = test_microvm.ssh_network_config(network_config, '1')

test_microvm.start()

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/performance/test_boottime.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _test_microvm_boottime(
mem_size_mib=1024
)
if net_config:
_tap = microvm.ssh_network_config(net_config, '1')
_tap, _, _ = microvm.ssh_network_config(net_config, '1')

# Configure logging.
log_fifo_path = os.path.join(microvm.path, 'log_fifo')
Expand Down

0 comments on commit ddcaa19

Please sign in to comment.