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