Exemple #1
0
 def test_run_mirror_success(self, Command):
     Command().side_effect = ['pass', 'pass']
     test_class = mirror.Mirror()
     try:
         test_class.run_mirror('ae5-admin')
     except Exception:
         assert False, 'Exception was thrown and should not have'
Exemple #2
0
 def test_upload_file(self, Command):
     test_class = mirror.Mirror()
     test_tarballs = ['test.tar.gz']
     with mock.patch('repo_mirror.pool.transfer.TransferConfig'):
         with mock.patch('repo_mirror.pool.boto3.client'):
             with mock.patch('repo_mirror.pool.boto3.client.upload'):
                 pool.upload_files(test_class, test_tarballs)
Exemple #3
0
    def test_main_error_channel(self, Command):
        test_class = mirror.Mirror()
        Command().return_value = ''

        raise_exception = mock.Mock()
        raise_exception.side_effect = [
            exceptions.MirrorRun(), '', '', '', '', '', '', '', '', '', '', ''
        ]
        with mock.patch('repo_mirror.mirror.Mirror.build_yaml'):
            with mock.patch('repo_mirror.mirror.Mirror.run_mirror',
                            side_effect=raise_exception):
                with mock.patch('repo_mirror.pool.upload_files'):
                    pool.main()

        temp_archives = glob.glob('*.tar.gz')

        platform_count = 0
        for key, value in test_class.channels.items():
            platform_count += len(value.get('platforms', []))

        self.assertEqual(len(temp_archives), platform_count - 1,
                         'Incorrect number of archives')
        for item in temp_archives:
            if 'main-linux-64' in item:
                assert False, 'Main archive should not have succeeded'
Exemple #4
0
    def test_build_yaml_no_channels(self):
        test_channel = 'unknown'
        test_class = mirror.Mirror()
        test_class.build_yaml(test_channel)

        if os.path.isfile('mirrors/unknown.yaml'):
            assert False, 'Created yaml file when should not have'
Exemple #5
0
    def test_remove_channel_fail(self):
        test_class = mirror.Mirror()
        channel_count = len(test_class.channels)
        test_class.remove_channel('unknown')

        self.assertEqual(
            channel_count, len(test_class.channels),
            'Channel counts do not match after failed channel remove')
Exemple #6
0
    def test_add_channel_bad_platform(self):
        test_name = 'test'
        test_url = 'https://conda.anaconda.org/test'
        test_platforms = ['linux-64', 'win-64', 'invalid']
        test_class = mirror.Mirror()
        test_class.add_channel(test_name, test_url, test_platforms)

        if test_class.channels.get('test'):
            assert False, (
                'Channel was added when it should have failed validation')
Exemple #7
0
    def test_add_channel_duplicate(self):
        test_name = 'ae5-admin'
        test_url = 'https://conda.anaconda.org/test'
        test_platforms = ['linux-64', 'win-64']
        test_class = mirror.Mirror()
        channel_count = len(test_class.channels)
        test_class.add_channel(test_name, test_url, test_platforms)

        self.assertEqual(
            channel_count, len(test_class.channels),
            'Channel counts do not match after duplicate channel add')
Exemple #8
0
 def test_init(self):
     test_class = mirror.Mirror()
     self.assertEqual(test_class.mirror_directory, 'mirrors',
                      'Invalid mirror dir')
     self.assertEqual(test_class.snapshot_directory, 'snapshot',
                      'Invalid snapshot directory')
     self.assertEqual(test_class.channels, models.DEFAULT_CHANNELS,
                      'Invalid set of default channels')
     self.assertEqual(test_class.aws_bucket, 'airgap.svc.anaconda.com',
                      'Invalid defalut aws bucket')
     if not os.path.exists('mirrors'):
         assert False, 'Mirror directory was not setup properly'
Exemple #9
0
 def test_run_mirror_bad_config(self, Command):
     Command().side_effect = [
         sh.ErrorReturnCode_1('cas-sync', ''.encode('utf-8'),
                              ''.encode('utf-8'))
     ]
     test_class = mirror.Mirror()
     try:
         test_class.run_mirror('ae5-admin')
         assert False, 'Exception was not thrown'
     except exceptions.MirrorConfig:
         pass
     except Exception:
         assert False, 'Did not catch proper exception'
