summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem@us.ibm.com>2016-03-08 18:05:47 +0000
committerMatt Riedemann <mriedem@us.ibm.com>2016-03-08 20:12:31 -0500
commit3c71e52b408bbd6c33fca85188db2c8f156fb341 (patch)
treeb96aed550a3ab211708cf0f072bb4c82b7a22cb1
parent9165c47123255fc76e86901117d9591226d5f992 (diff)
downloadpython-troveclient-3c71e52b408bbd6c33fca85188db2c8f156fb341.tar.gz
Revert "Time to get rid of any last vestiges of slave_of"2.1.1
This reverts commit a5234f0a07230e0d8195687e033adfe4cc0ad522 The change broke trove on stable/liberty since it's a backward incompatible change. To avoid capping python-troveclient<2.1.0 in stable/liberty global-requirements, we have to revert this change, blacklist the 2.1.0 version in g-r master and stable/liberty, and then release 2.2.0. And the slave_of code can't be removed until the last supported stable branch that uses it is end of life, which is liberty-eol. For now we keep the slave_of argument in the instance.create method, but emit a deprecation warning if it's specified, and we never pass it to the trove API for the create or edit operations since the API removed slave_of in 0c94a5bae0aacff7fde9a9742b7d526096e51767. Change-Id: I9b3ec6c101a89f30e61fc683808506c404e5474f Partial-Bug: #1538506
-rw-r--r--troveclient/tests/test_instances.py20
-rw-r--r--troveclient/v1/instances.py18
2 files changed, 31 insertions, 7 deletions
diff --git a/troveclient/tests/test_instances.py b/troveclient/tests/test_instances.py
index e893c3f..6d96e0e 100644
--- a/troveclient/tests/test_instances.py
+++ b/troveclient/tests/test_instances.py
@@ -88,7 +88,8 @@ class InstancesTest(testtools.TestCase):
super(InstancesTest, self).tearDown()
instances.Instances.__init__ = self.orig__init
- def test_create(self):
+ @mock.patch('warnings.warn')
+ def test_create(self, mock_warn):
def side_effect_func(path, body, inst):
return path, body, inst
@@ -98,7 +99,7 @@ class InstancesTest(testtools.TestCase):
['db1', 'db2'], ['u1', 'u2'],
datastore="datastore",
datastore_version="datastore-version",
- nics=nics)
+ nics=nics, slave_of='test')
self.assertEqual("/instances", p)
self.assertEqual("instance", i)
self.assertEqual(['db1', 'db2'], b["instance"]["databases"])
@@ -110,6 +111,11 @@ class InstancesTest(testtools.TestCase):
b["instance"]["datastore"]["version"])
self.assertEqual(nics, b["instance"]["nics"])
self.assertEqual(103, b["instance"]["flavorRef"])
+ # Assert that slave_of is not used and if specified, there is a warning
+ # and it's value is used for replica_of.
+ self.assertEqual('test', b['instance']['replica_of'])
+ self.assertNotIn('slave_of', b['instance'])
+ self.assertTrue(mock_warn.called)
def test_list(self):
page_mock = mock.Mock()
@@ -211,8 +217,14 @@ class InstancesTest(testtools.TestCase):
def test_edit(self):
resp = mock.Mock()
resp.status_code = 204
- body = None
- self.instances.api.client.patch = mock.Mock(return_value=(resp, body))
+
+ def fake_patch(url, body):
+ # Make sure we never pass slave_of to the API.
+ self.assertIn('instance', body)
+ self.assertNotIn('slave_of', body['instance'])
+ return resp, None
+
+ self.instances.api.client.patch = mock.Mock(side_effect=fake_patch)
self.instances.edit(123)
self.instances.edit(123, 321)
self.instances.edit(123, 321, 'name-1234')
diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py
index 6a4c40b..a9c5014 100644
--- a/troveclient/v1/instances.py
+++ b/troveclient/v1/instances.py
@@ -15,9 +15,12 @@
# License for the specific language governing permissions and limitations
# under the License.
+import warnings
+
from troveclient import base
from troveclient import common
from troveclient import exceptions
+from troveclient.i18n import _LW
from swiftclient import client as swift_client
@@ -78,10 +81,11 @@ class Instances(base.ManagerWithFind):
return swift_client.Connection(
auth_url, user, key, auth_version="2.0", os_options=os_options)
+ # TODO(mriedem): Remove slave_of after liberty-eol for Trove.
def create(self, name, flavor_id, volume=None, databases=None, users=None,
restorePoint=None, availability_zone=None, datastore=None,
datastore_version=None, nics=None, configuration=None,
- replica_of=None, replica_count=None):
+ replica_of=None, slave_of=None, replica_count=None):
"""Create (boot) a new instance."""
body = {"instance": {
@@ -109,8 +113,14 @@ class Instances(base.ManagerWithFind):
body["instance"]["nics"] = nics
if configuration:
body["instance"]["configuration"] = configuration
- if replica_of:
- body["instance"]["replica_of"] = base.getid(replica_of)
+ if replica_of or slave_of:
+ if slave_of:
+ warnings.warn(_LW("The 'slave_of' argument is deprecated in "
+ "favor of 'replica_of' and will be removed "
+ "after the Trove liberty series is end of "
+ "life."),
+ category=DeprecationWarning)
+ body["instance"]["replica_of"] = base.getid(replica_of) or slave_of
if replica_count:
body["instance"]["replica_count"] = replica_count
@@ -143,6 +153,8 @@ class Instances(base.ManagerWithFind):
if name is not None:
body["instance"]["name"] = name
if detach_replica_source:
+ # NOTE(mriedem): We don't send slave_of since it was removed from
+ # the trove API in mitaka.
body["instance"]["replica_of"] = None
url = "/instances/%s" % base.getid(instance)