From 9b17fdce5e3a97b3f7af53c0ddbf5513b7b1c59a Mon Sep 17 00:00:00 2001 From: Morgan McKenzie Date: Mon, 8 Feb 2016 15:06:56 +0000 Subject: [PATCH] Fix lxc cloud provided minion reporting present LXC minion is reporting as present when configured with cloud state, even though it is not. Fixes issue #31000 --- salt/states/cloud.py | 3 +-- tests/unit/states/cloud_test.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/salt/states/cloud.py b/salt/states/cloud.py index c297094c11..23051eb3b7 100644 --- a/salt/states/cloud.py +++ b/salt/states/cloud.py @@ -260,8 +260,7 @@ def profile(name, profile, onlyif=None, unless=None, **kwargs): if retcode(unless, python_shell=True) == 0: return _valid(name, comment='unless execution succeeded') instance = _get_instance([name]) - prov = str(next(six.iterkeys(instance))) - if instance and 'Not Actioned' not in prov: + if instance and not any('Not Actioned' in key for key in instance): ret['result'] = True ret['comment'] = 'Already present instance {0}'.format(name) return ret diff --git a/tests/unit/states/cloud_test.py b/tests/unit/states/cloud_test.py index a49925966f..68a5abc065 100644 --- a/tests/unit/states/cloud_test.py +++ b/tests/unit/states/cloud_test.py @@ -146,7 +146,11 @@ class CloudTestCase(TestCase): mock = MagicMock(side_effect=[True, False]) mock_dict = MagicMock(side_effect=[{'cloud': 'saltcloud'}, {'Not Actioned': True}, - {'Not Actioned': True}]) + {'Not Actioned': True}, + { + 'Not Found': True, + 'Not Actioned/Not Running': True + }]) mock_d = MagicMock(return_value={}) with patch.dict(cloud.__salt__, {'cmd.retcode': mock, 'cloud.profile': mock_d, @@ -179,6 +183,12 @@ class CloudTestCase(TestCase): ret.update({'comment': comt, 'result': False}) self.assertDictEqual(cloud.profile(name, profile), ret) + with patch.dict(cloud.__opts__, {'test': False}): + comt = (('Failed to create instance {0}' + 'using profile {1}').format(name, profile)) + ret.update({'comment': comt, 'result': False}) + self.assertDictEqual(cloud.profile(name, profile), ret) + # 'volume_present' function tests: 1 def test_volume_present(self):