Exemple #10
0
    def test_add_channel_success(self):
        test_name = 'test'
        test_url = 'https://conda.anaconda.org/test'
        test_platforms = ['linux-64', 'win-64']
        test_class = mirror.Mirror()
        test_class.add_channel(test_name, test_url, test_platforms)

        if not test_class.channels.get('test'):
            assert False, 'Could not find added channel'

        test_channel = test_class.channels.get('test')
        self.assertEqual(test_channel.get('channel'), test_url,
                         'URL was not found in channel listing')
        self.assertEqual(test_channel.get('platforms'), test_platforms,
                         'Platforms was not found in channel listing')
Exemple #11
0
    def test_main_error_file_list(self, Command):
        test_class = mirror.Mirror()
        Command().side_effect = [
            sh.ErrorReturnCode_1('tree', ''.encode('utf-8'),
                                 ''.encode('utf-8')), '', '', '', '', '', '',
            '', '', '', '', ''
        ]
        with mock.patch('repo_mirror.mirror.Mirror.build_yaml'):
            with mock.patch('repo_mirror.mirror.Mirror.run_mirror'):
                with mock.patch('repo_mirror.pool.upload_files'):
                    pool.main()

        temp_archives = glob.glob('*.tar.gz')
        platform_count = 0
        for key, value in test_class.channels.items():
            platform_count += len(value.get('platforms', []))

        self.assertEqual(len(temp_archives), platform_count,
                         'Incorrect number of archives')
Exemple #12
0
    def test_build_yaml_success(self):
        test_channel = 'ae5-admin'
        test_class = mirror.Mirror()
        test_class.build_yaml(test_channel)

        temp_paths = [f'{test_channel}-noarch']
        for temp in temp_paths:
            if not os.path.isfile(f'mirrors/{temp}.yaml'):
                assert False, 'Did not create yaml file as expected'

            if not os.path.isfile(f'mirrors/{temp}.yaml'):
                assert False, 'Did not create yaml file as expected'

            if not os.path.exists(f'mirrors/{temp}'):
                assert False, 'Channel directory was not created'

        yaml_contents = []
        with open(f'mirrors/{test_channel}-noarch.yaml', 'r') as f:
            yaml_contents = f.readlines()

        self.assertEqual(yaml_contents, models.TEST_NOARCH_YAML,
                         'noarch yaml file contents are not expected values')
Exemple #13
0
 def test_validate_platform_fail(self):
     test_platforms = ['linux-64', 'invalid']
     test_class = mirror.Mirror()
     self.assertEqual(test_class.validate_platforms(test_platforms), False,
                      'Invalid return on platforms')
Exemple #14
0
 def test_validate_platform_success(self):
     test_platforms = ['linux-64']
     test_class = mirror.Mirror()
     self.assertEqual(test_class.validate_platforms(test_platforms), True,
                      'Invalid return on platforms')
Exemple #15
0
 def test_validate_url_bad_domain(self):
     test_url = 'https://conda'
     test_class = mirror.Mirror()
     self.assertEqual(test_class.validate_url(test_url), False,
                      'Invalid return on URL')
Exemple #16
0
 def test_validate_url_bad_scheme(self):
     test_url = 'ftp://conda.anaconda.org/ae5-admin'
     test_class = mirror.Mirror()
     self.assertEqual(test_class.validate_url(test_url), False,
                      'Invalid return on URL')
Exemple #17
0
 def test_validate_url_success(self):
     test_url = 'https://conda.anaconda.org/ae5-admin'
     test_class = mirror.Mirror()
     self.assertEqual(test_class.validate_url(test_url), True,
                      'Invalid return on URL')
Exemple #18
0
    def test_remove_channel(self):
        test_class = mirror.Mirror()
        test_class.remove_channel('msys2')

        if test_class.channels.get('msys2'):
            assert False, ('Channel was not removed as expected')