Merge "zun: use containers.update for renaming"
This commit is contained in:
commit
1ebf414c73
|
@ -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)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue