Esempio n. 1
0
    def test_add_distro_tree(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            self.assertEquals(distro.osversion.osmajor.osmajor, u'RedHatEnterpriseLinux6')
            self.assertEquals(distro.osversion.osminor, u'1')
            self.assertEquals(distro.osversion.arches,
                    [Arch.by_name(u'i386'), Arch.by_name(u'x86_64')])
            self.assertEquals(distro.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('Workstation').path,
                    '')
            self.assertEquals(distro_tree.repo_by_id('ScalableFileSystem').path,
                    'ScalableFileSystem/')
            self.assertEquals(distro_tree.repo_by_id('optional').path,
                    '../../optional/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('debuginfo').path,
                    '../debug/')
            self.assertEquals(distro_tree.image_by_type(ImageType.kernel,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/vmlinuz')
            self.assertEquals(distro_tree.image_by_type(ImageType.initrd,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/initrd.img')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree

        # another lab controller adds the same distro tree
        self.server.auth.login_password(self.lc2.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.url_in_lab(self.lc2, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc2.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree
Esempio n. 2
0
    def test_add_distro_tree(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            self.assertEquals(distro.osversion.osmajor.osmajor, u'RedHatEnterpriseLinux6')
            self.assertEquals(distro.osversion.osminor, u'1')
            self.assertEquals(distro.osversion.arches,
                    [Arch.by_name(u'i386'), Arch.by_name(u'x86_64')])
            self.assertEquals(distro.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.date_created,
                    datetime.datetime(2011, 5, 10, 22, 53, 18))
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('Workstation').path,
                    '')
            self.assertEquals(distro_tree.repo_by_id('ScalableFileSystem').path,
                    'ScalableFileSystem/')
            self.assertEquals(distro_tree.repo_by_id('optional').path,
                    '../../optional/x86_64/os/')
            self.assertEquals(distro_tree.repo_by_id('debuginfo').path,
                    '../debug/')
            self.assertEquals(distro_tree.image_by_type(ImageType.kernel,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/vmlinuz')
            self.assertEquals(distro_tree.image_by_type(ImageType.initrd,
                    KernelType.by_name(u'default')).path,
                    'images/pxeboot/initrd.img')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree

        # another lab controller adds the same distro tree
        self.server.auth.login_password(self.lc2.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.url_in_lab(self.lc2, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.activity[0].field_name, u'lab_controller_assocs')
            self.assertEquals(distro_tree.activity[0].action, u'Added')
            self.assert_(self.lc2.fqdn in distro_tree.activity[0].new_value,
                    distro_tree.activity[0].new_value)
            del distro, distro_tree
Esempio n. 3
0
    def test_add_distro_tree(self):
        self.server.auth.login_password(self.lc.user.user_name, u"logmein")
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u"RHEL-6-U1")
            self.assertEquals(distro.osversion.osmajor.osmajor, u"RedHatEnterpriseLinux6")
            self.assertEquals(distro.osversion.osminor, u"1")
            self.assertEquals(distro.osversion.arches, [Arch.by_name(u"i386"), Arch.by_name(u"x86_64")])
            self.assertEquals(distro.date_created, datetime.datetime(2011, 5, 10, 22, 53, 18))
            distro_tree = DistroTree.query.filter_by(
                distro=distro, variant=u"Workstation", arch=Arch.by_name("x86_64")
            ).one()
            self.assertEquals(distro_tree.date_created, datetime.datetime(2011, 5, 10, 22, 53, 18))
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme="nfs"), "nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/"
            )
            self.assertEquals(distro_tree.repo_by_id("Workstation").path, "")
            self.assertEquals(distro_tree.repo_by_id("ScalableFileSystem").path, "ScalableFileSystem/")
            self.assertEquals(distro_tree.repo_by_id("optional").path, "../../optional/x86_64/os/")
            self.assertEquals(distro_tree.repo_by_id("debuginfo").path, "../debug/")
            self.assertEquals(
                distro_tree.image_by_type(ImageType.kernel, KernelType.by_name(u"default")).path,
                "images/pxeboot/vmlinuz",
            )
            self.assertEquals(
                distro_tree.image_by_type(ImageType.initrd, KernelType.by_name(u"default")).path,
                "images/pxeboot/initrd.img",
            )
            self.assertEquals(distro_tree.activity[0].field_name, u"lab_controller_assocs")
            self.assertEquals(distro_tree.activity[0].action, u"Added")
            self.assert_(self.lc.fqdn in distro_tree.activity[0].new_value, distro_tree.activity[0].new_value)
            del distro, distro_tree

        # another lab controller adds the same distro tree
        self.server.auth.login_password(self.lc2.user.user_name, u"logmein")
        self.server.labcontrollers.add_distro_tree(self.distro_data)
        with session.begin():
            distro = Distro.by_name(u"RHEL-6-U1")
            distro_tree = DistroTree.query.filter_by(
                distro=distro, variant=u"Workstation", arch=Arch.by_name("x86_64")
            ).one()
            self.assertEquals(
                distro_tree.url_in_lab(self.lc2, scheme="nfs"),
                "nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/",
            )
            self.assertEquals(distro_tree.activity[0].field_name, u"lab_controller_assocs")
            self.assertEquals(distro_tree.activity[0].action, u"Added")
            self.assert_(self.lc2.fqdn in distro_tree.activity[0].new_value, distro_tree.activity[0].new_value)
            del distro, distro_tree
Esempio n. 4
0
def create_rhel62():
    try:
        return Distro.by_name(u'RHEL-6.2')
    except DatabaseLookupError:
        rhel62 = data_setup.create_distro(name=u'RHEL-6.2',
                osmajor=u'RedHatEnterpriseLinux6', osminor=u'2')
        return rhel62
Esempio n. 5
0
 def setUp(self):
     with session.begin():
         if not Distro.by_name(u'BlueShoeLinux5-5'):
             data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
         self.user = data_setup.create_user(password=u'password')
     self.server = self.get_server()
     self.server.auth.login_password(self.user.user_name, 'password')
Esempio n. 6
0
 def setUp(self):
     self.browser = self.get_browser()
     with session.begin():
         self.user = data_setup.create_user(password=u'password')
         if not Distro.by_name(u'BlueShoeLinux5-5'):
             data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
         data_setup.create_product(product_name=u'the_product')
Esempio n. 7
0
def create_distro_tree(distro=None, distro_name=None, osmajor=u'DansAwesomeLinux6',
        distro_tags=None, arch=u'i386', variant=u'Server', lab_controllers=None,
        urls=None):
    if distro is None:
        if distro_name is None:
            distro = create_distro(osmajor=osmajor, tags=distro_tags)
        else:
            distro = Distro.by_name(distro_name)
            if not distro:
                distro = create_distro(name=distro_name)
    distro_tree = DistroTree.lazy_create(distro=distro,
            arch=Arch.by_name(arch), variant=variant)
    session.add(distro_tree)
    if distro_tree.arch not in distro.osversion.arches:
        distro.osversion.arches.append(distro_tree.arch)
    distro_tree.repos.append(DistroTreeRepo(repo_id=variant,
            repo_type=u'variant', path=u''))
    existing_urls = [lc_distro_tree.url for lc_distro_tree in distro_tree.lab_controller_assocs]
    # make it available in all lab controllers
    for lc in (lab_controllers or LabController.query):
        default_urls = [u'%s://%s%s/distros/%s/%s/%s/os/' % (scheme, lc.fqdn,
                scheme == 'nfs' and ':' or '',
                distro_tree.distro.name, distro_tree.variant,
                distro_tree.arch.arch) for scheme in ['nfs', 'http', 'ftp']]
        for url in (urls or default_urls):
            if url in existing_urls:
                break
            lab_controller_distro_tree = LabControllerDistroTree(
                lab_controller=lc, url=url)
            distro_tree.lab_controller_assocs.append(lab_controller_distro_tree)
    log.debug('Created distro tree %r', distro_tree)
    return distro_tree
Esempio n. 8
0
    def test_change_url(self):
        self.server.auth.login_password(self.lc.user.user_name, u"logmein")
        self.server.labcontrollers.add_distro_tree(self.distro_data)

        # add it again, but with different urls
        new_distro_data = dict(self.distro_data)
        new_distro_data["urls"] = [
            # nfs:// is not included here, so it shouldn't change
            "nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/",
            "http://moved/",
        ]
        self.server.labcontrollers.add_distro_tree(new_distro_data)
        with session.begin():
            distro = Distro.by_name(u"RHEL-6-U1")
            distro_tree = DistroTree.query.filter_by(
                distro=distro, variant=u"Workstation", arch=Arch.by_name("x86_64")
            ).one()
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme="nfs"), "nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/"
            )
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme="nfs+iso"),
                "nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/",
            )
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme="http"), "http://moved/")
            del distro, distro_tree
Esempio n. 9
0
    def test_change_url(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)

        # add it again, but with different urls
        new_distro_data = dict(self.distro_data)
        new_distro_data['urls'] = [
            # nfs:// is not included here, so it shouldn't change
            'nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/',
            'http://moved/',
        ]
        self.server.labcontrollers.add_distro_tree(new_distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(
                distro=distro,
                variant=u'Workstation',
                arch=Arch.by_name('x86_64')).one()
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme='nfs'),
                'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(
                distro_tree.url_in_lab(self.lc, scheme='nfs+iso'),
                'nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/')
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='http'),
                              'http://moved/')
            del distro, distro_tree
