示例#1
0
    def test_generate_minion_id_platform_localhost_only(self):
        '''
        Test if there is no other choice but localhost.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'localhost')
示例#2
0
    def test_generate_minion_id_platform_ip_addr_only(self):
        '''
        Test if IP address is the only what is used as a Minion ID in case no DNS name.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), '1.2.3.4')
示例#3
0
    def test_generate_minion_id_platform_localhost_filtered_all(self):
        '''
        Test if any of the localhost is filtered from everywhere.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), '1.2.3.4')
示例#4
0
    def test_generate_minion_id_platform_localhost_filtered(self):
        '''
        Test if localhost is filtered from the first occurrence.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
示例#5
0
    def test_generate_minion_id_platform_localhost_addrinfo(self):
        '''
        Test if addinfo is picked up.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
示例#6
0
    def test_generate_minion_id_platform_fqdn(self):
        '''
        Test if fqdn is picked up.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
示例#7
0
    def test_generate_minion_id_platform_localhost_addrinfo(self):
        '''
        Test if addinfo is picked up.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
示例#8
0
    def test_generate_minion_id_platform_localhost_only(self):
        '''
        Test if there is no other choice but localhost.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'localhost')
示例#9
0
    def test_generate_minion_id_platform_localhost_filtered_all(self):
        '''
        Test if any of the localhost is filtered from everywhere.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), '1.2.3.4')
示例#10
0
    def test_generate_minion_id_platform_localhost_filtered(self):
        '''
        Test if localhost is filtered from the first occurrence.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'hostname.domainname.blank')
示例#11
0
    def test_generate_minion_id_platform_fqdn(self):
        '''
        Test if fqdn is picked up.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
示例#12
0
    def test_generate_minion_id_platform_ip_addr_only(self):
        '''
        Test if IP address is the only what is used as a Minion ID in case no DNS name.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), '1.2.3.4')
示例#13
0
    def test_generate_minion_id_platform_used(self):
        '''
        Test if platform.node is used for the first occurrence.
        The platform.node is most common hostname resolver before anything else.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'very.long.and.complex.domain.name')
示例#14
0
    def test_generate_minion_id_with_long_hostname(self):
        """
        Validate the fix for:

        https://github.com/saltstack/salt/issues/51160
        """
        long_name = "localhost-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz"
        with patch("socket.gethostname", MagicMock(return_value=long_name)):
            # An exception is raised if unicode is passed to socket.getfqdn
            minion_id = network.generate_minion_id()
        assert minion_id != "", minion_id
示例#15
0
    def test_generate_minion_id_platform_localhost_addrinfo(self):
        '''
        Test if addinfo is picked up.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='localhost')), \
                patch('socket.gethostname', MagicMock(return_value='ip6-loopback')), \
                patch('socket.getfqdn', MagicMock(return_value='ip6-localhost')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'pick.me', ('127.0.1.1', 0))])), \
                patch('salt.utils.files.fopen', mock_open()), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['127.0.0.1', '::1', 'fe00::0', 'fe02::1'])):
            self.assertEqual(network.generate_minion_id(), 'pick.me')
示例#16
0
    def test_generate_minion_id_platform_localhost_filtered_all(self):
        '''
        Test if any of the localhost is filtered from everywhere.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='localhost')), \
                patch('socket.gethostname', MagicMock(return_value='ip6-loopback')), \
                patch('socket.getfqdn', MagicMock(return_value='ip6-localhost')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'localhost', ('127.0.1.1', 0))])), \
                patch('salt.utils.files.fopen', mock_open()), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['127.0.0.1', '::1', 'fe00::0', 'fe02::1', '1.2.3.4'])):
            self.assertEqual(network.generate_minion_id(), '1.2.3.4')
示例#17
0
    def test_generate_minion_id_platform_localhost_filtered(self):
        '''
        Test if localhost is filtered from the first occurrence.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='localhost')), \
                patch('socket.gethostname', MagicMock(return_value='pick.me')), \
                patch('socket.getfqdn', MagicMock(return_value='hostname.domainname.blank')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'hostname', ('127.0.1.1', 0))])), \
                patch('salt.utils.files.fopen', mock_open()), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['1.2.3.4', '1.2.3.4', '1.2.3.4'])):
            self.assertEqual(network.generate_minion_id(), 'hostname.domainname.blank')
示例#18
0
    def test_generate_minion_id_platform_ip_addr_only(self):
        '''
        Test if IP address is the only what is used as a Minion ID in case no DNS name.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='localhost')), \
                patch('socket.gethostname', MagicMock(return_value='ip6-loopback')), \
                patch('socket.getfqdn', MagicMock(return_value='ip6-localhost')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'localhost', ('127.0.1.1', 0))])), \
                patch('salt.utils.files.fopen', mock_open()), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['127.0.0.1', '::1', 'fe00::0', 'fe02::1', '1.2.3.4'])):
            self.assertEqual(network.generate_minion_id(), '1.2.3.4')
示例#19
0
    def test_generate_minion_id_platform_used(self):
        '''
        Test if platform.node is used for the first occurrence.
        The platform.node is most common hostname resolver before anything else.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='very.long.and.complex.domain.name')), \
                patch('socket.gethostname', MagicMock(return_value='hostname')), \
                patch('socket.getfqdn', MagicMock(return_value='')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'hostname', ('127.0.1.1', 0))])), \
                patch('salt.utils.files.fopen', mock_open()), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['1.2.3.4', '1.2.3.4', '1.2.3.4'])):
            self.assertEqual(network.generate_minion_id(), 'very.long.and.complex.domain.name')
