Пример #1
0
    def test_apt_consume_file(self):
        from infi.app_repo.indexers.apt import AptIndexer
        import gzip
        with self._setup_context() as config:
            indexer = AptIndexer(config, 'main-stable')
            indexer.initialise()
            filepath = self.write_new_package_in_incoming_directory(config, extension='deb')
            self.assertTrue(indexer.are_you_interested_in_file(filepath, 'linux-ubuntu-xenial', 'x86'))
            self.assertFalse(indexer.are_you_interested_in_file('foo.rpm', 'linux-ubuntu-xenial', 'x86'))
            indexer.consume_file(filepath, 'linux-ubuntu-xenial', 'i386')

            packages_file = path.join(indexer.base_directory, 'linux-ubuntu', 'dists', 'xenial', 'main', 'binary-i386', 'Packages')
            with fopen(packages_file) as fd:
                packages_contents = fd.read()
                self.assertNotEquals(packages_contents, '')
                self.assertIn("Filename: dists/xenial/main/binary-i386/some-package.deb", packages_contents)
            with gzip.open(packages_file + '.gz', 'rb') as fd:
                self.assertEquals(packages_contents, fd.read())

            release_dirpath = path.join(indexer.base_directory, 'linux-ubuntu', 'dists', 'xenial')
            self.assertTrue(path.exists(path.join(release_dirpath, 'main', 'binary-i386', 'some-package.deb')))

            release_filepath = path.join(release_dirpath, 'Release')
            # with fopen(release_filepath) as fd:
            #     self.assertEquals(fd.read(), 'Codename: xenial\nArchitectures: amd64 i386\nComponents: main\nok')
            self.assertTrue(path.exists(release_filepath))
Пример #2
0
 def test_hard_link_or_raise_exception(self):
     with temporary_directory_context():
         with fopen('src', 'w'):
             pass
         with self.assertRaises(FileAlreadyExists):
             hard_link_or_raise_exception('src', '.')
         hard_link_or_raise_exception('src', 'dst')
         with self.assertRaises(FileAlreadyExists):
             hard_link_or_raise_exception('src', 'dst')
Пример #3
0
def _install_upstart_job(service_name, commandline_arguments):
    from infi.app_repo import PROJECTROOT
    from infi.app_repo.__version__ import __version__
    script = path.join(PROJECTROOT, 'bin', 'eapp_repo')
    kwargs = {'version': __version__,
              'chdir': PROJECTROOT,
              'exec': '{} {}'.format(script, commandline_arguments).strip(),
              }
    config = TEMPLATE.format(**kwargs)
    with fopen(path.join(INIT, '%s.conf' % service_name), 'w') as fd:
        fd.write(config)
Пример #4
0
    def test_download(self):
        with fopen(path.join(self.config.incoming_directory, 'testfile'), 'w') as fd:
            fd.write('hello world')

        with patch.object(ftpserver.AppRepoFtpHandler, "on_file_sent") as on_file_sent:
            on_file_sent.side_effect = self.mark_success

            with self.ftp_server_context(self.config), self.ftp_client_context(self.config) as client:
                client.retrbinary('RETR incoming/testfile', lambda *args, **kwargs: None)

        self.assertTrue(self.test_succeded)
Пример #5
0
    def test_download(self):
        with fopen(path.join(self.config.incoming_directory, 'testfile'), 'w') as fd:
            fd.write('hello world')

        with patch.object(ftpserver.AppRepoFtpHandler, "on_file_sent") as on_file_sent:
            on_file_sent.side_effect = self.mark_success

            with self.ftp_server_context(self.config), self.ftp_client_context(self.config) as client:
                client.retrbinary('RETR incoming/testfile', lambda *args, **kwargs: None)

        self.assertTrue(self.test_succeded)
Пример #6
0
def _install_service(service_name, commandline_arguments):
    from infi.app_repo import PROJECTROOT
    from infi.app_repo.__version__ import __version__
    script = path.join(PROJECTROOT, 'bin', 'eapp_repo')
    kwargs = {
        'chdir': PROJECTROOT,
        'exec': '{} {}'.format(script, commandline_arguments).strip(),
    }
    config = TEMPLATE.format(**kwargs)
    with fopen(path.join(SYSTEMD, '%s.service' % service_name), 'w') as fd:
        fd.write(config)
Пример #7
0
 def write_new_package_in_incoming_directory(
         self,
         config,
         index='main-stable',
         package_basename='some-package',
         extension=None):
     filepath = path.join(
         config.incoming_directory, index,
         ('%s.%s' %
          (package_basename, extension)) if extension else package_basename)
     with fopen(filepath, 'w') as fd:
         pass
     logger.debug("write_new_package_in_incoming_directory %s" % filepath)
     return filepath
Пример #8
0
    def test_apt_consume_file(self):
        from infi.app_repo.indexers.apt import AptIndexer
        import gzip
        with self._setup_context() as config:
            indexer = AptIndexer(config, 'main-stable')
            indexer.initialise()
            filepath = self.write_new_package_in_incoming_directory(
                config, extension='deb')
            self.assertTrue(
                indexer.are_you_interested_in_file(filepath,
                                                   'linux-ubuntu-xenial',
                                                   'x86'))
            self.assertFalse(
                indexer.are_you_interested_in_file('foo.rpm',
                                                   'linux-ubuntu-xenial',
                                                   'x86'))
            indexer.consume_file(filepath, 'linux-ubuntu-xenial', 'i386')

            packages_file = path.join(indexer.base_directory, 'linux-ubuntu',
                                      'dists', 'xenial', 'main', 'binary-i386',
                                      'Packages')
            with fopen(packages_file) as fd:
                packages_contents = fd.read()
                self.assertNotEqual(packages_contents, '')
                self.assertIn(
                    "Filename: dists/xenial/main/binary-i386/some-package.deb",
                    packages_contents)
            with gzip.open(packages_file + '.gz', 'rb') as fd:
                self.assertEqual(packages_contents, fd.read().decode())

            release_dirpath = path.join(indexer.base_directory, 'linux-ubuntu',
                                        'dists', 'xenial')
            self.assertTrue(
                path.exists(
                    path.join(release_dirpath, 'main', 'binary-i386',
                              'some-package.deb')))

            release_filepath = path.join(release_dirpath, 'Release')
            # with fopen(release_filepath) as fd:
            #     self.assertEquals(fd.read(), 'Codename: xenial\nArchitectures: amd64 i386\nComponents: main\nok')
            self.assertTrue(path.exists(release_filepath))
Пример #9
0
def read_json_file(filepath):
    with fopen(filepath) as fd:
        return decode(fd.read())
Пример #10
0
 def write_new_package_in_incoming_directory(self, config, index='main-stable', package_basename='some-package', extension=None):
     filepath = path.join(config.incoming_directory, index, ('%s.%s' % (package_basename, extension)) if extension else package_basename)
     with fopen(filepath, 'w') as fd:
         pass
     logger.debug("write_new_package_in_incoming_directory %s" % filepath)
     return filepath
Пример #11
0
def read_json_file(filepath):
    with fopen(filepath) as fd:
        return decode(fd.read())