Esempio n. 10
0
 def get_osmajor(self, distro):
     """ pass in a distro name and get back the osmajor is belongs to.
     """
     try:
         osmajor = '%s' % Distro.by_name(distro).osversion.osmajor
     except DatabaseLookupError:
         raise BX(_('Invalid Distro: %s' % distro))
     return osmajor
Esempio n. 11
0
 def setUp(self):
     session.begin()
     from bkr.server.jobs import Jobs
     self.controller = Jobs()
     self.user = data_setup.create_user()
     if not Distro.by_name(u'BlueShoeLinux5-5'):
         data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
     session.flush()
Esempio n. 12
0
 def get_osmajor(self, distro):
     """ pass in a distro name and get back the osmajor is belongs to.
     """
     try:
         osmajor = '%s' % Distro.by_name(distro).osversion.osmajor
     except DatabaseLookupError:
         raise BX(_('Invalid Distro: %s' % distro))
     return osmajor
Esempio n. 13
0
def create_rhel62():
    try:
        return Distro.by_name(u'RHEL-6.2')
    except DatabaseLookupError:
        rhel62 = data_setup.create_distro(name=u'RHEL-6.2',
                                          osmajor=u'RedHatEnterpriseLinux6',
                                          osminor=u'2')
        return rhel62
Esempio n. 14
0
 def setUp(self):
     from bkr.server.jobs import Jobs
     self.controller = Jobs()
     self.user = data_setup.create_user()
     group = data_setup.create_group(group_name='somegroup')
     self.user.groups.append(group)
     testutil.set_identity_user(self.user)
     if not Distro.by_name(u'BlueShoeLinux5-5'):
         data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
     data_setup.create_product(product_name=u'the_product')
