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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/openvswitch/test_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:
18
18
import datetime
19
19
 
20
20
import mock
21
 
from oslo.config import cfg
22
 
from oslo.db import exception as db_exc
23
 
from oslo import messaging
24
 
from oslo.utils import timeutils
 
21
from oslo_config import cfg
 
22
from oslo_db import exception as db_exc
 
23
import oslo_messaging
 
24
from oslo_utils import timeutils
25
25
from webob import exc
26
26
 
27
27
from neutron.api import extensions
32
32
from neutron.common import constants
33
33
from neutron import context
34
34
from neutron.db import agents_db
 
35
from neutron.db import agentschedulers_db
35
36
from neutron.db import l3_agentschedulers_db
36
37
from neutron.extensions import agent
37
38
from neutron.extensions import dhcpagentscheduler
478
479
        self._delete('ports', port2['port']['id'])
479
480
        self.assertEqual(0, len(dhcp_agents['agents']))
480
481
 
 
482
    def test_is_eligible_agent(self):
 
483
        agent_startup = ('neutron.db.agentschedulers_db.'
 
484
                         'DhcpAgentSchedulerDbMixin.agent_starting_up')
 
485
        is_eligible_agent = ('neutron.db.agentschedulers_db.'
 
486
                             'AgentSchedulerDbMixin.is_eligible_agent')
 
487
        dhcp_mixin = agentschedulers_db.DhcpAgentSchedulerDbMixin()
 
488
        with contextlib.nested(
 
489
            mock.patch(agent_startup),
 
490
            mock.patch(is_eligible_agent)
 
491
        ) as (startup, elig):
 
492
            tests = [(True, True),
 
493
                     (True, False),
 
494
                     (False, True),
 
495
                     (False, False)]
 
496
            for rv1, rv2 in tests:
 
497
                startup.return_value = rv1
 
498
                elig.return_value = rv2
 
499
                self.assertEqual(rv1 or rv2,
 
500
                                 dhcp_mixin.is_eligible_agent(None,
 
501
                                                              None, None))
 
502
 
481
503
    def test_network_scheduler_with_down_agent(self):
482
504
        dhcp_hosta = {
483
505
            'binary': 'neutron-dhcp-agent',
488
510
                               },
489
511
            'agent_type': constants.AGENT_TYPE_DHCP}
490
512
        self._register_one_agent_state(dhcp_hosta)
491
 
        is_agent_down_str = 'neutron.db.agents_db.AgentDbMixin.is_agent_down'
492
 
        with mock.patch(is_agent_down_str) as mock_is_agent_down:
493
 
            mock_is_agent_down.return_value = False
 
513
        eligible_agent_str = ('neutron.db.agentschedulers_db.'
 
514
                              'DhcpAgentSchedulerDbMixin.is_eligible_agent')
 
515
        with mock.patch(eligible_agent_str) as eligible_agent:
 
516
            eligible_agent.return_value = True
494
517
            with self.port() as port:
495
518
                dhcp_agents = self._list_dhcp_agents_hosting_network(
496
519
                    port['port']['network_id'])
497
520
            self._delete('ports', port['port']['id'])
498
521
            self._delete('networks', port['port']['network_id'])
499
522
            self.assertEqual(1, len(dhcp_agents['agents']))
500
 
        with mock.patch(is_agent_down_str) as mock_is_agent_down:
501
 
            mock_is_agent_down.return_value = True
 
523
 
 
524
        with mock.patch(eligible_agent_str) as eligible_agent:
 
525
            eligible_agent.return_value = False
502
526
            with self.port() as port:
503
527
                dhcp_agents = self._list_dhcp_agents_hosting_network(
504
528
                    port['port']['network_id'])
663
687
            mock.patch.object(
664
688
                plugin, 'reschedule_router',
665
689
                side_effect=[
666
 
                    db_exc.DBError(), messaging.RemoteError(),
 
690
                    db_exc.DBError(), oslo_messaging.RemoteError(),
667
691
                    l3agentscheduler.RouterReschedulingFailed(router_id='f',
668
692
                                                              agent_id='f'),
669
693
                    ValueError('this raises')
1150
1174
                expected_code=exc.HTTPForbidden.code,
1151
1175
                admin_context=False)
1152
1176
 
 
1177
    def test_list_routers_hosted_by_l3_agent_with_invalid_agent(self):
 
1178
        invalid_agentid = 'non_existing_agent'
 
1179
        self._list_routers_hosted_by_l3_agent(invalid_agentid,
 
1180
                                              exc.HTTPNotFound.code)
 
1181
 
 
1182
    def test_list_networks_hosted_by_dhcp_agent_with_invalid_agent(self):
 
1183
        invalid_agentid = 'non_existing_agent'
 
1184
        self._list_networks_hosted_by_dhcp_agent(invalid_agentid,
 
1185
                                                 exc.HTTPNotFound.code)
 
1186
 
1153
1187
 
1154
1188
class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
1155
1189
                                   test_agent_ext_plugin.AgentDBTestMixIn,
1258
1292
                    host),
1259
1293
                mock.call(
1260
1294
                    mock.ANY,
 
1295
                    'subnet_create_end',
 
1296
                    subnet,
 
1297
                    host, 'dhcp_agent'),
 
1298
                mock.call(
 
1299
                    mock.ANY,
1261
1300
                    'port_create_end',
1262
1301
                    {'port': port['port']},
1263
1302
                    host, 'dhcp_agent')]