def test_list_availability_zones_with_filter(self):
     self._register_azs()
     helpers.set_agent_admin_state(self.agent3['id'], admin_state_up=False)
     helpers.set_agent_admin_state(self.agent4['id'], admin_state_up=False)
     expected = [
         {'name': 'nova1', 'resource': 'network', 'state': 'available'},
         {'name': 'nova2', 'resource': 'network', 'state': 'available'},
         {'name': 'nova2', 'resource': 'router', 'state': 'available'},
         {'name': 'nova3', 'resource': 'router', 'state': 'unavailable'}]
     res = self._list('availability_zones')
     azs = res['availability_zones']
     self.assertItemsEqual(expected, azs)
     # list with filter of 'name'
     res = self._list('availability_zones',
                      query_params="name=nova1")
     azs = res['availability_zones']
     self.assertItemsEqual(expected[:1], azs)
     # list with filter of 'resource'
     res = self._list('availability_zones',
                      query_params="resource=router")
     azs = res['availability_zones']
     self.assertItemsEqual(expected[-2:], azs)
     # list with filter of 'state' as 'available'
     res = self._list('availability_zones',
                      query_params="state=available")
     azs = res['availability_zones']
     self.assertItemsEqual(expected[:3], azs)
     # list with filter of 'state' as 'unavailable'
     res = self._list('availability_zones',
                      query_params="state=unavailable")
     azs = res['availability_zones']
     self.assertItemsEqual(expected[-1:], azs)
 def test_list_availability_zones(self):
     self._register_azs()
     helpers.set_agent_admin_state(self.agent3['id'], admin_state_up=False)
     helpers.set_agent_admin_state(self.agent4['id'], admin_state_up=False)
     expected = [{
         'name': 'nova1',
         'resource': 'network',
         'state': 'available'
     }, {
         'name': 'nova2',
         'resource': 'network',
         'state': 'available'
     }, {
         'name': 'nova2',
         'resource': 'router',
         'state': 'available'
     }, {
         'name': 'nova3',
         'resource': 'router',
         'state': 'unavailable'
     }]
     res = self._list('availability_zones')
     azs = res['availability_zones']
     self.assertItemsEqual(expected, azs)
     # not admin case
     ctx = context.Context('', 'noadmin')
     res = self._list('availability_zones', neutron_context=ctx)
     azs = res['availability_zones']
     self.assertItemsEqual(expected, azs)
Пример #3
0
 def _create_l3_agent(self,
                      host,
                      context,
                      agent_mode='legacy',
                      plugin=None,
                      state=True):
     agent = helpers.register_l3_agent(host, agent_mode)
     helpers.set_agent_admin_state(agent.id, state)
     return agent
 def _create_l3_agent(self,
                      host,
                      context,
                      agent_mode='legacy',
                      state=True,
                      ext_net_id=''):
     agent = helpers.register_l3_agent(host, agent_mode)
     helpers.set_agent_admin_state(agent.id, state)
     return agent
def register_bgp_dragent(host=helpers.HOST, admin_state_up=True, alive=True):
    agent = helpers._register_agent(_get_bgp_dragent_dict(host))

    if not admin_state_up:
        helpers.set_agent_admin_state(agent['id'])
    if not alive:
        helpers.kill_agent(agent['id'])

    return helpers.FakePlugin()._get_agent_by_type_and_host(
        context.get_admin_context(), agent['agent_type'], agent['host'])
Пример #6
0
def register_bgp_dragent(host=helpers.HOST, admin_state_up=True,
                        alive=True):
    agent = helpers._register_agent(
        _get_bgp_dragent_dict(host))

    if not admin_state_up:
        helpers.set_agent_admin_state(agent['id'])
    if not alive:
        helpers.kill_agent(agent['id'])

    return helpers.FakePlugin()._get_agent_by_type_and_host(
        context.get_admin_context(), agent['agent_type'], agent['host'])
Пример #7
0
 def test_list_availability_zones(self):
     self._register_azs()
     helpers.set_agent_admin_state(self.agent3['id'], admin_state_up=False)
     helpers.set_agent_admin_state(self.agent4['id'], admin_state_up=False)
     expected = [
         {'name': 'nova1', 'resource': 'network', 'state': 'available'},
         {'name': 'nova2', 'resource': 'network', 'state': 'available'},
         {'name': 'nova2', 'resource': 'router', 'state': 'available'},
         {'name': 'nova3', 'resource': 'router', 'state': 'unavailable'}]
     res = self._list('availability_zones')
     azs = res['availability_zones']
     self.assertItemsEqual(expected, azs)
     # not admin case
     ctx = context.Context('', 'noadmin')
     res = self._list('availability_zones', neutron_context=ctx)
     azs = res['availability_zones']
     self.assertItemsEqual(expected, azs)
