Beispiel #1
0
    def test_generate_minion_id_distinct(self):
        """
        Test if minion IDs are distinct in the pool.

        :return:
        """
        with patch("platform.node", MagicMock(return_value="nodename")), patch(
            "socket.gethostname", MagicMock(return_value="hostname")
        ), patch(
            "socket.getfqdn", MagicMock(return_value="hostname.domainname.blank")
        ), patch(
            "socket.getaddrinfo",
            MagicMock(return_value=[(2, 3, 0, "attrname", ("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", "5.6.7.8"]),
        ):
            self.assertEqual(
                network._generate_minion_id(),
                [
                    "hostname.domainname.blank",
                    "nodename",
                    "hostname",
                    "1.2.3.4",
                    "5.6.7.8",
                ],
            )
Beispiel #2
0
    def test_generate_minion_id_duplicate(self):
        '''
        Test if IP addresses in the minion IDs are distinct in the pool

        :return:
        '''
        self.assertEqual(network._generate_minion_id(), ['hostname', '1.2.3.4'])
Beispiel #3
0
 def test_generate_minion_id_127_name(self):
     '''
     Test if minion IDs can be named 127.foo
     :return:
     '''
     self.assertEqual(network._generate_minion_id(),
                      ['127.domainname.blank', '127', '1.2.3.4', '5.6.7.8'])
Beispiel #4
0
    def test_generate_minion_id_distinct(self):
        '''
        Test if minion IDs are distinct in the pool.

        :return:
        '''
        self.assertEqual(network._generate_minion_id(),
                         ['hostname.domainname.blank', 'nodename', 'hostname', '1.2.3.4', '5.6.7.8'])
Beispiel #5
0
 def test_generate_minion_id_127_name_startswith(self):
     '''
     Test if minion IDs can be named starting from "127"
     :return:
     '''
     self.assertEqual(
         network._generate_minion_id(),
         ['127890.domainname.blank', '127890', '1.2.3.4', '5.6.7.8'])
Beispiel #6
0
 def test__generate_minion_id_with_unicode_in_etc_hosts(self):
     '''
     Test that unicode in /etc/hosts doesn't raise an error when
     _generate_minion_id() helper is called to gather the hosts.
     '''
     content = textwrap.dedent('''\
     # 以下为主机名解析
     ## ccc
     127.0.0.1       localhost thisismyhostname     # 本机
     ''')
     fopen_mock = mock_open(read_data={'/etc/hosts': content})
     with patch('salt.utils.files.fopen', fopen_mock):
         assert 'thisismyhostname' in network._generate_minion_id()
Beispiel #7
0
    def test_generate_minion_id_duplicate(self):
        '''
        Test if IP addresses in the minion IDs are distinct in the pool

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='hostname')), \
                patch('socket.gethostname', MagicMock(return_value='hostname')), \
                patch('socket.getfqdn', MagicMock(return_value='hostname')), \
                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', '1.2.3.4'])
Beispiel #8
0
 def test__generate_minion_id_with_unicode_in_etc_hosts(self):
     """
     Test that unicode in /etc/hosts doesn't raise an error when
     _generate_minion_id() helper is called to gather the hosts.
     """
     content = textwrap.dedent("""\
     # 以下为主机名解析
     ## ccc
     127.0.0.1       localhost thisismyhostname     # 本机
     """)
     fopen_mock = mock_open(read_data={"/etc/hosts": content})
     with patch("salt.utils.files.fopen", fopen_mock):
         assert "thisismyhostname" in network._generate_minion_id()
Beispiel #9
0
    def test_generate_minion_id_127_name_startswith(self):
        '''
        Test if minion IDs can be named starting from "127"

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='127890')), \
                patch('socket.gethostname', MagicMock(return_value='127890')), \
                patch('socket.getfqdn', MagicMock(return_value='127890.domainname.blank')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'attrname', ('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', '5.6.7.8'])):
            self.assertEqual(network._generate_minion_id(),
                             ['127890.domainname.blank', '127890', '1.2.3.4', '5.6.7.8'])
Beispiel #10
0
    def test_generate_minion_id_distinct(self):
        '''
        Test if minion IDs are distinct in the pool.

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='nodename')), \
                patch('socket.gethostname', MagicMock(return_value='hostname')), \
                patch('socket.getfqdn', MagicMock(return_value='hostname.domainname.blank')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'attrname', ('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', '5.6.7.8'])):
            self.assertEqual(network._generate_minion_id(),
                             ['hostname.domainname.blank', 'nodename', 'hostname', '1.2.3.4', '5.6.7.8'])
Beispiel #11
0
    def test_generate_minion_id_127_name(self):
        '''
        Test if minion IDs can be named 127.foo

        :return:
        '''
        with patch('platform.node', MagicMock(return_value='127')), \
                patch('socket.gethostname', MagicMock(return_value='127')), \
                patch('socket.getfqdn', MagicMock(return_value='127.domainname.blank')), \
                patch('socket.getaddrinfo', MagicMock(return_value=[(2, 3, 0, 'attrname', ('127.0.1.1', 0))])), \
                patch('salt.utils.files.fopen', MagicMock(return_value=False)), \
                patch('os.path.exists', MagicMock(return_value=False)), \
                patch('salt.utils.network.ip_addrs', MagicMock(return_value=['1.2.3.4', '5.6.7.8'])):
            self.assertEqual(network._generate_minion_id(),
                             ['127.domainname.blank', '127', '1.2.3.4', '5.6.7.8'])
Beispiel #12
0
    def test_generate_minion_id_duplicate(self):
        """
        Test if IP addresses in the minion IDs are distinct in the pool

        :return:
        """
        with patch("platform.node", MagicMock(return_value="hostname")), patch(
            "socket.gethostname", MagicMock(return_value="hostname")
        ), patch("socket.getfqdn", MagicMock(return_value="hostname")), 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", "1.2.3.4"])
Beispiel #13
0
    def test_generate_minion_id_127_name_startswith(self):
        """
        Test if minion IDs can be named starting from "127"

        :return:
        """
        with patch("platform.node", MagicMock(return_value="127890")), patch(
                "socket.gethostname", MagicMock(return_value="127890")), patch(
                    "socket.getfqdn",
                    MagicMock(return_value="127890.domainname.blank")), patch(
                        "socket.getaddrinfo",
                        MagicMock(return_value=[(2, 3, 0, "attrname",
                                                 ("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", "5.6.7.8"]),
                    ):
            self.assertEqual(
                network._generate_minion_id(),
                ["127890.domainname.blank", "127890", "1.2.3.4", "5.6.7.8"],
            )