def _lookup_dvs_for_context(self, segment):
     physical_network = segment['physical_network']
     try:
         return self.network_map[physical_network]
     except KeyError:
         LOG.debug('No dvs mapped for physical network: %s',
                   physical_network)
         raise exceptions.NoDVSForPhysicalNetwork(
             physical_network=physical_network)
    def test_delete_port_postcommit_uncontrolled_dvs(self, is_valid_dvs):
        is_valid_dvs.side_effect = exceptions.NoDVSForPhysicalNetwork(
            physical_network='_dummy_physical_net_')

        self.assertRaises(exceptions.InvalidSystemState,
                          self.agent.delete_port_postcommit,
                          self.port_context.current,
                          self.port_context.original,
                          self.port_context.network.network_segments[0])
        self.assertTrue(is_valid_dvs.called)
        self.assertFalse(self.dvs.release_port.called)
    def test_update_port_postcommit_uncontrolled_dvs(self, is_valid_dvs):
        is_valid_dvs.side_effect = exceptions.NoDVSForPhysicalNetwork(
            physical_network='_dummy_physical_net_')
        self.port_context.current['admin_state_up'] = True
        self.port_context.original['admin_state_up'] = False

        self.assertRaises(exceptions.InvalidSystemState,
                          self.agent.update_port_postcommit,
                          self.port_context.current,
                          self.port_context.original,
                          self.port_context.network.network_segments[0])
        self.assertTrue(is_valid_dvs.called)
        self.assertFalse(self.dvs.switch_port_blocked_state.called)