Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F117521241
test_service_tftp-server.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
test_service_tftp-server.py
View Options
#!/usr/bin/env python3
#
# Copyright (C) 2019-2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
re
import
os
import
unittest
from
psutil
import
process_iter
from
vyos.configsession
import
ConfigSession
from
vyos.configsession
import
ConfigSessionError
from
vyos.util
import
read_file
from
vyos.util
import
process_named_running
from
vyos.validate
import
is_ipv6
PROCESS_NAME
=
'in.tftpd'
base_path
=
[
'service'
,
'tftp-server'
]
class
TestServiceTFTPD
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
session
=
ConfigSession
(
os
.
getpid
())
self
.
session
.
delete
(
base_path
)
def
tearDown
(
self
):
self
.
session
.
delete
(
base_path
)
self
.
session
.
commit
()
del
self
.
session
def
test_tftpd_single
(
self
):
directory
=
'/tmp'
address
=
'127.0.0.1'
port
=
'69'
# default port
self
.
session
.
set
(
base_path
+
[
'allow-upload'
])
self
.
session
.
set
(
base_path
+
[
'directory'
,
directory
])
self
.
session
.
set
(
base_path
+
[
'listen-address'
,
address
])
# commit changes
self
.
session
.
commit
()
config
=
read_file
(
'/etc/default/tftpd0'
)
# verify listen IP address
self
.
assertIn
(
f
'{address}:{port} -4'
,
config
)
# verify directory
self
.
assertIn
(
directory
,
config
)
# verify upload
self
.
assertIn
(
'--create --umask 000'
,
config
)
# Check for running process
self
.
assertTrue
(
process_named_running
(
PROCESS_NAME
))
def
test_tftpd_multi
(
self
):
directory
=
'/tmp'
address
=
[
'127.0.0.1'
,
'::1'
]
port
=
'70'
self
.
session
.
set
(
base_path
+
[
'directory'
,
directory
])
for
addr
in
address
:
self
.
session
.
set
(
base_path
+
[
'listen-address'
,
addr
])
self
.
session
.
set
(
base_path
+
[
'port'
,
port
])
# commit changes
self
.
session
.
commit
()
for
idx
in
range
(
0
,
len
(
address
)):
config
=
read_file
(
f
'/etc/default/tftpd{idx}'
)
addr
=
address
[
idx
]
# verify listen IP address
if
is_ipv6
(
addr
):
addr
=
f
'[{addr}]'
self
.
assertIn
(
f
'{addr}:{port} -6'
,
config
)
else
:
self
.
assertIn
(
f
'{addr}:{port} -4'
,
config
)
# verify directory
self
.
assertIn
(
directory
,
config
)
# Check for running processes - one process is spawned per listen
# IP address, wheter it's IPv4 or IPv6
count
=
0
for
p
in
process_iter
():
if
PROCESS_NAME
in
p
.
name
():
count
+=
1
self
.
assertEqual
(
count
,
len
(
address
))
if
__name__
==
'__main__'
:
unittest
.
main
()
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Sat, Sep 26, 2:27 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4285393
Default Alt Text
test_service_tftp-server.py (3 KB)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment