コード例 #1
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_get_agent_by_host(self):
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     agent = l2pop_db.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #2
0
    def test_auto_schedule_one_network_two_segments_with_one_subnet_each(self):
        net_id = self._create_network()
        seg1_id = self._create_segment(net_id)
        self._create_subnet(seg1_id, net_id)
        helpers.register_dhcp_agent(HOST_D)
        segments_service_db.update_segment_host_mapping(
            self.ctx, HOST_D, {seg1_id})
        scheduler = dhcp_agent_scheduler.ChanceScheduler()
        observed_val_first_segment = scheduler.auto_schedule_networks(
            self.plugin, self.ctx, HOST_D)
        self.assertTrue(observed_val_first_segment)
        agents = self.plugin.get_dhcp_agents_hosting_networks(
            self.ctx, [net_id])
        self.assertEqual(1, len(agents))

        seg2_id = self._create_segment(net_id)
        self._create_subnet(seg2_id, net_id, '192.168.11.0/24')
        helpers.register_dhcp_agent(HOST_C)
        segments_service_db.update_segment_host_mapping(
            self.ctx, HOST_C, {seg2_id})
        observed_val_second_segment = scheduler.auto_schedule_networks(
            self.plugin, self.ctx, HOST_C)
        self.assertTrue(observed_val_second_segment)
        agents = self.plugin.get_dhcp_agents_hosting_networks(
            self.ctx, [net_id])
        self.assertEqual(2, len(agents))
コード例 #3
0
ファイル: test_db.py プロジェクト: abhilabh/neutron
 def test_get_agent_by_host_no_candidate(self):
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = self.db_mixin.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)
コード例 #4
0
ファイル: test_agent.py プロジェクト: openstack/neutron
    def _register_agent_states(self, lbaas_agents=False):
        """Register two L3 agents and two DHCP agents."""
        l3_hosta = helpers._get_l3_agent_dict(
            L3_HOSTA, constants.L3_AGENT_MODE_LEGACY)
        l3_hostb = helpers._get_l3_agent_dict(
            L3_HOSTB, constants.L3_AGENT_MODE_LEGACY)
        dhcp_hosta = helpers._get_dhcp_agent_dict(DHCP_HOSTA)
        dhcp_hostc = helpers._get_dhcp_agent_dict(DHCP_HOSTC)
        helpers.register_l3_agent(host=L3_HOSTA)
        helpers.register_l3_agent(host=L3_HOSTB)
        helpers.register_dhcp_agent(host=DHCP_HOSTA)
        helpers.register_dhcp_agent(host=DHCP_HOSTC)

        res = [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc]
        if lbaas_agents:
            lbaas_hosta = {
                'binary': 'neutron-loadbalancer-agent',
                'host': LBAAS_HOSTA,
                'topic': 'LOADBALANCER_AGENT',
                'configurations': {'device_drivers': ['haproxy_ns']},
                'agent_type': constants.AGENT_TYPE_LOADBALANCER}
            lbaas_hostb = copy.deepcopy(lbaas_hosta)
            lbaas_hostb['host'] = LBAAS_HOSTB
            callback = agents_db.AgentExtRpcCallback()
            callback.report_state(
                self.adminContext,
                agent_state={'agent_state': lbaas_hosta},
                time=datetime.utcnow().strftime(constants.ISO8601_TIME_FORMAT))
            callback.report_state(
                self.adminContext,
                agent_state={'agent_state': lbaas_hostb},
                time=datetime.utcnow().strftime(constants.ISO8601_TIME_FORMAT))
            res += [lbaas_hosta, lbaas_hostb]

        return res
コード例 #5
0
    def _test_host_changed(self, twice):
        self._register_ml2_agents()
        helpers.register_dhcp_agent()

        with self.subnet(network=self._network) as subnet:
            host_arg = {portbindings.HOST_ID: HOST}
            with self.port(subnet=subnet,
                           device_owner=DEVICE_OWNER_COMPUTE,
                           arg_list=(portbindings.HOST_ID,),
                           **host_arg) as port1:
                p1 = port1['port']
                s1 = subnet['subnet']
                device1 = 'tap' + p1['id']

                p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
                s1_cidr = s1['cidr'][s1['cidr'].index('/'):]
                expected1 = {'id': p1['id'],
                             'network_id': p1['network_id'],
                             'mac_address': p1['mac_address'],
                             'ip_address': p1_ips[0] + s1_cidr,
                             'gateway_ip': s1['gateway_ip'],
                             'evpn': {'import_rt': '64512:101',
                                      'export_rt': '64512:101'
                                      }
                             }

                self.callbacks.update_device_up(self.adminContext,
                                                agent_id=HOST,
                                                device=device1)

                self.mock_cast.assert_called_once_with(
                    mock.ANY, 'attach_port_on_bagpipe_network',
                    expected1, HOST)
コード例 #6
0
 def test_scheduler_one_agents_per_network(self):
     self._save_networks(['1111'])
     helpers.register_dhcp_agent(HOST_C)
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx,
                                            {'id': '1111'})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx,
                                                           ['1111'])
     self.assertEqual(1, len(agents))
コード例 #7
0
 def test_scheduler_two_agents_per_network(self):
     cfg.CONF.set_override("dhcp_agents_per_network", 2)
     net_id = self._create_network()
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx, {"id": net_id})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx, [net_id])
     self.assertEqual(2, len(agents))
コード例 #8
0
ファイル: test_db.py プロジェクト: abhilabh/neutron
 def test_get_dvr_active_network_ports_no_candidate(self):
     self._setup_port_binding()
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     tunnel_network_ports = self.db_mixin.get_dvr_active_network_ports(
         self.ctx.session, 'network_id')
     self.assertEqual(0, len(tunnel_network_ports))
コード例 #9
0
 def test_scheduler_one_agents_per_network(self):
     net_id = self._create_network()
     helpers.register_dhcp_agent(HOST_C)
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx,
                                            {'id': net_id})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx,
                                                           [net_id])
     self.assertEqual(1, len(agents))
コード例 #10
0
ファイル: test_db.py プロジェクト: abhilabh/neutron
 def test_get_agent_by_host(self):
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     agent = self.db_mixin.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #11
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_get_nondistributed_active_network_ports_no_candidate(self):
     self._setup_port_binding(dvr=False)
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(0, len(fdb_network_ports))
コード例 #12
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_get_distributed_active_network_ports_no_candidate(self):
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_DVR_INTERFACE)
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     tunnel_network_ports = l2pop_db.get_distributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(0, len(tunnel_network_ports))
コード例 #13
0
 def test_scheduler_two_agents_per_network(self):
     cfg.CONF.set_override('dhcp_agents_per_network', 2)
     self._save_networks(['1111'])
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx,
                                            {'id': '1111'})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx,
                                                           ['1111'])
     self.assertEqual(2, len(agents))
コード例 #14
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test__get_ha_router_interface_ids_with_ha_replicated_port(self):
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     self._create_ha_router()
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_HA_REPLICATED_INT,
         device_id=TEST_ROUTER_ID)
     ha_iface_ids = l2pop_db._get_ha_router_interface_ids(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(list(ha_iface_ids)))