Esempio n. 15
0
 def test_existing_distro_row_with_incorrect_osversion(self):
     # We want to add 'RHEL6-bz825913' with osversion
     # 'RedHatEnterpriseLinux6.1'. But that distro already exists
     # with osversion 'RedHatEnterpriseLinux6.0'.
     name = "RHEL6-bz825913"
     with session.begin():
         data_setup.create_distro(name=name, osmajor=u"RedHatEnterpriseLinux6", osminor=u"0")
     distro_data = dict(self.distro_data)
     distro_data.update({"name": name, "osmajor": "RedHatEnterpriseLinux6", "osminor": "1"})
     self.server.auth.login_password(self.lc.user.user_name, u"logmein")
     self.server.labcontrollers.add_distro_tree(distro_data)
     with session.begin():
         distro = Distro.by_name(name)
         self.assertEquals(distro.osversion.osmajor.osmajor, u"RedHatEnterpriseLinux6")
         self.assertEquals(distro.osversion.osminor, u"1")
Esempio n. 16
0
 def get_arch(self, filter):
     """ pass in a dict() with either distro or osmajor to get possible arches
     """
     if 'distro' in filter:
         # look up distro
         try:
             arches = [arch.arch for arch in Distro.by_name(filter['distro']).osversion.arches]
         except DatabaseLookupError:
             raise BX(_('Invalid Distro: %s' % filter['distro']))
     elif 'osmajor' in filter:
         # look up osmajor
         try:
             arches = [arch.arch for arch in OSMajor.by_name(filter['osmajor']).osversions[0].arches]
         except InvalidRequestError:
             raise BX(_('Invalid OSMajor: %s' % filter['osmajor']))
     return arches
