OpenStack Networking (Neutron)
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.
 
 
 
 

255 lines
9.5 KiB

  1. # Copyright 2018 Ericsson
  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. import functools
  15. from neutron_lib import constants
  16. from neutron.common import utils
  17. from neutron.tests.common import net_helpers
  18. from neutron.tests.fullstack import base
  19. from neutron.tests.fullstack.resources import config as f_const
  20. from neutron.tests.fullstack.resources import environment
  21. from neutron.tests.unit import testlib_api
  22. load_tests = testlib_api.module_load_tests
  23. BR_MAPPINGS = 'bridge_mappings'
  24. DEV_MAPPINGS = 'device_mappings'
  25. def _get_physnet_names_from_mapping(mapping):
  26. physnets = []
  27. for pair in mapping.split(','):
  28. physnets.append(pair.split(':')[0])
  29. return physnets
  30. def _add_new_device_to_agent_config(l2_agent_config, mapping_key_name,
  31. new_dev):
  32. old_bw = l2_agent_config[constants.RP_BANDWIDTHS]
  33. old_mappings = l2_agent_config[mapping_key_name]
  34. if new_dev in old_bw or new_dev in old_mappings:
  35. return
  36. new_mappings = 'physnetnew:%s' % new_dev
  37. new_bw = '%s:%s:%s' % (new_dev,
  38. f_const.MINIMUM_BANDWIDTH_EGRESS_KBPS,
  39. f_const.MINIMUM_BANDWIDTH_INGRESS_KBPS)
  40. l2_agent_config[mapping_key_name] = '%s,%s' % (
  41. old_mappings, new_mappings)
  42. l2_agent_config[constants.RP_BANDWIDTHS] = '%s,%s' % (
  43. old_bw, new_bw)
  44. def _change_agent_conf(l2_agent_config, l2_agent,
  45. mapping_key_name, new_dev):
  46. _add_new_device_to_agent_config(l2_agent_config, mapping_key_name, new_dev)
  47. l2_agent.agent_cfg_fixture.write_config_to_configfile()
  48. def _add_new_bridge_and_restart_agent(host):
  49. l2_agent = host.l2_agent
  50. l2_agent_config = l2_agent.agent_cfg_fixture.config
  51. if 'ovs' in host.agents:
  52. new_dev = utils.get_rand_device_name(prefix='br-new')
  53. _change_agent_conf(
  54. l2_agent_config['ovs'], l2_agent, BR_MAPPINGS, new_dev)
  55. physnets = _get_physnet_names_from_mapping(
  56. l2_agent_config['ovs'][BR_MAPPINGS])
  57. br_phys_new = host.useFixture(
  58. net_helpers.OVSBridgeFixture(new_dev)).bridge
  59. host.connect_to_central_network_via_vlans(br_phys_new)
  60. elif 'sriov' in host.agents:
  61. new_dev = utils.get_rand_device_name(prefix='ens7')
  62. _change_agent_conf(
  63. l2_agent_config['sriov_nic'], l2_agent,
  64. 'physical_device_mappings', new_dev)
  65. physnets = _get_physnet_names_from_mapping(
  66. l2_agent_config['sriov_nic']['physical_device_mappings'])
  67. l2_agent.restart()
  68. return physnets
  69. class TestAgentBandwidthReport(base.BaseFullStackTestCase):
  70. scenarios = [
  71. (constants.AGENT_TYPE_OVS,
  72. {'l2_agent_type': constants.AGENT_TYPE_OVS}),
  73. (constants.AGENT_TYPE_NIC_SWITCH,
  74. {'l2_agent_type': constants.AGENT_TYPE_NIC_SWITCH})
  75. ]
  76. def setUp(self, env=None):
  77. if not env:
  78. host_desc = [environment.HostDescription(
  79. l3_agent=False,
  80. l2_agent_type=self.l2_agent_type)]
  81. env_desc = environment.EnvironmentDescription(
  82. network_type='vlan',
  83. l2_pop=False,
  84. report_bandwidths=True,
  85. )
  86. env = environment.Environment(env_desc, host_desc)
  87. super(TestAgentBandwidthReport, self).setUp(env)
  88. def _check_agent_configurations(self, agent_id, expected_physnets):
  89. agent = self.client.show_agent(agent_id)['agent']
  90. agent_configurations = agent['configurations']
  91. if 'Open vSwitch' in agent['agent_type']:
  92. mapping_key = BR_MAPPINGS
  93. elif 'NIC Switch' in agent['agent_type']:
  94. mapping_key = DEV_MAPPINGS
  95. else:
  96. return False
  97. for physnet in expected_physnets:
  98. if physnet not in agent_configurations[mapping_key]:
  99. return False
  100. bridge_or_devices = agent_configurations[mapping_key][physnet]
  101. if (constants.RP_BANDWIDTHS not in agent_configurations or
  102. constants.RP_INVENTORY_DEFAULTS not in
  103. agent_configurations):
  104. return False
  105. if mapping_key == BR_MAPPINGS:
  106. if (bridge_or_devices not in
  107. agent_configurations[constants.RP_BANDWIDTHS]):
  108. return False
  109. else:
  110. for device in bridge_or_devices:
  111. if (device not in
  112. agent_configurations[constants.RP_BANDWIDTHS]):
  113. return False
  114. for device in agent_configurations[constants.RP_BANDWIDTHS]:
  115. conf_device = agent_configurations[constants.RP_BANDWIDTHS][device]
  116. if (f_const.MINIMUM_BANDWIDTH_INGRESS_KBPS !=
  117. conf_device['ingress'] and
  118. f_const.MINIMUM_BANDWIDTH_EGRESS_KBPS !=
  119. conf_device[device]['egress']):
  120. return False
  121. return True
  122. def test_agent_configurations(self):
  123. agents = self.client.list_agents()
  124. self.assertEqual(1, len(agents['agents']))
  125. self.assertTrue(agents['agents'][0]['alive'])
  126. agent_config = self.environment.hosts[0].l2_agent.agent_config
  127. if 'ovs' in self.environment.hosts[0].agents:
  128. physnets = _get_physnet_names_from_mapping(
  129. agent_config['ovs'][BR_MAPPINGS])
  130. elif 'sriov' in self.environment.hosts[0].agents:
  131. physnets = _get_physnet_names_from_mapping(
  132. agent_config['sriov_nic']['physical_device_mappings'])
  133. self.assertTrue(
  134. self._check_agent_configurations(agents['agents'][0]['id'],
  135. physnets))
  136. # Add new physnet with bandwidth value to agent config and check
  137. # if after agent restart and report_interval wait it is visible in
  138. # the configurations field.
  139. physnets = _add_new_bridge_and_restart_agent(self.environment.hosts[0])
  140. agents = self.client.list_agents()
  141. l2_agent = agents['agents'][0]
  142. neutron_config = self.environment.hosts[0].l2_agent.neutron_config
  143. report_interval = neutron_config['agent']['report_interval']
  144. check_agent_alive = functools.partial(self._check_agent_configurations,
  145. l2_agent['id'],
  146. physnets)
  147. utils.wait_until_true(
  148. predicate=check_agent_alive,
  149. timeout=float(report_interval) + 10,
  150. sleep=5)
  151. class TestPlacementBandwidthReport(base.BaseFullStackTestCase):
  152. scenarios = [
  153. (constants.AGENT_TYPE_OVS,
  154. {'l2_agent_type': constants.AGENT_TYPE_OVS,
  155. 'mech_drivers': 'openvswitch,linuxbridge',
  156. 'placement_port': '8080'}),
  157. (constants.AGENT_TYPE_NIC_SWITCH,
  158. {'l2_agent_type': constants.AGENT_TYPE_NIC_SWITCH,
  159. 'mech_drivers': 'sriovnicswitch',
  160. 'placement_port': '8081'})
  161. ]
  162. def setUp(self):
  163. host_desc = [environment.HostDescription(
  164. l3_agent=False,
  165. l2_agent_type=self.l2_agent_type)]
  166. env_desc = environment.EnvironmentDescription(
  167. network_type='vlan',
  168. l2_pop=False,
  169. mech_drivers=self.mech_drivers,
  170. report_bandwidths=True,
  171. has_placement=True,
  172. placement_port=self.placement_port
  173. )
  174. env = environment.Environment(env_desc, host_desc)
  175. super(TestPlacementBandwidthReport, self).setUp(env)
  176. def _check_agent_not_synced(self):
  177. return not self._check_agent_synced()
  178. def _check_agent_synced(self):
  179. agents = self.client.list_agents(agent_type=self.l2_agent_type)
  180. for agent in agents['agents']:
  181. if (agent['id'] == self.original_agent_id and
  182. agent['resources_synced']):
  183. return True
  184. return False
  185. def test_configurations_are_synced_towards_placement(self):
  186. neutron_config = self.environment.hosts[0].l2_agent.neutron_config
  187. report_interval = int(neutron_config['agent']['report_interval'])
  188. agents = self.client.list_agents(agent_type=self.l2_agent_type)
  189. self.assertEqual(1, len(agents['agents']))
  190. self.original_agent_id = agents['agents'][0]['id']
  191. check_agent_synced = functools.partial(self._check_agent_synced)
  192. utils.wait_until_true(
  193. predicate=check_agent_synced,
  194. timeout=report_interval + 10,
  195. sleep=1)
  196. self.environment.placement.process_fixture.stop()
  197. _add_new_bridge_and_restart_agent(self.environment.hosts[0])
  198. check_agent_not_synced = functools.partial(
  199. self._check_agent_not_synced)
  200. utils.wait_until_true(
  201. predicate=check_agent_not_synced,
  202. timeout=report_interval + 10,
  203. sleep=1)
  204. self.environment.placement.process_fixture.start()
  205. check_agent_synced = functools.partial(self._check_agent_synced)
  206. utils.wait_until_true(
  207. predicate=check_agent_synced,
  208. timeout=report_interval + 10,
  209. sleep=1)