示例#20
0
    def test_generate_minion_id_platform_localhost_only(self):
        '''
        Test if there is no other choice but localhost.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='localhost')), \
                patch('socket.gethostname', MagicMock(return_value='ip6-loopback')), \
                patch('socket.getfqdn', MagicMock(return_value='ip6-localhost')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'localhost', ('127.0.1.1', 0))])), \
                patch('salt.utils.fopen', MagicMock(return_value=False)), \
                patch('os.path.exists', MagicMock(return_value=False)), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['127.0.0.1', '::1', 'fe00::0', 'fe02::1'])):
            self.assertEqual(network.generate_minion_id(), 'localhost')
示例#21
0
    def test_generate_minion_id_platform_localhost_addrinfo(self):
        """
        Test if addinfo is picked up.

        :return:
        """
        with patch("platform.node", MagicMock(return_value="localhost")), patch(
            "socket.gethostname", MagicMock(return_value="ip6-loopback")
        ), patch("socket.getfqdn", MagicMock(return_value="ip6-localhost")), patch(
            "socket.getaddrinfo",
            MagicMock(return_value=[(2, 3, 0, "pick.me", ("127.0.1.1", 0))]),
        ), patch(
            "salt.utils.files.fopen", mock_open()
        ), patch(
            "salt.utils.network.ip_addrs",
            MagicMock(return_value=["127.0.0.1", "::1", "fe00::0", "fe02::1"]),
        ):
            self.assertEqual(network.generate_minion_id(), "pick.me")
示例#22
0
    def test_generate_minion_id_platform_ip_addr_only(self):
        """
        Test if IP address is the only what is used as a Minion ID in case no DNS name.

        :return:
        """
        with patch("platform.node", MagicMock(return_value="localhost")), patch(
            "socket.gethostname", MagicMock(return_value="ip6-loopback")
        ), patch("socket.getfqdn", MagicMock(return_value="ip6-localhost")), patch(
            "socket.getaddrinfo",
            MagicMock(return_value=[(2, 3, 0, "localhost", ("127.0.1.1", 0))]),
        ), patch(
            "salt.utils.files.fopen", mock_open()
        ), patch(
            "salt.utils.network.ip_addrs",
            MagicMock(
                return_value=["127.0.0.1", "::1", "fe00::0", "fe02::1", "1.2.3.4"]
            ),
        ):
            self.assertEqual(network.generate_minion_id(), "1.2.3.4")
示例#23
0
    def test_generate_minion_id_platform_localhost_filtered_all(self):
        """
        Test if any of the localhost is filtered from everywhere.

        :return:
        """
        with patch("platform.node", MagicMock(return_value="localhost")), patch(
            "socket.gethostname", MagicMock(return_value="ip6-loopback")
        ), patch("socket.getfqdn", MagicMock(return_value="ip6-localhost")), patch(
            "socket.getaddrinfo",
            MagicMock(return_value=[(2, 3, 0, "localhost", ("127.0.1.1", 0))]),
        ), patch(
            "salt.utils.files.fopen", mock_open()
        ), patch(
            "salt.utils.network.ip_addrs",
            MagicMock(
                return_value=["127.0.0.1", "::1", "fe00::0", "fe02::1", "1.2.3.4"]
            ),
        ):
            self.assertEqual(network.generate_minion_id(), "1.2.3.4")
示例#24
0
    def test_generate_minion_id_platform_localhost_filtered(self):
        """
        Test if localhost is filtered from the first occurrence.

        :return:
        """
        with patch("platform.node", MagicMock(return_value="localhost")), patch(
            "socket.gethostname", MagicMock(return_value="pick.me")
        ), patch(
            "socket.getfqdn", MagicMock(return_value="hostname.domainname.blank")
        ), patch(
            "socket.getaddrinfo",
            MagicMock(return_value=[(2, 3, 0, "hostname", ("127.0.1.1", 0))]),
        ), patch(
            "salt.utils.files.fopen", mock_open()
        ), patch(
            "salt.utils.network.ip_addrs",
            MagicMock(return_value=["1.2.3.4", "1.2.3.4", "1.2.3.4"]),
        ):
            self.assertEqual(network.generate_minion_id(), "hostname.domainname.blank")
示例#25
0
    def test_generate_minion_id_platform_used(self):
        """
        Test if platform.node is used for the first occurrence.
        The platform.node is most common hostname resolver before anything else.

        :return:
        """
        with patch(
            "platform.node", MagicMock(return_value="very.long.and.complex.domain.name")
        ), patch("socket.gethostname", MagicMock(return_value="hostname")), patch(
            "socket.getfqdn", MagicMock(return_value="")
        ), patch(
            "socket.getaddrinfo",
            MagicMock(return_value=[(2, 3, 0, "hostname", ("127.0.1.1", 0))]),
        ), patch(
            "salt.utils.files.fopen", mock_open()
        ), patch(
            "salt.utils.network.ip_addrs",
            MagicMock(return_value=["1.2.3.4", "1.2.3.4", "1.2.3.4"]),
        ):
            self.assertEqual(
                network.generate_minion_id(), "very.long.and.complex.domain.name"
            )
示例#26
0
 def test_generate_minion_id(self):
     self.assertTrue(network.generate_minion_id())
示例#27
0
 def test_generate_minion_id(self):
     self.assertTrue(network.generate_minion_id())