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')
Beispiel #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')
    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')
Beispiel #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')
    def test_generate_minion_id_platform_localhost_addrinfo(self):
        '''
        Test if addinfo is picked up.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
    def test_generate_minion_id_platform_fqdn(self):
        '''
        Test if fqdn is picked up.

        :return:
        '''
        self.assertEqual(network.generate_minion_id(), 'pick.me')
    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')
Beispiel #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')
Beispiel #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
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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")
Beispiel #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")
Beispiel #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")
Beispiel #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")
Beispiel #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"
            )
Beispiel #26
0
 def test_generate_minion_id(self):
     self.assertTrue(network.generate_minion_id())
Beispiel #27
0
 def test_generate_minion_id(self):
     self.assertTrue(network.generate_minion_id())