Esempio n. 17
0
 def _get_distro_tree_options(self, distro=None, system=None, **kwargs):
     """
     Returns a list of distro trees for the given distro.
     """
     if not distro:
         return []
     try:
         distro = Distro.by_name(distro)
     except DatabaseLookupError:
         return []
     trees = distro.dyn_trees.join(DistroTree.arch)\
             .filter(DistroTree.lab_controller_assocs.any())\
             .order_by(DistroTree.variant, Arch.arch)
     if system:
         try:
             system = System.by_fqdn(system, identity.current.user)
         except DatabaseLookupError:
             return []
         trees = system.distro_trees(query=trees)
     return [(tree.id, unicode(tree)) for tree in trees]
Esempio n. 18
0
 def _get_distro_tree_options(self, distro=None, system=None, **kwargs):
     """
     Returns a list of distro trees for the given distro.
     """
     if not distro:
         return []
     try:
         distro = Distro.by_name(distro)
     except DatabaseLookupError:
         return []
     trees = distro.dyn_trees.join(DistroTree.arch)\
             .filter(DistroTree.lab_controller_assocs.any())\
             .order_by(DistroTree.variant, Arch.arch)
     if system:
         try:
             system = System.by_fqdn(system, identity.current.user)
         except NoResultFound:
             return []
         trees = system.distro_trees(query=trees)
     return [(tree.id, unicode(tree)) for tree in trees]
Esempio n. 19
0
 def test_existing_distro_row_with_incorrect_osversion(self):
     # We want to add 'RHEL6-bz825913' with osversion
     # 'RedHatEnterpriseLinux6.1'. But that distro already exists
     # with osversion 'RedHatEnterpriseLinux6.0'.
     name = 'RHEL6-bz825913'
     with session.begin():
         data_setup.create_distro(name=name,
                 osmajor=u'RedHatEnterpriseLinux6', osminor=u'0')
     distro_data = dict(self.distro_data)
     distro_data.update({
         'name': name,
         'osmajor': 'RedHatEnterpriseLinux6',
         'osminor': '1',
     })
     self.server.auth.login_password(self.lc.user.user_name, u'logmein')
     self.server.labcontrollers.add_distro_tree(distro_data)
     with session.begin():
         distro = Distro.by_name(name)
         self.assertEquals(distro.osversion.osmajor.osmajor,
                 u'RedHatEnterpriseLinux6')
         self.assertEquals(distro.osversion.osminor, u'1')
Esempio n. 20
0
 def test_existing_distro_row_with_incorrect_osversion(self):
     # We want to add 'RHEL6-bz825913' with osversion
     # 'RedHatEnterpriseLinux6.1'. But that distro already exists
     # with osversion 'RedHatEnterpriseLinux6.0'.
     name = 'RHEL6-bz825913'
     with session.begin():
         data_setup.create_distro(name=name,
                 osmajor=u'RedHatEnterpriseLinux6', osminor=u'0')
     distro_data = dict(self.distro_data)
     distro_data.update({
         'name': name,
         'osmajor': 'RedHatEnterpriseLinux6',
         'osminor': '1',
     })
     self.server.auth.login_password(self.lc.user.user_name, u'logmein')
     self.server.labcontrollers.add_distro_tree(distro_data)
     with session.begin():
         distro = Distro.by_name(name)
         self.assertEquals(distro.osversion.osmajor.osmajor,
                 u'RedHatEnterpriseLinux6')
         self.assertEquals(distro.osversion.osminor, u'1')
Esempio n. 21
0
 def _get_distro_tree_options(self, distro=None, lab_controller_id=None, **kwargs):
     """
     Returns a list of distro trees for the given distro.
     """
     if not distro:
         return []
     try:
         distro = Distro.by_name(distro)
     except NoResultFound:
         return []
     trees = distro.dyn_trees.join(DistroTree.arch)\
             .order_by(DistroTree.variant, Arch.arch)
     if lab_controller_id:
         try:
             lc = LabController.by_id(lab_controller_id)
         except NoResultFound:
             return []
         trees = trees.filter(DistroTree.lab_controller_assocs.any(
                 LabControllerDistroTree.lab_controller == lc))
     else:
         trees = trees.filter(DistroTree.lab_controller_assocs.any())
     return [(tree.id, unicode(tree)) for tree in trees]
Esempio n. 22
0
 def get_arch(self, filter):
     """ pass in a dict() with either distro or osmajor to get possible arches
     """
     if 'distro' in filter:
         # look up distro
         try:
             arches = [
                 arch.arch for arch in Distro.by_name(
                     filter['distro']).osversion.arches
             ]
         except DatabaseLookupError:
             raise BX(_('Invalid Distro: %s' % filter['distro']))
     elif 'osmajor' in filter:
         # look up osmajor
         try:
             arches = [
                 arch.arch for arch in OSMajor.by_name(
                     filter['osmajor']).osversions[0].arches
             ]
         except InvalidRequestError:
             raise BX(_('Invalid OSMajor: %s' % filter['osmajor']))
     return arches