コード例 #15
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_get_nondistributed_active_network_ports(self):
     self._setup_port_binding(dvr=False)
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(fdb_network_ports))
     _, agent = fdb_network_ports[0]
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #16
0
ファイル: test_db.py プロジェクト: abhilabh/neutron
 def test_get_nondvr_active_network_ports(self):
     self._setup_port_binding(dvr=False)
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     fdb_network_ports = self.db_mixin.get_nondvr_active_network_ports(
         self.ctx.session, 'network_id')
     self.assertEqual(1, len(fdb_network_ports))
     _, agent = fdb_network_ports[0]
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #17
0
ファイル: test_db.py プロジェクト: 21atlas/neutron
 def test_get_dvr_active_network_ports(self):
     self._setup_port_binding()
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     tunnel_network_ports = l2pop_db.get_dvr_active_network_ports(
         self.ctx.session, 'network_id')
     self.assertEqual(1, len(tunnel_network_ports))
     _, agent = tunnel_network_ports[0]
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #18
0
 def test_schedule_segment_no_host_mapping(self):
     net_id = self._create_network()
     seg_id = self._create_segment(net_id)
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     net = self.plugin.get_network(self.ctx, net_id)
     seg = self.segments_plugin.get_segment(self.ctx, seg_id)
     net['candidate_hosts'] = seg['hosts']
     agents = self.plugin.network_scheduler.schedule(
         self.plugin, self.ctx, net)
     self.assertEqual(0, len(agents))
コード例 #19
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_get_distributed_active_network_ports(self):
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_DVR_INTERFACE)
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     tunnel_network_ports = l2pop_db.get_distributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(tunnel_network_ports))
     _, agent = tunnel_network_ports[0]
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #20
0
 def test_schedule_segment_one_hostable_agent(self):
     net_id = self._create_network()
     seg_id = self._create_segment(net_id)
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_C, {seg_id})
     net = self._get_network_with_candidate_hosts(net_id, seg_id)
     agents = self.plugin.network_scheduler.schedule(
         self.plugin, self.ctx, net)
     self.assertEqual(1, len(agents))
     self.assertEqual(HOST_C, agents[0].host)
コード例 #21
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_get_ha_agents_by_router_id(self):
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     self._create_ha_router()
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     agents = l2pop_db.get_ha_agents_by_router_id(
         self.ctx.session, TEST_ROUTER_ID)
     ha_agents = [agent.host for agent in agents]
     self.assertEqual(tools.UnorderedList([HOST, HOST_2]), ha_agents)
コード例 #22
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_active_port_count_with_ha_dvr_snat_port(self):
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     self._create_ha_router()
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     port_count = l2pop_db.get_agent_network_active_port_count(
         self.ctx.session, HOST, TEST_NETWORK_ID)
     self.assertEqual(1, port_count)
     port_count = l2pop_db.get_agent_network_active_port_count(
         self.ctx.session, HOST_2, TEST_NETWORK_ID)
     self.assertEqual(1, port_count)
コード例 #23
0
 def test_auto_schedule_one_network_one_segment_one_subnet(self):
     net_id = self._create_network()
     seg_id = self._create_segment(net_id)
     self._create_subnet(seg_id, net_id)
     helpers.register_dhcp_agent(HOST_C)
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_C, {seg_id})
     scheduler = dhcp_agent_scheduler.ChanceScheduler()
     observed_return_val = scheduler.auto_schedule_networks(
         self.plugin, self.ctx, HOST_C)
     self.assertTrue(observed_return_val)
     agent1 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, [net_id])
     self.assertEqual(1, len(agent1))
     self.assertEqual('host-c', agent1[0]['host'])
コード例 #24
0
 def test_schedule_segment_two_agents_per_segment_one_hostable_agent(self):
     cfg.CONF.set_override('dhcp_agents_per_network', 2)
     net_id = self._create_network()
     seg_id = self._create_segment(net_id)
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_C, {seg_id})
     net = self.plugin.get_network(self.ctx, net_id)
     seg = self.segments_plugin.get_segment(self.ctx, seg_id)
     net['candidate_hosts'] = seg['hosts']
     agents = self.plugin.network_scheduler.schedule(
         self.plugin, self.ctx, net)
     self.assertEqual(1, len(agents))
     self.assertEqual(HOST_C, agents[0].host)
