def test_get_or_create_ofport_existing(self):
    port_dict = {'device': 'port-id', 'security_groups': [123, 456]}
    of_port = create_ofport(port_dict)
    self.firewall.sg_port_map.ports[of_port.id] = of_port
    port = self.firewall.get_or_create_ofport(port_dict)
    (sg1, sg2) = sorted(self.firewall.sg_port_map.sec_groups.values(), key=(lambda x: x.id))
    self.assertIs(of_port, port)
    self.assertIn(port, self.firewall.sg_port_map.ports.values())
    self.assertEqual(sorted(port.sec_groups, key=(lambda x: x.id)), [sg1, sg2])
    self.assertIn(port, sg1.ports)
    self.assertIn(port, sg2.ports)
def test_get_or_create_ofport_existing(self):
    port_dict = {'device': 'port-id', 'security_groups': [123, 456]}
    of_port = create_ofport(port_dict)
    self.firewall.sg_port_map.ports[of_port.id] = of_port
    port = self.firewall.get_or_create_ofport(port_dict)
    (sg1, sg2) = sorted(self.firewall.sg_port_map.sec_groups.values(), key=(lambda x: x.id))
    self.assertIs(of_port, port)
    self.assertIn(port, self.firewall.sg_port_map.ports.values())
    self.assertEqual(sorted(port.sec_groups, key=(lambda x: x.id)), [sg1, sg2])
    self.assertIn(port, sg1.ports)
    self.assertIn(port, sg2.ports)