def test_marks_multiple_projects(self, session, tmpdir, url): pecan.conf.binary_root = str(tmpdir) pecan.conf.repos = { 'ceph': { 'all': { 'ceph-deploy': ['master'] }, }, 'rhcs': { 'all': { 'ceph-deploy': ['master'] }, }, '__force_dict__': True, } session.commit() session.app.post(url, upload_files=[('file', 'ceph-deploy_9.0.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) ceph_project = Project.filter_by(name='ceph').first() rhcs_project = Project.filter_by(name='rhcs').first() assert Repo.filter_by( project=ceph_project).first().needs_update is True assert Repo.filter_by( project=rhcs_project).first().needs_update is True
def test_skips_marking_needs_update(self, session, tmpdir, url): pecan.conf.binary_root = str(tmpdir) pecan.conf.repos = { 'ceph-deploy': { 'automatic': False, }, '__force_dict__': True, } session.app.post(url, upload_files=[('file', 'ceph-deploy_9.0.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) project = Project.filter_by(name='ceph-deploy').first() repo = Repo.filter_by(project=project).first() # newly created repos will default to ``needs_update`` as ``True``, # revert so we can test if disabling automatic repos works repo.needs_update = False session.commit() session.app.post(url, upload_files=[('file', 'ceph-deploy_10.0.0-0.el6.x86_64.rpm', b_('newer version'))]) project = Project.filter_by(name='ceph-deploy').first() repo = Repo.filter_by(project=project).first() assert repo.needs_update is False
def test_does_list_projects_without_built_repos(self, session): p = Project('foobar') Repo( p, "firefly", "ubuntu", "trusty", ) Project('baz') session.commit() result = session.app.get('/repos/') assert result.status_int == 200 assert len(result.json) == 2
def test_get_rid_of_new_and_old_repos_without_days(self, session, no_update_timestamp): repo = Repo( project=Project('nfs-ganesha'), ref='next', distro='centos', distro_version='7', flavor='ceph_master', ) repo.modified = self.three_weeks_ago conf.purge_rotation = { 'nfs-ganesha': { 'flavor': { 'ceph_master': { 'keep_minimum': 0 } }, 'ref': { 'next': { 'keep_minimum': 0 } } }, '__force_dict__': True } session.commit() recurring.purge_repos() assert len(Repo.query.all()) == 0
def test_single_distro_should_have_one_item(self, session): p = Project('ceph') Binary('ceph-1.0.0.deb', p, ref='master', distro='ubuntu', distro_version='12.04', arch='i386') session.commit() result = session.app.get('/projects/ceph/master/ubuntu/') assert result.status_int == 200 assert len(result.json) == 1
def test_list_unique_flavor(self, session): project = Project('ceph') Binary( 'ceph-1.0.0.rpm', project, ref='giant', sha1="head", distro='centos', distro_version='el6', arch='x86_64', flavor='tcmalloc' ) Binary( 'ceph-1.0.0.rpm', project, ref='giant', sha1="head", distro='centos', distro_version='el7', arch='x86_64', flavor='tcmalloc' ) session.commit() result = session.app.get( '/binaries/ceph/giant/head/centos/el6/x86_64/flavors/', ) assert result.json['tcmalloc'] == ['ceph-1.0.0.rpm']
def test_get_index_ref_with_distros(self, session): p = Project('ceph') Binary('ceph-1.0.0.rpm', p, ref='master', distro='centos', distro_version='el6', arch='i386') Binary('ceph-1.0.0.deb', p, ref='master', distro='ubuntu', distro_version='trusty', arch='i386') session.commit() result = session.app.get('/projects/ceph/master/') assert result.json.keys() == ['centos', 'ubuntu']
def test_get_rid_of_new_and_old_repos_without_days(self, session, fake, monkeypatch): Repo( project=Project('nfs-ganesha'), ref='next', distro='centos', distro_version='7', flavor='ceph_master', ) conf.purge_rotation = { 'nfs-ganesha': { 'flavor': { 'ceph_master': { 'keep_minimum': 0 } }, 'ref': { 'next': { 'keep_minimum': 0 } } }, '__force_dict__': True } fake_datetime = fake(utcnow=lambda: self.old, now=self.now) monkeypatch.setattr(datetime, 'datetime', fake_datetime) session.commit() recurring.purge_repos(_now=self.now) assert len(Repo.query.all()) == 0
def test_get_rid_of_new_repos_without_offset(self, session, no_update_timestamp): Repo( project=Project('nfs-ganesha'), ref='next', distro='centos', distro_version='7', flavor='ceph_master', ) conf.purge_rotation = { 'nfs-ganesha': { 'flavor': { 'ceph_master': { 'days': 0 } }, 'ref': { 'next': { 'days': 0 } } }, '__force_dict__': True } session.commit() recurring.purge_repos() assert len(Repo.query.all()) == 0
def test_get_project_refs(self, session): p = Project('foobar') Binary('ceph-1.0.0.rpm', p, ref='master', sha1="HEAD", distro='centos', distro_version='el6', arch='i386') Binary('ceph-1.0.0.rpm', p, ref='firefly', sha1="HEAD", distro='centos', distro_version='el6', arch='i386') session.commit() result = session.app.get('/binaries/foobar/') assert result.json == {'firefly': ['HEAD'], 'master': ['HEAD']}
def test_search_by_distro_gets_more_than_one_item(self, session): project = Project('ceph') Binary('ceph-1.0.0.rpm', project, ref='giant', distro='centos', distro_version='el6', arch='x86_64') Binary('ceph-1.0.0.rpm', project, ref='giant', distro='centos', distro_version='el7', arch='x86_64') session.commit() result = session.app.get('/search/?distro=centos') assert len(result.json) == 2
def test_distro_should_list_unique_versions(self, session): p = Project('ceph') Binary('ceph-1.0.0.deb', p, ref='master', distro='ubuntu', distro_version='trusty', arch='i386') Binary('ceph-1.0.1.deb', p, ref='master', distro='ubuntu', distro_version='trusty', arch='i386') session.commit() result = session.app.get('/projects/ceph/master/ubuntu/trusty/') assert result.json == {u'i386': [u'ceph-1.0.1.deb', u'ceph-1.0.0.deb']}
def test_list_a_distinct_distro(self, session): p = Project('ceph') Binary('ceph-1.0.0.deb', p, ref='master', distro='ubuntu', distro_version='trusty', arch='i386') Binary('ceph-1.0.0.rpm', p, ref='master', distro='centos', distro_version='el6', arch='i386') session.commit() result = session.app.get('/projects/ceph/master/ubuntu/') assert result.json == {'trusty': ['i386']}
def test_list_one_flavor(self, session): project = Project('ceph') Binary( 'ceph-1.0.0.rpm', project, ref='giant', sha1="head", distro='centos', distro_version='el6', arch='x86_64', flavor='tcmalloc' ) Binary( 'ceph-1.0.0.rpm', project, ref='giant', sha1="head", distro='centos', distro_version='el7', arch='x86_64', flavor='default' ) session.commit() result = session.app.get( '/binaries/ceph/giant/head/centos/el6/x86_64/flavors/', ) # default flavor is for a different distro_version in this case # and should not show up assert result.json.keys() == ['tcmalloc']
def test_raw_post_update(self, session, recorder, monkeypatch): pecan.conf.repos_root = '/tmp/root' url = '/repos/foobar/master/head/windows/999/' p = Project('foobar') repo = Repo( p, "master", "windows", "999", sha1="head", ) session.commit() repo.get(1) # create a raw type repo result = session.app.post_json( url, params={ 'type': 'raw', 'needs_update': False, }, ) assert result.json['type'] == 'raw' # check that update just marks it 'ready' immediately fake_post_status = recorder() monkeypatch.setattr(asynch, 'post_status', fake_post_status) result = session.app.post(url + 'update/') assert fake_post_status.recorder_calls[0]['args'][0] == 'ready'
def test_get_rid_of_new_and_old_repos_by_flavor_configured_in_days( self, session, no_update_timestamp): repo = Repo( project=Project('nfs-ganesha'), ref='next', distro='centos', distro_version='7', flavor='ceph_master', ) repo.modified = self.one_minute # cause lifespan for this repo to be 0 days, thus remove it conf.purge_rotation = { 'nfs-ganesha': { 'flavor': { 'ceph_master': { 'days': 0 } } }, '__force_dict__': True } session.commit() recurring.purge_repos() assert len(Repo.query.all()) == 0
def test_single_distro_should_have_a_name(self, session): p = Project('ceph') Binary('ceph-1.0.0.deb', p, ref='master', distro='ubuntu', distro_version='12.04', arch='i386') session.commit() result = session.app.get('/projects/ceph/master/ubuntu/') print result assert result.json['12.04'] == ['i386']
def test_get_index_ref_with_sha1s(self, session): p = Project('ceph') Binary('ceph-1.0.0.rpm', p, ref='master', sha1="sha1", distro='centos', distro_version='el6', arch='i386') Binary('ceph-1.0.0.deb', p, ref='master', sha1="head", distro='ubuntu', distro_version='trusty', arch='i386') session.commit() result = session.app.get('/binaries/ceph/master/') assert set(result.json.keys()) == set(['head', 'sha1'])
def test_search_like_name(self, session): project = Project('ceph') Binary('ceph-1.0.0.rpm', project, ref='giant', distro='centos', distro_version='el6', arch='x86_64') Binary('radosgw-agent-1.0.0.rpm', project, ref='giant', distro='centos', distro_version='el7', arch='x86_64') session.commit() result = session.app.get('/search/?name-has=ceph') assert len(result.json) == 1 assert result.json[0]['name'] == 'ceph-1.0.0.rpm'
def test_get_ref_with_distinct_sha1s(self, session): p = Project('ceph') Binary('ceph-1.0.0.rpm', p, ref='master', sha1="sha1", distro='centos', distro_version='el6', arch='i386') # note how we are using a different ref Binary('ceph-1.0.0.deb', p, ref='firefly', sha1="head", distro='ubuntu', distro_version='trusty', arch='i386') session.commit() result = session.app.get('/binaries/ceph/master/') assert list(result.json.keys()) == ['sha1']
def setup(self): self.p = Project('ceph') self.repo = Repo( self.p, ref='firefly', distro='centos', distro_version='7', )
def test_list_a_few_projects(self, session): for p in range(20): Project('foo_%s' % p) session.commit() result = session.app.get('/binaries/') json = result.json assert result.status_int == 200 assert len(json) == 20
def test_search_by_distro_gets_full_metadata(self, session): project = Project('ceph') Binary('ceph-1.0.0.rpm', project, ref='giant', distro='centos', distro_version='el6', arch='x86_64') session.commit() result = session.app.get('/search/?distro=centos').json[0] assert result['name'] == 'ceph-1.0.0.rpm' assert result['distro'] == 'centos' assert result['distro_version'] == 'el6' assert result['arch'] == 'x86_64' assert result['ref'] == 'giant'
def __init__(self, distro_version): self.distro_version = distro_version self.project = Project.get(request.context['project_id']) self.distro_name = request.context['distro'] self.ref = request.context['ref'] request.context['distro_version'] = self.distro_version self.repo = self.project.built_repos.filter_by( distro=self.distro_name, distro_version=self.distro_version, ref=self.ref, ).first()
def test_marks_existing_related_project(self, session, tmpdir, url): pecan.conf.binary_root = str(tmpdir) pecan.conf.repos = { 'ceph': { 'all': { 'ceph-deploy': ['master'] } }, '__force_dict__': True, } Project(name='ceph') session.commit() session.app.post(url, upload_files=[('file', 'ceph-deploy_9.0.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) project = Project.filter_by(name='ceph').first() assert project is not None repo = Repo.filter_by(project=project).first() assert repo.needs_update is True
def test_marks_multiple_projects(self, session, tmpdir): pecan.conf.binary_root = str(tmpdir) pecan.conf.repos = { 'ceph': { 'all': {'ceph-deploy': ['master']}, }, 'rhcs': { 'all': {'ceph-deploy': ['master']}, }, '__force_dict__': True, } session.commit() session.app.post( '/binaries/ceph-deploy/master/centos/6/x86_64/', upload_files=[('file', 'ceph-deploy_9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) ceph_project = Project.filter_by(name='ceph').first() rhcs_project = Project.filter_by(name='rhcs').first() assert Repo.filter_by(project=ceph_project).first().needs_update is True assert Repo.filter_by(project=rhcs_project).first().needs_update is True
def test_get_index_single_ref(self, session): p = Project('ceph') Binary('ceph-1.0.0.rpm', p, ref='master', sha1="head", distro='centos', distro_version='el6', arch='i386') session.commit() result = session.app.get('/binaries/ceph/master/') assert result.json == {'head': ['centos']}
def test_binary_file_deleted_removes_project(self, session, tmpdir): # if a project has no binaries related to it after binary deletion, it is deleted as well pecan.conf.binary_root = str(tmpdir) session.app.post( '/binaries/ceph/giant/ceph/el6/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) result = session.app.delete('/binaries/ceph/giant/ceph/el6/x86_64/ceph-9.0.0-0.el6.x86_64.rpm/') assert result.status_int == 204 p = Project.get(1) assert not p
def test_shows_distro_that_has_no_built_repos(self, session): p = Project('foobar') Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) session.commit() result = session.app.get('/repos/foobar/firefly/head/ubuntu/') assert result.json == ["trusty"]
def test_binary_file_deleted_removes_project(self, session, tmpdir): # if a project has no binaries related to it after binary deletion, it is deleted as well pecan.conf.binary_root = str(tmpdir) session.app.post('/binaries/ceph/giant/head/ceph/el6/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) result = session.app.delete( '/binaries/ceph/giant/head/ceph/el6/x86_64/ceph-9.0.0-0.el6.x86_64.rpm/' ) assert result.status_int == 204 p = Project.get(1) assert not p
def __init__(self, binary_name): self.binary_name = binary_name self.project = Project.get(request.context['project_id']) self.distro_version = request.context['distro_version'] self.distro = request.context['distro'] self.arch = request.context['arch'] self.ref = request.context['ref'] self.binary = Binary.query.filter_by( name=binary_name, ref=self.ref, distro=self.distro, distro_version=self.distro_version, project=self.project).first()
def test_single_binary_should_have_default_size_cero(self, session): p = Project('ceph') Binary('ceph-9.0.0-0.el6.x86_64.rpm', p, ref='giant', sha1="head", distro='centos', distro_version='el6', arch='x86_64') session.commit() result = session.app.get( '/binaries/ceph/giant/head/centos/el6/x86_64/') assert result.json['ceph-9.0.0-0.el6.x86_64.rpm']['size'] == 0
def test_list_arch_one_binary(self, session): project = Project('ceph') Binary('ceph-1.0.0.rpm', project, ref='giant', sha1="head", distro='centos', distro_version='el6', arch='x86_64') session.commit() result = session.app.get( '/binaries/ceph/giant/head/centos/el6/x86_64/') assert result.json['ceph-1.0.0.rpm']
def test_arch_not_found_with_head(self, session): project = Project('ceph') Binary('ceph-1.0.0.rpm', project, ref='giant', sha1="head", distro='centos', distro_version='el6', arch='x86_64') session.commit() result = session.app.head( '/binaries/ceph/giant/head/centos/el7/x86_64/', expect_errors=True) assert result.status_int == 404
def test_marks_nonexsitent_related_project_type(self, session, tmpdir): pecan.conf.binary_root = str(tmpdir) pecan.conf.repos = { 'ceph': { 'all': {'ceph-deploy': ['master']} }, '__force_dict__': True, } session.app.post( '/binaries/ceph-deploy/master/centos/6/x86_64/', upload_files=[('file', 'ceph-deploy_9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) project = Project.filter_by(name='ceph').first() repo = Repo.filter_by(project=project).first() assert repo.type == 'rpm'
def test_marks_nonexsitent_related_project(self, session, tmpdir): pecan.conf.binary_root = str(tmpdir) pecan.conf.repos = { 'ceph': { 'all': {'ceph-deploy': ['master']} }, '__force_dict__': True, } session.app.post( '/binaries/ceph-deploy/master/centos/6/x86_64/', upload_files=[('file', 'ceph-deploy_9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) project = Project.filter_by(name='ceph').first() # should've create the ceph project because it didn't exist assert project is not None repo = Repo.filter_by(project=project).first() assert repo.needs_update is True
def test_binary_file_deleted_project_exists(self, session, tmpdir): # if a project has binaries related to it after binary deletion, it will still exist pecan.conf.binary_root = str(tmpdir) session.app.post( '/binaries/ceph/giant/ceph/el6/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) session.app.post( '/binaries/ceph/giant/ceph/el7/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) result = session.app.delete('/binaries/ceph/giant/ceph/el6/x86_64/ceph-9.0.0-0.el6.x86_64.rpm/') assert result.status_int == 204 p = Project.get(1) assert p.name == "ceph"
def __init__(self, binary_name): self.binary_name = binary_name self.project = Project.get(request.context['project_id']) self.distro_version = request.context['distro_version'] self.distro = request.context['distro'] self.arch = request.context['arch'] self.ref = request.context['ref'] self.sha1 = request.context['sha1'] self.flavor = request.context.get('flavor', 'default') self.binary = Binary.query.filter_by( name=binary_name, ref=self.ref, sha1=self.sha1, distro=self.distro, distro_version=self.distro_version, flavor=self.flavor, arch=self.arch, project=self.project).first()
def __init__(self, ref_name): self.ref_name = ref_name self.project = Project.get(request.context['project_id']) request.context['ref'] = self.ref_name
def __init__(self, ref_name): self.ref_name = ref_name self.project = Project.get(request.context["project_id"]) request.context["ref"] = self.ref_name
def __init__(self, sha1): self.sha1 = sha1 self.project = Project.get(request.context['project_id']) self.ref = request.context['ref'] request.context['sha1'] = sha1
def __init__(self, binary_name): self.binary_name = binary_name self.project = Project.get(request.context['project_id']) self.binary = Binary.query.filter_by(name=binary_name, project=self.project).first()
def __init__(self, distro_name): self.distro_name = distro_name self.project = Project.get(request.context['project_id']) self.ref = request.context['ref'] self.sha1 = request.context['sha1'] request.context['distro'] = distro_name
def __init__(self, distro_name): self.distro_name = distro_name self.project = Project.get(request.context["project_id"]) self.ref = request.context["ref"] request.context["distro"] = distro_name