コード例 #25
0
ファイル: test_db.py プロジェクト: sebrandon1/neutron
 def test_active_network_ports_with_dvr_snat_port(self):
     # Test to get agent hosting dvr snat port
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     # create DVR router
     self._create_router()
     # setup DVR snat port
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     helpers.register_dhcp_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(fdb_network_ports))
コード例 #26
0
 def test_schedule_segment_two_agents_per_segment(self):
     cfg.CONF.set_override('dhcp_agents_per_network', 2)
     net_id = self._create_network()
     seg_id = self._create_segment(net_id)
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_C, {seg_id})
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_D, {seg_id})
     net = self._get_network_with_candidate_hosts(net_id, seg_id)
     agents = self.plugin.network_scheduler.schedule(
         self.plugin, self.ctx, net)
     self.assertEqual(2, len(agents))
     self.assertIn(agents[0].host, [HOST_C, HOST_D])
     self.assertIn(agents[1].host, [HOST_C, HOST_D])
コード例 #27
0
 def test_schedule_segment_many_hostable_agents(self):
     net_id = self._create_network()
     seg_id = self._create_segment(net_id)
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D)
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_C, {seg_id})
     segments_service_db.update_segment_host_mapping(
         self.ctx, HOST_D, {seg_id})
     net = self.plugin.get_network(self.ctx, net_id)
     seg = self.segments_plugin.get_segment(self.ctx, seg_id)
     net['candidate_hosts'] = seg['hosts']
     agents = self.plugin.network_scheduler.schedule(
         self.plugin, self.ctx, net)
     self.assertEqual(1, len(agents))
     self.assertIn(agents[0].host, [HOST_C, HOST_D])
コード例 #28
0
ファイル: test_db.py プロジェクト: openstack/neutron
 def test_active_network_ports_with_ha_dvr_snat_port(self):
     # test to get HA agents hosting HA+DVR snat port
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     # create HA+DVR router
     self._create_ha_router()
     # setup HA snat port
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx, TEST_NETWORK_ID)
     self.assertEqual(0, len(fdb_network_ports))
     ha_ports = l2pop_db.get_ha_active_network_ports(
         self.ctx, TEST_NETWORK_ID)
     self.assertEqual(2, len(ha_ports))
コード例 #29
0
 def test_az_scheduler_default_az_hints(self):
     cfg.CONF.set_override("default_availability_zones", ["az1"])
     self._save_networks(["1111"])
     helpers.register_dhcp_agent("az1-host1", networks=1, az="az1")
     helpers.register_dhcp_agent("az1-host2", networks=2, az="az1")
     helpers.register_dhcp_agent("az2-host1", networks=3, az="az2")
     helpers.register_dhcp_agent("az2-host2", networks=4, az="az2")
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx, {"id": "1111", "availability_zone_hints": []})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx, ["1111"])
     self.assertEqual(1, len(agents))
     self.assertEqual("az1-host1", agents[0]["host"])
コード例 #30
0
 def test_az_scheduler_one_az_hints(self):
     self._save_networks(['1111'])
     helpers.register_dhcp_agent('az1-host1', networks=1, az='az1')
     helpers.register_dhcp_agent('az1-host2', networks=2, az='az1')
     helpers.register_dhcp_agent('az2-host1', networks=3, az='az2')
     helpers.register_dhcp_agent('az2-host2', networks=4, az='az2')
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx,
         {'id': '1111', 'availability_zone_hints': ['az2']})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx,
                                                           ['1111'])
     self.assertEqual(1, len(agents))
     self.assertEqual('az2-host1', agents[0]['host'])
コード例 #31
0
 def test_az_scheduler_default_az_hints(self):
     net_id = uuidutils.generate_uuid()
     cfg.CONF.set_override('default_availability_zones', ['az1'])
     self._save_networks([net_id])
     helpers.register_dhcp_agent('az1-host1', networks=1, az='az1')
     helpers.register_dhcp_agent('az1-host2', networks=2, az='az1')
     helpers.register_dhcp_agent('az2-host1', networks=3, az='az2')
     helpers.register_dhcp_agent('az2-host2', networks=4, az='az2')
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx, {
         'id': net_id,
         'availability_zone_hints': []
     })
     agents = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, [net_id])
     self.assertEqual(1, len(agents))
     self.assertEqual('az1-host1', agents[0]['host'])
