Fix Mac OS X socket.AF_INET6 code
Linux is using AF_INET6 code equal to 10 on Mac OS X it's 30 because of that numeric codes changed for socket reference. Additionally a few lines changed to be more pythonic - removed unnecessary plus signs from beginning of line. Change-Id: Ie5afa2a98ea1b98d8e4148f258c071971975d9b9 Closes-Bug: #1540662
This commit is contained in:
parent
c6a9be4b74
commit
d5137d1733
@ -15,6 +15,7 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import socket
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -165,7 +166,7 @@ class ServerTestCase(base.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{'message': 'OK',
|
{'message': 'OK',
|
||||||
'details': 'Configuration file is valid\nhaproxy daemon for'
|
'details': 'Configuration file is valid\nhaproxy daemon for'
|
||||||
+ ' 123 started'},
|
' 123 started'},
|
||||||
json.loads(rv.data.decode('utf-8')))
|
json.loads(rv.data.decode('utf-8')))
|
||||||
mock_subprocess.assert_called_with(
|
mock_subprocess.assert_called_with(
|
||||||
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
|
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
|
||||||
@ -284,11 +285,11 @@ class ServerTestCase(base.TestCase):
|
|||||||
rv.headers['Content-Type'])
|
rv.headers['Content-Type'])
|
||||||
|
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.util.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.util.'
|
||||||
+ 'get_listeners')
|
'get_listeners')
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_check_listener_status')
|
'_check_listener_status')
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_parse_haproxy_file')
|
'_parse_haproxy_file')
|
||||||
def test_get_all_listeners(self, mock_parse, mock_status, mock_listener):
|
def test_get_all_listeners(self, mock_parse, mock_status, mock_listener):
|
||||||
# no listeners
|
# no listeners
|
||||||
mock_listener.side_effect = [[]]
|
mock_listener.side_effect = [[]]
|
||||||
@ -321,9 +322,9 @@ class ServerTestCase(base.TestCase):
|
|||||||
json.loads(rv.data.decode('utf-8')))
|
json.loads(rv.data.decode('utf-8')))
|
||||||
|
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_check_listener_status')
|
'_check_listener_status')
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_parse_haproxy_file')
|
'_parse_haproxy_file')
|
||||||
@mock.patch('octavia.amphorae.backends.utils.haproxy_query.HAProxyQuery')
|
@mock.patch('octavia.amphorae.backends.utils.haproxy_query.HAProxyQuery')
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
def test_get_listener(self, mock_exists, mock_query, mock_parse,
|
def test_get_listener(self, mock_exists, mock_query, mock_parse,
|
||||||
@ -692,7 +693,7 @@ class ServerTestCase(base.TestCase):
|
|||||||
|
|
||||||
# Happy path
|
# Happy path
|
||||||
netns_handle.get_addr.return_value = [{
|
netns_handle.get_addr.return_value = [{
|
||||||
'index': 3, 'family': 2,
|
'index': 3, 'family': socket.AF_INET,
|
||||||
'attrs': [['IFA_ADDRESS', '203.0.113.2']]}]
|
'attrs': [['IFA_ADDRESS', '203.0.113.2']]}]
|
||||||
netns_handle.get_links.return_value = [{
|
netns_handle.get_links.return_value = [{
|
||||||
'attrs': [['IFLA_IFNAME', 'eth0']]}]
|
'attrs': [['IFLA_IFNAME', 'eth0']]}]
|
||||||
@ -703,7 +704,7 @@ class ServerTestCase(base.TestCase):
|
|||||||
|
|
||||||
# Happy path with IPv6 address normalization
|
# Happy path with IPv6 address normalization
|
||||||
netns_handle.get_addr.return_value = [{
|
netns_handle.get_addr.return_value = [{
|
||||||
'index': 3, 'family': 10,
|
'index': 3, 'family': socket.AF_INET6,
|
||||||
'attrs': [['IFA_ADDRESS',
|
'attrs': [['IFA_ADDRESS',
|
||||||
'0000:0000:0000:0000:0000:0000:0000:0001']]}]
|
'0000:0000:0000:0000:0000:0000:0000:0001']]}]
|
||||||
netns_handle.get_links.return_value = [{
|
netns_handle.get_links.return_value = [{
|
||||||
|
@ -15,6 +15,7 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import socket
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -172,7 +173,7 @@ class ServerTestCase(base.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{'message': 'OK',
|
{'message': 'OK',
|
||||||
'details': 'Configuration file is valid\nhaproxy daemon for'
|
'details': 'Configuration file is valid\nhaproxy daemon for'
|
||||||
+ ' 123 started'},
|
' 123 started'},
|
||||||
json.loads(rv.data.decode('utf-8')))
|
json.loads(rv.data.decode('utf-8')))
|
||||||
mock_subprocess.assert_called_with(
|
mock_subprocess.assert_called_with(
|
||||||
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
|
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
|
||||||
@ -290,11 +291,11 @@ class ServerTestCase(base.TestCase):
|
|||||||
rv.headers['Content-Type'])
|
rv.headers['Content-Type'])
|
||||||
|
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.util.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.util.'
|
||||||
+ 'get_listeners')
|
'get_listeners')
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_check_listener_status')
|
'_check_listener_status')
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_parse_haproxy_file')
|
'_parse_haproxy_file')
|
||||||
def test_get_all_listeners(self, mock_parse, mock_status, mock_listener):
|
def test_get_all_listeners(self, mock_parse, mock_status, mock_listener):
|
||||||
# no listeners
|
# no listeners
|
||||||
mock_listener.side_effect = [[]]
|
mock_listener.side_effect = [[]]
|
||||||
@ -327,9 +328,9 @@ class ServerTestCase(base.TestCase):
|
|||||||
json.loads(rv.data.decode('utf-8')))
|
json.loads(rv.data.decode('utf-8')))
|
||||||
|
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_check_listener_status')
|
'_check_listener_status')
|
||||||
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
@mock.patch('octavia.amphorae.backends.agent.api_server.listener.'
|
||||||
+ '_parse_haproxy_file')
|
'_parse_haproxy_file')
|
||||||
@mock.patch('octavia.amphorae.backends.utils.haproxy_query.HAProxyQuery')
|
@mock.patch('octavia.amphorae.backends.utils.haproxy_query.HAProxyQuery')
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
def test_get_listener(self, mock_exists, mock_query, mock_parse,
|
def test_get_listener(self, mock_exists, mock_query, mock_parse,
|
||||||
@ -698,7 +699,7 @@ class ServerTestCase(base.TestCase):
|
|||||||
|
|
||||||
# Happy path
|
# Happy path
|
||||||
netns_handle.get_addr.return_value = [{
|
netns_handle.get_addr.return_value = [{
|
||||||
'index': 3, 'family': 2,
|
'index': 3, 'family': socket.AF_INET,
|
||||||
'attrs': [['IFA_ADDRESS', '203.0.113.2']]}]
|
'attrs': [['IFA_ADDRESS', '203.0.113.2']]}]
|
||||||
netns_handle.get_links.return_value = [{
|
netns_handle.get_links.return_value = [{
|
||||||
'attrs': [['IFLA_IFNAME', 'eth0']]}]
|
'attrs': [['IFLA_IFNAME', 'eth0']]}]
|
||||||
@ -709,7 +710,7 @@ class ServerTestCase(base.TestCase):
|
|||||||
|
|
||||||
# Happy path with IPv6 address normalization
|
# Happy path with IPv6 address normalization
|
||||||
netns_handle.get_addr.return_value = [{
|
netns_handle.get_addr.return_value = [{
|
||||||
'index': 3, 'family': 10,
|
'index': 3, 'family': socket.AF_INET6,
|
||||||
'attrs': [['IFA_ADDRESS',
|
'attrs': [['IFA_ADDRESS',
|
||||||
'0000:0000:0000:0000:0000:0000:0000:0001']]}]
|
'0000:0000:0000:0000:0000:0000:0000:0001']]}]
|
||||||
netns_handle.get_links.return_value = [{
|
netns_handle.get_links.return_value = [{
|
||||||
|
Loading…
Reference in New Issue
Block a user