|
|
|
|
@ -594,6 +594,14 @@ class FakeConnection:
|
|
|
|
|
name = root.get("name")
|
|
|
|
|
if not name:
|
|
|
|
|
raise FakeLibvirtError("nwfilter name missing")
|
|
|
|
|
existing = self.backend.nwfilters.get(name)
|
|
|
|
|
if existing is not None:
|
|
|
|
|
existing_uuid = ET.fromstring(
|
|
|
|
|
existing.XMLDesc(0)).findtext("uuid")
|
|
|
|
|
requested_uuid = root.findtext("uuid")
|
|
|
|
|
if requested_uuid != existing_uuid:
|
|
|
|
|
raise FakeLibvirtError(
|
|
|
|
|
f"filter '{name}' already exists with uuid {existing_uuid}")
|
|
|
|
|
network_filter = FakeNWFilter(self.backend, xml)
|
|
|
|
|
self.backend.nwfilters[name] = network_filter
|
|
|
|
|
self.backend.nwfilter_define_xmls.append(copy.deepcopy(root))
|
|
|
|
|
@ -925,6 +933,42 @@ class VMServiceTests(unittest.TestCase):
|
|
|
|
|
self.assertFalse(drifted["matches"])
|
|
|
|
|
self.assertEqual(drifted["sync_state"], "drifted")
|
|
|
|
|
|
|
|
|
|
def test_disabled_firewall_can_be_enabled_without_uuid_conflict(self):
|
|
|
|
|
service = self.cloud_service()
|
|
|
|
|
created = self.create_cloud_vm(service, self.cloud_spec())
|
|
|
|
|
rules = [{
|
|
|
|
|
"protocol": "tcp", "source_cidr": "203.0.113.55/32",
|
|
|
|
|
"port_from": 22, "port_to": 22, "description": "SSH",
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
disabled = service.apply_firewall_policy(
|
|
|
|
|
created["uuid"], enabled=False, rules=rules)
|
|
|
|
|
filter_name = self.service_module.firewall_filter_name(created["uuid"])
|
|
|
|
|
assigned_uuid = ET.fromstring(
|
|
|
|
|
self.backend.nwfilters[filter_name].XMLDesc(0)).findtext("uuid")
|
|
|
|
|
|
|
|
|
|
enabled = service.apply_firewall_policy(
|
|
|
|
|
created["uuid"], enabled=True, rules=rules)
|
|
|
|
|
|
|
|
|
|
self.assertFalse(disabled["enabled"])
|
|
|
|
|
self.assertTrue(enabled["enabled"])
|
|
|
|
|
self.assertEqual(len(self.backend.nwfilter_define_xmls), 2)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.backend.nwfilter_define_xmls[-1].findtext("uuid"),
|
|
|
|
|
assigned_uuid,
|
|
|
|
|
)
|
|
|
|
|
applied_root = ET.fromstring(
|
|
|
|
|
self.backend.nwfilters[filter_name].XMLDesc(0))
|
|
|
|
|
self.assertEqual(applied_root.findtext("uuid"), assigned_uuid)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
[child.tag for rule in applied_root.findall("rule")
|
|
|
|
|
if rule.get("action") == "drop" for child in rule],
|
|
|
|
|
["all-ipv6", "all"],
|
|
|
|
|
)
|
|
|
|
|
evidence = service.reconcile_firewall_policy(
|
|
|
|
|
created["uuid"], enabled=True, rules=rules)
|
|
|
|
|
self.assertTrue(evidence["matches"])
|
|
|
|
|
|
|
|
|
|
def test_public_ip_helper_updates_managed_firewall_without_adding_baseline(self):
|
|
|
|
|
vm_id = "00000000-0000-4000-8000-000000000001"
|
|
|
|
|
interface = ET.fromstring(
|
|
|
|
|
|