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:
parent
9287d3b437
commit
4cedbe3c03
|
@ -53,6 +53,7 @@ get_neutron_client = _client.get_neutron_client
|
||||||
find_subnet = _client.find_subnet
|
find_subnet = _client.find_subnet
|
||||||
find_port = _client.find_port
|
find_port = _client.find_port
|
||||||
list_ports = _client.list_ports
|
list_ports = _client.list_ports
|
||||||
|
get_port_extra_dhcp_opts = _client.get_port_extra_dhcp_opts
|
||||||
create_port = _client.create_port
|
create_port = _client.create_port
|
||||||
delete_port = _client.delete_port
|
delete_port = _client.delete_port
|
||||||
list_subnets = _client.list_subnets
|
list_subnets = _client.list_subnets
|
||||||
|
|
|
@ -115,6 +115,11 @@ def list_ports(client=None, **params):
|
||||||
return tobiko.select(ports)
|
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]
|
NeutronSubnetType = typing.Dict[str, typing.Any]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ CirrosSameHostServerStackFixture = _cirros.CirrosSameHostServerStackFixture
|
||||||
RebootCirrosServerOperation = _cirros.RebootCirrosServerOperation
|
RebootCirrosServerOperation = _cirros.RebootCirrosServerOperation
|
||||||
EvacuableCirrosImageFixture = _cirros.EvacuableCirrosImageFixture
|
EvacuableCirrosImageFixture = _cirros.EvacuableCirrosImageFixture
|
||||||
EvacuableServerStackFixture = _cirros.EvacuableServerStackFixture
|
EvacuableServerStackFixture = _cirros.EvacuableServerStackFixture
|
||||||
|
ExtraDhcpOptsCirrosServerStackFixture = (
|
||||||
|
_cirros.ExtraDhcpOptsCirrosServerStackFixture)
|
||||||
|
|
||||||
FedoraFlavorStackFixture = _fedora.FedoraFlavorStackFixture
|
FedoraFlavorStackFixture = _fedora.FedoraFlavorStackFixture
|
||||||
FedoraImageFixture = _fedora.FedoraImageFixture
|
FedoraImageFixture = _fedora.FedoraImageFixture
|
||||||
|
|
|
@ -91,3 +91,7 @@ class EvacuableServerStackFixture(CirrosServerStackFixture):
|
||||||
|
|
||||||
#: Glance image used to create a Nova server instance
|
#: Glance image used to create a Nova server instance
|
||||||
image_fixture = tobiko.required_setup_fixture(EvacuableCirrosImageFixture)
|
image_fixture = tobiko.required_setup_fixture(EvacuableCirrosImageFixture)
|
||||||
|
|
||||||
|
|
||||||
|
class ExtraDhcpOptsCirrosServerStackFixture(CirrosServerStackFixture):
|
||||||
|
use_extra_dhcp_opts = True
|
||||||
|
|
|
@ -41,6 +41,11 @@ parameters:
|
||||||
description: Security groups to subscrive server port
|
description: Security groups to subscrive server port
|
||||||
default: []
|
default: []
|
||||||
|
|
||||||
|
use_extra_dhcp_opts:
|
||||||
|
type: boolean
|
||||||
|
description: A set of zero or more extra DHCP option pairs
|
||||||
|
default: false
|
||||||
|
|
||||||
has_floating_ip:
|
has_floating_ip:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: Whenever server has floating IP associated
|
description: Whenever server has floating IP associated
|
||||||
|
@ -72,6 +77,8 @@ conditions:
|
||||||
has_floating_ip:
|
has_floating_ip:
|
||||||
get_param: has_floating_ip
|
get_param: has_floating_ip
|
||||||
|
|
||||||
|
use_extra_dhcp_opts:
|
||||||
|
get_param: use_extra_dhcp_opts
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
|
|
||||||
|
@ -82,6 +89,20 @@ resources:
|
||||||
network: {get_param: network}
|
network: {get_param: network}
|
||||||
port_security_enabled: {get_param: port_security_enabled}
|
port_security_enabled: {get_param: port_security_enabled}
|
||||||
security_groups: {get_param: security_groups}
|
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:
|
server_name:
|
||||||
type: OS::Heat::RandomString
|
type: OS::Heat::RandomString
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
@ -24,6 +25,7 @@ import testtools
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.shell import ping
|
from tobiko.shell import ping
|
||||||
from tobiko.shell import ip
|
from tobiko.shell import ip
|
||||||
|
from tobiko.shell import sh
|
||||||
from tobiko.openstack import neutron
|
from tobiko.openstack import neutron
|
||||||
from tobiko.openstack import nova
|
from tobiko.openstack import nova
|
||||||
from tobiko.openstack import stacks
|
from tobiko.openstack import stacks
|
||||||
|
@ -195,3 +197,26 @@ class PortLogsTest(testtools.TestCase):
|
||||||
responses_text = ''.join(f'\t{r}\n' for r in responses)
|
responses_text = ''.join(f'\t{r}\n' for r in responses)
|
||||||
tobiko.fail(f"Unexpected events found after '{name}':\n"
|
tobiko.fail(f"Unexpected events found after '{name}':\n"
|
||||||
f"{responses_text}")
|
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))
|
||||||
|
|
Loading…
Reference in New Issue