Beispiel #1
0
 def test_sync_archives(self):
     '''
     Test sync archives
     :return:
     '''
     support = saltsupport.SaltSupportModule()
     support.archives = MagicMock(return_value=[
         '/mnt/storage/one-support-000-000.bz2',
         '/mnt/storage/two-support-111-111.bz2',
         '/mnt/storage/three-support-222-222.bz2'
     ])
     out = support.sync('group-name', host='buzz', all=True, move=False)
     assert 'files' in out
     for arc_name in out['files']:
         assert out['files'][arc_name] == 'copied'
     assert saltsupport.os.unlink.call_count == 1
     assert saltsupport.os.unlink.call_args_list[0][0][0] == 'dummy'
     calls = []
     for call in saltsupport.os.write.call_args_list:
         assert len(call) == 2
         calls.append(call[0])
     assert calls == [(0, b'one-support-000-000.bz2'),
                      (0, os.linesep.encode()),
                      (0, b'two-support-111-111.bz2'),
                      (0, os.linesep.encode()),
                      (0, b'three-support-222-222.bz2'),
                      (0, os.linesep.encode())]
Beispiel #2
0
    def test_delete_all_archives_failure(self):
        '''
        Test delete archives failure
        :return:
        '''
        support = saltsupport.SaltSupportModule()
        support.archives = MagicMock(return_value=[
            '/mnt/storage/one-support-000-000.bz2',
            '/mnt/storage/two-support-111-111.bz2',
            '/mnt/storage/three-support-222-222.bz2'
        ])
        ret = support.delete_archives()
        assert 'files' in ret
        assert 'errors' in ret
        assert bool(ret['errors'])
        assert bool(ret['files'])
        assert isinstance(ret['errors'], dict)
        assert isinstance(ret['files'], dict)

        assert ret['files'][
            '/mnt/storage/three-support-222-222.bz2'] == 'removed'
        assert ret['files']['/mnt/storage/one-support-000-000.bz2'] == 'left'
        assert ret['files']['/mnt/storage/two-support-111-111.bz2'] == 'left'

        assert len(ret['errors']) == 2
        assert ret['errors'][
            '/mnt/storage/one-support-000-000.bz2'] == 'Decreasing electron flux'
        assert ret['errors'][
            '/mnt/storage/two-support-111-111.bz2'] == 'Solar flares interference'
Beispiel #3
0
    def test_get_archive_name(self):
        '''
        Test archive name construction.

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        assert support._get_archive_name(
        ) == '/mnt/storage/c-3po-support-000-000.bz2'
Beispiel #4
0
    def test_get_archive_name(self):
        '''
        Test archive name construction.

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        assert support._get_archive_name() == os.path.join(
            'mnt', 'storage', 'c-3po-support-000-000.bz2')
Beispiel #5
0
    def test_sync_no_archive_to_transfer_failure(self):
        '''
        Test sync failed when no archive was found to transfer

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        support.archives = MagicMock(return_value=[])
        with pytest.raises(salt.exceptions.SaltInvocationError) as err:
            support.sync('group-name', all=True)
        assert 'No archives found to transfer' in str(err)
Beispiel #6
0
    def test_profiles_format(self):
        '''
        Test profiles format.

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        profiles = support.profiles()
        assert 'custom' in profiles
        assert 'standard' in profiles
        assert 'message' in profiles['standard']
        assert profiles['custom'] == []
        assert profiles['standard']['message'] == 'Feature was not beta tested'
Beispiel #7
0
 def test_last_archive(self):
     '''
     Get last archive name
     :return:
     '''
     support = saltsupport.SaltSupportModule()
     support.archives = MagicMock(return_value=[
         '/mnt/storage/one-support-000-000.bz2',
         '/mnt/storage/two-support-111-111.bz2',
         '/mnt/storage/three-support-222-222.bz2'
     ])
     assert support.last_archive(
     ) == '/mnt/storage/three-support-222-222.bz2'
