Пример #1
0
    def _make_service(self, ri, fw, rule, servs):
        prefix = va_utils.get_firewall_object_prefix(ri, fw)

        if rule.get('protocol'):
            key = rule.get('protocol')
            if rule.get('source_port'):
                key += '-' + rule.get('source_port')
            if rule.get('destination_port'):
                key += '-' + rule.get('destination_port')
        else:
            return

        if key in servs:
            name = '%s_%d' % (prefix, servs[key])
        else:
            # create new service object with index
            idx = len(servs)
            servs[key] = idx
            name = '%s_%d' % (prefix, idx)

            body = {'name': name}
            self.rest.rest_api('POST', va_utils.REST_URL_CONF_SERVICE, body)
            body = self._make_service_rule(rule)
            self.rest.rest_api(
                'POST',
                va_utils.REST_URL_CONF + va_utils.REST_SERVICE_NAME % name,
                body)
            self.rest.commit()

        return name
Пример #2
0
    def _make_address(self, ri, fw, rule, addrs, is_src):
        prefix = va_utils.get_firewall_object_prefix(ri, fw)

        if is_src:
            key = rule.get('source_ip_address')
        else:
            key = rule.get('destination_ip_address')

        if not key:
            return

        if key in addrs:
            name = '%s_%d' % (prefix, addrs[key])
        else:
            # create new address object with idx
            idx = len(addrs)
            addrs[key] = idx
            name = '%s_%d' % (prefix, idx)

            body = {
                'name': name,
                'type': 'ipv4',
                'ipv4': key
            }
            self.rest.rest_api('POST', va_utils.REST_URL_CONF_ADDR, body)
            self.rest.commit()

        return name
Пример #3
0
    def test_firewall_without_rule(self):
        router = self._create_router()
        fwaas = self._create_fwaas()
        try:
            router.rest.auth()
        except Exception:
            # skip the test, firewall is not deployed
            return

        ri = self._prepare_router_data(enable_snat=True)
        self._add_internal_ports(ri.router, port_count=1)
        self._add_floating_ips(ri.router, port_count=1)
        router._router_added(ri.router['id'], ri.router)

        rl = [ri]

        fw = self._prepare_firewall_data()
        fwaas.create_firewall(rl, fw)

        url = varmour_utils.REST_URL_CONF_POLICY
        prefix = varmour_utils.get_firewall_object_prefix(ri, fw)

        n = fwaas.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0)

        fwaas.delete_firewall(rl, fw)
        n = fwaas.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0)

        router._router_removed(ri.router['id'])
Пример #4
0
    def _make_service(self, ri, fw, rule, servs):
        prefix = va_utils.get_firewall_object_prefix(ri, fw)

        if rule.get('protocol'):
            key = rule.get('protocol')
            if rule.get('source_port'):
                key += '-' + rule.get('source_port')
            if rule.get('destination_port'):
                key += '-' + rule.get('destination_port')
        else:
            return

        if key in servs:
            name = '%s_%d' % (prefix, servs[key])
        else:
            # create new service object with index
            idx = len(servs)
            servs[key] = idx
            name = '%s_%d' % (prefix, idx)

            body = {'name': name}
            self.rest.rest_api('POST',
                               va_utils.REST_URL_CONF_SERVICE,
                               body)
            body = self._make_service_rule(rule)
            self.rest.rest_api('POST',
                               va_utils.REST_URL_CONF +
                               va_utils.REST_SERVICE_NAME % name,
                               body)
            self.rest.commit()

        return name
Пример #5
0
    def test_firewall_without_rule(self):
        router = self._create_router()
        fwaas = self._create_fwaas()
        try:
            router.rest.auth()
        except Exception:
            # skip the test, firewall is not deployed
            return

        ri = self._prepare_router_data(enable_snat=True)
        self._add_internal_ports(ri.router, port_count=1)
        self._add_floating_ips(ri.router, port_count=1)
        router._router_added(ri.router['id'], ri.router)

        rl = [ri]

        fw = self._prepare_firewall_data()
        fwaas.create_firewall(rl, fw)

        url = varmour_utils.REST_URL_CONF_POLICY
        prefix = varmour_utils.get_firewall_object_prefix(ri, fw)

        n = fwaas.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0)

        fwaas.delete_firewall(rl, fw)
        n = fwaas.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0)

        router._router_removed(ri.router['id'])
Пример #6
0
    def _make_address(self, ri, fw, rule, addrs, is_src):
        prefix = va_utils.get_firewall_object_prefix(ri, fw)

        if is_src:
            key = rule.get('source_ip_address')
        else:
            key = rule.get('destination_ip_address')

        if not key:
            return

        if key in addrs:
            name = '%s_%d' % (prefix, addrs[key])
        else:
            # create new address object with idx
            idx = len(addrs)
            addrs[key] = idx
            name = '%s_%d' % (prefix, idx)

            body = {
                'name': name,
                'type': 'ipv4',
                'ipv4': key
            }
            self.rest.rest_api('POST', va_utils.REST_URL_CONF_ADDR, body)
            self.rest.commit()

        return name