コード例 #32
0
 def _create_and_set_agents_down(self,
                                 hosts,
                                 down_agent_count=0,
                                 admin_state_up=True,
                                 az=helpers.DEFAULT_AZ):
     agents = []
     for i, host in enumerate(hosts):
         is_alive = i >= down_agent_count
         agents.append(
             helpers.register_dhcp_agent(host,
                                         admin_state_up=admin_state_up,
                                         alive=is_alive,
                                         az=az))
     return agents
コード例 #33
0
ファイル: test_agent.py プロジェクト: zlzlnet/neutron
    def _register_agent_states(self, lbaas_agents=False):
        """Register two L3 agents and two DHCP agents."""
        l3_hosta = helpers._get_l3_agent_dict(L3_HOSTA,
                                              constants.L3_AGENT_MODE_LEGACY)
        l3_hostb = helpers._get_l3_agent_dict(L3_HOSTB,
                                              constants.L3_AGENT_MODE_LEGACY)
        dhcp_hosta = helpers._get_dhcp_agent_dict(DHCP_HOSTA)
        dhcp_hostc = helpers._get_dhcp_agent_dict(DHCP_HOSTC)
        helpers.register_l3_agent(host=L3_HOSTA)
        helpers.register_l3_agent(host=L3_HOSTB)
        helpers.register_dhcp_agent(host=DHCP_HOSTA)
        helpers.register_dhcp_agent(host=DHCP_HOSTC)

        res = [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc]
        if lbaas_agents:
            lbaas_hosta = {
                'binary': 'neutron-loadbalancer-agent',
                'host': LBAAS_HOSTA,
                'topic': 'LOADBALANCER_AGENT',
                'configurations': {
                    'device_drivers': ['haproxy_ns']
                },
                'agent_type': constants.AGENT_TYPE_LOADBALANCER
            }
            lbaas_hostb = copy.deepcopy(lbaas_hosta)
            lbaas_hostb['host'] = LBAAS_HOSTB
            callback = agents_db.AgentExtRpcCallback()
            callback.report_state(self.adminContext,
                                  agent_state={'agent_state': lbaas_hosta},
                                  time=timeutils.strtime())
            callback.report_state(self.adminContext,
                                  agent_state={'agent_state': lbaas_hostb},
                                  time=timeutils.strtime())
            res += [lbaas_hosta, lbaas_hostb]

        return res
コード例 #34
0
 def test_az_scheduler_two_az_hints_one_available_az(self):
     cfg.CONF.set_override('dhcp_agents_per_network', 2)
     self._save_networks(['1111'])
     helpers.register_dhcp_agent('az1-host1', networks=1, az='az1')
     helpers.register_dhcp_agent('az1-host2', networks=2, az='az1')
     helpers.register_dhcp_agent('az2-host1', networks=3, alive=False,
                                 az='az2')
     helpers.register_dhcp_agent('az2-host2', networks=4,
                                 admin_state_up=False, az='az2')
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx,
         {'id': '1111', 'availability_zone_hints': ['az1', 'az2']})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx,
                                                           ['1111'])
     self.assertEqual(2, len(agents))
     expected_hosts = set(['az1-host1', 'az1-host2'])
     hosts = set([a['host'] for a in agents])
     self.assertEqual(expected_hosts, hosts)
コード例 #35
0
 def setUp(self):
     super(TestDHCPAgentShimControllers, self).setUp()
     policy.init()
     policy._ENFORCER.set_rules(
         oslo_policy.Rules.from_dict(
             {'get_dhcp-agents': 'role:admin',
              'get_dhcp-networks': 'role:admin',
              'create_dhcp-networks': 'role:admin',
              'delete_dhcp-networks': 'role:admin'}),
         overwrite=False)
     plugin = directory.get_plugin()
     ctx = context.get_admin_context()
     self.network = pecan_utils.create_network(ctx, plugin)
     self.agent = helpers.register_dhcp_agent()
     # NOTE(blogan): Not sending notifications because this test is for
     # testing the shim controllers
     plugin.agent_notifiers[n_const.AGENT_TYPE_DHCP] = None
