def try_to_bind(self, context, agent=None):
for segment in context.segments_to_bind:
if self.check_segment(segment, agent):
+ port_status = (constants.PORT_STATUS_ACTIVE if agent is None
+ else constants.PORT_STATUS_DOWN)
context.set_binding(segment[api.ID],
self.vif_type,
self._get_vif_details(segment),
- constants.PORT_STATUS_ACTIVE)
+ port_status)
LOG.debug("Bound using segment: %s", segment)
return True
return False
class SriovSwitchMechVifDetailsTestCase(SriovNicSwitchMechanismBaseTestCase):
- def test_vif_details_contains_vlan_id(self):
- VLAN_SEGMENTS = [{api.ID: 'vlan_segment_id',
- api.NETWORK_TYPE: 'vlan',
- api.PHYSICAL_NETWORK: 'fake_physical_network',
- api.SEGMENTATION_ID: 1234}]
+ VLAN_SEGMENTS = [{api.ID: 'vlan_segment_id',
+ api.NETWORK_TYPE: 'vlan',
+ api.PHYSICAL_NETWORK: 'fake_physical_network',
+ api.SEGMENTATION_ID: 1234}]
+ def test_vif_details_contains_vlan_id(self):
context = TestFakePortContext(self.AGENT_TYPE,
self.AGENTS,
- VLAN_SEGMENTS,
+ self.VLAN_SEGMENTS,
portbindings.VNIC_DIRECT)
self.driver.bind_port(context)
with testtools.ExpectedException(exc.SriovUnsupportedNetworkType):
self.driver._get_vif_details(segment)
+ def test_get_vif_details_without_agent(self):
+ cfg.CONF.set_override('agent_required', False, 'ml2_sriov')
+ self.driver = mech_driver.SriovNicSwitchMechanismDriver()
+ self.driver.initialize()
+ context = TestFakePortContext(self.AGENT_TYPE,
+ self.AGENTS,
+ self.VLAN_SEGMENTS,
+ portbindings.VNIC_DIRECT)
+
+ self.driver.bind_port(context)
+ self.assertEqual(constants.PORT_STATUS_ACTIVE, context._bound_state)
+
+ def test_get_vif_details_with_agent(self):
+ context = TestFakePortContext(self.AGENT_TYPE,
+ self.AGENTS,
+ self.VLAN_SEGMENTS,
+ portbindings.VNIC_DIRECT)
+
+ self.driver.bind_port(context)
+ self.assertEqual(constants.PORT_STATUS_DOWN, context._bound_state)
+
class SriovSwitchMechConfigTestCase(SriovNicSwitchMechanismBaseTestCase):
def _set_config(self, pci_devs=['aa:bb']):