Пример #7
0
    def test_firewall_add_remove_rules(self):
        router = self._create_router()
        fwaas = self._create_fwaas()
        try:
            router.rest.auth()
        except Exception:
            # skip the test, firewall is not deployed
            return

        ri = self._prepare_router_data(enable_snat=True)
        self._add_internal_ports(ri.router, port_count=1)
        self._add_floating_ips(ri.router, port_count=1)
        router._router_added(ri.router['id'], ri.router)

        rl = [ri]

        fw = self._prepare_firewall_data()
        self._add_firewall_rules(fw, 2)
        fwaas.create_firewall(rl, fw)

        prefix = varmour_utils.get_firewall_object_prefix(ri, fw)
        pol_url = varmour_utils.REST_URL_CONF_POLICY
        serv_url = varmour_utils.REST_URL_CONF_SERVICE
        addr_url = varmour_utils.REST_URL_CONF_ADDR

        # 3x number of policies
        n = fwaas.rest.count_cfg_objs(pol_url, prefix)
        self.assertEqual(n, 6)
        n = fwaas.rest.count_cfg_objs(addr_url, prefix)
        self.assertEqual(n, 2)
        n = fwaas.rest.count_cfg_objs(serv_url, prefix)
        self.assertEqual(n, 2)

        self._add_firewall_rules(fw, 1)
        fwaas.create_firewall(rl, fw)
        n = fwaas.rest.count_cfg_objs(pol_url, prefix)
        self.assertEqual(n, 3)
        n = fwaas.rest.count_cfg_objs(addr_url, prefix)
        self.assertEqual(n, 1)
        n = fwaas.rest.count_cfg_objs(serv_url, prefix)
        self.assertEqual(n, 1)

        fwaas.delete_firewall(rl, fw)
        n = fwaas.rest.count_cfg_objs(pol_url, prefix)
        self.assertEqual(n, 0)

        router._router_removed(ri.router['id'])
Пример #8
0
    def test_firewall_add_remove_rules(self):
        router = self._create_router()
        fwaas = self._create_fwaas()
        try:
            router.rest.auth()
        except Exception:
            # skip the test, firewall is not deployed
            return

        ri = self._prepare_router_data(enable_snat=True)
        self._add_internal_ports(ri.router, port_count=1)
        self._add_floating_ips(ri.router, port_count=1)
        router._router_added(ri.router['id'], ri.router)

        rl = [ri]

        fw = self._prepare_firewall_data()
        self._add_firewall_rules(fw, 2)
        fwaas.create_firewall(rl, fw)

        prefix = varmour_utils.get_firewall_object_prefix(ri, fw)
        pol_url = varmour_utils.REST_URL_CONF_POLICY
        serv_url = varmour_utils.REST_URL_CONF_SERVICE
        addr_url = varmour_utils.REST_URL_CONF_ADDR

        # 3x number of policies
        n = fwaas.rest.count_cfg_objs(pol_url, prefix)
        self.assertEqual(n, 6)
        n = fwaas.rest.count_cfg_objs(addr_url, prefix)
        self.assertEqual(n, 2)
        n = fwaas.rest.count_cfg_objs(serv_url, prefix)
        self.assertEqual(n, 2)

        self._add_firewall_rules(fw, 1)
        fwaas.create_firewall(rl, fw)
        n = fwaas.rest.count_cfg_objs(pol_url, prefix)
        self.assertEqual(n, 3)
        n = fwaas.rest.count_cfg_objs(addr_url, prefix)
        self.assertEqual(n, 1)
        n = fwaas.rest.count_cfg_objs(serv_url, prefix)
        self.assertEqual(n, 1)

        fwaas.delete_firewall(rl, fw)
        n = fwaas.rest.count_cfg_objs(pol_url, prefix)
        self.assertEqual(n, 0)

        router._router_removed(ri.router['id'])
Пример #9
0
 def _clear_policy(self, ri, fw):
     prefix = va_utils.get_firewall_object_prefix(ri, fw)
     self.rest.del_cfg_objs(va_utils.REST_URL_CONF_POLICY, prefix)
     self.rest.del_cfg_objs(va_utils.REST_URL_CONF_ADDR, prefix)
     self.rest.del_cfg_objs(va_utils.REST_URL_CONF_SERVICE, prefix)
Пример #10
0
 def _clear_policy(self, ri, fw):
     prefix = va_utils.get_firewall_object_prefix(ri, fw)
     self.rest.del_cfg_objs(va_utils.REST_URL_CONF_POLICY, prefix)
     self.rest.del_cfg_objs(va_utils.REST_URL_CONF_ADDR, prefix)
     self.rest.del_cfg_objs(va_utils.REST_URL_CONF_SERVICE, prefix)