コード例 #36
0
 def _test_az_scheduler_no_az_hints(self, multiple_agent=False):
     num_agent = 2 if multiple_agent else 1
     cfg.CONF.set_override('dhcp_agents_per_network', num_agent)
     self._save_networks(['1111'])
     helpers.register_dhcp_agent('az1-host1', networks=2, az='az1')
     helpers.register_dhcp_agent('az1-host2', networks=3, az='az1')
     helpers.register_dhcp_agent('az2-host1', networks=2, az='az2')
     helpers.register_dhcp_agent('az2-host2', networks=1, az='az2')
     self.plugin.network_scheduler.schedule(self.plugin, self.ctx,
         {'id': '1111', 'availability_zone_hints': []})
     agents = self.plugin.get_dhcp_agents_hosting_networks(self.ctx,
                                                           ['1111'])
     self.assertEqual(num_agent, len(agents))
     if multiple_agent:
         expected_hosts = set(['az1-host1', 'az2-host2'])
     else:
         expected_hosts = set(['az2-host2'])
     hosts = {a['host'] for a in agents}
     self.assertEqual(expected_hosts, hosts)
コード例 #37
0
 def test_scheduler_equal_distribution(self):
     self._save_networks(['1111', '2222', '3333'])
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D, networks=1)
     self.plugin.network_scheduler.schedule(
         self.plugin, context.get_admin_context(), {'id': '1111'})
     helpers.register_dhcp_agent(HOST_D, networks=2)
     self.plugin.network_scheduler.schedule(
         self.plugin, context.get_admin_context(), {'id': '2222'})
     helpers.register_dhcp_agent(HOST_C, networks=4)
     self.plugin.network_scheduler.schedule(
         self.plugin, context.get_admin_context(), {'id': '3333'})
     agent1 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, ['1111'])
     agent2 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, ['2222'])
     agent3 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, ['3333'])
     self.assertEqual('host-c', agent1[0]['host'])
     self.assertEqual('host-c', agent2[0]['host'])
     self.assertEqual('host-d', agent3[0]['host'])
コード例 #38
0
 def test_scheduler_equal_distribution(self):
     net_id_1 = self._create_network()
     net_id_2 = self._create_network()
     net_id_3 = self._create_network()
     helpers.register_dhcp_agent(HOST_C)
     helpers.register_dhcp_agent(HOST_D, networks=1)
     self.plugin.network_scheduler.schedule(
         self.plugin, context.get_admin_context(), {'id': net_id_1})
     helpers.register_dhcp_agent(HOST_D, networks=2)
     self.plugin.network_scheduler.schedule(
         self.plugin, context.get_admin_context(), {'id': net_id_2})
     helpers.register_dhcp_agent(HOST_C, networks=4)
     self.plugin.network_scheduler.schedule(
         self.plugin, context.get_admin_context(), {'id': net_id_3})
     agent1 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, [net_id_1])
     agent2 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, [net_id_2])
     agent3 = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, [net_id_3])
     self.assertEqual('host-c', agent1[0]['host'])
     self.assertEqual('host-c', agent2[0]['host'])
     self.assertEqual('host-d', agent3[0]['host'])
コード例 #39
0
    def test_az_scheduler_select_az_with_least_weight(self):
        self._save_networks(['1111'])
        dhcp_agents = []
        # Register 6 dhcp agents in 3 AZs, every AZ will have 2 agents.
        dhcp_agents.append(
            helpers.register_dhcp_agent('az1-host1', networks=6, az='az1'))
        dhcp_agents.append(
            helpers.register_dhcp_agent('az1-host2', networks=5, az='az1'))
        dhcp_agents.append(
            helpers.register_dhcp_agent('az2-host1', networks=4, az='az2'))
        dhcp_agents.append(
            helpers.register_dhcp_agent('az2-host2', networks=3, az='az2'))
        dhcp_agents.append(
            helpers.register_dhcp_agent('az3-host1', networks=2, az='az3'))
        dhcp_agents.append(
            helpers.register_dhcp_agent('az3-host2', networks=1, az='az3'))

        # Try multiple times to verify that the select of AZ scheduler will
        # output stably.
        for i in range(3):
            # Shuffle the agents
            random.shuffle(dhcp_agents)
            # Select agents with empty resource_hosted_agents. This means each
            # AZ will have same amount of agents scheduled (0 in this case)
            agents_select = self.plugin.network_scheduler.select(
                self.plugin, self.ctx, dhcp_agents, [], 2)

            self.assertEqual(2, len(agents_select))
            # The agent and az with least weight should always be selected
            # first
            self.assertEqual('az3-host2', agents_select[0]['host'])
            self.assertEqual('az3', agents_select[0]['availability_zone'])
            # The second selected agent should be the agent with least weight,
            # which is also not in the same az as the first selected agent.
            self.assertEqual('az2-host2', agents_select[1]['host'])
            self.assertEqual('az2', agents_select[1]['availability_zone'])
コード例 #40
0
 def test_az_scheduler_two_az_hints(self):
     net_id = uuidutils.generate_uuid()
     cfg.CONF.set_override('dhcp_agents_per_network', 2)
     self._save_networks([net_id])
     helpers.register_dhcp_agent('az1-host1', networks=1, az='az1')
     helpers.register_dhcp_agent('az1-host2', networks=2, az='az1')
     helpers.register_dhcp_agent('az2-host1', networks=3, az='az2')
     helpers.register_dhcp_agent('az2-host2', networks=4, az='az2')
     helpers.register_dhcp_agent('az3-host1', networks=5, az='az3')
     helpers.register_dhcp_agent('az3-host2', networks=6, az='az3')
     self.plugin.network_scheduler.schedule(
         self.plugin, self.ctx, {
             'id': net_id,
             'availability_zone_hints': ['az1', 'az3']
         })
     agents = self.plugin.get_dhcp_agents_hosting_networks(
         self.ctx, [net_id])
     self.assertEqual(2, len(agents))
     expected_hosts = set(['az1-host1', 'az3-host1'])
     hosts = set([a['host'] for a in agents])
     self.assertEqual(expected_hosts, hosts)
コード例 #41
0
ファイル: test_db.py プロジェクト: fcxliang/lzf5-study
 def test_get_agent_by_host_no_candidate(self):
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = l2pop_db.get_agent_by_host(self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)
コード例 #42
0
ファイル: test_db.py プロジェクト: fcxliang/lzf5-study
 def test_get_agent_by_host(self):
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     agent = l2pop_db.get_agent_by_host(self.ctx.session, helpers.HOST)
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
コード例 #43
0
ファイル: test_db.py プロジェクト: dingboopt/neutron-x
 def test_get_agent_by_host_no_candidate(self):
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = l2pop_db.get_agent_by_host(self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)
コード例 #44
0
 def test_list_agent_with_az(self):
     helpers.register_dhcp_agent(host='host1', az='nova1')
     res = self._list('agents')
     self.assertEqual('nova1', res['agents'][0]['availability_zone'])
コード例 #45
0
 def _register_azs(self):
     self.agent1 = helpers.register_dhcp_agent(host='host1', az='nova1')
     self.agent2 = helpers.register_dhcp_agent(host='host2', az='nova2')
     self.agent3 = helpers.register_l3_agent(host='host2', az='nova2')
     self.agent4 = helpers.register_l3_agent(host='host3', az='nova3')
     self.agent5 = helpers.register_l3_agent(host='host4', az='nova2')