Beispiel #8
0
    def test_get_custom_archive_name(self):
        '''
        Test get custom archive name.

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        temp_name = support._get_archive_name(archname='Darth Wader')
        assert temp_name == '/mnt/storage/c-3po-darthwader-000-000.bz2'
        temp_name = support._get_archive_name(archname='Яйця з сіллю')
        assert temp_name == '/mnt/storage/c-3po-support-000-000.bz2'
        temp_name = support._get_archive_name(
            archname='!@#$%^&*()Fillip J. Fry')
        assert temp_name == '/mnt/storage/c-3po-fillipjfry-000-000.bz2'
Beispiel #9
0
 def test_last_archive(self):
     '''
     Get last archive name
     :return:
     '''
     support = saltsupport.SaltSupportModule()
     files = [
         os.path.join('mnt', 'storage', 'one-support-000-000.bz2'),
         os.path.join('mnt', 'storage', 'two-support-111-111.bz2'),
         os.path.join('mnt', 'storage', 'three-support-222-222.bz2'),
     ]
     support.archives = MagicMock(return_value=files)
     assert support.last_archive() == os.path.join(
         'mnt', 'storage', 'three-support-222-222.bz2')
Beispiel #10
0
    def test_get_existing_archives(self):
        '''
        Get list of existing archives.

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        out = support.archives()
        assert len(out) == 3
        for name in [
                '/mnt/storage/one-support-000-000.bz2',
                '/mnt/storage/two-support-111-111.bz2',
                '/mnt/storage/000-support-000-000.bz2'
        ]:
            assert name in out
Beispiel #11
0
    def test_sync_specified_archive_not_found_failure(self):
        '''
        Test sync failed when archive was not found (last picked)

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        support.archives = MagicMock(return_value=[
            '/mnt/storage/one-support-000-000.bz2',
            '/mnt/storage/two-support-111-111.bz2',
            '/mnt/storage/three-support-222-222.bz2'
        ])

        with pytest.raises(salt.exceptions.SaltInvocationError) as err:
            support.sync('group-name', name='lost.bz2')
        assert ' Support archive "lost.bz2" was not found' in str(err)
Beispiel #12
0
    def test_get_existing_archives(self):
        '''
        Get list of existing archives.

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        out = support.archives()
        assert len(out) == 3
        files = [
            os.path.join('mnt', 'storage', 'one-support-000-000.bz2'),
            os.path.join('mnt', 'storage', 'two-support-111-111.bz2'),
            os.path.join('mnt', 'storage', '000-support-000-000.bz2'),
        ]
        for name in files:
            assert name in out
Beispiel #13
0
    def test_format_sync_stats(self):
        '''
        Test format rsync stats for preserving ordering of the keys

        :return:
        '''
        support = saltsupport.SaltSupportModule()
        stats = '''
robot: Bender
cute: Leela
weird: Zoidberg
professor: Farnsworth
        '''
        f_stats = support.format_sync_stats({'retcode': 0, 'stdout': stats})
        assert list(f_stats['transfer'].keys()) == [
            'robot', 'cute', 'weird', 'professor'
        ]
        assert list(f_stats['transfer'].values()) == [
            'Bender', 'Leela', 'Zoidberg', 'Farnsworth'
        ]
Beispiel #14
0
    def test_delete_all_archives_success(self):
        '''
        Test delete archives
        :return:
        '''
        support = saltsupport.SaltSupportModule()
        support.archives = MagicMock(return_value=[
            '/mnt/storage/one-support-000-000.bz2',
            '/mnt/storage/two-support-111-111.bz2',
            '/mnt/storage/three-support-222-222.bz2'
        ])
        ret = support.delete_archives()
        assert 'files' in ret
        assert 'errors' in ret
        assert not bool(ret['errors'])
        assert bool(ret['files'])
        assert isinstance(ret['errors'], dict)
        assert isinstance(ret['files'], dict)

        for arc in support.archives():
            assert ret['files'][arc] == 'removed'
Beispiel #15
0
    def test_run_support(self):
        '''
        Test run support
        :return:
        '''
        saltsupport.SupportDataCollector(None, None).archive_path = 'dummy'
        support = saltsupport.SaltSupportModule()
        support.collect_internal_data = MagicMock()
        support.collect_local_data = MagicMock()
        out = support.run()

        for section in ['messages', 'archive']:
            assert section in out
        assert out['archive'] == 'dummy'
        for section in ['warning', 'error', 'info']:
            assert section in out['messages']
        ld_call = support.collect_local_data.call_args_list[0][1]
        assert 'profile' in ld_call
        assert ld_call['profile'] == 'default'
        assert 'profile_source' in ld_call
        assert ld_call['profile_source'] is None
        assert support.collector.open.call_count == 1
        assert support.collector.close.call_count == 1
        assert support.collect_internal_data.call_count == 1