1
# Copyright 2013 IBM Corp.
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
15
from neutron.tests.tempest.api.network import base
16
from neutron.tests.tempest import test
19
class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
22
def resource_setup(cls):
23
super(DHCPAgentSchedulersTestJSON, cls).resource_setup()
24
if not test.is_extension_enabled('dhcp_agent_scheduler', 'network'):
25
msg = "dhcp_agent_scheduler extension not enabled."
26
raise cls.skipException(msg)
27
# Create a network and make sure it will be hosted by a
28
# dhcp agent: this is done by creating a regular port
29
cls.network = cls.create_network()
30
cls.subnet = cls.create_subnet(cls.network)
31
cls.cidr = cls.subnet['cidr']
32
cls.port = cls.create_port(cls.network)
34
@test.attr(type='smoke')
35
@test.idempotent_id('5032b1fe-eb42-4a64-8f3b-6e189d8b5c7d')
36
def test_list_dhcp_agent_hosting_network(self):
37
self.admin_client.list_dhcp_agent_hosting_network(
40
@test.attr(type='smoke')
41
@test.idempotent_id('30c48f98-e45d-4ffb-841c-b8aad57c7587')
42
def test_list_networks_hosted_by_one_dhcp(self):
43
body = self.admin_client.list_dhcp_agent_hosting_network(
45
agents = body['agents']
46
self.assertIsNotNone(agents)
48
self.assertTrue(self._check_network_in_dhcp_agent(
49
self.network['id'], agent))
51
def _check_network_in_dhcp_agent(self, network_id, agent):
53
body = self.admin_client.list_networks_hosted_by_one_dhcp_agent(
55
networks = body['networks']
56
for network in networks:
57
network_ids.append(network['id'])
58
return network_id in network_ids
60
@test.attr(type='smoke')
61
@test.idempotent_id('a0856713-6549-470c-a656-e97c8df9a14d')
62
def test_add_remove_network_from_dhcp_agent(self):
63
# The agent is now bound to the network, we can free the port
64
self.client.delete_port(self.port['id'])
65
self.ports.remove(self.port)
67
agent['agent_type'] = None
68
body = self.admin_client.list_agents()
69
agents = body['agents']
71
if a['agent_type'] == 'DHCP agent':
74
self.assertEqual(agent['agent_type'], 'DHCP agent', 'Could not find '
75
'DHCP agent in agent list though dhcp_agent_scheduler'
77
network = self.create_network()
78
network_id = network['id']
79
if self._check_network_in_dhcp_agent(network_id, agent):
80
self._remove_network_from_dhcp_agent(network_id, agent)
81
self._add_dhcp_agent_to_network(network_id, agent)
83
self._add_dhcp_agent_to_network(network_id, agent)
84
self._remove_network_from_dhcp_agent(network_id, agent)
86
def _remove_network_from_dhcp_agent(self, network_id, agent):
87
self.admin_client.remove_network_from_dhcp_agent(
89
network_id=network_id)
90
self.assertFalse(self._check_network_in_dhcp_agent(
93
def _add_dhcp_agent_to_network(self, network_id, agent):
94
self.admin_client.add_dhcp_agent_to_network(agent['id'],
96
self.assertTrue(self._check_network_in_dhcp_agent(