Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
010b6c8d
authored
Jun 06, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: fix the Vlan's get_new_address() method, and add test
parent
51f7a578
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
7 deletions
+14
-7
circle/firewall/models.py
+5
-7
circle/firewall/tests/test_firewall.py
+9
-0
No files found.
circle/firewall/models.py
View file @
010b6c8d
...
...
@@ -36,7 +36,6 @@ from django.core.validators import MinValueValidator, MaxValueValidator
from
django.core.urlresolvers
import
reverse
import
django.conf
from
django.db.models.signals
import
post_save
,
post_delete
from
django.db.models
import
Q
from
celery.exceptions
import
TimeoutError
from
netaddr
import
IPSet
,
EUI
,
IPNetwork
,
IPAddress
,
ipv6_full
...
...
@@ -500,12 +499,11 @@ class Vlan(AclBase, models.Model):
def
get_new_address
(
self
):
hosts
=
self
.
host_set
query
=
Q
(
shared_ip
=
False
)
\
|
Q
(
external_ipv4__isnull
=
False
)
\
|
Q
(
vlan
=
self
)
ipv4_hosts
=
Host
.
objects
.
filter
(
query
)
used_v4
=
IPSet
(
ipv4_hosts
.
values_list
(
'ipv4'
,
flat
=
True
))
used_ext_addrs
=
Host
.
objects
.
filter
(
external_ipv4__isnull
=
False
)
.
values_list
(
'external_ipv4'
,
flat
=
True
)
used_v4
=
IPSet
(
hosts
.
values_list
(
'ipv4'
,
flat
=
True
))
.
union
(
used_ext_addrs
)
.
union
([
self
.
network4
.
ip
])
used_v6
=
IPSet
(
hosts
.
exclude
(
ipv6__isnull
=
True
)
.
values_list
(
'ipv6'
,
flat
=
True
))
...
...
circle/firewall/tests/test_firewall.py
View file @
010b6c8d
...
...
@@ -102,6 +102,15 @@ class GetNewAddressTestCase(MockCeleryMixin, TestCase):
owner
=
self
.
u1
)
.
save
()
self
.
assertRaises
(
ValidationError
,
self
.
vlan
.
get_new_address
)
def
test_all_addr_in_use2
(
self
):
Host
(
hostname
=
'h-xd'
,
mac
=
'01:02:03:04:05:06'
,
ipv4
=
'10.0.0.6'
,
vlan
=
self
.
vlan
,
owner
=
self
.
u1
)
.
save
()
Host
(
hostname
=
'h-arni'
,
mac
=
'01:02:03:04:05:02'
,
ipv4
=
'100.0.0.1'
,
vlan
=
self
.
vlan
,
external_ipv4
=
'10.0.0.2'
,
owner
=
self
.
u1
)
.
save
()
self
.
assertRaises
(
ValidationError
,
self
.
vlan
.
get_new_address
)
def
test_new_addr
(
self
):
used_v4
=
IPSet
(
self
.
vlan
.
host_set
.
values_list
(
'ipv4'
,
flat
=
True
))
assert
self
.
vlan
.
get_new_address
()[
'ipv4'
]
not
in
used_v4
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment