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.
 
 
 

102 lines
4.3 KiB

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