Esempio n. 23
0
    def test_change_url(self):
        self.server.auth.login_password(self.lc.user.user_name, u'logmein')
        self.server.labcontrollers.add_distro_tree(self.distro_data)

        # add it again, but with different urls
        new_distro_data = dict(self.distro_data)
        new_distro_data['urls'] = [
            # nfs:// is not included here, so it shouldn't change
            'nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/',
            'http://moved/',
        ]
        self.server.labcontrollers.add_distro_tree(new_distro_data)
        with session.begin():
            distro = Distro.by_name(u'RHEL-6-U1')
            distro_tree = DistroTree.query.filter_by(distro=distro,
                    variant=u'Workstation', arch=Arch.by_name('x86_64')).one()
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='nfs'),
                    'nfs://example.invalid:/RHEL-6-Workstation/U1/x86_64/os/')
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='nfs+iso'),
                    'nfs+iso://example.invalid:/RHEL-6-Workstation/U1/x86_64/iso/')
            self.assertEquals(distro_tree.url_in_lab(self.lc, scheme='http'),
                    'http://moved/')
            del distro, distro_tree
Esempio n. 24
0
File: tasks.py Progetto: omps/beaker
    def filter(self, filter):
        """
        Returns a list of tasks filtered by the given criteria.

        The *filter* argument must be an XML-RPC structure (dict), with any of the following keys:

            'distro_name'
                Distro name. Include only tasks which are compatible 
                with this distro.
            'osmajor'
                OSVersion OSMajor, like RedHatEnterpriseLinux6.  Include only
                tasks which are compatible with this OSMajor.
            'names'
                Task name. Include only tasks that are named. Useful when
                combined with 'osmajor' or 'distro_name'.
            'packages'
                List of package names. Include only tasks which have a Run-For 
                entry matching any of these packages.
            'types'
                List of task types. Include only tasks which have one or more 
                of these types.
            'valid'
                bool 0 or 1. Include only tasks which are valid or not.
            'destructive'
                bool 0 or 1. Set to 0 for only non-destructive tasks. Set to 
                1 for only destructive tasks.

        The return value is an array of dicts, which are name and arches. 
        name is the name of the matching tasks.
        arches is an array of arches which this task does not apply for.
        Call :meth:`tasks.to_dict` to fetch metadata for a particular task.

        .. versionchanged:: 0.9
           Changed 'install_name' to 'distro_name' in the *filter* argument.
        """
        if filter.get('distro_name'):
            distro = Distro.by_name(filter['distro_name'])
            tasks = distro.tasks()
        elif 'osmajor' in filter and filter['osmajor']:
            try:
                osmajor = OSMajor.by_name(filter['osmajor'])
            except InvalidRequestError:
                raise BX(_('Invalid OSMajor: %s' % filter['osmajor']))
            tasks = osmajor.tasks()
        else:
            tasks = Task.query

        # Filter by valid task if requested
        if 'valid' in filter:
            tasks = tasks.filter(Task.valid==bool(filter['valid']))

        # Filter by destructive if requested
        if 'destructive' in filter:
            tasks = tasks.filter(Task.destructive==bool(filter['destructive']))

        # Filter by name if specified
        # /distribution/install, /distribution/reservesys
        if 'names' in filter and filter['names']:
            # if not a list, make it into a list.
            if isinstance(filter['names'], str):
                filter['names'] = [filter['names']]
            or_names = []
            for tname in filter['names']:
                or_names.append(Task.name==tname)
            tasks = tasks.filter(or_(*or_names))

        # Filter by packages if specified
        # apache, kernel, mysql, etc..
        if 'packages' in filter and filter['packages']:
            # if not a list, make it into a list.
            if isinstance(filter['packages'], str):
                filter['packages'] = [filter['packages']]
            tasks = tasks.filter(Task.runfor.any(or_(
                    *[TaskPackage.package == package for package in filter['packages']])))

        # Filter by type if specified
        # Tier1, Regression, KernelTier1, etc..
        if 'types' in filter and filter['types']:
            # if not a list, make it into a list.
            if isinstance(filter['types'], str):
                filter['types'] = [filter['types']]
            tasks = tasks.join('types')
            or_types = []
            for type in filter['types']:
                try:
                    tasktype = TaskType.by_name(type)
                except InvalidRequestError, err:
                    raise BX(_('Invalid Task Type: %s' % type))
                or_types.append(TaskType.id==tasktype.id)
            tasks = tasks.filter(or_(*or_types))
