Exemplo n.º 1
0
    def test_platform_information_container(self, mock_linux_dist):
        import sys
        if sys.version_info >= (3, 0):
            mocked_fn = 'builtins.open'
        else:
            mocked_fn = '__builtin__.open'

        with mock.patch(
                mocked_fn,
                mock.mock_open(read_data="""1:name=systemd:/system.slice \
                                                 /docker-39cc1fb.scope"""),
                create=True) as m:
            self.assertEqual(
                ('docker', 'docker', 'docker'),
                ceph_detect_init.platform_information(),
            )
            m.assert_called_once_with('/proc/self/cgroup', 'r')

        with mock.patch(mocked_fn, mock.mock_open(), create=True) as m:
            m.side_effect = IOError()
            mock_linux_dist.return_value = ('Red Hat Enterprise Linux Server',
                                            '7.3', 'Maipo')
            # Just run the code to validate the code won't raise IOError
            ceph_detect_init.platform_information()

        with mock.patch('os.path.isfile', mock.MagicMock()) as m:
            m.return_value = True
            self.assertEqual(
                ('docker', 'docker', 'docker'),
                ceph_detect_init.platform_information(),
            )
            m.assert_called_once_with('/.dockerenv')
Exemplo n.º 2
0
    def test_platform_information(self):
        with mock.patch('platform.linux_distribution',
                        lambda: (('debian', '6.0', ''))):
            self.assertEqual(('debian', '6.0', 'squeeze'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution',
                        lambda: (('debian', '7.0', ''))):
            self.assertEqual(('debian', '7.0', 'wheezy'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution',
                        lambda: (('debian', '8.0', ''))):
            self.assertEqual(('debian', '8.0', 'jessie'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution',
                        lambda: (('debian', 'jessie/sid', ''))):
            self.assertEqual(('debian', 'jessie/sid', 'sid'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution',
                        lambda: (('debian', 'sid/jessie', ''))):
            self.assertEqual(('debian', 'sid/jessie', 'sid'),
                             ceph_detect_init.platform_information())
Exemplo n.º 3
0
    def test_platform_information(self):
        with mock.patch('platform.linux_distribution', lambda:
                        (('debian', '6.0', ''))):
            self.assertEqual(('debian', '6.0', 'squeeze'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda:
                        (('debian', '7.0', ''))):
            self.assertEqual(('debian', '7.0', 'wheezy'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda:
                        (('debian', '8.0', ''))):
            self.assertEqual(('debian', '8.0', 'jessie'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda:
                        (('debian', 'jessie/sid', ''))):
            self.assertEqual(('debian', 'jessie/sid', 'sid'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda:
                        (('debian', 'sid/jessie', ''))):
            self.assertEqual(('debian', 'sid/jessie', 'sid'),
                             ceph_detect_init.platform_information())
Exemplo n.º 4
0
    def test_platform_information_container(self, mock_linux_dist):
        import sys
        if sys.version_info >= (3, 0):
            mocked_fn = 'builtins.open'
        else:
            mocked_fn = '__builtin__.open'

        with mock.patch(mocked_fn,
                        mock.mock_open(read_data="""1:name=systemd:/system.slice \
                                                 /docker-39cc1fb.scope"""),
                        create=True) as m:
            self.assertEqual(('docker',
                              'docker',
                              'docker'),
                             ceph_detect_init.platform_information(),)
            m.assert_called_once_with('/proc/self/cgroup', 'r')

        with mock.patch(mocked_fn, mock.mock_open(), create=True) as m:
            m.side_effect = IOError()
            mock_linux_dist.return_value = ('Red Hat Enterprise Linux Server',
                                            '7.3', 'Maipo')
            # Just run the code to validate the code won't raise IOError
            ceph_detect_init.platform_information()

        with mock.patch('os.path.isfile', mock.MagicMock()) as m:
            m.return_value = True
            self.assertEqual(('docker',
                              'docker',
                              'docker'),
                             ceph_detect_init.platform_information(),)
            m.assert_called_once_with('/.dockerenv')
Exemplo n.º 5
0
    def test_platform_information_linux(self):
        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('debian', '6.0', ''))):
            self.assertEqual(('debian', '6.0', 'squeeze'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('debian', '7.0', ''))):
            self.assertEqual(('debian', '7.0', 'wheezy'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('debian', '8.0', ''))):
            self.assertEqual(('debian', '8.0', 'jessie'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('debian', 'jessie/sid', ''))):
            self.assertEqual(('debian', 'jessie/sid', 'sid'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('debian', 'sid/jessie', ''))):
            self.assertEqual(('debian', 'sid/jessie', 'sid'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('Oracle Linux Server', '7.3', ''))):
            self.assertEqual(('Oracle Linux Server', '7.3', 'OL7.3'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('Oracle VM server', '3.4.2', ''))):
            self.assertEqual(('Oracle VM server', '3.4.2', 'OVS3.4.2'),
                             ceph_detect_init.platform_information())
Exemplo n.º 6
0
    def test_platform_information_linux(self):
        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('debian', '8.0', ''))):
            self.assertEqual(('debian', '8.0'),
                             ceph_detect_init.platform_information()[:-1])

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('Oracle Linux Server', '7.3', ''))):
            self.assertEqual(('Oracle Linux Server', '7.3', 'OL7.3'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('Oracle VM server', '3.4.2', ''))):
            self.assertEqual(('Oracle VM server', '3.4.2', 'OVS3.4.2'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution', lambda **kwargs:
                        (('Virtuozzo Linux', '7.3', ''))):
            self.assertEqual(('Virtuozzo Linux', '7.3', 'virtuozzo'),
                             ceph_detect_init.platform_information())
Exemplo n.º 7
0
    def test_platform_information_linux(self):
        with mock.patch('platform.linux_distribution',
                        lambda **kwargs: (('debian', '8.0', ''))):
            self.assertEqual(('debian', '8.0'),
                             ceph_detect_init.platform_information()[:-1])

        with mock.patch('platform.linux_distribution',
                        lambda **kwargs: (('Oracle Linux Server', '7.3', ''))):
            self.assertEqual(('Oracle Linux Server', '7.3', 'OL7.3'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution',
                        lambda **kwargs: (('Oracle VM server', '3.4.2', ''))):
            self.assertEqual(('Oracle VM server', '3.4.2', 'OVS3.4.2'),
                             ceph_detect_init.platform_information())

        with mock.patch('platform.linux_distribution',
                        lambda **kwargs: (('Virtuozzo Linux', '7.3', ''))):
            self.assertEqual(('Virtuozzo Linux', '7.3', 'virtuozzo'),
                             ceph_detect_init.platform_information())
Exemplo n.º 8
0
 def test_platform_information_freebsd(self):
     with mock.patch.multiple('platform',
                              release=lambda: '12.0-CURRENT',
                              version=lambda: 'FreeBSD 12.0 #1 r306554M:'):
         self.assertEqual(('freebsd', '12.0-CURRENT', 'r306554M'),
                          ceph_detect_init.platform_information())
Exemplo n.º 9
0
 def test_platform_information_freebsd(self):
     with mock.patch.multiple('platform',
                              release=lambda: '12.0-CURRENT',
                              version=lambda: 'FreeBSD 12.0 #1 r306554M:'):
         self.assertEqual(('freebsd', '12.0-CURRENT', 'r306554M'),
                          ceph_detect_init.platform_information())