Example #1
0
 def test_concurrent_same_tree(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
         Distro.lazy_create(name=distro_data["name"], osversion=osversion)
     self.add_distro_trees_concurrently(distro_data, distro_data)
Example #2
0
 def test_concurrent_same_tree(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     self.add_distro_trees_concurrently(distro_data, distro_data)
Example #3
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
         Distro.lazy_create(name=distro_data["name"], osversion=osversion)
     # ensure two different trees
     distro_data["variant"] = u"Workstation"
     distro_data2 = dict(distro_data)
     distro_data2["variant"] = u"Server"
     self.add_distro_trees_concurrently(distro_data, distro_data2)
Example #4
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
Example #5
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
Example #6
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
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     # ensure two different trees
     distro_data['variant'] = u'Workstation'
     distro_data2 = dict(distro_data)
     distro_data2['variant'] = u'Server'
     self.add_distro_trees_concurrently(distro_data, distro_data2)
Example #8
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     # ensure two different trees
     distro_data['variant'] = u'Workstation'
     distro_data2 = dict(distro_data)
     distro_data2['variant'] = u'Server'
     self.add_distro_trees_concurrently(distro_data, distro_data2)
Example #9
0
def create_distro(name=None,
                  osmajor=u'DansAwesomeLinux6',
                  osminor=u'9',
                  arches=None,
                  tags=None,
                  harness_dir=True,
                  osmajor_installopts=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get(
                'kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'),
                                   distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
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
Example #11
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
                  arches=None, tags=None, harness_dir=True, osmajor_installopts=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(osmajor_id=osmajor.id,
                                                   arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get('kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Example #12
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')
Example #13
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
Example #14
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
Example #15
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
Example #16
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')
Example #17
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()
Example #18
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
Example #19
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
Example #20
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
Example #21
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')
Example #22
0
 def save_tag(self, id=None, tag=None, *args, **kw):
     try:
         distro = Distro.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid distro id %s" % id))
         redirect(".")
     if tag['text']:
         distro.tags.append(tag['text'])
         distro.activity.append(DistroActivity(
                 user=identity.current.user, service=u'WEBUI',
                 action=u'Added', field_name=u'Tag',
                 old_value=None, new_value=tag['text']))
     flash(_(u"Added Tag %s" % tag['text']))
     redirect("./view?id=%s" % id)
Example #23
0
 def save_tag(self, id=None, tag=None, *args, **kw):
     try:
         distro = Distro.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid distro id %s" % id))
         redirect(".")
     if tag['text']:
         distro.tags.append(tag['text'])
         distro.activity.append(DistroActivity(
                 user=identity.current.user, service=u'WEBUI',
                 action=u'Added', field_name=u'Tag',
                 old_value=None, new_value=tag['text']))
     flash(_(u"Added Tag %s" % tag['text']))
     redirect("./view?id=%s" % id)
Example #24
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")
Example #25
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
Example #26
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
        arches=None, tags=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    log.debug('Created distro %r', distro)
    harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
    if not os.path.exists(harness_dir):
        os.makedirs(harness_dir)
    return distro
Example #27
0
 def tag_remove(self, id=None, tag=None, *args, **kw):
     try:
         distro = Distro.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid distro id %s" % id))
         redirect(".")
     if tag:
         for dtag in distro.tags:
             if dtag == tag:
                 distro.tags.remove(dtag)
                 distro.activity.append(DistroActivity(
                         user=identity.current.user, service=u'WEBUI',
                         action=u'Removed', field_name=u'Tag',
                         old_value=tag, new_value=None))
                 flash(_(u"Removed Tag %s" % tag))
     redirect("./view?id=%s" % id)
Example #28
0
 def tag_remove(self, id=None, tag=None, *args, **kw):
     try:
         distro = Distro.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid distro id %s" % id))
         redirect(".")
     if tag:
         for dtag in distro.tags:
             if dtag == tag:
                 distro.tags.remove(dtag)
                 distro.activity.append(DistroActivity(
                         user=identity.current.user, service=u'WEBUI',
                         action=u'Removed', field_name=u'Tag',
                         old_value=tag, new_value=None))
                 flash(_(u"Removed Tag %s" % tag))
     redirect("./view?id=%s" % id)
Example #29
0
 def view(self, id=None, *args, **kw):
     try:
         distro = Distro.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid distro id %s" % id))
         redirect(".")
     is_admin = identity.current.user and identity.current.user.is_admin() or False
     task_form = TaskSearchForm(hidden=dict(distro=True, osmajor_id=True))
     return dict(title       = 'Distro',
                 value       = distro,
                 value_task  = dict(distro_id = distro.id),
                 form        = self.tag_form,
                 form_task   = task_form,
                 action      = './save_tag',
                 action_task = '/tasks/do_search',
                 options   = dict(tags = distro.tags,
                                 readonly = not is_admin))
Example #30
0
 def view(self, id=None, *args, **kw):
     try:
         distro = Distro.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid distro id %s" % id))
         redirect(".")
     is_admin = identity.current.user and identity.current.user.is_admin(
     ) or False
     task_form = TaskSearchForm(hidden=dict(distro=True, osmajor_id=True))
     return dict(title='Distro',
                 value=distro,
                 value_task=dict(distro_id=distro.id),
                 form=self.tag_form,
                 form_task=task_form,
                 action='./save_tag',
                 action_task='/tasks/do_search',
                 options=dict(tags=distro.tags, readonly=not is_admin))
Example #31
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
        arches=None, tags=None, harness_dir=True):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Example #32
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]
Example #33
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]
Example #34
0
def create_distro(name=None,
                  osmajor=u'DansAwesomeLinux6',
                  osminor=u'9',
                  arches=None,
                  tags=None,
                  harness_dir=True,
                  osmajor_installopts=None,
                  date_created=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        # list arches may contains unicode name or instance
        # Comparing instance to attribute is prohibited in SQLAlchemy 1.1 and later
        osversion.arches = [
            Arch.by_name(arch.arch if isinstance(arch, Arch) else arch)
            for arch in arches
        ]
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    if date_created is not None:
        distro.date_created = date_created
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get(
                'kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'),
                                   distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
Example #35
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')
Example #36
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')
Example #37
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
Example #38
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]
Example #39
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
Example #40
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(
                _('Cannot import distro as %s: it is configured as an alias for %s'
                  % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor,
                                          osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'],
                                    osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                                             variant=variant,
                                             arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                                                 repo_id=repo['repoid'],
                                                 repo_type=repo['type'],
                                                 path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue  # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue  # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                                  image_type=image_type,
                                                  kernel_type=kernel_type,
                                                  path=image['path'])

        DistroTrees.add_distro_urls(distro_tree, lab_controller,
                                    new_distro['urls'])

        return distro_tree.id
Example #41
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')
Example #42
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()
Example #43
0
 def expire(self, name, service=u'XMLRPC'):
     distro = Distro.by_name(name)
     distro.expire(service)
Example #44
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))
Example #45
0
 def expire(self, name, service=u'XMLRPC'):
     distro = Distro.by_name(name)
     distro.expire(service)
Example #46
0
File: tasks.py Project: 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))
Example #47
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(
                _('Cannot import distro as %s: it is configured as an alias for %s'
                  % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor,
                                          osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'],
                                    osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                                             variant=variant,
                                             arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                                                 repo_id=repo['repoid'],
                                                 repo_type=repo['type'],
                                                 path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue  # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue  # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                                  image_type=image_type,
                                                  kernel_type=kernel_type,
                                                  path=image['path'])

        new_urls_by_scheme = dict(
            (urlparse.urlparse(url).scheme, url) for url in new_distro['urls'])
        if None in new_urls_by_scheme:
            raise ValueError('URL %r is not absolute' %
                             new_urls_by_scheme[None])
        for lca in distro_tree.lab_controller_assocs:
            if lca.lab_controller == lab_controller:
                scheme = urlparse.urlparse(lca.url).scheme
                new_url = new_urls_by_scheme.pop(scheme, None)
                if new_url != None and lca.url != new_url:
                    distro_tree.activity.append(
                        DistroTreeActivity(user=identity.current.user,
                                           service=u'XMLRPC',
                                           action=u'Changed',
                                           field_name=u'lab_controller_assocs',
                                           old_value=u'%s %s' %
                                           (lca.lab_controller, lca.url),
                                           new_value=u'%s %s' %
                                           (lca.lab_controller, new_url)))
                    lca.url = new_url
        for url in new_urls_by_scheme.values():
            distro_tree.lab_controller_assocs.append(
                LabControllerDistroTree(lab_controller=lab_controller,
                                        url=url))
            distro_tree.activity.append(
                DistroTreeActivity(user=identity.current.user,
                                   service=u'XMLRPC',
                                   action=u'Added',
                                   field_name=u'lab_controller_assocs',
                                   old_value=None,
                                   new_value=u'%s %s' % (lab_controller, url)))

        return distro_tree.id
Example #48
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        # osmajor is required
        if 'osmajor' in new_distro:
            osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        else:
            return ''

        if 'osminor' in new_distro:
            osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=new_distro['osminor'])
        else:
            return ''

        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                try:
                   arch = Arch.by_name(arch_name)
                   if arch not in osversion.arches:
                       osversion.arches.append(arch)
                except NoResultFound:
                   pass

        distro = Distro.lazy_create(name=new_distro['name'], osversion=osversion)
        arch = Arch.lazy_create(arch=new_distro['arch'])
        variant = new_distro.get('variant')
        distro_tree = DistroTree.lazy_create(distro=distro,
                variant=variant, arch=arch)

        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                if tag not in distro.tags:
                    distro.tags.append(tag)

        if arch not in distro.osversion.arches:
            distro.osversion.arches.append(arch)
        distro_tree.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))
        distro.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = distro_tree.repo_by_id(repo['repoid'])
                if dtr is None:
                    dtr = DistroTreeRepo(repo_id=repo['repoid'])
                    distro_tree.repos.append(dtr)
                dtr.repo_type = repo['type']
                dtr.path = repo['path']

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except NoResultFound:
                    continue # ignore
                dti = distro_tree.image_by_type(image_type, kernel_type)
                if dti is None:
                    dti = DistroTreeImage(image_type=image_type,
                                          kernel_type=kernel_type)
                    distro_tree.images.append(dti)
                dti.path = image['path']

        new_urls_by_scheme = dict((urlparse.urlparse(url).scheme, url)
                for url in new_distro['urls'])
        if None in new_urls_by_scheme:
            raise ValueError('URL %r is not absolute' % new_urls_by_scheme[None])
        for lca in distro_tree.lab_controller_assocs:
            if lca.lab_controller == lab_controller:
                scheme = urlparse.urlparse(lca.url).scheme
                new_url = new_urls_by_scheme.pop(scheme, None)
                if new_url != None and lca.url != new_url:
                    distro_tree.activity.append(DistroTreeActivity(
                            user=identity.current.user, service=u'XMLRPC',
                            action=u'Changed', field_name=u'lab_controller_assocs',
                            old_value=u'%s %s' % (lca.lab_controller, lca.url),
                            new_value=u'%s %s' % (lca.lab_controller, new_url)))
                    lca.url = new_url
        for url in new_urls_by_scheme.values():
            distro_tree.lab_controller_assocs.append(LabControllerDistroTree(
                    lab_controller=lab_controller, url=url))
            distro_tree.activity.append(DistroTreeActivity(
                    user=identity.current.user, service=u'XMLRPC',
                    action=u'Added', field_name=u'lab_controller_assocs',
                    old_value=None, new_value=u'%s %s' % (lab_controller, url)))

        return distro_tree.id