def test_running(self): ''' Test to ensure that a container is running. ''' name = 'web01' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(return_value={'state': {'new': 'stop'}}) mock_t = MagicMock(side_effect=[None, 'running', 'stopped', 'start']) with patch.dict(lxc.__salt__, {'lxc.exists': mock, 'lxc.state': mock_t, 'lxc.start': mock}): comt = ('Container \'{0}\' does not exist'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(lxc.running(name), ret) comt = ("Container 'web01' is already running") ret.update({'comment': comt, 'result': True}) self.assertDictEqual(lxc.running(name), ret) with patch.dict(lxc.__opts__, {'test': True}): comt = ("Container 'web01' would be started") ret.update({'comment': comt, 'result': None}) self.assertDictEqual(lxc.running(name), ret) with patch.dict(lxc.__opts__, {'test': False}): comt = ("Unable to start container 'web01'") ret.update({'comment': comt, 'result': False, 'changes': {'state': {'new': 'stop', 'old': 'start'}}}) self.assertDictEqual(lxc.running(name), ret)
def test_running(self): """ Test to ensure that a container is running. """ name = "web01" ret = {"name": name, "result": False, "comment": "", "changes": {}} mock = MagicMock(return_value={"state": {"new": "stop"}}) mock_t = MagicMock(side_effect=[None, "running", "stopped", "start"]) with patch.dict(lxc.__salt__, { "lxc.exists": mock, "lxc.state": mock_t, "lxc.start": mock }): comt = "Container '{}' does not exist".format(name) ret.update({"comment": comt}) self.assertDictEqual(lxc.running(name), ret) comt = "Container 'web01' is already running" ret.update({"comment": comt, "result": True}) self.assertDictEqual(lxc.running(name), ret) with patch.dict(lxc.__opts__, {"test": True}): comt = "Container 'web01' would be started" ret.update({"comment": comt, "result": None}) self.assertDictEqual(lxc.running(name), ret) with patch.dict(lxc.__opts__, {"test": False}): comt = "Unable to start container 'web01'" ret.update({ "comment": comt, "result": False, "changes": { "state": { "new": "stop", "old": "start" } }, }) self.assertDictEqual(lxc.running(name), ret)