Пример #8
0
    def test_auto_schedule_router(self):
        scheduler = l3_agent_scheduler.AZLeastRoutersScheduler()
        ha = False
        if self.max_l3_agents_per_router:
            self.config(max_l3_agents_per_router=self.max_l3_agents_per_router)
            self.config(min_l3_agents_per_router=self.min_l3_agents_per_router)
            ha = True

        # create l3 agents
        l3_agents = {}
        for i in range(self.az_count):
            az = 'az%s' % i
            l3_agents[az] = self._create_legacy_agents(
                self.agent_count[i], self.down_agent_count[i], az)

        # create router.
        # note that ha-router needs enough agents beforehand.
        az_hints = ['az%s' % i for i in range(self.router_az_hints)]
        router = self._create_router(az_hints, ha)

        # schedule some agents before calling auto schedule
        for i in range(self.az_count):
            az = 'az%s' % i
            for j in range(self.scheduled_agent_count[i]):
                agent = l3_agents[az][j + self.down_agent_count[i]]
                scheduler.bind_router(self.l3_plugin, self.adminContext,
                                      router['id'], agent.id)

        # activate down agent and call auto_schedule_routers
        activate_agent = l3_agents[self.agent_az][0]
        helpers.set_agent_admin_state(activate_agent['id'],
                                      admin_state_up=True)

        scheduler.auto_schedule_routers(self.l3_plugin, self.adminContext,
                                        activate_agent['host'], None)

        scheduled_agents = self.l3_plugin.get_l3_agents_hosting_routers(
            self.adminContext, [router['id']])

        scheduled_azs = collections.defaultdict(int)
        for agent in scheduled_agents:
            scheduled_azs[agent['availability_zone']] += 1

        for i in range(self.az_count):
            self.assertEqual(self.expected_scheduled_agent_count[i],
                             scheduled_azs.get('az%s' % i, 0))
    def test_auto_schedule_router(self):
        scheduler = l3_agent_scheduler.AZLeastRoutersScheduler()
        ha = False
        if self.max_l3_agents_per_router:
            self.config(max_l3_agents_per_router=self.max_l3_agents_per_router)
            self.config(min_l3_agents_per_router=self.min_l3_agents_per_router)
            ha = True

        # create l3 agents
        l3_agents = {}
        for i in range(self.az_count):
            az = 'az%s' % i
            l3_agents[az] = self._create_legacy_agents(
                self.agent_count[i], self.down_agent_count[i], az)

        # create router.
        # note that ha-router needs enough agents beforehand.
        az_hints = ['az%s' % i for i in range(self.router_az_hints)]
        router = self._create_router(az_hints, ha)

        # schedule some agents before calling auto schedule
        for i in range(self.az_count):
            az = 'az%s' % i
            for j in range(self.scheduled_agent_count[i]):
                agent = l3_agents[az][j + self.down_agent_count[i]]
                scheduler.bind_router(self.l3_plugin, self.adminContext,
                                      router['id'], agent.id)

        # activate down agent and call auto_schedule_routers
        activate_agent = l3_agents[self.agent_az][0]
        helpers.set_agent_admin_state(activate_agent['id'],
                                      admin_state_up=True)

        scheduler.auto_schedule_routers(self.l3_plugin, self.adminContext,
                                        activate_agent['host'], None)

        scheduled_agents = self.l3_plugin.get_l3_agents_hosting_routers(
            self.adminContext, [router['id']])

        scheduled_azs = collections.defaultdict(int)
        for agent in scheduled_agents:
            scheduled_azs[agent['availability_zone']] += 1

        for i in range(self.az_count):
            self.assertEqual(self.expected_scheduled_agent_count[i],
                             scheduled_azs.get('az%s' % i, 0))
Пример #10
0
 def _create_l3_agent(self, host, context, agent_mode='legacy',
                      state=True, ext_net_id=''):
     agent = helpers.register_l3_agent(host, agent_mode,
                                       ext_net_id=ext_net_id)
     helpers.set_agent_admin_state(agent.id, state)
     return agent
Пример #11
0
 def _create_l3_agent(self, host, context, agent_mode='legacy', plugin=None,
                      state=True, az='nova'):
     agent = helpers.register_l3_agent(host, agent_mode, az=az)
     helpers.set_agent_admin_state(agent.id, state)
     return agent