示例#1
0
 def test_add_host(self):
     tmp = self.tmp_hosts_file(self.hostspath)
     list_hosts.hosts_filename = tmp
     add_host.hosts_filename = tmp
     assert add_host('192.168.1.123', 'newip')
     self.assertTrue(has_pair('192.168.1.123', 'newip'))
     self.assertEqual(len(list_hosts()), 7)
     assert add_host('127.0.0.1', 'othernameip')
     self.assertEqual(len(list_hosts()), 7)
示例#2
0
 def test_add_host(self):
     tmp = self.tmp_hosts_file(self.hostspath)
     list_hosts.hosts_filename = tmp
     add_host.hosts_filename = tmp
     assert add_host('192.168.1.123', 'newip')
     self.assertTrue(has_pair('192.168.1.123', 'newip'))
     self.assertEqual(len(list_hosts()), 7)
     assert add_host('127.0.0.1', 'othernameip')
     self.assertEqual(len(list_hosts()), 7)
示例#3
0
 def test_add_host_create_entry(self):
     '''
     Tests if specified host entry gets added from the hosts file
     '''
     with patch('salt.utils.fopen', mock_open()):
         mock_opt = MagicMock(return_value=None)
         with patch.dict(hosts.__salt__, {'config.option': mock_opt}):
             self.assertTrue(hosts.add_host('10.10.10.10', 'Salt1'))
示例#4
0
文件: hosts_test.py 项目: DaveQB/salt
 def test_add_host_create_entry(self):
     '''
     Tests if specified host entry gets added from the hosts file
     '''
     with patch('salt.utils.fopen', mock_open()):
         mock_opt = MagicMock(return_value=None)
         with patch.dict(hosts.__salt__, {'config.option': mock_opt}):
             self.assertTrue(hosts.add_host('10.10.10.10', 'Salt1'))
示例#5
0
文件: hosts_test.py 项目: bryson/salt
 def test_add_host_create_entry(self):
     """
     Tests if specified host entry gets added from the hosts file
     """
     with patch("salt.utils.fopen", mock_open()):
         mock_opt = MagicMock(return_value=None)
         with patch.dict(hosts.__salt__, {"config.option": mock_opt}):
             self.assertTrue(hosts.add_host("10.10.10.10", "Salt1"))
示例#6
0
 def test_add_host_no_file(self):
     '''
     Tests if specified host entry gets added from the hosts file
     '''
     with patch('salt.utils.files.fopen', mock_open()), \
             patch('os.path.isfile', MagicMock(return_value=False)):
         mock_opt = MagicMock(return_value=None)
         with patch.dict(hosts.__salt__, {'config.option': mock_opt}):
             self.assertFalse(hosts.add_host('10.10.10.10', 'Salt1'))
示例#7
0
 def test_add_host_create_entry(self):
     """
     Tests if specified host entry gets added from the hosts file
     """
     with patch("salt.utils.files.fopen",
                mock_open()), patch("os.path.isfile",
                                    MagicMock(return_value=True)):
         mock_opt = MagicMock(return_value=None)
         with patch.dict(hosts.__salt__, {"config.option": mock_opt}):
             self.assertTrue(hosts.add_host("10.10.10.10", "Salt1"))
示例#8
0
    def test_add_host(self):
        '''
        Tests if specified host entry gets added from the hosts file
        '''
        hosts_file = '/etc/hosts'
        if salt.utils.is_windows():
            hosts_file = r'C:\Windows\System32\Drivers\etc\hosts'

        with patch('salt.utils.fopen', mock_open()), \
                patch('salt.modules.hosts.__get_hosts_filename',
                      MagicMock(return_value=hosts_file)):
            mock_opt = MagicMock(return_value=None)
            with patch.dict(hosts.__salt__, {'config.option': mock_opt}):
                self.assertTrue(hosts.add_host('10.10.10.10', 'Salt1'))
示例#9
0
    def test_add_host(self):
        """
        Tests if specified host entry gets added from the hosts file
        """
        hosts_file = "/etc/hosts"
        if salt.utils.platform.is_windows():
            hosts_file = r"C:\Windows\System32\Drivers\etc\hosts"

        with patch("salt.utils.files.fopen", mock_open()), patch(
                "salt.modules.hosts.__get_hosts_filename",
                MagicMock(return_value=hosts_file),
        ):
            mock_opt = MagicMock(return_value=None)
            with patch.dict(hosts.__salt__, {"config.option": mock_opt}):
                self.assertTrue(hosts.add_host("10.10.10.10", "Salt1"))