Skip to content

Commit

Permalink
device: add DHCP step
Browse files Browse the repository at this point in the history
  • Loading branch information
bloom1 authored and fblackburn1 committed Dec 17, 2024
1 parent 4078e29 commit 28e0421
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions wazo_acceptance/helpers/provd.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def delete_device(self, device_id):
except ProvdError:
pass

def get_device_by_mac(self, mac):
return self._find_by('mac', mac)

def delete_device_with_mac(self, mac):
device = self._find_by('mac', mac)
if device:
Expand Down
27 changes: 27 additions & 0 deletions wazo_acceptance/steps/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import requests
from behave import given, step, then, when
from scapy.all import BOOTP, DHCP, IP, UDP, Ether, conf, srp1


@given('there are devices with infos')
Expand Down Expand Up @@ -31,6 +32,23 @@ def when_the_following_devices_are_created_via_http_requets_to_the_provisioning_
context.helpers.provd.create_device_via_http_request(**body)


@step('the following devices are created via DHCP requests')
def when_the_following_devices_are_created_via_dhcp_requests(context):
conf.checkIPaddr = False
dhcp_discover = Ether(dst='ff:ff:ff:ff:ff:ff') / IP(src='0.0.0.0', dst='255.255.255.255') / UDP(sport=68, dport=67)
for row in context.table:
body = row.as_dict()
vci = body['vci']
mac = body['mac']

mac_parts = mac.split(':')
mac_binary = bytes([int(part, base=16) for part in mac_parts])

dhcp_discover_device = dhcp_discover / BOOTP(chaddr=mac_binary) / DHCP(options=[('message-type', 'discover'), ('vendor_class_id', vci), 'end'])
result = srp1(dhcp_discover_device)
assert result is not None


@then('the following provisioning files are available over HTTP using port "{port}"')
def then_the_following_provisioning_files_are_available_over_http_using_port(context, port):
host = context.wazo_config['provd']['provisioning_host']
Expand All @@ -45,6 +63,15 @@ def then_the_following_provisioning_files_are_available_over_https(context):
_provisioning_files_are_available(context, base_url)


@then('the following devices exist on wazo-provd')
def then_the_following_devices_exist_on_wazo_provd(context):
for row in context.table:
body = row.as_dict()
mac = body['mac']
provd_result = context.helpers.provd.get_by_mac(mac)
assert provd_result is not None


@then('the following provisioning files are available over HTTPS using provisioning key "{provisioning_key}"')
def then_the_following_provisioning_files_are_available_over_https_using_key(context, provisioning_key):
host = context.wazo_config['provd']['provisioning_host']
Expand Down

0 comments on commit 28e0421

Please sign in to comment.