OpenStack Testing (Tempest) of an existing cloud
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_dhcp_agent_scheduler.py 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. from tempest.api.network import base
  15. from tempest.common import utils
  16. from tempest.lib import decorators
  17. class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
  18. @classmethod
  19. def skip_checks(cls):
  20. super(DHCPAgentSchedulersTestJSON, cls).skip_checks()
  21. if not utils.is_extension_enabled('dhcp_agent_scheduler', 'network'):
  22. msg = "dhcp_agent_scheduler extension not enabled."
  23. raise cls.skipException(msg)
  24. @classmethod
  25. def resource_setup(cls):
  26. super(DHCPAgentSchedulersTestJSON, cls).resource_setup()
  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.create_subnet(cls.network)
  31. cls.port = cls.create_port(cls.network)
  32. @decorators.idempotent_id('5032b1fe-eb42-4a64-8f3b-6e189d8b5c7d')
  33. def test_list_dhcp_agent_hosting_network(self):
  34. self.admin_networks_client.list_dhcp_agents_on_hosting_network(
  35. self.network['id'])
  36. @decorators.idempotent_id('30c48f98-e45d-4ffb-841c-b8aad57c7587')
  37. def test_list_networks_hosted_by_one_dhcp(self):
  38. body = self.admin_networks_client.list_dhcp_agents_on_hosting_network(
  39. self.network['id'])
  40. agents = body['agents']
  41. self.assertNotEmpty(agents, "no dhcp agent")
  42. agent = agents[0]
  43. self.assertTrue(self._check_network_in_dhcp_agent(
  44. self.network['id'], agent))
  45. def _check_network_in_dhcp_agent(self, network_id, agent):
  46. network_ids = []
  47. body = self.admin_agents_client.list_networks_hosted_by_one_dhcp_agent(
  48. agent['id'])
  49. networks = body['networks']
  50. for network in networks:
  51. network_ids.append(network['id'])
  52. return network_id in network_ids
  53. @decorators.idempotent_id('a0856713-6549-470c-a656-e97c8df9a14d')
  54. def test_add_remove_network_from_dhcp_agent(self):
  55. # The agent is now bound to the network, we can free the port
  56. self.ports_client.delete_port(self.port['id'])
  57. agent = dict()
  58. agent['agent_type'] = None
  59. body = self.admin_agents_client.list_agents()
  60. agents = body['agents']
  61. for a in agents:
  62. if a['agent_type'] == 'DHCP agent':
  63. agent = a
  64. break
  65. self.assertEqual(agent['agent_type'], 'DHCP agent', 'Could not find '
  66. 'DHCP agent in agent list though dhcp_agent_scheduler'
  67. ' is enabled.')
  68. network = self.create_network()
  69. network_id = network['id']
  70. if self._check_network_in_dhcp_agent(network_id, agent):
  71. self._remove_network_from_dhcp_agent(network_id, agent)
  72. self._add_dhcp_agent_to_network(network_id, agent)
  73. else:
  74. self._add_dhcp_agent_to_network(network_id, agent)
  75. self._remove_network_from_dhcp_agent(network_id, agent)
  76. def _remove_network_from_dhcp_agent(self, network_id, agent):
  77. self.admin_agents_client.delete_network_from_dhcp_agent(
  78. agent_id=agent['id'],
  79. network_id=network_id)
  80. self.assertFalse(self._check_network_in_dhcp_agent(
  81. network_id, agent))
  82. def _add_dhcp_agent_to_network(self, network_id, agent):
  83. self.admin_agents_client.add_dhcp_agent_to_network(
  84. agent['id'], network_id=network_id)
  85. self.assertTrue(self._check_network_in_dhcp_agent(
  86. network_id, agent))