~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/tempest/api/network/admin/test_dhcp_agent_scheduler.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2013 IBM Corp.
 
2
#
 
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
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
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
 
13
#    under the License.
 
14
 
 
15
from neutron.tests.tempest.api.network import base
 
16
from neutron.tests.tempest import test
 
17
 
 
18
 
 
19
class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
 
20
 
 
21
    @classmethod
 
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)
 
33
 
 
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(
 
38
            self.network['id'])
 
39
 
 
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(
 
44
            self.network['id'])
 
45
        agents = body['agents']
 
46
        self.assertIsNotNone(agents)
 
47
        agent = agents[0]
 
48
        self.assertTrue(self._check_network_in_dhcp_agent(
 
49
            self.network['id'], agent))
 
50
 
 
51
    def _check_network_in_dhcp_agent(self, network_id, agent):
 
52
        network_ids = []
 
53
        body = self.admin_client.list_networks_hosted_by_one_dhcp_agent(
 
54
            agent['id'])
 
55
        networks = body['networks']
 
56
        for network in networks:
 
57
            network_ids.append(network['id'])
 
58
        return network_id in network_ids
 
59
 
 
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)
 
66
        agent = dict()
 
67
        agent['agent_type'] = None
 
68
        body = self.admin_client.list_agents()
 
69
        agents = body['agents']
 
70
        for a in agents:
 
71
            if a['agent_type'] == 'DHCP agent':
 
72
                agent = a
 
73
                break
 
74
        self.assertEqual(agent['agent_type'], 'DHCP agent', 'Could not find '
 
75
                         'DHCP agent in agent list though dhcp_agent_scheduler'
 
76
                         ' is enabled.')
 
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)
 
82
        else:
 
83
            self._add_dhcp_agent_to_network(network_id, agent)
 
84
            self._remove_network_from_dhcp_agent(network_id, agent)
 
85
 
 
86
    def _remove_network_from_dhcp_agent(self, network_id, agent):
 
87
        self.admin_client.remove_network_from_dhcp_agent(
 
88
            agent_id=agent['id'],
 
89
            network_id=network_id)
 
90
        self.assertFalse(self._check_network_in_dhcp_agent(
 
91
            network_id, agent))
 
92
 
 
93
    def _add_dhcp_agent_to_network(self, network_id, agent):
 
94
        self.admin_client.add_dhcp_agent_to_network(agent['id'],
 
95
                                                    network_id)
 
96
        self.assertTrue(self._check_network_in_dhcp_agent(
 
97
            network_id, agent))