Add extra-dhcp-opts test

Create a server with a port using extra-dhcp-opts parameter and check
the opts provided are actually applied to the VM instance

Change-Id: I2670d1fe122bf6736eea4d17c0b360e02272e415
This commit is contained in:
Eduardo Olivares 2021-08-20 13:05:31 +02:00
parent 9287d3b437
commit 4cedbe3c03
6 changed files with 58 additions and 0 deletions

View File

@ -53,6 +53,7 @@ get_neutron_client = _client.get_neutron_client
find_subnet = _client.find_subnet
find_port = _client.find_port
list_ports = _client.list_ports
get_port_extra_dhcp_opts = _client.get_port_extra_dhcp_opts
create_port = _client.create_port
delete_port = _client.delete_port
list_subnets = _client.list_subnets

View File

@ -115,6 +115,11 @@ def list_ports(client=None, **params):
return tobiko.select(ports)
def get_port_extra_dhcp_opts(port_id, client=None, **params):
port = neutron_client(client).show_port(port_id, **params)['port']
return port['extra_dhcp_opts']
NeutronSubnetType = typing.Dict[str, typing.Any]

View File

@ -41,6 +41,8 @@ CirrosSameHostServerStackFixture = _cirros.CirrosSameHostServerStackFixture
RebootCirrosServerOperation = _cirros.RebootCirrosServerOperation
EvacuableCirrosImageFixture = _cirros.EvacuableCirrosImageFixture
EvacuableServerStackFixture = _cirros.EvacuableServerStackFixture
ExtraDhcpOptsCirrosServerStackFixture = (
_cirros.ExtraDhcpOptsCirrosServerStackFixture)
FedoraFlavorStackFixture = _fedora.FedoraFlavorStackFixture
FedoraImageFixture = _fedora.FedoraImageFixture

View File

@ -91,3 +91,7 @@ class EvacuableServerStackFixture(CirrosServerStackFixture):
#: Glance image used to create a Nova server instance
image_fixture = tobiko.required_setup_fixture(EvacuableCirrosImageFixture)
class ExtraDhcpOptsCirrosServerStackFixture(CirrosServerStackFixture):
use_extra_dhcp_opts = True

View File

@ -41,6 +41,11 @@ parameters:
description: Security groups to subscrive server port
default: []
use_extra_dhcp_opts:
type: boolean
description: A set of zero or more extra DHCP option pairs
default: false
has_floating_ip:
type: boolean
description: Whenever server has floating IP associated
@ -72,6 +77,8 @@ conditions:
has_floating_ip:
get_param: has_floating_ip
use_extra_dhcp_opts:
get_param: use_extra_dhcp_opts
resources:
@ -82,6 +89,20 @@ resources:
network: {get_param: network}
port_security_enabled: {get_param: port_security_enabled}
security_groups: {get_param: security_groups}
value_specs:
# TODO(eolivare): I tried a different approach to define
# extra_dhcp_opts, but it did not work: providing a list of
# dictionaries from the python class
# ExtraDhcpOptsCirrosServerStackFixture would have been my preferred
# option but I got the following error from neutron:
# No valid key specs matched for: ...
# Apparently heat does not parse correctly the list of dictionaries and
# instead it provides a list of strings to neutron
extra_dhcp_opts:
if:
- 'use_extra_dhcp_opts'
- [{'opt_name': 'domain-name', 'opt_value': '"tobiko.domain"'}]
- []
server_name:
type: OS::Heat::RandomString

View File

@ -15,6 +15,7 @@
from __future__ import absolute_import
import json
import re
import typing
import netaddr
@ -24,6 +25,7 @@ import testtools
import tobiko
from tobiko.shell import ping
from tobiko.shell import ip
from tobiko.shell import sh
from tobiko.openstack import neutron
from tobiko.openstack import nova
from tobiko.openstack import stacks
@ -195,3 +197,26 @@ class PortLogsTest(testtools.TestCase):
responses_text = ''.join(f'\t{r}\n' for r in responses)
tobiko.fail(f"Unexpected events found after '{name}':\n"
f"{responses_text}")
class ExtraDhcpOptsPortTest(PortTest):
"""Test extra-dhcp-options port parameter"""
stack = tobiko.required_setup_fixture(
stacks.ExtraDhcpOptsCirrosServerStackFixture)
def test_extra_dhcp_opts(self):
extra_dhcp_options = neutron.get_port_extra_dhcp_opts(
self.stack.port_id)
for option in extra_dhcp_options:
if 'domain-name' == option['opt_name']:
domain = option['opt_value'].replace('"', '')
break
else:
tobiko.fail('No extra-dhcp-opt found for domain-name')
vm_resolv_conf = sh.execute('cat /etc/resolv.conf',
ssh_client=self.stack.ssh_client).stdout
self.assertIsNotNone(
re.search(r'^search\s+{domain}$'.format(domain=domain),
vm_resolv_conf,
re.MULTILINE))