summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-27 19:18:12 +0000
committerGerrit Code Review <review@openstack.org>2018-07-27 19:18:12 +0000
commit1ebf414c73572d066225572326b35430af115aac (patch)
tree0a611069be2cfa1a5cfc7a03d785bc9b7013e083
parent2125395c20db3999e98242bd283b1cae47919fe0 (diff)
parentde549a931cf77aeecab98eb3a4d8e1ac8a7b5b84 (diff)
downloadheat-1ebf414c73572d066225572326b35430af115aac.tar.gz
Merge "zun: use containers.update for renaming"
-rw-r--r--heat/engine/clients/os/zun.py17
-rw-r--r--heat/engine/resources/openstack/zun/container.py6
-rw-r--r--heat/tests/clients/test_zun_client.py30
-rw-r--r--heat/tests/openstack/zun/test_container.py10
-rw-r--r--lower-constraints.txt2
-rw-r--r--requirements.txt2
6 files changed, 54 insertions, 13 deletions
diff --git a/heat/engine/clients/os/zun.py b/heat/engine/clients/os/zun.py
index af829275c..a50a6428d 100644
--- a/heat/engine/clients/os/zun.py
+++ b/heat/engine/clients/os/zun.py
@@ -26,14 +26,15 @@ class ZunClientPlugin(client_plugin.ClientPlugin):
default_version = '1.12'
supported_versions = [
- V1_12
+ V1_12, V1_18
] = [
- '1.12'
+ '1.12', '1.18'
]
def _create(self, version=None):
if not version:
version = self.default_version
+
interface = self._get_client_option(CLIENT_NAME, 'endpoint_type')
args = {
'interface': interface,
@@ -45,6 +46,18 @@ class ZunClientPlugin(client_plugin.ClientPlugin):
client = zun_client.Client(version, **args)
return client
+ def update_container(self, container_id, **prop_diff):
+ try:
+ if prop_diff:
+ self.client(version=self.V1_18).containers.update(
+ container_id, **prop_diff)
+ except zc_exc.NotAcceptable:
+ if 'name' in prop_diff:
+ name = prop_diff.pop('name')
+ self.client().containers.rename(container_id, name=name)
+ if prop_diff:
+ self.client().containers.update(container_id, **prop_diff)
+
def is_not_found(self, ex):
return isinstance(ex, zc_exc.NotFound)
diff --git a/heat/engine/resources/openstack/zun/container.py b/heat/engine/resources/openstack/zun/container.py
index 56a312c24..3db1eded2 100644
--- a/heat/engine/resources/openstack/zun/container.py
+++ b/heat/engine/resources/openstack/zun/container.py
@@ -279,11 +279,7 @@ class Container(resource.Resource):
.status)
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
- if self.NAME in prop_diff:
- name = prop_diff.pop(self.NAME)
- self.client().containers.rename(self.resource_id, name=name)
- if prop_diff:
- self.client().containers.update(self.resource_id, **prop_diff)
+ self.client_plugin().update_container(self.resource_id, **prop_diff)
def handle_delete(self):
if not self.resource_id:
diff --git a/heat/tests/clients/test_zun_client.py b/heat/tests/clients/test_zun_client.py
index 2bb636554..2573a095a 100644
--- a/heat/tests/clients/test_zun_client.py
+++ b/heat/tests/clients/test_zun_client.py
@@ -10,12 +10,24 @@
# License for the specific language governing permissions and limitations
# under the License.
+import mock
+
+from zunclient import exceptions as zc_exc
+
from heat.tests import common
from heat.tests import utils
class ZunClientPluginTest(common.HeatTestCase):
+ def setUp(self):
+ super(ZunClientPluginTest, self).setUp()
+ self.client = mock.Mock()
+ context = utils.dummy_context()
+ self.plugin = context.clients.client_plugin('zun')
+ self.plugin.client = lambda **kw: self.client
+ self.resource_id = '123456'
+
def test_create(self):
context = utils.dummy_context()
plugin = context.clients.client_plugin('zun')
@@ -24,3 +36,21 @@ class ZunClientPluginTest(common.HeatTestCase):
client.containers.api.session.auth.endpoint)
self.assertEqual('1.12',
client.api_version.get_string())
+
+ def test_container_update(self):
+ prop_diff = {'cpu': 10, 'memory': 10, 'name': 'fake-container'}
+ self.plugin.update_container(self.resource_id, **prop_diff)
+ self.client.containers.update.assert_called_once_with(
+ self.resource_id, cpu=10, memory=10, name='fake-container')
+
+ def test_container_update_not_acceptable(self):
+ self.client.containers.update.side_effect = [
+ zc_exc.NotAcceptable(), None]
+ prop_diff = {'cpu': 10, 'memory': 10, 'name': 'fake-container'}
+ self.plugin.update_container(self.resource_id, **prop_diff)
+ self.client.containers.update.assert_has_calls([
+ mock.call(self.resource_id, cpu=10, memory=10,
+ name='fake-container'),
+ mock.call(self.resource_id, cpu=10, memory=10)])
+ self.client.containers.rename.assert_called_once_with(
+ self.resource_id, name='fake-container')
diff --git a/heat/tests/openstack/zun/test_container.py b/heat/tests/openstack/zun/test_container.py
index f4be7b3d3..7c06ac1c7 100644
--- a/heat/tests/openstack/zun/test_container.py
+++ b/heat/tests/openstack/zun/test_container.py
@@ -20,6 +20,7 @@ from zunclient import exceptions as zc_exc
from heat.common import exception
from heat.common import template_format
+from heat.engine.clients.os import zun
from heat.engine.resources.openstack.zun import container
from heat.engine import scheduler
from heat.engine import template
@@ -125,6 +126,8 @@ class ZunContainerTest(common.HeatTestCase):
self.patchobject(container.Container, 'neutron',
return_value=self.neutron_client)
self.stub_VolumeConstraint_validate()
+ self.mock_update = self.patchobject(zun.ZunClientPlugin,
+ 'update_container')
def _mock_get_client(self):
value = mock.MagicMock()
@@ -263,10 +266,9 @@ class ZunContainerTest(common.HeatTestCase):
rsrc_defns = template.Template(new_t).resource_definitions(self.stack)
new_c = rsrc_defns[self.fake_name]
scheduler.TaskRunner(c.update, new_c)()
- self.client.containers.update.assert_called_once_with(
- self.resource_id, cpu=10, memory=10)
- self.client.containers.rename.assert_called_once_with(
- self.resource_id, name='fake-container')
+ self.mock_update.assert_called_once_with(
+ self.resource_id,
+ cpu=10, memory=10, name='fake-container')
self.assertEqual((c.UPDATE, c.COMPLETE), c.state)
def test_container_delete(self):
diff --git a/lower-constraints.txt b/lower-constraints.txt
index e9954c396..9278abdb9 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -124,7 +124,7 @@ python-subunit==1.2.0
python-swiftclient==3.2.0
python-troveclient==2.2.0
python-zaqarclient==1.0.0
-python-zunclient==1.3.0
+python-zunclient==2.0.0
pytz==2013.6
PyYAML==3.12
qpid-python==0.26;python_version=='2.7' # Apache-2.0
diff --git a/requirements.txt b/requirements.txt
index 097885f06..0c094354a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -50,7 +50,7 @@ python-saharaclient>=1.4.0 # Apache-2.0
python-swiftclient>=3.2.0 # Apache-2.0
python-troveclient>=2.2.0 # Apache-2.0
python-zaqarclient>=1.0.0 # Apache-2.0
-python-zunclient>=1.3.0 # Apache-2.0
+python-zunclient>=2.0.0 # Apache-2.0
pytz>=2013.6 # MIT
PyYAML>=3.12 # MIT
requests>=2.14.2 # Apache-2.0