Esempio n. 25
0
 def setUp(self):
     if not Distro.by_name(u'BlueShoeLinux5-5'):
         data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
     data_setup.create_product(product_name=u'the_product')
     self.browser = self.get_browser()
Esempio n. 26
0
    def filter(self, filter):
        """
        Returns a list of tasks filtered by the given criteria.

        The *filter* argument must be an XML-RPC structure (dict), with any of the following keys:

            'distro_name'
                Distro name. Include only tasks which are compatible 
                with this distro.
            'osmajor'
                OSVersion OSMajor, like RedHatEnterpriseLinux6.  Include only
                tasks which are compatible with this OSMajor.
            'names'
                Task name. Include only tasks that are named. Useful when
                combined with 'osmajor' or 'distro_name'.
            'packages'
                List of package names. Include only tasks which have a Run-For 
                entry matching any of these packages.
            'types'
                List of task types. Include only tasks which have one or more 
                of these types.
            'valid'
                bool 0 or 1. Include only tasks which are valid or not.
            'destructive'
                bool 0 or 1. Set to 0 for only non-destructive tasks. Set to 
                1 for only destructive tasks.

        The return value is an array of dicts, which are name and arches. 
        name is the name of the matching tasks.
        arches is an array of arches which this task does not apply for.
        Call :meth:`tasks.to_dict` to fetch metadata for a particular task.

        .. versionchanged:: 0.9
           Changed 'install_name' to 'distro_name' in the *filter* argument.
        """
        if filter.get('distro_name'):
            distro = Distro.by_name(filter['distro_name'])
            tasks = distro.tasks()
        elif 'osmajor' in filter and filter['osmajor']:
            try:
                osmajor = OSMajor.by_name(filter['osmajor'])
            except InvalidRequestError:
                raise BX(_('Invalid OSMajor: %s' % filter['osmajor']))
            tasks = osmajor.tasks()
        else:
            tasks = Task.query

        # Filter by valid task if requested
        if 'valid' in filter:
            tasks = tasks.filter(Task.valid == bool(filter['valid']))

        # Filter by destructive if requested
        if 'destructive' in filter:
            tasks = tasks.filter(
                Task.destructive == bool(filter['destructive']))

        # Filter by name if specified
        # /distribution/install, /distribution/reservesys
        if 'names' in filter and filter['names']:
            # if not a list, make it into a list.
            if isinstance(filter['names'], str):
                filter['names'] = [filter['names']]
            or_names = []
            for tname in filter['names']:
                or_names.append(Task.name == tname)
            tasks = tasks.filter(or_(*or_names))

        # Filter by packages if specified
        # apache, kernel, mysql, etc..
        if 'packages' in filter and filter['packages']:
            # if not a list, make it into a list.
            if isinstance(filter['packages'], str):
                filter['packages'] = [filter['packages']]
            tasks = tasks.filter(
                Task.runfor.any(
                    or_(*[
                        TaskPackage.package == package
                        for package in filter['packages']
                    ])))

        # Filter by type if specified
        # Tier1, Regression, KernelTier1, etc..
        if 'types' in filter and filter['types']:
            # if not a list, make it into a list.
            if isinstance(filter['types'], str):
                filter['types'] = [filter['types']]
            tasks = tasks.join('types')
            or_types = []
            for type in filter['types']:
                try:
                    tasktype = TaskType.by_name(type)
                except InvalidRequestError, err:
                    raise BX(_('Invalid Task Type: %s' % type))
                or_types.append(TaskType.id == tasktype.id)
            tasks = tasks.filter(or_(*or_types))
Esempio n. 27
0
 def expire(self, name, service=u'XMLRPC'):
     distro = Distro.by_name(name)
     distro.expire(service)
Esempio n. 28
0
 def setUp(self):
     data_setup.create_product(product_name=u'the_product')
     data_setup.create_group(group_name='somegroup')
     if not Distro.by_name(u'BlueShoeLinux5-5'):
         data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
Esempio n. 29
0
 def expire(self, name, service=u'XMLRPC'):
     distro = Distro.by_name(name)
     distro.expire(service)