OpenStack Testing (Tempest) of an existing cloud
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
4.3 KiB

# Copyright 2013 IBM Corp.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from import base
from tempest.common import utils
from tempest.lib import decorators
class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
"""Test network DHCP agent scheduler extension"""
def skip_checks(cls):
super(DHCPAgentSchedulersTestJSON, cls).skip_checks()
if not utils.is_extension_enabled('dhcp_agent_scheduler', 'network'):
msg = "dhcp_agent_scheduler extension not enabled."
raise cls.skipException(msg)
def resource_setup(cls):
super(DHCPAgentSchedulersTestJSON, cls).resource_setup()
# Create a network and make sure it will be hosted by a
# dhcp agent: this is done by creating a regular port = cls.create_network()
cls.port = cls.create_port(
def test_list_dhcp_agent_hosting_network(self):
"""Test Listing DHCP agents hosting a network"""
def test_list_networks_hosted_by_one_dhcp(self):
"""Test Listing networks hosted by a DHCP agent"""
body = self.admin_networks_client.list_dhcp_agents_on_hosting_network(['id'])
agents = body['agents']
self.assertNotEmpty(agents, "no dhcp agent")
agent = agents[0]
self.assertTrue(self._check_network_in_dhcp_agent(['id'], agent))
def _check_network_in_dhcp_agent(self, network_id, agent):
network_ids = []
body = self.admin_agents_client.list_networks_hosted_by_one_dhcp_agent(
networks = body['networks']
for network in networks:
return network_id in network_ids
def test_add_remove_network_from_dhcp_agent(self):
"""Test adding and removing network from a DHCP agent"""
# The agent is now bound to the network, we can free the port
agent = dict()
agent['agent_type'] = None
body = self.admin_agents_client.list_agents()
agents = body['agents']
for a in agents:
if a['agent_type'] == 'DHCP agent':
agent = a
self.assertEqual(agent['agent_type'], 'DHCP agent', 'Could not find '
'DHCP agent in agent list though dhcp_agent_scheduler'
' is enabled.')
network = self.create_network()
network_id = network['id']
if self._check_network_in_dhcp_agent(network_id, agent):
self._remove_network_from_dhcp_agent(network_id, agent)
self._add_dhcp_agent_to_network(network_id, agent)
self._add_dhcp_agent_to_network(network_id, agent)
self._remove_network_from_dhcp_agent(network_id, agent)
def _remove_network_from_dhcp_agent(self, network_id, agent):
network_id, agent))
def _add_dhcp_agent_to_network(self, network_id, agent):
agent['id'], network_id=network_id)
network_id, agent))