示例#1
0
 def test_only_success(self):
     '''
     Test only() when state successfully changes
     '''
     expected = {
         'name':
         '127.0.1.1',
         'changes': {
             '127.0.1.1': {
                 'old': 'foo.bar',
                 'new': 'foo.bar foo'
             }
         },
         'result':
         True,
         'comment':
         'successfully changed 127.0.1.1' +
         ' from "foo.bar" to "foo.bar foo"'
     }
     mock = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock}):
         mock = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {'hosts.set_host': mock}):
             with patch.dict(host.__opts__, {'test': False}):
                 self.assertDictEqual(
                     expected, host.only("127.0.1.1", ['foo.bar', 'foo']))
示例#2
0
 def test_only_success(self):
     """
     Test only() when state successfully changes
     """
     expected = {
         "name":
         "127.0.1.1",
         "changes": {
             "127.0.1.1": {
                 "old": "foo.bar",
                 "new": "foo.bar foo"
             }
         },
         "result":
         True,
         "comment":
         "successfully changed 127.0.1.1" +
         ' from "foo.bar" to "foo.bar foo"',
     }
     mock = MagicMock(return_value=["foo.bar"])
     with patch.dict(host.__salt__, {"hosts.get_alias": mock}):
         mock = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {"hosts.set_host": mock}):
             with patch.dict(host.__opts__, {"test": False}):
                 self.assertDictEqual(
                     expected, host.only("127.0.1.1", ["foo.bar", "foo"]))
示例#3
0
def test_only_dryrun():
    """
    Test only() when state would change, but it's a dry run
    """
    expected = {
        "name": "127.0.1.1",
        "changes": {},
        "result": None,
        "comment": 'Would change 127.0.1.1 from "foo.bar" to "foo.bar foo"',
    }
    mock1 = MagicMock(return_value=["foo.bar"])
    with patch.dict(host.__salt__, {"hosts.get_alias": mock1}):
        mock2 = MagicMock(return_value=True)
        with patch.dict(host.__salt__, {"hosts.set_host": mock2}):
            with patch.dict(host.__opts__, {"test": True}):
                assert expected == host.only("127.0.1.1", ["foo.bar", "foo"])
示例#4
0
def test_only_already():
    """
    Test only() when the state hasn't changed
    """
    expected = {
        "name": "127.0.1.1",
        "changes": {},
        "result": True,
        "comment": 'IP address 127.0.1.1 already set to "foo.bar"',
    }
    mock1 = MagicMock(return_value=["foo.bar"])
    with patch.dict(host.__salt__, {"hosts.get_alias": mock1}):
        mock2 = MagicMock(return_value=True)
        with patch.dict(host.__salt__, {"hosts.set_host": mock2}):
            with patch.dict(host.__opts__, {"test": False}):
                assert expected == host.only("127.0.1.1", "foo.bar")
示例#5
0
 def test_only_dryrun(self):
     '''
     Test only() when state would change, but it's a dry run
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {},
         'result': None,
         'comment': 'Would change 127.0.1.1 from "foo.bar" to "foo.bar foo"'
     }
     mock1 = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock1}):
         mock2 = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {'hosts.set_host': mock2}):
             with patch.dict(host.__opts__, {'test': True}):
                 self.assertDictEqual(
                     expected, host.only("127.0.1.1", ['foo.bar', 'foo']))
示例#6
0
 def test_only_already(self):
     '''
     Test only() when the state hasn't changed
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {},
         'result': True,
         'comment': 'IP address 127.0.1.1 already set to "foo.bar"'
     }
     mock1 = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock1}):
         mock2 = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {'hosts.set_host': mock2}):
             with patch.dict(host.__opts__, {'test': False}):
                 self.assertDictEqual(expected,
                                      host.only("127.0.1.1", 'foo.bar'))
示例#7
0
 def test_only_dryrun(self):
     '''
     Test only() when state would change, but it's a dry run
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {},
         'result': None,
         'comment': 'Would change 127.0.1.1 from "foo.bar" to "foo.bar foo"'}
     mock1 = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock1}):
         mock2 = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {'hosts.set_host': mock2}):
             with patch.dict(host.__opts__, {'test': True}):
                 self.assertDictEqual(
                     expected,
                     host.only("127.0.1.1", ['foo.bar', 'foo']))
示例#8
0
 def test_only_already(self):
     '''
     Test only() when the state hasn't changed
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {},
         'result': True,
         'comment': 'IP address 127.0.1.1 already set to "foo.bar"'}
     mock1 = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock1}):
         mock2 = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {'hosts.set_host': mock2}):
             with patch.dict(host.__opts__, {'test': False}):
                 self.assertDictEqual(
                     expected,
                     host.only("127.0.1.1", 'foo.bar'))
示例#9
0
def test_only_fail():
    """
    Test only() when state change fails
    """
    expected = {
        "name": "127.0.1.1",
        "changes": {},
        "result": False,
        "comment": "hosts.set_host failed to change 127.0.1.1"
        + ' from "foo.bar" to "foo.bar foo"',
    }
    mock = MagicMock(return_value=["foo.bar"])
    with patch.dict(host.__salt__, {"hosts.get_alias": mock}):
        mock = MagicMock(return_value=False)
        with patch.dict(host.__salt__, {"hosts.set_host": mock}):
            with patch.dict(host.__opts__, {"test": False}):
                assert expected == host.only("127.0.1.1", ["foo.bar", "foo"])
示例#10
0
 def test_only_fail(self):
     '''
     Test only() when state change fails
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {},
         'result': False,
         'comment': 'hosts.set_host failed to change 127.0.1.1'
             + ' from "foo.bar" to "foo.bar foo"'}
     mock = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock}):
         mock = MagicMock(return_value=False)
         with patch.dict(host.__salt__, {'hosts.set_host': mock}):
             with patch.dict(host.__opts__, {'test': False}):
                 self.assertDictEqual(
                     expected,
                     host.only("127.0.1.1", ['foo.bar', 'foo']))
示例#11
0
 def test_only_success(self):
     '''
     Test only() when state successfully changes
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {'127.0.1.1': {'old': 'foo.bar', 'new': 'foo.bar foo'}},
         'result': True,
         'comment': 'successfully changed 127.0.1.1'
             + ' from "foo.bar" to "foo.bar foo"'}
     mock = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock}):
         mock = MagicMock(return_value=True)
         with patch.dict(host.__salt__, {'hosts.set_host': mock}):
             with patch.dict(host.__opts__, {'test': False}):
                 self.assertDictEqual(
                     expected,
                     host.only("127.0.1.1", ['foo.bar', 'foo']))
示例#12
0
 def test_only_fail(self):
     '''
     Test only() when state change fails
     '''
     expected = {
         'name': '127.0.1.1',
         'changes': {},
         'result': False,
         'comment': 'hosts.set_host failed to change 127.0.1.1'
             + ' from "foo.bar" to "foo.bar foo"'}
     mock = MagicMock(return_value=['foo.bar'])
     with patch.dict(host.__salt__, {'hosts.get_alias': mock}):
         mock = MagicMock(return_value=False)
         with patch.dict(host.__salt__, {'hosts.set_host': mock}):
             with patch.dict(host.__opts__, {'test': False}):
                 self.assertDictEqual(
                     expected,
                     host.only("127.0.1.1", ['foo.bar', 'foo']))