trivial: Remove dead function, variable
These are no longer used anywhere and can be removed. Change-Id: Iad73cdf92e4aec94b70d05f2f9a823432b1dea1a
This commit is contained in:
@@ -17,8 +17,6 @@ import hashlib
|
||||
import importlib
|
||||
import os
|
||||
import os.path
|
||||
import socket
|
||||
import struct
|
||||
import tempfile
|
||||
|
||||
import eventlet
|
||||
@@ -460,58 +458,6 @@ Exit code: -2''')
|
||||
mock.call(['a', '1'], None)])
|
||||
|
||||
|
||||
class VPNPingTestCase(test.NoDBTestCase):
|
||||
"""Unit tests for utils.vpn_ping()."""
|
||||
def setUp(self):
|
||||
super(VPNPingTestCase, self).setUp()
|
||||
self.port = 'fake'
|
||||
self.address = 'fake'
|
||||
self.session_id = 0x1234
|
||||
self.fmt = '!BQxxxxxQxxxx'
|
||||
|
||||
def fake_reply_packet(self, pkt_id=0x40):
|
||||
return struct.pack(self.fmt, pkt_id, 0x0, self.session_id)
|
||||
|
||||
def setup_socket(self, mock_socket, return_value, side_effect=None):
|
||||
socket_obj = mock.MagicMock()
|
||||
if side_effect is not None:
|
||||
socket_obj.recv.side_effect = side_effect
|
||||
else:
|
||||
socket_obj.recv.return_value = return_value
|
||||
mock_socket.return_value = socket_obj
|
||||
|
||||
@mock.patch.object(socket, 'socket')
|
||||
def test_vpn_ping_timeout(self, mock_socket):
|
||||
"""Server doesn't reply within timeout."""
|
||||
self.setup_socket(mock_socket, None, socket.timeout)
|
||||
rc = utils.vpn_ping(self.address, self.port,
|
||||
session_id=self.session_id)
|
||||
self.assertFalse(rc)
|
||||
|
||||
@mock.patch.object(socket, 'socket')
|
||||
def test_vpn_ping_bad_len(self, mock_socket):
|
||||
"""Test a short/invalid server reply."""
|
||||
self.setup_socket(mock_socket, 'fake_reply')
|
||||
rc = utils.vpn_ping(self.address, self.port,
|
||||
session_id=self.session_id)
|
||||
self.assertFalse(rc)
|
||||
|
||||
@mock.patch.object(socket, 'socket')
|
||||
def test_vpn_ping_bad_id(self, mock_socket):
|
||||
"""Server sends an unknown packet ID."""
|
||||
self.setup_socket(mock_socket, self.fake_reply_packet(pkt_id=0x41))
|
||||
rc = utils.vpn_ping(self.address, self.port,
|
||||
session_id=self.session_id)
|
||||
self.assertFalse(rc)
|
||||
|
||||
@mock.patch.object(socket, 'socket')
|
||||
def test_vpn_ping_ok(self, mock_socket):
|
||||
self.setup_socket(mock_socket, self.fake_reply_packet())
|
||||
rc = utils.vpn_ping(self.address, self.port,
|
||||
session_id=self.session_id)
|
||||
self.assertTrue(rc)
|
||||
|
||||
|
||||
class MonkeyPatchTestCase(test.NoDBTestCase):
|
||||
"""Unit test for utils.monkey_patch()."""
|
||||
def setUp(self):
|
||||
|
||||
@@ -28,8 +28,6 @@ import pyclbr
|
||||
import random
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
@@ -64,15 +62,6 @@ CONF = nova.conf.CONF
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# used in limits
|
||||
TIME_UNITS = {
|
||||
'SECOND': 1,
|
||||
'MINUTE': 60,
|
||||
'HOUR': 3600,
|
||||
'DAY': 86400
|
||||
}
|
||||
|
||||
|
||||
_IS_NEUTRON = None
|
||||
|
||||
synchronized = lockutils.synchronized_with_prefix('nova-')
|
||||
@@ -100,58 +89,6 @@ VIM_IMAGE_ATTRIBUTES = (
|
||||
_FILE_CACHE = {}
|
||||
|
||||
|
||||
def vpn_ping(address, port, timeout=0.05, session_id=None):
|
||||
"""Sends a vpn negotiation packet and returns the server session.
|
||||
|
||||
Returns Boolean indicating whether the vpn_server is listening.
|
||||
Basic packet structure is below.
|
||||
|
||||
Client packet (14 bytes)::
|
||||
|
||||
0 1 8 9 13
|
||||
+-+--------+-----+
|
||||
|x| cli_id |?????|
|
||||
+-+--------+-----+
|
||||
x = packet identifier 0x38
|
||||
cli_id = 64 bit identifier
|
||||
? = unknown, probably flags/padding
|
||||
|
||||
Server packet (26 bytes)::
|
||||
|
||||
0 1 8 9 13 14 21 2225
|
||||
+-+--------+-----+--------+----+
|
||||
|x| srv_id |?????| cli_id |????|
|
||||
+-+--------+-----+--------+----+
|
||||
x = packet identifier 0x40
|
||||
cli_id = 64 bit identifier
|
||||
? = unknown, probably flags/padding
|
||||
bit 9 was 1 and the rest were 0 in testing
|
||||
|
||||
"""
|
||||
# NOTE(tonyb) session_id isn't used for a real VPN connection so using a
|
||||
# cryptographically weak value is fine.
|
||||
if session_id is None:
|
||||
session_id = random.randint(0, 0xffffffffffffffff)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
data = struct.pack('!BQxxxxx', 0x38, session_id)
|
||||
sock.sendto(data, (address, port))
|
||||
sock.settimeout(timeout)
|
||||
try:
|
||||
received = sock.recv(2048)
|
||||
except socket.timeout:
|
||||
return False
|
||||
finally:
|
||||
sock.close()
|
||||
fmt = '!BQxxxxxQxxxx'
|
||||
if len(received) != struct.calcsize(fmt):
|
||||
LOG.warning(_LW('Expected to receive %(exp)s bytes, '
|
||||
'but actually %(act)s'),
|
||||
dict(exp=struct.calcsize(fmt), act=len(received)))
|
||||
return False
|
||||
(identifier, server_sess, client_sess) = struct.unpack(fmt, received)
|
||||
return (identifier == 0x40 and client_sess == session_id)
|
||||
|
||||
|
||||
def get_root_helper():
|
||||
if CONF.workarounds.disable_rootwrap:
|
||||
cmd = 'sudo'
|
||||
|
||||
Reference in New Issue
Block a user