Beispiel #1
0
    def test_build_network_settings(self):
        '''
        Test if it build the global network script.
        '''
        with patch.dict(debian_ip.__grains__, {'osfullname': 'Ubuntu',
                                               'osrelease': '14'}):
            mock = MagicMock(return_value=True)
            with patch.dict(debian_ip.__salt__, {'service.available': mock,
                                                 'service.disable': mock,
                                                 'service.enable': mock}):
                self.assertEqual(debian_ip.build_network_settings(),
                                 [u'NETWORKING=yes\n',
                                  u'HOSTNAME=Salt\n',
                                  u'DOMAIN=saltstack.com\n'])

                mock = MagicMock(side_effect=jinja2.exceptions.TemplateNotFound
                                 ('error'))
                with patch.object(jinja2.Environment, 'get_template', mock):
                    self.assertEqual(debian_ip.build_network_settings(), '')

        with patch.dict(debian_ip.__grains__, {'osfullname': 'Ubuntu',
                                               'osrelease': '10'}):
            mock = MagicMock(return_value=True)
            with patch.dict(debian_ip.__salt__, {'service.available': mock,
                                                 'service.disable': mock,
                                                 'service.enable': mock}):
                mock = MagicMock(side_effect=jinja2.exceptions.TemplateNotFound
                                 ('error'))
                with patch.object(jinja2.Environment, 'get_template', mock):
                    self.assertEqual(debian_ip.build_network_settings(), '')

                with patch.object(debian_ip, '_read_temp',
                                  MagicMock(return_value=True)):
                    self.assertTrue(debian_ip.build_network_settings
                                    (test='True'))
Beispiel #2
0
    def test_build_network_settings(self):
        '''
        Test if it build the global network script.
        '''
        with patch('salt.modules.debian_ip._parse_network_settings',
                   MagicMock(return_value={'networking': 'yes',
                                           'hostname': 'Salt.saltstack.com',
                                           'domainname': 'saltstack.com',
                                           'search': 'test.saltstack.com'})), \
                patch('salt.modules.debian_ip._write_file_network',
                      MagicMock(return_value=True)):
            with patch.dict(debian_ip.__grains__, {
                    'osfullname': 'Ubuntu',
                    'osrelease': '14'
            }):
                mock = MagicMock(return_value=True)
                with patch.dict(
                        debian_ip.__salt__, {
                            'service.available': mock,
                            'service.disable': mock,
                            'service.enable': mock
                        }):
                    self.assertEqual(debian_ip.build_network_settings(), [
                        u'NETWORKING=yes\n', u'HOSTNAME=Salt\n',
                        u'DOMAIN=saltstack.com\n',
                        u'SEARCH=test.saltstack.com\n'
                    ])

                    mock = MagicMock(side_effect=jinja2.exceptions.
                                     TemplateNotFound('error'))
                    with patch.object(jinja2.Environment, 'get_template',
                                      mock):
                        self.assertEqual(debian_ip.build_network_settings(),
                                         '')

            with patch.dict(debian_ip.__grains__, {
                    'osfullname': 'Ubuntu',
                    'osrelease': '10'
            }):
                mock = MagicMock(return_value=True)
                with patch.dict(
                        debian_ip.__salt__, {
                            'service.available': mock,
                            'service.disable': mock,
                            'service.enable': mock
                        }):
                    mock = MagicMock(side_effect=jinja2.exceptions.
                                     TemplateNotFound('error'))
                    with patch.object(jinja2.Environment, 'get_template',
                                      mock):
                        self.assertEqual(debian_ip.build_network_settings(),
                                         '')

                    with patch.object(debian_ip, '_read_temp',
                                      MagicMock(return_value=True)):
                        self.assertTrue(
                            debian_ip.build_network_settings(test='True'))
    def test_build_network_settings(self):
        """
        Test if it build the global network script.
        """
        with patch(
                "salt.modules.debian_ip._parse_network_settings",
                MagicMock(
                    return_value={
                        "networking": "yes",
                        "hostname": "Salt.saltstack.com",
                        "domainname": "saltstack.com",
                        "search": "test.saltstack.com",
                    }),
        ), patch("salt.modules.debian_ip._write_file_network",
                 MagicMock(return_value=True)):
            with patch.dict(debian_ip.__grains__, {
                    "osfullname": "Ubuntu",
                    "osrelease": "14"
            }):
                mock = MagicMock(return_value=True)
                with patch.dict(
                        debian_ip.__salt__,
                    {
                        "service.available": mock,
                        "service.disable": mock,
                        "service.enable": mock,
                    },
                ):
                    self.assertEqual(
                        debian_ip.build_network_settings(),
                        [
                            "NETWORKING=yes\n",
                            "HOSTNAME=Salt\n",
                            "DOMAIN=saltstack.com\n",
                            "SEARCH=test.saltstack.com\n",
                        ],
                    )

                    mock = MagicMock(side_effect=jinja2.exceptions.
                                     TemplateNotFound("error"))
                    with patch.object(jinja2.Environment, "get_template",
                                      mock):
                        self.assertEqual(debian_ip.build_network_settings(),
                                         "")

            with patch.dict(debian_ip.__grains__, {
                    "osfullname": "Ubuntu",
                    "osrelease": "10"
            }):
                mock = MagicMock(return_value=True)
                with patch.dict(
                        debian_ip.__salt__,
                    {
                        "service.available": mock,
                        "service.disable": mock,
                        "service.enable": mock,
                    },
                ):
                    mock = MagicMock(side_effect=jinja2.exceptions.
                                     TemplateNotFound("error"))
                    with patch.object(jinja2.Environment, "get_template",
                                      mock):
                        self.assertEqual(debian_ip.build_network_settings(),
                                         "")

                    with patch.object(debian_ip, "_read_temp",
                                      MagicMock(return_value=True)):
                        self.assertTrue(
                            debian_ip.build_network_settings(test="True"))