Ejemplo n.º 1
0
 def test_packager_context_setup_spec(self, mkdtemp, copy):
     with patch('rpmbuild.open', self.open, create=True):
         context = PackagerContext('foo', spec='foo.spec')
         context.template.render = MagicMock()
         context.setup()
         copy.assert_called_with('foo.spec', '/context')
         self.context_defaults.update(image='foo', spec='foo.spec')
         context.template.render.assert_called_with(**self.context_defaults)
Ejemplo n.º 2
0
 def test_sources_dir_is_set_if_path_exists(self):
     self.file = '/root/magicfile.txt'
     with patch('os.path.exists') as exists_mock:
         exists_mock.return_value = True
         self.assertEqual(
             PackagerContext(image='foo', sources_dir=self.file).sources_dir,
             self.file,
             'Sources dir should exists if os.path.exists says it does exists.')
Ejemplo n.º 3
0
def main():
    args = docopt(__doc__, version='Docker Packager 0.0.1')

    if args['build']:
        context = PackagerContext(
            args['<image>'],
            defines=args['--define'],
            sources=args['--source'],
            sources_dir=args['--sources-dir'],
            spec=args['--spec'],
            macrofiles=args['--macrofile'],
            retrieve=args['--retrieve'],
        )

    if args['rebuild']:
        context = PackagerContext(args['<image>'], srpm=args['--srpm'])

    try:
        with Packager(context, get_docker_config(args)) as p:
            for line in p.build_image():
                if is_py26:
                    parsed = json.loads(line.decode('UTF-8'))
                else:
                    parsed = json.loads(line.decode(encoding='UTF-8'))
                if 'stream' not in parsed:
                    print(parsed)
                else:
                    print(parsed['stream'].strip())

            container, logs = p.build_package()

            for line in logs:
                if is_py26:
                    print(line.decode('UTF-8').strip())
                else:
                    print(line.decode(encoding='UTF-8').strip())

            for path in p.export_package(args['--output']):
                print('Wrote: %s' % path)

    except PackagerException:
        print('Container build failed!', file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 4
0
 def test_sources_dir_is_none_if_path_does_not_exists(self):
     self.file = '/root/magicfile.txt'
     with patch('os.path.exists') as exists_mock:
         exists_mock.return_value = False
         self.assert_(PackagerContext(image='foo', sources_dir=self.file).sources_dir is None,
                           'Sources dir should not be set when os.path.exists says it does not')
Ejemplo n.º 5
0
 def test_sources_is_empty_list_if_not_provided(self):
     self.assertEqual(PackagerContext(image='foo').sources, [])
Ejemplo n.º 6
0
 def test_packager_context_teardown(self, mkdtemp, copy, rmtree):
     with patch('rpmbuild.open', self.open, create=True):
         context = PackagerContext('foo', spec='foo.spec')
         context.setup()
         context.teardown()
         rmtree.assert_called_with('/context')
Ejemplo n.º 7
0
 def test_packager_context_setup_srpm(self, mkdtemp, copy):
     with patch('rpmbuild.open', self.open, create=True):
         context = PackagerContext('foo', srpm='foo.srpm')
         context.setup()
         copy.assert_called_with('foo.srpm', '/context')
Ejemplo n.º 8
0
 def test_packager_context_setup_spec_sources_dir(self, mkdtemp, copy, copytree):
     with patch('rpmbuild.open', self.open, create=True):
         context = PackagerContext('foo', spec='foo.spec', sources_dir='/tmp')
         context.setup()
         copy.assert_called_with('foo.spec', '/context')
         copytree.assert_called_with('/tmp', '/context/SOURCES')
Ejemplo n.º 9
0
 def test_packager_context_setup_sources(self, mkdtemp, copy):
     with patch('rpmbuild.open', self.open, create=True):
         context = PackagerContext('foo', sources=['foo.tar.gz'])
         context.setup()
         copy.assert_called_with('foo.tar.gz', '/context')
Ejemplo n.º 10
0
 def test_packager_context_str(self):
     context = PackagerContext('foo', spec='foo.spec')
     self.assertEqual(str(context), 'foo.spec')
     context = PackagerContext('foo', srpm='foo.srpm')
     self.assertEqual(str(context), 'foo.srpm')
Ejemplo n.º 11
0
 def test_packager_context_setup_macrofiles(self, mkdtemp, copy):
     with patch('rpmbuild.open', self.open, create=True):
         context = PackagerContext('foo', macrofiles=['foo.macro'], spec='foo.spec')
         context.setup()
         copy.assert_any_call('foo.macro', '/context')