From 950b601a9c9e87661e35c6ed7a97ae9611560bc5 Mon Sep 17 00:00:00 2001 From: Sivasathurappan Radhakrishnan Date: Tue, 5 Apr 2016 22:45:17 +0000 Subject: [PATCH] Modified REPLICATE request to use replication_ip direct_client.direct_get_suffix_hashes doesn't use replication ip and port for REPLICATE request. Since we have an option of doing replication in separate network, we can add replication_ip and port while creating rings if not it will get filled in with the regular node's ip. Change-Id: I34067df27042fc3146b795191ab8043ee1aed3ce Closes-Bug:1566395 --- swift/common/direct_client.py | 5 +++-- test/unit/common/test_direct_client.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/swift/common/direct_client.py b/swift/common/direct_client.py index 0dea8acefc..a507901edc 100644 --- a/swift/common/direct_client.py +++ b/swift/common/direct_client.py @@ -482,8 +482,9 @@ def direct_get_suffix_hashes(node, part, suffixes, conn_timeout=5, path = '/%s' % '-'.join(suffixes) with Timeout(conn_timeout): - conn = http_connect(node['ip'], node['port'], node['device'], part, - 'REPLICATE', path, headers=gen_headers(headers)) + conn = http_connect(node['replication_ip'], node['replication_port'], + node['device'], part, 'REPLICATE', path, + headers=gen_headers(headers)) with Timeout(response_timeout): resp = conn.getresponse() if not is_success(resp.status): diff --git a/test/unit/common/test_direct_client.py b/test/unit/common/test_direct_client.py index 664a6227b1..2bcc94c13d 100644 --- a/test/unit/common/test_direct_client.py +++ b/test/unit/common/test_direct_client.py @@ -19,6 +19,7 @@ import os from contextlib import contextmanager from hashlib import md5 import time +import pickle import mock import six @@ -97,7 +98,8 @@ def mocked_http_conn(*args, **kwargs): class TestDirectClient(unittest.TestCase): def setUp(self): - self.node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda'} + self.node = {'ip': '1.2.3.4', 'port': '6000', 'device': 'sda', + 'replication_ip': '1.2.3.5', 'replication_port': '7000'} self.part = '0' self.account = u'\u062a account' @@ -617,6 +619,18 @@ class TestDirectClient(unittest.TestCase): self.assertEqual(err.http_status, 503) self.assertTrue('DELETE' in str(err)) + def test_direct_get_suffix_hashes(self): + data = {'a83': 'c130a2c17ed45102aada0f4eee69494ff'} + body = pickle.dumps(data) + with mocked_http_conn(200, {}, body) as conn: + resp = direct_client.direct_get_suffix_hashes(self.node, + self.part, ['a83']) + self.assertEqual(conn.method, 'REPLICATE') + self.assertEqual(conn.path, '/sda/0/a83') + self.assertEqual(conn.host, '1.2.3.5') + self.assertEqual(conn.port, '7000') + self.assertEqual(data, resp) + def test_direct_put_object_with_content_length(self): contents = six.StringIO('123456')